nfnetlink_queue updates
Subsystems (2)
[email protected]
maintainercover nfnetlink_queue updates
From: Pablo Neira Ayuso <[email protected]>
Hi,
The following patches aim to provide a workaround for the problem described by Florian Westphal in:
http://marc.info/?l=netfilter-devel&m=134519473212536&w=2
The idea (by now) is to limit the maximum support length to what we can handle, which is 65535 - 4 bytes and add a new attribute that allows us to know the real packet length in the kernel.
Pablo Neira Ayuso (2):
netfilter: nfnetlink_queue: fix maximum packet length to userspace
netfilter: nfnetlink_queue: add NFQA_CAP_LEN attribute
include/linux/netfilter/nfnetlink_queue.h | 1 + net/netfilter/nfnetlink_queue_core.c | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-)
Signature · 1 line
1.7.10.4
[email protected]
maintainerPATCH 1/2 netfilter: nfnetlink_queue: fix maximum packet length to userspace
From: Pablo Neira Ayuso <[email protected]>
The packets that we send via NFQUEUE are encapsulated in the NFQA_PAYLOAD attribute. The length of the packet in userspace is obtained via attr->nla_len field. This field contains the size of the Netlink attribute header plus the packet length.
If the maximum packet length is specified, ie. 65535 bytes, and packets in the range of (65531,65535] are sent to userspace, the attr->nla_len overflows and it reports bogus lengths to the application.
To fix this, this patch limits the maximum packet length to 65531 bytes. If larger packet length is specified, the packet that we send to user-space is truncated to 65531 bytes.
To support 65535 bytes packets, we have to revisit the idea of the 32-bits Netlink attribute length.
--- net/netfilter/nfnetlink_queue_core.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
net/netfilter/nfnetlink_queue_core.c +7 -3
@@ -526,9 +526,13 @@ nfqnl_set_mode(struct nfqnl_instance *queue,case NFQNL_COPY_PACKET : queue->copy_mode = mode; -/* we're using struct nlattr which has 16bit nla_len */ -if (range >0xffff ) - queue->copy_range =0xffff ; +/* We're using struct nlattr which has 16bit nla_len. Note that +* nla_len includes the header length. Thus, the maximum packet +* length that we support is 65531 bytes. We send truncated +* packets if the specified length is larger than that. +*/ +if (range >0xffff -NLA_HDRLEN ) + queue->copy_range =0xffff -NLA_HDRLEN ;else queue->copy_range = range;break ;
Signature · 1 line
1.7.10.4
[email protected]
maintainerPATCH 2/2 netfilter: nfnetlink_queue: add NFQA_CAP_LEN attribute
In reply to [email protected]From: Pablo Neira Ayuso <[email protected]>
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 just retrieve just a few bytes from the packet instead of all of it).
Security software that inspects packet 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 (netfilter: nfnetlink_queue: fix maximum packet length to userspace).
Original idea from Florian Westphal.
--- include/linux/netfilter/nfnetlink_queue.h | 1 + net/netfilter/nfnetlink_queue_core.c | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-)
include/linux/netfilter/nfnetlink_queue.h +1 -0
@@ -44,6 +44,7 @@ enum nfqnl_attr_type {NFQA_PAYLOAD ,/* opaque data payload */ NFQA_CT ,/* nf_conntrack_netlink.h */ NFQA_CT_INFO ,/* enum ip_conntrack_info */ +NFQA_CAP_LEN ,/* __u32 length of captured packet */ __NFQA_MAX };
net/netfilter/nfnetlink_queue_core.c +7 -2
@@ -225,7 +225,7 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue, {sk_buff_data_t old_tail;size_t size; -size_t data_len =0 ; +size_t data_len =0 , cap_len =0 ;struct sk_buff *skb;struct nlattr *nla;struct nfqnl_msg_packet_hdr *pmsg;
@@ -247,7 +247,8 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue,#endif +nla_total_size (sizeof (u_int32_t))/* mark */ +nla_total_size (sizeof (struct nfqnl_msg_packet_hw )) - +nla_total_size (sizeof (struct nfqnl_msg_packet_timestamp )); + +nla_total_size (sizeof (struct nfqnl_msg_packet_timestamp ) + +nla_total_size (sizeof (u_int32_t)));/* cap_len */ outdev = entry->outdev;
@@ -266,6 +267,7 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue, data_len = entskb->len; size +=nla_total_size (data_len); + cap_len = entskb->len;break ; }
@@ -402,6 +404,9 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue,if (ct &&nfqnl_ct_put (skb, ct, ctinfo) <0 ) goto nla_put_failure; +if (cap_len >0 &&nla_put_be32 (skb,NFQA_CAP_LEN ,htonl (cap_len))) + goto nla_put_failure; + nlh->nlmsg_len = skb->tail - old_tail;return skb;
Signature · 1 line
1.7.10.4