Skip to content

Commit 51e0158

Browse files
Cong Wangborkmann
authored andcommitted
skmsg: Pass psock pointer to ->psock_update_sk_prot()
Using sk_psock() to retrieve psock pointer from sock requires RCU read lock, but we already get psock pointer before calling ->psock_update_sk_prot() in both cases, so we can just pass it without bothering sk_psock(). Fixes: 8a59f9d ("sock: Introduce sk->sk_prot->psock_update_sk_prot()") Reported-by: [email protected] Signed-off-by: Cong Wang <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Tested-by: [email protected] Reviewed-by: Jakub Sitnicki <[email protected]> Acked-by: John Fastabend <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent cbaa683 commit 51e0158

File tree

7 files changed

+12
-10
lines changed

7 files changed

+12
-10
lines changed

include/linux/skmsg.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ struct sk_psock {
9999
void (*saved_close)(struct sock *sk, long timeout);
100100
void (*saved_write_space)(struct sock *sk);
101101
void (*saved_data_ready)(struct sock *sk);
102-
int (*psock_update_sk_prot)(struct sock *sk, bool restore);
102+
int (*psock_update_sk_prot)(struct sock *sk, struct sk_psock *psock,
103+
bool restore);
103104
struct proto *sk_proto;
104105
struct mutex work_mutex;
105106
struct sk_psock_work_state work_state;
@@ -405,7 +406,7 @@ static inline void sk_psock_restore_proto(struct sock *sk,
405406
{
406407
sk->sk_prot->unhash = psock->saved_unhash;
407408
if (psock->psock_update_sk_prot)
408-
psock->psock_update_sk_prot(sk, true);
409+
psock->psock_update_sk_prot(sk, psock, true);
409410
}
410411

411412
static inline void sk_psock_set_state(struct sk_psock *psock,

include/net/sock.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,7 @@ struct inet_hashinfo;
11141114
struct raw_hashinfo;
11151115
struct smc_hashinfo;
11161116
struct module;
1117+
struct sk_psock;
11171118

11181119
/*
11191120
* caches using SLAB_TYPESAFE_BY_RCU should let .next pointer from nulls nodes
@@ -1185,7 +1186,9 @@ struct proto {
11851186
void (*rehash)(struct sock *sk);
11861187
int (*get_port)(struct sock *sk, unsigned short snum);
11871188
#ifdef CONFIG_BPF_SYSCALL
1188-
int (*psock_update_sk_prot)(struct sock *sk, bool restore);
1189+
int (*psock_update_sk_prot)(struct sock *sk,
1190+
struct sk_psock *psock,
1191+
bool restore);
11891192
#endif
11901193

11911194
/* Keeping track of sockets in use */

include/net/tcp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2215,7 +2215,7 @@ struct sk_psock;
22152215

22162216
#ifdef CONFIG_BPF_SYSCALL
22172217
struct proto *tcp_bpf_get_proto(struct sock *sk, struct sk_psock *psock);
2218-
int tcp_bpf_update_proto(struct sock *sk, bool restore);
2218+
int tcp_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore);
22192219
void tcp_bpf_clone(const struct sock *sk, struct sock *newsk);
22202220
#endif /* CONFIG_BPF_SYSCALL */
22212221

include/net/udp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ static inline void udp_post_segment_fix_csum(struct sk_buff *skb)
543543
#ifdef CONFIG_BPF_SYSCALL
544544
struct sk_psock;
545545
struct proto *udp_bpf_get_proto(struct sock *sk, struct sk_psock *psock);
546-
int udp_bpf_update_proto(struct sock *sk, bool restore);
546+
int udp_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore);
547547
#endif
548548

549549
#endif /* _UDP_H */

net/core/sock_map.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static int sock_map_init_proto(struct sock *sk, struct sk_psock *psock)
188188
if (!sk->sk_prot->psock_update_sk_prot)
189189
return -EINVAL;
190190
psock->psock_update_sk_prot = sk->sk_prot->psock_update_sk_prot;
191-
return sk->sk_prot->psock_update_sk_prot(sk, false);
191+
return sk->sk_prot->psock_update_sk_prot(sk, psock, false);
192192
}
193193

194194
static struct sk_psock *sock_map_psock_get_checked(struct sock *sk)

net/ipv4/tcp_bpf.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,8 @@ static int tcp_bpf_assert_proto_ops(struct proto *ops)
499499
ops->sendpage == tcp_sendpage ? 0 : -ENOTSUPP;
500500
}
501501

502-
int tcp_bpf_update_proto(struct sock *sk, bool restore)
502+
int tcp_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore)
503503
{
504-
struct sk_psock *psock = sk_psock(sk);
505504
int family = sk->sk_family == AF_INET6 ? TCP_BPF_IPV6 : TCP_BPF_IPV4;
506505
int config = psock->progs.msg_parser ? TCP_BPF_TX : TCP_BPF_BASE;
507506

net/ipv4/udp_bpf.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,9 @@ static int __init udp_bpf_v4_build_proto(void)
103103
}
104104
core_initcall(udp_bpf_v4_build_proto);
105105

106-
int udp_bpf_update_proto(struct sock *sk, bool restore)
106+
int udp_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore)
107107
{
108108
int family = sk->sk_family == AF_INET ? UDP_BPF_IPV4 : UDP_BPF_IPV6;
109-
struct sk_psock *psock = sk_psock(sk);
110109

111110
if (restore) {
112111
sk->sk_write_space = psock->saved_write_space;

0 commit comments

Comments
 (0)