inet: prevent skb changes in udp{4|6}_lib_lookup_skb()
Subsystems (4)
cover inet: prevent skb changes in udp{4|6}_lib_lookup_skb()
From: Eric Dumazet <[email protected]>
This came while reviewing Alexander Lobakin patch against UDP GRO:
We want to make sure skb wont be changed by these helpers while it is owned by GRO stack.
Eric Dumazet (2):
inet: constify inet_sdif() argument
inet: udp{4|6}_lib_lookup_skb() skb argument is const
include/net/ip.h | 2 +- include/net/udp.h | 6 +++--- net/ipv4/udp.c | 2 +- net/ipv6/udp.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-)
Signature · 1 line
2.29.2.222.g5d2a92d10f8-goog
PATCH 1/2 inet: constify inet_sdif() argument
From: Eric Dumazet <[email protected]>
inet_sdif() does not modify the skb.
This will permit propagating the const qualifier in udp{4|6}_lib_lookup_skb() functions.
--- include/net/ip.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/ip.h +1 -1
@@ -99,7 +99,7 @@ static inline void ipcm_init_sk(struct ipcm_cookie *ipcm,#define PKTINFO_SKB_CB (skb) ((struct in_pktinfo *)((skb)->cb))/* return enslaved device index if relevant */ -static inline int inet_sdif (struct sk_buff *skb) +static inline int inet_sdif (const struct sk_buff *skb) {#if IS_ENABLED (CONFIG_NET_L3_MASTER_DEV )if (skb &&ipv4_l3mdev_skb (IPCB (skb)->flags))
Signature · 1 line
2.29.2.222.g5d2a92d10f8-goog
PATCH 2/2 inet: udp{4|6}_lib_lookup_skb() skb argument is const
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
The skb is needed only to fetch the keys for the lookup.
Both functions are used from GRO stack, we do not want accidental modification of the skb.
--- include/net/udp.h | 6 +++--- net/ipv4/udp.c | 2 +- net/ipv6/udp.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
include/net/udp.h +3 -3
@@ -164,7 +164,7 @@ static inline void udp_csum_pull_header(struct sk_buff *skb)UDP_SKB_CB (skb)->cscov -=sizeof (struct udphdr ); } -typedef struct sock *(*udp_lookup_t )(struct sk_buff *skb,__be16 sport, +typedef struct sock *(*udp_lookup_t )(const struct sk_buff *skb,__be16 sport,__be16 dport); INDIRECT_CALLABLE_DECLARE(struct sk_buff *udp4_gro_receive(struct list_head *,
@@ -313,7 +313,7 @@ struct sock *udp4_lib_lookup(struct net *net, __be32 saddr, __be16 sport,struct sock *__udp4_lib_lookup (struct net *net,__be32 saddr,__be16 sport,__be32 daddr,__be16 dport,int dif,int sdif,struct udp_table *tbl,struct sk_buff *skb); -struct sock *udp4_lib_lookup_skb (struct sk_buff *skb, +struct sock *udp4_lib_lookup_skb (const struct sk_buff *skb,__be16 sport,__be16 dport); struct sock *udp6_lib_lookup(struct net *net, const struct in6_addr *saddr, __be16 sport,
@@ -324,7 +324,7 @@ struct sock *__udp6_lib_lookup(struct net *net, const struct in6_addr *daddr, __be16 dport, int dif, int sdif, struct udp_table *tbl, struct sk_buff *skb); -struct sock *udp6_lib_lookup_skb (struct sk_buff *skb, +struct sock *udp6_lib_lookup_skb (const struct sk_buff *skb,__be16 sport,__be16 dport);/* UDP uses skb->dev_scratch to cache as much information as possible and avoid
net/ipv4/udp.c +1 -1
@@ -541,7 +541,7 @@ static inline struct sock *__udp4_lib_lookup_skb(struct sk_buff *skb, inet_sdif(skb), udptable, skb); } -struct sock *udp4_lib_lookup_skb (struct sk_buff *skb, +struct sock *udp4_lib_lookup_skb (const struct sk_buff *skb,__be16 sport,__be16 dport) {const struct iphdr *iph =ip_hdr (skb);
net/ipv6/udp.c +1 -1
@@ -276,7 +276,7 @@ static struct sock *__udp6_lib_lookup_skb(struct sk_buff *skb, inet6_sdif(skb), udptable, skb); } -struct sock *udp6_lib_lookup_skb (struct sk_buff *skb, +struct sock *udp6_lib_lookup_skb (const struct sk_buff *skb,__be16 sport,__be16 dport) {const struct ipv6hdr *iph =ipv6_hdr (skb);
Signature · 1 line
2.29.2.222.g5d2a92d10f8-goog
Quoted 6 lines · On Mon, 9 Nov 2020 15:13:47 -0800 Eric Dumazet wrote:
From: Eric Dumazet <[email protected]>
This came while reviewing Alexander Lobakin patch against UDP GRO:
We want to make sure skb wont be changed by these helpers while it is owned by GRO stack.
Applied, thank you!