All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] ax25: use after free in ax25_connect
@ 2022-01-11  4:20 Hangyu Hua
  2022-01-11 20:56 ` Eric Dumazet
  0 siblings, 1 reply; 8+ messages in thread
From: Hangyu Hua @ 2022-01-11  4:20 UTC (permalink / raw)
  To: jreuter, ralf, davem, kuba; +Cc: linux-hams, netdev, linux-kernel, Hangyu Hua

sk_to_ax25(sk) needs to be called after lock_sock(sk) to avoid UAF
caused by a race condition.

Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
---
 net/ax25/af_ax25.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c
index cfca99e295b8..c5d62420a2a8 100644
--- a/net/ax25/af_ax25.c
+++ b/net/ax25/af_ax25.c
@@ -1127,7 +1127,7 @@ static int __must_check ax25_connect(struct socket *sock,
 	struct sockaddr *uaddr, int addr_len, int flags)
 {
 	struct sock *sk = sock->sk;
-	ax25_cb *ax25 = sk_to_ax25(sk), *ax25t;
+	ax25_cb *ax25, *ax25t;
 	struct full_sockaddr_ax25 *fsa = (struct full_sockaddr_ax25 *)uaddr;
 	ax25_digi *digi = NULL;
 	int ct = 0, err = 0;
@@ -1155,6 +1155,8 @@ static int __must_check ax25_connect(struct socket *sock,
 
 	lock_sock(sk);
 
+	ax25 = sk_to_ax25(sk);
+
 	/* deal with restarts */
 	if (sock->state == SS_CONNECTING) {
 		switch (sk->sk_state) {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-01-17  1:35 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-11  4:20 [PATCH net] ax25: use after free in ax25_connect Hangyu Hua
2022-01-11 20:56 ` Eric Dumazet
2022-01-12  2:13   ` Hangyu Hua
2022-01-12  9:59     ` Eric Dumazet
2022-01-12 11:11       ` Hangyu Hua
2022-01-14  6:54         ` Hangyu Hua
2022-01-14 15:19           ` Eric Dumazet
2022-01-17  1:35             ` Hangyu Hua

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.