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

net/x25: fix nonblocking connect

This patch fixes 2 issues in x25_connect():

1. It makes absolutely no sense to reset the neighbour and the
connection state after a (successful) nonblocking call of x25_connect.
This prevents any connection from being established, since the response
(call accept) cannot be processed.

2. Any further calls to x25_connect() while a call is pending should
simply return, instead of creating new Call Request (on different
logical channels).

This patch should also fix the "KASAN: null-ptr-deref Write in
x25_connect" and "BUG: unable to handle kernel NULL pointer dereference
in x25_connect" bugs reported by syzbot.

Signed-off-by: Martin Schiller <ms@dev.tdt.de>
Reported-by: syzbot+429c200ffc8772bfe070@syzkaller.appspotmail.com
Reported-by: syzbot+eec0c87f31a7c3b66f7b@syzkaller.appspotmail.com
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Martin Schiller and committed by
David S. Miller
e21dba7a 3249b1e4

+5 -1
+5 -1
net/x25/af_x25.c
··· 766 766 if (sk->sk_state == TCP_ESTABLISHED) 767 767 goto out; 768 768 769 + rc = -EALREADY; /* Do nothing if call is already in progress */ 770 + if (sk->sk_state == TCP_SYN_SENT) 771 + goto out; 772 + 769 773 sk->sk_state = TCP_CLOSE; 770 774 sock->state = SS_UNCONNECTED; 771 775 ··· 816 812 /* Now the loop */ 817 813 rc = -EINPROGRESS; 818 814 if (sk->sk_state != TCP_ESTABLISHED && (flags & O_NONBLOCK)) 819 - goto out_put_neigh; 815 + goto out; 820 816 821 817 rc = x25_wait_for_connection_establishment(sk); 822 818 if (rc)