Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 576a30eb authored by Herbert Xu's avatar Herbert Xu Committed by David S. Miller
Browse files

[NET]: Added GSO header verification



When GSO packets come from an untrusted source (e.g., a Xen guest domain),
we need to verify the header integrity before passing it to the hardware.

Since the first step in GSO is to verify the header, we can reuse that
code by adding a new bit to gso_type: SKB_GSO_DODGY.  Packets with this
bit set can only be fed directly to devices with the corresponding bit
NETIF_F_GSO_ROBUST.  If the device doesn't have that bit, then the skb
is fed to the GSO engine which will allow the packet to be sent to the
hardware if it passes the header check.

This patch changes the sg flag to a full features flag.  The same method
can be used to implement TSO ECN support.  We simply have to mark packets
with CWR set with SKB_GSO_ECN so that only hardware with a corresponding
NETIF_F_TSO_ECN can accept them.  The GSO engine can either fully segment
the packet, or segment the first MTU and pass the rest to the hardware for
further segmentation.

Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 68c1692e
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -315,6 +315,7 @@ struct net_device
#define NETIF_F_GSO_SHIFT	16
#define NETIF_F_TSO		(SKB_GSO_TCPV4 << NETIF_F_GSO_SHIFT)
#define NETIF_F_UFO		(SKB_GSO_UDPV4 << NETIF_F_GSO_SHIFT)
#define NETIF_F_GSO_ROBUST	(SKB_GSO_DODGY << NETIF_F_GSO_SHIFT)

#define NETIF_F_GEN_CSUM	(NETIF_F_NO_CSUM | NETIF_F_HW_CSUM)
#define NETIF_F_ALL_CSUM	(NETIF_F_IP_CSUM | NETIF_F_GEN_CSUM)
@@ -543,7 +544,8 @@ struct packet_type {
					 struct net_device *,
					 struct packet_type *,
					 struct net_device *);
	struct sk_buff		*(*gso_segment)(struct sk_buff *skb, int sg);
	struct sk_buff		*(*gso_segment)(struct sk_buff *skb,
						int features);
	void			*af_packet_priv;
	struct list_head	list;
};
@@ -968,7 +970,7 @@ extern int netdev_max_backlog;
extern int		weight_p;
extern int		netdev_set_master(struct net_device *dev, struct net_device *master);
extern int skb_checksum_help(struct sk_buff *skb, int inward);
extern struct sk_buff *skb_gso_segment(struct sk_buff *skb, int sg);
extern struct sk_buff *skb_gso_segment(struct sk_buff *skb, int features);
#ifdef CONFIG_BUG
extern void netdev_rx_csum_fault(struct net_device *dev);
#else
@@ -988,11 +990,16 @@ extern void dev_seq_stop(struct seq_file *seq, void *v);

extern void linkwatch_run_queue(void);

static inline int skb_gso_ok(struct sk_buff *skb, int features)
{
	int feature = skb_shinfo(skb)->gso_size ?
		      skb_shinfo(skb)->gso_type << NETIF_F_GSO_SHIFT : 0;
	return (features & feature) != feature;
}

static inline int netif_needs_gso(struct net_device *dev, struct sk_buff *skb)
{
	int feature = skb_shinfo(skb)->gso_type << NETIF_F_GSO_SHIFT;
	return skb_shinfo(skb)->gso_size &&
	       (dev->features & feature) != feature;
	return skb_gso_ok(skb, dev->features);
}

#endif /* __KERNEL__ */
+4 −1
Original line number Diff line number Diff line
@@ -172,6 +172,9 @@ enum {
enum {
	SKB_GSO_TCPV4 = 1 << 0,
	SKB_GSO_UDPV4 = 1 << 1,

	/* This indicates the skb is from an untrusted source. */
	SKB_GSO_DODGY = 1 << 2,
};

/** 
@@ -1299,7 +1302,7 @@ extern void skb_split(struct sk_buff *skb,
				 struct sk_buff *skb1, const u32 len);

extern void	       skb_release_data(struct sk_buff *skb);
extern struct sk_buff *skb_segment(struct sk_buff *skb, int sg);
extern struct sk_buff *skb_segment(struct sk_buff *skb, int features);

static inline void *skb_header_pointer(const struct sk_buff *skb, int offset,
				       int len, void *buffer)
+2 −1
Original line number Diff line number Diff line
@@ -36,7 +36,8 @@
struct net_protocol {
	int			(*handler)(struct sk_buff *skb);
	void			(*err_handler)(struct sk_buff *skb, u32 info);
	struct sk_buff	       *(*gso_segment)(struct sk_buff *skb, int sg);
	struct sk_buff	       *(*gso_segment)(struct sk_buff *skb,
					       int features);
	int			no_policy;
};

+1 −1
Original line number Diff line number Diff line
@@ -1086,7 +1086,7 @@ extern struct request_sock_ops tcp_request_sock_ops;

extern int tcp_v4_destroy_sock(struct sock *sk);

extern struct sk_buff *tcp_tso_segment(struct sk_buff *skb, int sg);
extern struct sk_buff *tcp_tso_segment(struct sk_buff *skb, int features);

#ifdef CONFIG_PROC_FS
extern int  tcp4_proc_init(void);
+2 −2
Original line number Diff line number Diff line
@@ -184,6 +184,6 @@ void br_dev_setup(struct net_device *dev)
	dev->set_mac_address = br_set_mac_address;
	dev->priv_flags = IFF_EBRIDGE;

 	dev->features = NETIF_F_SG | NETIF_F_FRAGLIST
 		| NETIF_F_HIGHDMA | NETIF_F_TSO | NETIF_F_NO_CSUM;
 	dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_HIGHDMA |
 			NETIF_F_TSO | NETIF_F_NO_CSUM | NETIF_F_GSO_ROBUST;
}
Loading