net: core: let skb_partial_csum_set() set transport header
Subsystems (5)
PATCH 1/3 net: core: let skb_partial_csum_set() set transport header
For untrusted packets with partial checksum, we need to set the transport header for precise packet length estimation. We can just let skb_pratial_csum_set() to do this to avoid extra call to skb_flow_dissect() and simplify the caller.
--- net/core/skbuff.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
net/core/skbuff.c +1 -0
@@ -3370,6 +3370,7 @@ bool skb_partial_csum_set(struct sk_buff *skb, u16 start, u16 off) skb->ip_summed =CHECKSUM_PARTIAL ; skb->csum_start =skb_headroom (skb) + start; skb->csum_offset = off; +skb_set_transport_header (skb, start);return true; }EXPORT_SYMBOL_GPL (skb_partial_csum_set);
Signature · 1 line
1.7.1
PATCH 2/3 net: core: introduce skb_probe_transport_header()
Sometimes, we need probe and set the transport header for packets (e.g from untrusted source). This patch introduces a new helper skb_probe_transport_header() which tries to probe and set the l4 header through skb_flow_dissect(), if not just set the transport header to the hint passed by caller.
--- include/linux/skbuff.h | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-)
include/linux/skbuff.h +14 -0
@@ -32,6 +32,7 @@#include <linux/hrtimer.h> #include <linux/dma-mapping.h> #include <linux/netdev_features.h> +#include <net/flow_keys.h> /* Don't change this without changing skb_csum_unnecessary! */ #define CHECKSUM_NONE 0
@@ -1559,6 +1560,19 @@ static inline void skb_set_transport_header(struct sk_buff *skb, skb->transport_header += offset; } +static inline void skb_probe_transport_header (struct sk_buff *skb, +const int offset_hint) +{ +struct flow_keys keys; + +if (skb_transport_header_was_set (skb)) +return ; +else if (skb_flow_dissect (skb, &keys)) +skb_set_transport_header (skb, keys.thoff); +else +skb_set_transport_header (skb, offset_hint); +} +static inline unsigned char *skb_network_header (const struct sk_buff *skb) {return skb->head + skb->network_header;
Signature · 1 line
1.7.1
Re: [PATCH net-next 2/3] net: core: introduce skb_probe_transport_header()
Quoted 11 lines · Jason Wang
Sometimes, we need probe and set the transport header for packets (e.g from untrusted source). This patch introduces a new helper
skb_probe_transport_header()which tries to probe and set the l4 header throughskb_flow_dissect(), if not just set the transport header to the hint passed by caller.Cc Eric Dumazet <[email protected]>Signed-off-by Jason Wang <[email protected]>--- include/linux/skbuff.h | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-)
Re: [PATCH net-next 2/3] net: core: introduce skb_probe_transport_header()
From: Eric Dumazet <[email protected]>
Date: Wed, 27 Mar 2013 07:45:50 -0700
Quoted 7 lines · Jason Wang
Quoted 6 lines
Sometimes, we need probe and set the transport header for packets (e.g from untrusted source). This patch introduces a new helper
skb_probe_transport_header()which tries to probe and set the l4 header throughskb_flow_dissect(), if not just set the transport header to the hint passed by caller.
Quoted 7 lines
Quoted 5 lines
Cc Eric Dumazet <[email protected]>Signed-off-by Jason Wang <[email protected]>--- include/linux/skbuff.h | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-)Acked-by Eric Dumazet <[email protected]>
Applied.
PATCH 3/3 net: switch to use skb_probe_transport_header()
In reply to Jason WangSwitch to use the new help skb_probe_transport_header() to do the l4 header probing for untrusted sources. For packets with partial csum, the header should already been set by skb_partial_csum_set().
--- drivers/net/macvtap.c | 9 +-------- drivers/net/tun.c | 10 +--------- drivers/net/xen-netback/netback.c | 10 +--------- net/packet/af_packet.c | 22 +++------------------- 4 files changed, 6 insertions(+), 45 deletions(-)
drivers/net/macvtap.c +1 -8
@@ -21,7 +21,6 @@#include <net/rtnetlink.h> #include <net/sock.h> #include <linux/virtio_net.h> -#include <net/flow_keys.h> /* * A macvtap queue is the central object of this driver, it connects
@@ -646,7 +645,6 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,int vnet_hdr_len =0 ;int copylen =0 ;bool zerocopy = false; -struct flow_keys keys;if (q->flags &IFF_VNET_HDR ) { vnet_hdr_len = q->vnet_hdr_sz;
@@ -727,12 +725,7 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m, goto err_kfree; } -if (skb->ip_summed ==CHECKSUM_PARTIAL ) -skb_set_transport_header (skb,skb_checksum_start_offset (skb)); -else if (skb_flow_dissect (skb, &keys)) -skb_set_transport_header (skb, keys.thoff); -else -skb_set_transport_header (skb,ETH_HLEN ); +skb_probe_transport_header (skb,ETH_HLEN );rcu_read_lock_bh (); vlan =rcu_dereference_bh (q->vlan);
drivers/net/tun.c +1 -9
@@ -70,7 +70,6 @@#include <net/sock.h> #include <asm/uaccess.h> -#include <net/flow_keys.h> /* Uncomment to enable debugging */ /* #define TUN_DEBUG 1 */
@@ -1050,7 +1049,6 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,bool zerocopy = false;int err;u32 rxhash; -struct flow_keys keys;if (!(tun->flags &TUN_NO_PI )) {if ((len -=sizeof (pi)) > total_len)
@@ -1205,13 +1203,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, }skb_reset_network_header (skb); - -if (skb->ip_summed ==CHECKSUM_PARTIAL ) -skb_set_transport_header (skb,skb_checksum_start_offset (skb)); -else if (skb_flow_dissect (skb, &keys)) -skb_set_transport_header (skb, keys.thoff); -else -skb_reset_transport_header (skb); +skb_probe_transport_header (skb,0 ); rxhash =skb_get_rxhash (skb);netif_rx_ni (skb);
drivers/net/xen-netback/netback.c +1 -9
@@ -39,7 +39,6 @@#include <linux/udp.h> #include <net/tcp.h> -#include <net/flow_keys.h> #include <xen/xen.h> #include <xen/events.h>
@@ -1506,14 +1505,7 @@ static void xen_netbk_tx_submit(struct xen_netbk *netbk)continue ; } -if (!skb_transport_header_was_set (skb)) { -struct flow_keys keys; - -if (skb_flow_dissect (skb, &keys)) -skb_set_transport_header (skb, keys.thoff); -else -skb_reset_transport_header (skb); - } +skb_probe_transport_header (skb,0 ); vif->dev->stats.rx_bytes += skb->len; vif->dev->stats.rx_packets++;
net/packet/af_packet.c +3 -19
@@ -88,7 +88,6 @@#include <linux/virtio_net.h> #include <linux/errqueue.h> #include <linux/net_tstamp.h> -#include <net/flow_keys.h> #ifdef CONFIG_INET #include <net/inet_common.h>
@@ -1413,7 +1412,6 @@ static int packet_sendmsg_spkt(struct kiocb *iocb, struct socket *sock,__be16 proto =0 ;int err;int extra_len =0 ; -struct flow_keys keys;/* * Get and verify the address.
@@ -1514,10 +1512,7 @@ retry:if (unlikely (extra_len ==4 )) skb->no_fcs =1 ; -if (skb_flow_dissect (skb, &keys)) -skb_set_transport_header (skb, keys.thoff); -else -skb_reset_transport_header (skb); +skb_probe_transport_header (skb,0 );dev_queue_xmit (skb);rcu_read_unlock ();
@@ -1925,7 +1920,6 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,struct page *page;void *data;int err; -struct flow_keys keys; ph.raw = frame;
@@ -1950,11 +1944,7 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,skb_reserve (skb, hlen);skb_reset_network_header (skb); - -if (skb_flow_dissect (skb, &keys)) -skb_set_transport_header (skb, keys.thoff); -else -skb_reset_transport_header (skb); +skb_probe_transport_header (skb,0 );if (po->tp_tx_has_off) {int off_min, off_max, off;
@@ -2212,7 +2202,6 @@ static int packet_snd(struct socket *sock,unsigned short gso_type =0 ;int hlen, tlen;int extra_len =0 ; -struct flow_keys keys;/* * Get and verify the address.
@@ -2365,12 +2354,7 @@ static int packet_snd(struct socket *sock, len += vnet_hdr_len; } -if (skb->ip_summed ==CHECKSUM_PARTIAL ) -skb_set_transport_header (skb,skb_checksum_start_offset (skb)); -else if (skb_flow_dissect (skb, &keys)) -skb_set_transport_header (skb, keys.thoff); -else -skb_set_transport_header (skb, reserve); +skb_probe_transport_header (skb, reserve);if (unlikely (extra_len ==4 )) skb->no_fcs =1 ;
Signature · 1 line
1.7.1
Re: [PATCH net-next 3/3] net: switch to use skb_probe_transport_header()
Quoted 4 lines · Jason Wang
Switch to use the new help
skb_probe_transport_header()to do the l4 header probing for untrusted sources. For packets with partial csum, the header should already been set byskb_partial_csum_set().
Quoted 8 lines
Cc Eric Dumazet <[email protected]>Signed-off-by Jason Wang <[email protected]>--- drivers/net/macvtap.c | 9 +-------- drivers/net/tun.c | 10 +--------- drivers/net/xen-netback/netback.c | 10 +--------- net/packet/af_packet.c | 22 +++------------------- 4 files changed, 6 insertions(+), 45 deletions(-)
Re: [PATCH net-next 3/3] net: switch to use skb_probe_transport_header()
From: Eric Dumazet <[email protected]>
Date: Wed, 27 Mar 2013 07:46:42 -0700
Quoted 14 lines · Jason Wang
Quoted 4 lines
Switch to use the new help
skb_probe_transport_header()to do the l4 header probing for untrusted sources. For packets with partial csum, the header should already been set byskb_partial_csum_set().Quoted 8 lines
Cc Eric Dumazet <[email protected]>Signed-off-by Jason Wang <[email protected]>--- drivers/net/macvtap.c | 9 +-------- drivers/net/tun.c | 10 +--------- drivers/net/xen-netback/netback.c | 10 +--------- net/packet/af_packet.c | 22 +++------------------- 4 files changed, 6 insertions(+), 45 deletions(-)
Quoted 1 line
Acked-by Eric Dumazet <[email protected]>
Applied.
Quoted 15 lines · Jason Wang
For untrusted packets with partial checksum, we need to set the transport header for precise packet length estimation. We can just let
skb_pratial_csum_set()to do this to avoid extra call toskb_flow_dissect()and simplify the caller.Cc Eric Dumazet <[email protected]>Signed-off-by Jason Wang <[email protected]>--- net/core/skbuff.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)net/core/skbuff.c +0
-0
net/core/skbuff.c bool skb_partial_csum_set(struct sk_buff *skb, u16 start, u16 off) · line 3376
Quoted 7 lines
net/core/skbuff.c +1
-0@@ -3370,6 +3370,7 @@ bool skb_partial_csum_set(struct sk_buff *skb, u16 start, u16 off) skb->ip_summed =CHECKSUM_PARTIAL ; skb->csum_start =skb_headroom (skb) + start; skb->csum_offset = off; +skb_set_transport_header (skb, start);return true; }EXPORT_SYMBOL_GPL (skb_partial_csum_set);
From: Eric Dumazet <[email protected]>
Date: Wed, 27 Mar 2013 07:42:56 -0700
Quoted 11 lines · Jason Wang
Quoted 10 lines
For untrusted packets with partial checksum, we need to set the transport header for precise packet length estimation. We can just let
skb_pratial_csum_set()to do this to avoid extra call toskb_flow_dissect()and simplify the caller.Cc Eric Dumazet <[email protected]>Signed-off-by Jason Wang <[email protected]>--- net/core/skbuff.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
Quoted 14 lines
net/core/skbuff.c bool skb_partial_csum_set(struct sk_buff *skb, u16 start, u16 off) · line 3376
Quoted 12 lines
net/core/skbuff.c +1
-0@@ -3370,6 +3370,7 @@ bool skb_partial_csum_set(struct sk_buff *skb, u16 start, u16 off) skb->ip_summed =CHECKSUM_PARTIAL ; skb->csum_start =skb_headroom (skb) + start; skb->csum_offset = off; +skb_set_transport_header (skb, start);return true; }EXPORT_SYMBOL_GPL (skb_partial_csum_set);Acked-by Eric Dumazet <[email protected]>
Applied.