Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tls: get psock ref after taking rxlock to avoid leak

At the start of tls_sw_recvmsg, we take a reference on the psock, and
then call tls_rx_reader_lock. If that fails, we return directly
without releasing the reference.

Instead of adding a new label, just take the reference after locking
has succeeded, since we don't need it before.

Fixes: 4cbc325ed6b4 ("tls: rx: allow only one reader at a time")
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://lore.kernel.org/r/fe2ade22d030051ce4c3638704ed58b67d0df643.1711120964.git.sd@queasysnail.net
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Sabrina Dubroca and committed by
Jakub Kicinski
417e91e8 dc54b813

+1 -1
+1 -1
net/tls/tls_sw.c
··· 1976 1976 if (unlikely(flags & MSG_ERRQUEUE)) 1977 1977 return sock_recv_errqueue(sk, msg, len, SOL_IP, IP_RECVERR); 1978 1978 1979 - psock = sk_psock_get(sk); 1980 1979 err = tls_rx_reader_lock(sk, ctx, flags & MSG_DONTWAIT); 1981 1980 if (err < 0) 1982 1981 return err; 1982 + psock = sk_psock_get(sk); 1983 1983 bpf_strp_enabled = sk_psock_strp_enabled(psock); 1984 1984 1985 1985 /* If crypto failed the connection is broken */