Skip to content

Commit 6ee584b

Browse files
committed
netfilter: nfnetlink_queue: add NFQA_CAP_LEN attribute
This patch adds the NFQA_CAP_LEN attribute that allows us to know what is the real packet size from user-space (even if we decided to retrieve just a few bytes from the packet instead of all of it). Security software that inspects packets should always check for this new attribute to make sure that it is inspecting the entire packet. This also helps to provide a workaround for the problem described in: http://marc.info/?l=netfilter-devel&m=134519473212536&w=2 Original idea from Florian Westphal. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent ba8d3b0 commit 6ee584b

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎include/linux/netfilter/nfnetlink_queue.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ enum nfqnl_attr_type {
4444
NFQA_PAYLOAD, /* opaque data payload */
4545
NFQA_CT, /* nf_conntrack_netlink.h */
4646
NFQA_CT_INFO, /* enum ip_conntrack_info */
47+
NFQA_CAP_LEN, /* __u32 length of captured packet */
4748

4849
__NFQA_MAX
4950
};

‎net/netfilter/nfnetlink_queue_core.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue,
225225
{
226226
sk_buff_data_t old_tail;
227227
size_t size;
228-
size_t data_len = 0;
228+
size_t data_len = 0, cap_len = 0;
229229
struct sk_buff *skb;
230230
struct nlattr *nla;
231231
struct nfqnl_msg_packet_hdr *pmsg;
@@ -247,7 +247,8 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue,
247247
#endif
248248
+ nla_total_size(sizeof(u_int32_t)) /* mark */
249249
+ nla_total_size(sizeof(struct nfqnl_msg_packet_hw))
250-
+ nla_total_size(sizeof(struct nfqnl_msg_packet_timestamp));
250+
+ nla_total_size(sizeof(struct nfqnl_msg_packet_timestamp)
251+
+ nla_total_size(sizeof(u_int32_t))); /* cap_len */
251252

252253
outdev = entry->outdev;
253254

@@ -266,6 +267,7 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue,
266267
data_len = entskb->len;
267268

268269
size += nla_total_size(data_len);
270+
cap_len = entskb->len;
269271
break;
270272
}
271273

@@ -402,6 +404,9 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue,
402404
if (ct && nfqnl_ct_put(skb, ct, ctinfo) < 0)
403405
goto nla_put_failure;
404406

407+
if (cap_len > 0 && nla_put_be32(skb, NFQA_CAP_LEN, htonl(cap_len)))
408+
goto nla_put_failure;
409+
405410
nlh->nlmsg_len = skb->tail - old_tail;
406411
return skb;
407412

0 commit comments

Comments
 (0)