[PATCH v2 net-next 00/10]
Subsystems (8)
v2 cover [PATCH v2 net-next 00/10]
From: Eric Dumazet <[email protected]>
net: add annotations for sk->sk_bound_dev_if
While writes on sk->sk_bound_dev_if are protected by socket lock, we have many lockless reads all over the places.
This is based on syzbot report found in the first patch changelog.
v2: inline ipv6 function only defined if IS_ENABLED(CONFIG_IPV6) (kernel bots)
Change the INET6_MATCH() to inet6_match(), this is no longer a macro. Change INET_MATCH() to inet_match() (Olivier Hartkopp & Jakub Kicinski)
Eric Dumazet (10):
net: annotate races around sk->sk_bound_dev_if
sctp: read sk->sk_bound_dev_if once in sctp_rcv()
tcp: sk->sk_bound_dev_if once in inet_request_bound_dev_if()
net: core: add READ_ONCE/WRITE_ONCE annotations for
sk->sk_bound_dev_if
dccp: use READ_ONCE() to read sk->sk_bound_dev_if
inet: add READ_ONCE(sk->sk_bound_dev_if) in inet_csk_bind_conflict()
net_sched: em_meta: add READ_ONCE() in var_sk_bound_if()
l2tp: use add READ_ONCE() to fetch sk->sk_bound_dev_if
ipv6: add READ_ONCE(sk->sk_bound_dev_if) in INET6_MATCH()
inet: rename INET_MATCH()
include/net/inet6_hashtables.h | 28 +++++++++++++++++++--------- include/net/inet_hashtables.h | 2 +- include/net/inet_sock.h | 5 +++-- include/net/ip.h | 2 +- include/net/sock.h | 5 +++-- net/core/sock.c | 11 +++++++---- net/dccp/ipv4.c | 2 +- net/dccp/ipv6.c | 4 ++-- net/ipv4/inet_connection_sock.c | 12 ++++++++---- net/ipv4/inet_hashtables.c | 10 +++++----- net/ipv4/udp.c | 2 +- net/ipv6/datagram.c | 6 +++--- net/ipv6/inet6_hashtables.c | 6 +++--- net/ipv6/udp.c | 13 +++++++------ net/l2tp/l2tp_ip.c | 4 +++- net/l2tp/l2tp_ip6.c | 8 +++++--- net/sched/em_meta.c | 7 +++++-- net/sctp/input.c | 4 +++- 18 files changed, 80 insertions(+), 51 deletions(-)
Signature · 1 line
2.36.0.550.gb090851708-goog
PATCH v2 1/10 net: annotate races around sk->sk_bound_dev_if
From: Eric Dumazet <[email protected]>
UDP sendmsg() is lockless, and reads sk->sk_bound_dev_if while this field can be changed by another thread.
Adds minimal annotations to avoid KCSAN splats for UDP. Following patches will add more annotations to potential lockless readers.
BUG: KCSAN: data-race in __ip6_datagram_connect / udpv6_sendmsg
write to 0xffff888136d47a94 of 4 bytes by task 7681 on cpu 0:
__ip6_datagram_connect+0x6e2/0x930 net/ipv6/datagram.c:221 ip6_datagram_connect+0x2a/0x40 net/ipv6/datagram.c:272 inet_dgram_connect+0x107/0x190 net/ipv4/af_inet.c:576 __sys_connect_file net/socket.c:1900 [inline] __sys_connect+0x197/0x1b0 net/socket.c:1917 __do_sys_connect net/socket.c:1927 [inline] __se_sys_connect net/socket.c:1924 [inline] __x64_sys_connect+0x3d/0x50 net/socket.c:1924 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x2b/0x50 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x44/0xae
read to 0xffff888136d47a94 of 4 bytes by task 7670 on cpu 1:
udpv6_sendmsg+0xc60/0x16e0 net/ipv6/udp.c:1436 inet6_sendmsg+0x5f/0x80 net/ipv6/af_inet6.c:652 sock_sendmsg_nosec net/socket.c:705 [inline] sock_sendmsg net/socket.c:725 [inline] ____sys_sendmsg+0x39a/0x510 net/socket.c:2413 ___sys_sendmsg net/socket.c:2467 [inline] __sys_sendmmsg+0x267/0x4c0 net/socket.c:2553 __do_sys_sendmmsg net/socket.c:2582 [inline] __se_sys_sendmmsg net/socket.c:2579 [inline] __x64_sys_sendmmsg+0x53/0x60 net/socket.c:2579 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x2b/0x50 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x44/0xae
value changed: 0x00000000 -> 0xffffff9b
Reported by Kernel Concurrency Sanitizer on:
CPU: 1 PID: 7670 Comm: syz-executor.3 Tainted: G W 5.18.0-rc1-syzkaller-dirty #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
I chose to not add Fixes: tag because race has minor consequences and stable teams busy enough.
--- include/net/ip.h | 2 +- include/net/sock.h | 5 +++-- net/ipv6/datagram.c | 6 +++--- net/ipv6/udp.c | 11 ++++++----- 4 files changed, 13 insertions(+), 11 deletions(-)
include/net/ip.h +1 -1
@@ -93,7 +93,7 @@ static inline void ipcm_init_sk(struct ipcm_cookie *ipcm, ipcm->sockc.mark = inet->sk.sk_mark; ipcm->sockc.tsflags = inet->sk.sk_tsflags; - ipcm->oif = inet->sk.sk_bound_dev_if; + ipcm->oif =READ_ONCE (inet->sk.sk_bound_dev_if); ipcm->addr = inet->inet_saddr; }
include/net/sock.h +3 -2
@@ -2875,13 +2875,14 @@ static inline void sk_pacing_shift_update(struct sock *sk, int val)*/ static inline bool sk_dev_equal_l3scope (struct sock *sk,int dif) { +int bound_dev_if =READ_ONCE (sk->sk_bound_dev_if);int mdif; -if (!sk->sk_bound_dev_if || sk->sk_bound_dev_if == dif) +if (!bound_dev_if || bound_dev_if == dif)return true; mdif =l3mdev_master_ifindex_by_index (sock_net (sk), dif); -if (mdif && mdif == sk->sk_bound_dev_if) +if (mdif && mdif == bound_dev_if)return true;return false;
net/ipv6/datagram.c +3 -3
@@ -218,11 +218,11 @@ int __ip6_datagram_connect(struct sock *sk, struct sockaddr *uaddr, err = -EINVAL ; goto out; } - sk->sk_bound_dev_if = usin->sin6_scope_id; +WRITE_ONCE (sk->sk_bound_dev_if, usin->sin6_scope_id); }if (!sk->sk_bound_dev_if && (addr_type &IPV6_ADDR_MULTICAST )) - sk->sk_bound_dev_if = np->mcast_oif; +WRITE_ONCE (sk->sk_bound_dev_if, np->mcast_oif);/* Connect to link-local address requires an interface */ if (!sk->sk_bound_dev_if) {
@@ -798,7 +798,7 @@ int ip6_datagram_send_ctl(struct net *net, struct sock *sk,if (src_idx) {if (fl6->flowi6_oif && src_idx != fl6->flowi6_oif && - (sk->sk_bound_dev_if != fl6->flowi6_oif || + (READ_ONCE (sk->sk_bound_dev_if) != fl6->flowi6_oif || !sk_dev_equal_l3scope (sk, src_idx)))return -EINVAL ; fl6->flowi6_oif = src_idx;
net/ipv6/udp.c +6 -5
@@ -105,7 +105,7 @@ static int compute_score(struct sock *sk, struct net *net, const struct in6_addr *daddr, unsigned short hnum, int dif, int sdif) { - int score; + int bound_dev_if, score;struct inet_sock *inet;bool dev_match;
@@ -132,10 +132,11 @@ static int compute_score(struct sock *sk, struct net *net, score++; } - dev_match =udp_sk_bound_dev_eq (net, sk->sk_bound_dev_if, dif, sdif); + bound_dev_if =READ_ONCE (sk->sk_bound_dev_if); + dev_match =udp_sk_bound_dev_eq (net, bound_dev_if, dif, sdif);if (!dev_match)return -1 ; -if (sk->sk_bound_dev_if) +if (bound_dev_if) score++;if (READ_ONCE (sk->sk_incoming_cpu) ==raw_smp_processor_id ())
@@ -789,7 +790,7 @@ static bool __udp_v6_is_mcast_sock(struct net *net, struct sock *sk, (inet->inet_dport && inet->inet_dport != rmt_port) || (!ipv6_addr_any (&sk->sk_v6_daddr) && !ipv6_addr_equal (&sk->sk_v6_daddr, rmt_addr)) || - !udp_sk_bound_dev_eq (net, sk->sk_bound_dev_if, dif, sdif) || + !udp_sk_bound_dev_eq (net,READ_ONCE (sk->sk_bound_dev_if), dif, sdif) || (!ipv6_addr_any (&sk->sk_v6_rcv_saddr) && !ipv6_addr_equal(&sk->sk_v6_rcv_saddr, loc_addr))) return false;
@@ -1433,7 +1434,7 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) }if (!fl6->flowi6_oif) - fl6->flowi6_oif = sk->sk_bound_dev_if; + fl6->flowi6_oif =READ_ONCE (sk->sk_bound_dev_if);if (!fl6->flowi6_oif) fl6->flowi6_oif = np->sticky_pktinfo.ipi6_ifindex;
Signature · 1 line
2.36.0.550.gb090851708-goog
PATCH v2 2/10 sctp: read sk->sk_bound_dev_if once in sctp_rcv()
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
sctp_rcv() reads sk->sk_bound_dev_if twice while the socket is not locked. Another cpu could change this field under us.
--- net/sctp/input.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/sctp/input.c +3 -1
@@ -92,6 +92,7 @@ int sctp_rcv(struct sk_buff *skb)struct sctp_chunk *chunk;union sctp_addr src;union sctp_addr dest; +int bound_dev_if;int family;struct sctp_af *af;struct net *net =dev_net (skb->dev);
@@ -169,7 +170,8 @@ int sctp_rcv(struct sk_buff *skb)* If a frame arrives on an interface and the receiving socket is * bound to another interface, via SO_BINDTODEVICE, treat it as OOTB */ -if (sk->sk_bound_dev_if && (sk->sk_bound_dev_if != af->skb_iif (skb))) { + bound_dev_if =READ_ONCE (sk->sk_bound_dev_if); +if (bound_dev_if && (bound_dev_if != af->skb_iif (skb))) {if (transport) {sctp_transport_put (transport); asoc =NULL ;
Signature · 1 line
2.36.0.550.gb090851708-goog
Re: [PATCH v2 net-next 02/10] sctp: read sk->sk_bound_dev_if once in sctp_rcv()
Quoted 6 lines · Eric Dumazet
From: Eric Dumazet <[email protected]>
sctp_rcv()readssk->sk_bound_dev_iftwice while the socket is not locked. Another cpu could change this field under us.Fixes 0fd9a65a76e8 ("[SCTP] Support SO_BINDTODEVICE socket option on incoming packets.")
2005.. :-)
Quoted 4 lines
Signed-off-by Eric Dumazet <[email protected]>Cc Neil Horman <[email protected]>Cc Vlad Yasevich <[email protected]>Cc Marcelo Ricardo Leitner <[email protected]>
PATCH v2 3/10 tcp: sk->sk_bound_dev_if once in inet_request_bound_dev_if()
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
inet_request_bound_dev_if() reads sk->sk_bound_dev_if twice while listener socket is not locked.
Another cpu could change this field under us.
--- include/net/inet_sock.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
include/net/inet_sock.h +3 -2
@@ -116,14 +116,15 @@ static inline u32 inet_request_mark(const struct sock *sk, struct sk_buff *skb)static inline int inet_request_bound_dev_if (const struct sock *sk,struct sk_buff *skb) { +int bound_dev_if =READ_ONCE (sk->sk_bound_dev_if);#ifdef CONFIG_NET_L3_MASTER_DEV struct net *net =sock_net (sk); -if (!sk->sk_bound_dev_if && net->ipv4.sysctl_tcp_l3mdev_accept) +if (!bound_dev_if && net->ipv4.sysctl_tcp_l3mdev_accept)return l3mdev_master_ifindex_by_index (net, skb->skb_iif);#endif -return sk->sk_bound_dev_if; +return bound_dev_if; }static inline int inet_sk_bound_l3mdev (const struct sock *sk)
Signature · 1 line
2.36.0.550.gb090851708-goog
PATCH v2 4/10 net: core: add READ_ONCE/WRITE_ONCE annotations for sk->sk_bound_dev_if
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
sock_bindtoindex_locked() needs to use WRITE_ONCE(sk->sk_bound_dev_if, val), because other cpus/threads might locklessly read this field.
sock_getbindtodevice(), sock_getsockopt() need READ_ONCE() because they run without socket lock held.
--- net/core/sock.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
net/core/sock.c +7 -4
@@ -635,7 +635,9 @@ static int sock_bindtoindex_locked(struct sock *sk, int ifindex)if (ifindex <0 ) goto out; - sk->sk_bound_dev_if = ifindex; +/* Paired with all READ_ONCE() done locklessly. */ +WRITE_ONCE (sk->sk_bound_dev_if, ifindex); +if (sk->sk_prot->rehash) sk->sk_prot->rehash (sk);sk_dst_reset (sk);
@@ -713,10 +715,11 @@ static int sock_getbindtodevice(struct sock *sk, char __user *optval, {int ret = -ENOPROTOOPT ;#ifdef CONFIG_NETDEVICES +int bound_dev_if =READ_ONCE (sk->sk_bound_dev_if);struct net *net =sock_net (sk);char devname[IFNAMSIZ ]; -if (sk->sk_bound_dev_if ==0 ) { +if (bound_dev_if ==0 ) { len =0 ; goto zero; }
@@ -725,7 +728,7 @@ static int sock_getbindtodevice(struct sock *sk, char __user *optval,if (len <IFNAMSIZ ) goto out; - ret =netdev_get_name (net, devname, sk->sk_bound_dev_if); + ret =netdev_get_name (net, devname, bound_dev_if);if (ret) goto out;
@@ -1861,7 +1864,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,break ;case SO_BINDTOIFINDEX : - v.val = sk->sk_bound_dev_if; + v.val =READ_ONCE (sk->sk_bound_dev_if);break ;case SO_NETNS_COOKIE :
Signature · 1 line
2.36.0.550.gb090851708-goog
PATCH v2 5/10 dccp: use READ_ONCE() to read sk->sk_bound_dev_if
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
When reading listener sk->sk_bound_dev_if locklessly, we must use READ_ONCE().
--- net/dccp/ipv4.c | 2 +- net/dccp/ipv6.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
net/dccp/ipv4.c +1 -1
@@ -628,7 +628,7 @@ int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb)sk_daddr_set (req_to_sk (req),ip_hdr (skb)->saddr); ireq->ir_mark =inet_request_mark (sk, skb); ireq->ireq_family =AF_INET ; - ireq->ir_iif = sk->sk_bound_dev_if; + ireq->ir_iif =READ_ONCE (sk->sk_bound_dev_if);/* * Step 3: Process LISTEN state
net/dccp/ipv6.c +2 -2
@@ -374,10 +374,10 @@ static int dccp_v6_conn_request(struct sock *sk, struct sk_buff *skb)refcount_inc (&skb->users); ireq->pktopts = skb; } - ireq->ir_iif = sk->sk_bound_dev_if; + ireq->ir_iif =READ_ONCE (sk->sk_bound_dev_if);/* So that link locals have meaning */ -if (!sk->sk_bound_dev_if && +if (!ireq->ir_iif &&ipv6_addr_type (&ireq->ir_v6_rmt_addr) &IPV6_ADDR_LINKLOCAL ) ireq->ir_iif =inet6_iif (skb);
Signature · 1 line
2.36.0.550.gb090851708-goog
PATCH v2 6/10 inet: add READ_ONCE(sk->sk_bound_dev_if) in inet_csk_bind_conflict()
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
inet_csk_bind_conflict() can access sk->sk_bound_dev_if for unlocked sockets.
--- net/ipv4/inet_connection_sock.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
net/ipv4/inet_connection_sock.c +8 -4
@@ -155,10 +155,14 @@ static int inet_csk_bind_conflict(const struct sock *sk,*/ sk_for_each_bound (sk2, &tb->owners) { -if (sk != sk2 && - (!sk->sk_bound_dev_if || - !sk2->sk_bound_dev_if || - sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) { +int bound_dev_if2; + +if (sk == sk2) +continue ; + bound_dev_if2 =READ_ONCE (sk2->sk_bound_dev_if); +if ((!sk->sk_bound_dev_if || + !bound_dev_if2 || + sk->sk_bound_dev_if == bound_dev_if2)) {if (reuse && sk2->sk_reuse && sk2->sk_state !=TCP_LISTEN ) { if ((!relax ||
Signature · 1 line
2.36.0.550.gb090851708-goog
PATCH v2 7/10 net_sched: em_meta: add READ_ONCE() in var_sk_bound_if()
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
sk->sk_bound_dev_if can change under us, use READ_ONCE() annotation.
--- net/sched/em_meta.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/sched/em_meta.c +5 -2
@@ -311,12 +311,15 @@ META_COLLECTOR(int_sk_bound_if)META_COLLECTOR (var_sk_bound_if) { +int bound_dev_if; +if (skip_nonlocal (skb)) { *err =-1 ;return ; } -if (skb->sk->sk_bound_dev_if ==0 ) { + bound_dev_if =READ_ONCE (skb->sk->sk_bound_dev_if); +if (bound_dev_if ==0 ) { dst->value = (unsigned long )"any" ; dst->len =3 ; }else {
@@ -324,7 +327,7 @@ META_COLLECTOR(var_sk_bound_if)rcu_read_lock (); dev =dev_get_by_index_rcu (sock_net (skb->sk), - skb->sk->sk_bound_dev_if); + bound_dev_if); *err =var_dev (dev, dst);rcu_read_unlock (); }
Signature · 1 line
2.36.0.550.gb090851708-goog
PATCH v2 8/10 l2tp: use add READ_ONCE() to fetch sk->sk_bound_dev_if
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
Use READ_ONCE() in paths not holding the socket lock.
--- net/l2tp/l2tp_ip.c | 4 +++- net/l2tp/l2tp_ip6.c | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-)
net/l2tp/l2tp_ip.c +3 -1
@@ -50,11 +50,13 @@ static struct sock *__l2tp_ip_bind_lookup(const struct net *net, __be32 laddr,sk_for_each_bound (sk, &l2tp_ip_bind_table) {const struct l2tp_ip_sock *l2tp =l2tp_ip_sk (sk);const struct inet_sock *inet =inet_sk (sk); +int bound_dev_if;if (!net_eq (sock_net (sk), net))continue ; -if (sk->sk_bound_dev_if && dif && sk->sk_bound_dev_if != dif) + bound_dev_if =READ_ONCE (sk->sk_bound_dev_if); +if (bound_dev_if && dif && bound_dev_if != dif)continue ; if (inet->inet_rcv_saddr && laddr &&
net/l2tp/l2tp_ip6.c +5 -3
@@ -62,11 +62,13 @@ static struct sock *__l2tp_ip6_bind_lookup(const struct net *net,const struct in6_addr *sk_laddr =inet6_rcv_saddr (sk);const struct in6_addr *sk_raddr = &sk->sk_v6_daddr;const struct l2tp_ip6_sock *l2tp =l2tp_ip6_sk (sk); +int bound_dev_if;if (!net_eq (sock_net (sk), net))continue ; -if (sk->sk_bound_dev_if && dif && sk->sk_bound_dev_if != dif) + bound_dev_if =READ_ONCE (sk->sk_bound_dev_if); +if (bound_dev_if && dif && bound_dev_if != dif)continue ; if (sk_laddr && !ipv6_addr_any(sk_laddr) &&
@@ -445,7 +447,7 @@ static int l2tp_ip6_getname(struct socket *sock, struct sockaddr *uaddr, lsa->l2tp_conn_id = lsk->conn_id; }if (ipv6_addr_type (&lsa->l2tp_addr) &IPV6_ADDR_LINKLOCAL ) - lsa->l2tp_scope_id = sk->sk_bound_dev_if; + lsa->l2tp_scope_id =READ_ONCE (sk->sk_bound_dev_if);return sizeof (*lsa); }
@@ -560,7 +562,7 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) }if (fl6.flowi6_oif ==0 ) - fl6.flowi6_oif = sk->sk_bound_dev_if; + fl6.flowi6_oif =READ_ONCE (sk->sk_bound_dev_if);if (msg->msg_controllen) { opt = &opt_space;
Signature · 1 line
2.36.0.550.gb090851708-goog
PATCH v2 9/10 ipv6: add READ_ONCE(sk->sk_bound_dev_if) in INET6_MATCH()
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
INET6_MATCH() runs without holding a lock on the socket.
We probably need to annotate most reads.
This patch makes INET6_MATCH() an inline function
to ease our changes.
v2: inline function only defined if IS_ENABLED(CONFIG_IPV6)
Change the name to inet6_match(), this is no longer a macro.
--- include/net/inet6_hashtables.h | 28 +++++++++++++++++++--------- net/ipv4/inet_hashtables.c | 2 +- net/ipv6/inet6_hashtables.c | 6 +++--- net/ipv6/udp.c | 2 +- 4 files changed, 24 insertions(+), 14 deletions(-)
include/net/inet6_hashtables.h +19 -9
@@ -103,15 +103,25 @@ struct sock *inet6_lookup(struct net *net, struct inet_hashinfo *hashinfo, const int dif);int inet6_hash (struct sock *sk); + +static inline bool inet6_match (struct net *net,const struct sock *sk, +const struct in6_addr *saddr, +const struct in6_addr *daddr, +const __portpair ports, +const int dif,const int sdif) +{ +int bound_dev_if; + +if (!net_eq (sock_net (sk), net) || + sk->sk_family !=AF_INET6 || + sk->sk_portpair != ports || + !ipv6_addr_equal (&sk->sk_v6_daddr, saddr) || + !ipv6_addr_equal (&sk->sk_v6_rcv_saddr, daddr)) +return false; + + bound_dev_if =READ_ONCE (sk->sk_bound_dev_if); +return bound_dev_if == dif || bound_dev_if == sdif; +}#endif /* IS_ENABLED(CONFIG_IPV6) */ -#define INET6_MATCH (__sk, __net, __saddr, __daddr, __ports, __dif, __sdif) \ - (((__sk)->sk_portpair == (__ports)) && \ - ((__sk)->sk_family == AF_INET6) && \ - ipv6_addr_equal(&(__sk)->sk_v6_daddr, (__saddr)) && \ - ipv6_addr_equal(&(__sk)->sk_v6_rcv_saddr, (__daddr)) && \ - (((__sk)->sk_bound_dev_if == (__dif)) || \ - ((__sk)->sk_bound_dev_if == (__sdif))) && \ - net_eq(sock_net(__sk), (__net))) -#endif /* _INET6_HASHTABLES_H */
net/ipv4/inet_hashtables.c +1 -1
@@ -499,7 +499,7 @@ static bool inet_ehash_lookup_by_sk(struct sock *sk, }#if IS_ENABLED (CONFIG_IPV6 ) else if (sk->sk_family == AF_INET6) { -if (unlikely (INET6_MATCH (esk, net, +if (unlikely (inet6_match (net, esk, &sk->sk_v6_daddr, &sk->sk_v6_rcv_saddr, ports, dif, sdif))) {
net/ipv6/inet6_hashtables.c +3 -3
@@ -71,12 +71,12 @@ struct sock *__inet6_lookup_established(struct net *net,sk_nulls_for_each_rcu (sk, node, &head->chain) {if (sk->sk_hash != hash)continue ; -if (!INET6_MATCH (sk, net, saddr, daddr, ports, dif, sdif)) +if (!inet6_match (net, sk, saddr, daddr, ports, dif, sdif))continue ;if (unlikely (!refcount_inc_not_zero (&sk->sk_refcnt))) goto out; -if (unlikely (!INET6_MATCH (sk, net, saddr, daddr, ports, dif, sdif))) { +if (unlikely (!inet6_match (net, sk, saddr, daddr, ports, dif, sdif))) {sock_gen_put (sk); goto begin; }
@@ -268,7 +268,7 @@ static int __inet6_check_established(struct inet_timewait_death_row *death_row,if (sk2->sk_hash != hash)continue ; -if (likely (INET6_MATCH (sk2, net, saddr, daddr, ports, +if (likely (inet6_match (net, sk2, saddr, daddr, ports, dif, sdif))) {if (sk2->sk_state ==TCP_TIME_WAIT ) { tw =inet_twsk (sk2);
net/ipv6/udp.c +1 -1
@@ -1044,7 +1044,7 @@ static struct sock *__udp6_lib_demux_lookup(struct net *net,udp_portaddr_for_each_entry_rcu (sk, &hslot2->head) {if (sk->sk_state ==TCP_ESTABLISHED && -INET6_MATCH (sk, net, rmt_addr, loc_addr, ports, dif, sdif)) +inet6_match (net, sk, rmt_addr, loc_addr, ports, dif, sdif))return sk;/* Only check first socket in chain */ break ;
Signature · 1 line
2.36.0.550.gb090851708-goog
PATCH v2 10/10 inet: rename INET_MATCH()
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
This is no longer a macro, but an inlined function.
INET_MATCH() -> inet_match()
--- include/net/inet_hashtables.h | 2 +- net/ipv4/inet_hashtables.c | 8 ++++---- net/ipv4/udp.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-)
include/net/inet_hashtables.h +1 -1
@@ -267,7 +267,7 @@ static inline struct sock *inet_lookup_listener(struct net *net, ((__force __u64)(__be32)(__saddr)))#endif /* __BIG_ENDIAN */ -static inline bool INET_MATCH (struct net *net,const struct sock *sk, +static inline bool inet_match (struct net *net,const struct sock *sk,const __addrpair cookie,const __portpair ports,int dif,int sdif) {
net/ipv4/inet_hashtables.c +4 -4
@@ -373,10 +373,10 @@ struct sock *__inet_lookup_established(struct net *net,sk_nulls_for_each_rcu (sk, node, &head->chain) {if (sk->sk_hash != hash)continue ; -if (likely (INET_MATCH (net, sk, acookie, ports, dif, sdif))) { +if (likely (inet_match (net, sk, acookie, ports, dif, sdif))) {if (unlikely (!refcount_inc_not_zero (&sk->sk_refcnt))) goto out; -if (unlikely (!INET_MATCH (net, sk, acookie, +if (unlikely (!inet_match (net, sk, acookie, ports, dif, sdif))) {sock_gen_put (sk); goto begin;
@@ -426,7 +426,7 @@ static int __inet_check_established(struct inet_timewait_death_row *death_row,if (sk2->sk_hash != hash)continue ; -if (likely (INET_MATCH (net, sk2, acookie, ports, dif, sdif))) { +if (likely (inet_match (net, sk2, acookie, ports, dif, sdif))) {if (sk2->sk_state ==TCP_TIME_WAIT ) { tw =inet_twsk (sk2);if (twsk_unique (sk, sk2, twp))
@@ -492,7 +492,7 @@ static bool inet_ehash_lookup_by_sk(struct sock *sk,if (esk->sk_hash != sk->sk_hash)continue ;if (sk->sk_family ==AF_INET ) { -if (unlikely (INET_MATCH (net, esk, acookie, +if (unlikely (inet_match (net, esk, acookie, ports, dif, sdif))) {return true; }
net/ipv4/udp.c +1 -1
@@ -2563,7 +2563,7 @@ static struct sock *__udp4_lib_demux_lookup(struct net *net,struct sock *sk;udp_portaddr_for_each_entry_rcu (sk, &hslot2->head) { -if (INET_MATCH (net, sk, acookie, ports, dif, sdif)) +if (inet_match (net, sk, acookie, ports, dif, sdif))return sk;/* Only check first socket in chain */ break ;
Signature · 1 line
2.36.0.550.gb090851708-goog
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Quoted 8 lines · On Fri, 13 May 2022 11:55:40 -0700 you wrote:
From: Eric Dumazet <[email protected]>
net: add annotations for
sk->sk_bound_dev_ifWhile writes on
sk->sk_bound_dev_ifare protected by socket lock, we have many lockless reads all over the places.[...]
Here is the summary with links:
- [v2,net-next,01/10] net: annotate races around sk->sk_bound_dev_if
https://git.kernel.org/netdev/net-next/c/4c971d2f3548 - [v2,net-next,02/10] sctp: read sk->sk_bound_dev_if once in sctp_rcv() https://git.kernel.org/netdev/net-next/c/a20ea298071f - [v2,net-next,03/10] tcp: sk->sk_bound_dev_if once in inet_request_bound_dev_if() https://git.kernel.org/netdev/net-next/c/fdb5fd7f736e - [v2,net-next,04/10] net: core: add READ_ONCE/WRITE_ONCE annotations for sk->sk_bound_dev_if https://git.kernel.org/netdev/net-next/c/e5fccaa1eb7f - [v2,net-next,05/10] dccp: use READ_ONCE() to read sk->sk_bound_dev_if https://git.kernel.org/netdev/net-next/c/36f7cec4f3af - [v2,net-next,06/10] inet: add READ_ONCE(sk->sk_bound_dev_if) in inet_csk_bind_conflict() https://git.kernel.org/netdev/net-next/c/d2c135619cb8 - [v2,net-next,07/10] net_sched: em_meta: add READ_ONCE() in var_sk_bound_if() https://git.kernel.org/netdev/net-next/c/70f87de9fa0d - [v2,net-next,08/10] l2tp: use add READ_ONCE() to fetch sk->sk_bound_dev_if https://git.kernel.org/netdev/net-next/c/ff0094030f14 - [v2,net-next,09/10] ipv6: add READ_ONCE(sk->sk_bound_dev_if) in INET6_MATCH() (no matching commit) - [v2,net-next,10/10] inet: rename INET_MATCH() https://git.kernel.org/netdev/net-next/c/eda090c31fe9
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html