]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: Rename ->stream_memory_read to ->sock_is_readable
authorCong Wang <cong.wang@bytedance.com>
Fri, 8 Oct 2021 20:33:03 +0000 (13:33 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 27 Jun 2025 10:04:09 +0000 (11:04 +0100)
[ Upstream commit 7b50ecfcc6cdfe87488576bc3ed443dc8d083b90 ]

The proto ops ->stream_memory_read() is currently only used
by TCP to check whether psock queue is empty or not. We need
to rename it before reusing it for non-TCP protocols, and
adjust the exsiting users accordingly.

Signed-off-by: Cong Wang <cong.wang@bytedance.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20211008203306.37525-2-xiyou.wangcong@gmail.com
Stable-dep-of: 2660a544fdc0 ("net: Fix TOCTOU issue in sk_is_readable()")
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/net/sock.h
include/net/tls.h
net/ipv4/tcp.c
net/ipv4/tcp_bpf.c
net/tls/tls_main.c
net/tls/tls_sw.c

index 548f9aab9aa105fca90493f47b15761b510850b2..b9e34b955c561ed8ff29fc9254b1d9abb4d544c1 100644 (file)
@@ -1226,7 +1226,7 @@ struct proto {
 #endif
 
        bool                    (*stream_memory_free)(const struct sock *sk, int wake);
-       bool                    (*stream_memory_read)(const struct sock *sk);
+       bool                    (*sock_is_readable)(struct sock *sk);
        /* Memory pressure */
        void                    (*enter_memory_pressure)(struct sock *sk);
        void                    (*leave_memory_pressure)(struct sock *sk);
@@ -2825,4 +2825,10 @@ void sock_set_sndtimeo(struct sock *sk, s64 secs);
 
 int sock_bind_add(struct sock *sk, struct sockaddr *addr, int addr_len);
 
+static inline bool sk_is_readable(struct sock *sk)
+{
+       if (sk->sk_prot->sock_is_readable)
+               return sk->sk_prot->sock_is_readable(sk);
+       return false;
+}
 #endif /* _SOCK_H */
index d9cb597cab46a717f38ff4812496f33066649a33..c76a827a678ae1aeb6f1f876679a67665cc2d456 100644 (file)
@@ -377,7 +377,7 @@ void tls_sw_release_resources_rx(struct sock *sk);
 void tls_sw_free_ctx_rx(struct tls_context *tls_ctx);
 int tls_sw_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
                   int nonblock, int flags, int *addr_len);
-bool tls_sw_stream_read(const struct sock *sk);
+bool tls_sw_sock_is_readable(struct sock *sk);
 ssize_t tls_sw_splice_read(struct socket *sock, loff_t *ppos,
                           struct pipe_inode_info *pipe,
                           size_t len, unsigned int flags);
index 0332fdab942db32c0f1d000f7f151508fe1acee5..2d870d5e31cfbf45822a636b3fa851a424ab7141 100644 (file)
@@ -480,10 +480,7 @@ static bool tcp_stream_is_readable(struct sock *sk, int target)
 {
        if (tcp_epollin_ready(sk, target))
                return true;
-
-       if (sk->sk_prot->stream_memory_read)
-               return sk->sk_prot->stream_memory_read(sk);
-       return false;
+       return sk_is_readable(sk);
 }
 
 /*
index 9765fda6cc3785699847574ed7c970ebf13a96c0..f97e357e2644d76b6b49d18e41133413564755b9 100644 (file)
@@ -233,7 +233,7 @@ int tcp_bpf_sendmsg_redir(struct sock *sk, struct sk_msg *msg,
 EXPORT_SYMBOL_GPL(tcp_bpf_sendmsg_redir);
 
 #ifdef CONFIG_BPF_SYSCALL
-static bool tcp_bpf_stream_read(const struct sock *sk)
+static bool tcp_bpf_sock_is_readable(struct sock *sk)
 {
        struct sk_psock *psock;
        bool empty = true;
@@ -582,7 +582,7 @@ static void tcp_bpf_rebuild_protos(struct proto prot[TCP_BPF_NUM_CFGS],
        prot[TCP_BPF_BASE].destroy              = sock_map_destroy;
        prot[TCP_BPF_BASE].close                = sock_map_close;
        prot[TCP_BPF_BASE].recvmsg              = tcp_bpf_recvmsg;
-       prot[TCP_BPF_BASE].stream_memory_read   = tcp_bpf_stream_read;
+       prot[TCP_BPF_BASE].sock_is_readable     = tcp_bpf_sock_is_readable;
 
        prot[TCP_BPF_TX]                        = prot[TCP_BPF_BASE];
        prot[TCP_BPF_TX].sendmsg                = tcp_bpf_sendmsg;
index 9d7b52370155bed805b8bf1ddd3afb17a8379ceb..63517995c692ac92696437fef56364ad90d82f28 100644 (file)
@@ -731,12 +731,12 @@ static void build_protos(struct proto prot[TLS_NUM_CONFIG][TLS_NUM_CONFIG],
 
        prot[TLS_BASE][TLS_SW] = prot[TLS_BASE][TLS_BASE];
        prot[TLS_BASE][TLS_SW].recvmsg            = tls_sw_recvmsg;
-       prot[TLS_BASE][TLS_SW].stream_memory_read = tls_sw_stream_read;
+       prot[TLS_BASE][TLS_SW].sock_is_readable   = tls_sw_sock_is_readable;
        prot[TLS_BASE][TLS_SW].close              = tls_sk_proto_close;
 
        prot[TLS_SW][TLS_SW] = prot[TLS_SW][TLS_BASE];
        prot[TLS_SW][TLS_SW].recvmsg            = tls_sw_recvmsg;
-       prot[TLS_SW][TLS_SW].stream_memory_read = tls_sw_stream_read;
+       prot[TLS_SW][TLS_SW].sock_is_readable   = tls_sw_sock_is_readable;
        prot[TLS_SW][TLS_SW].close              = tls_sk_proto_close;
 
 #ifdef CONFIG_TLS_DEVICE
index 0723b3a4f6d915733bc515e045ad699c420d67fd..7a448fd96f81c6922c8f2542877e6818bb1b4e86 100644 (file)
@@ -2047,7 +2047,7 @@ splice_read_end:
        return copied ? : err;
 }
 
-bool tls_sw_stream_read(const struct sock *sk)
+bool tls_sw_sock_is_readable(struct sock *sk)
 {
        struct tls_context *tls_ctx = tls_get_ctx(sk);
        struct tls_sw_context_rx *ctx = tls_sw_ctx_rx(tls_ctx);