diff options
author | Jakub Kicinski <kuba@kernel.org> | 2022-06-23 12:33:24 -0700 |
---|---|---|
committer | Jakub Kicinski <kuba@kernel.org> | 2022-06-23 12:33:24 -0700 |
commit | 93817be8b62c7fa1f1bdc3e8c037a73a60026be9 (patch) | |
tree | 873c207abc783edb4ead73b2b3a8a9b105f94420 /net/core/filter.c | |
parent | nfp: add 'ethtool --identify' support (diff) | |
parent | Merge tag 'net-5.19-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net (diff) | |
download | linux-dev-93817be8b62c7fa1f1bdc3e8c037a73a60026be9.tar.xz linux-dev-93817be8b62c7fa1f1bdc3e8c037a73a60026be9.zip |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net
No conflicts.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'net/core/filter.c')
-rw-r--r-- | net/core/filter.c | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/net/core/filter.c b/net/core/filter.c index 151aa4756bd6..994d91680b12 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -6514,10 +6514,21 @@ __bpf_sk_lookup(struct sk_buff *skb, struct bpf_sock_tuple *tuple, u32 len, ifindex, proto, netns_id, flags); if (sk) { - sk = sk_to_full_sk(sk); - if (!sk_fullsock(sk)) { + struct sock *sk2 = sk_to_full_sk(sk); + + /* sk_to_full_sk() may return (sk)->rsk_listener, so make sure the original sk + * sock refcnt is decremented to prevent a request_sock leak. + */ + if (!sk_fullsock(sk2)) + sk2 = NULL; + if (sk2 != sk) { sock_gen_put(sk); - return NULL; + /* Ensure there is no need to bump sk2 refcnt */ + if (unlikely(sk2 && !sock_flag(sk2, SOCK_RCU_FREE))) { + WARN_ONCE(1, "Found non-RCU, unreferenced socket!"); + return NULL; + } + sk = sk2; } } @@ -6551,10 +6562,21 @@ bpf_sk_lookup(struct sk_buff *skb, struct bpf_sock_tuple *tuple, u32 len, flags); if (sk) { - sk = sk_to_full_sk(sk); - if (!sk_fullsock(sk)) { + struct sock *sk2 = sk_to_full_sk(sk); + + /* sk_to_full_sk() may return (sk)->rsk_listener, so make sure the original sk + * sock refcnt is decremented to prevent a request_sock leak. + */ + if (!sk_fullsock(sk2)) + sk2 = NULL; + if (sk2 != sk) { sock_gen_put(sk); - return NULL; + /* Ensure there is no need to bump sk2 refcnt */ + if (unlikely(sk2 && !sock_flag(sk2, SOCK_RCU_FREE))) { + WARN_ONCE(1, "Found non-RCU, unreferenced socket!"); + return NULL; + } + sk = sk2; } } |