Skip to content

Commit 7643507

Browse files
vpai-akamaiummakynes
authored andcommitted
netfilter: xt_NFLOG: nflog-range does not truncate packets
li->u.ulog.copy_len is currently ignored by the kernel, we should truncate the packet to either li->u.ulog.copy_len (if set) or copy_range before sending it to userspace. 0 is a valid input for copy_len, so add a new flag to indicate whether this was option was specified by the user or not. Add two flags to indicate whether nflog-size/copy_len was set or not. XT_NFLOG_F_COPY_LEN is for XT_NFLOG and NFLOG_F_COPY_LEN for nfnetlink_log On the userspace side, this was initially represented by the option nflog-range, this will be replaced by --nflog-size now. --nflog-range would still exist but does not do anything. Reported-by: Joe Dollard <jdollard@akamai.com> Reviewed-by: Josh Hunt <johunt@akamai.com> Signed-off-by: Vishwanath Pai <vpai@akamai.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent e1dbbc5 commit 7643507

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

include/net/netfilter/nf_log.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#define NF_LOG_UID 0x08 /* Log UID owning local socket */
1313
#define NF_LOG_MASK 0x0f
1414

15+
/* This flag indicates that copy_len field in nf_loginfo is set */
16+
#define NF_LOG_F_COPY_LEN 0x1
17+
1518
enum nf_log_type {
1619
NF_LOG_TYPE_LOG = 0,
1720
NF_LOG_TYPE_ULOG,
@@ -22,9 +25,13 @@ struct nf_loginfo {
2225
u_int8_t type;
2326
union {
2427
struct {
28+
/* copy_len will be used iff you set
29+
* NF_LOG_F_COPY_LEN in flags
30+
*/
2531
u_int32_t copy_len;
2632
u_int16_t group;
2733
u_int16_t qthreshold;
34+
u_int16_t flags;
2835
} ulog;
2936
struct {
3037
u_int8_t level;

include/uapi/linux/netfilter/xt_NFLOG.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
#define XT_NFLOG_DEFAULT_GROUP 0x1
77
#define XT_NFLOG_DEFAULT_THRESHOLD 0
88

9-
#define XT_NFLOG_MASK 0x0
9+
#define XT_NFLOG_MASK 0x1
10+
11+
/* This flag indicates that 'len' field in xt_nflog_info is set*/
12+
#define XT_NFLOG_F_COPY_LEN 0x1
1013

1114
struct xt_nflog_info {
15+
/* 'len' will be used iff you set XT_NFLOG_F_COPY_LEN in flags */
1216
__u32 len;
1317
__u16 group;
1418
__u16 threshold;

net/netfilter/nfnetlink_log.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -700,10 +700,13 @@ nfulnl_log_packet(struct net *net,
700700
break;
701701

702702
case NFULNL_COPY_PACKET:
703-
if (inst->copy_range > skb->len)
703+
data_len = inst->copy_range;
704+
if ((li->u.ulog.flags & NF_LOG_F_COPY_LEN) &&
705+
(li->u.ulog.copy_len < data_len))
706+
data_len = li->u.ulog.copy_len;
707+
708+
if (data_len > skb->len)
704709
data_len = skb->len;
705-
else
706-
data_len = inst->copy_range;
707710

708711
size += nla_total_size(data_len);
709712
break;

net/netfilter/xt_NFLOG.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ nflog_tg(struct sk_buff *skb, const struct xt_action_param *par)
3333
li.u.ulog.group = info->group;
3434
li.u.ulog.qthreshold = info->threshold;
3535

36+
if (info->flags & XT_NFLOG_F_COPY_LEN)
37+
li.u.ulog.flags |= NF_LOG_F_COPY_LEN;
38+
3639
nfulnl_log_packet(net, par->family, par->hooknum, skb, par->in,
3740
par->out, &li, info->prefix);
3841
return XT_CONTINUE;

0 commit comments

Comments
 (0)