Skip to contentSkip to conversation

inet: prevent skb changes in udp{4|6}_lib_lookup_skb()

PATCH Applied Eric Dumazet 2 participants 4 messages Nov 9, 2020 – Nov 11, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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.

Cc Alexander Lobakin <[email protected]>
---
 include/net/ip.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/ip.h +1 -1
index 2d6b985d11ccaa75827b3a15ac3f898d7a193242..e20874059f826eb0f9e899aed556bfbc9c9d71e8 100644
@@ -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
#2 lore raw

PATCH 2/2 inet: udp{4|6}_lib_lookup_skb() skb argument is const

In reply to Eric Dumazet

From: 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.

Cc Alexander Lobakin <[email protected]>
---
 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
index 295d52a73598277dc5071536f777d1a87e7df1d1..877832bed4713a011a514a2f6f522728c8c89e20 100644
@@ -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
index ca04a8a35e52dbcff50b03da2710726dc6ee98bd..8c9f08343e171ba9b78ebe7bfe22e6508ab15c42 100644
@@ -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
index cde9b8874d4bce4cdbee557d89a0be0ddf3f87df..c32f50d2a0694580426ea71e52a1cee23ed07045 100644
@@ -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
maintainer Applied
#3 lore raw
In reply to Eric Dumazet
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!