Skip to content

Commit

Permalink
netfilter: nft_log: restrict the log prefix length to 127
Browse files Browse the repository at this point in the history
First, log prefix will be truncated to NF_LOG_PREFIXLEN-1, i.e. 127,
at nf_log_packet(), so the extra part is useless.

Second, after adding a log rule with a very very long prefix, we will
fail to dump the nft rules after this _special_ one, but acctually,
they do exist. For example:
  # name_65000=$(printf "%0.sQ" {1..65000})
  # nft add rule filter output log prefix "$name_65000"
  # nft add rule filter output counter
  # nft add rule filter output counter
  # nft list chain filter output
  table ip filter {
      chain output {
          type filter hook output priority 0; policy accept;
      }
  }

So now, restrict the log prefix length to NF_LOG_PREFIXLEN-1.

Fixes: 9651851 ("netfilter: add nftables")
Signed-off-by: Liping Zhang <[email protected]>
Signed-off-by: Pablo Neira Ayuso <[email protected]>
  • Loading branch information
Liping Zhang authored and ummakynes committed Jan 24, 2017
1 parent b2fbd04 commit 5ce6b04
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include/uapi/linux/netfilter/nf_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
#define NF_LOG_MACDECODE 0x20 /* Decode MAC header */
#define NF_LOG_MASK 0x2f

#define NF_LOG_PREFIXLEN 128

#endif /* _NETFILTER_NF_LOG_H */
1 change: 0 additions & 1 deletion net/netfilter/nf_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
/* Internal logging interface, which relies on the real
LOG target modules */

#define NF_LOG_PREFIXLEN 128
#define NFLOGGER_NAME_LEN 64

static struct nf_logger __rcu *loggers[NFPROTO_NUMPROTO][NF_LOG_TYPE_MAX] __read_mostly;
Expand Down
3 changes: 2 additions & 1 deletion net/netfilter/nft_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ static void nft_log_eval(const struct nft_expr *expr,

static const struct nla_policy nft_log_policy[NFTA_LOG_MAX + 1] = {
[NFTA_LOG_GROUP] = { .type = NLA_U16 },
[NFTA_LOG_PREFIX] = { .type = NLA_STRING },
[NFTA_LOG_PREFIX] = { .type = NLA_STRING,
.len = NF_LOG_PREFIXLEN - 1 },
[NFTA_LOG_SNAPLEN] = { .type = NLA_U32 },
[NFTA_LOG_QTHRESHOLD] = { .type = NLA_U16 },
[NFTA_LOG_LEVEL] = { .type = NLA_U32 },
Expand Down

0 comments on commit 5ce6b04

Please sign in to comment.