summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorYueHaibing <yuehaibing@huawei.com>2020-04-28 16:12:08 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2020-08-05 10:06:02 +0200
commit9a5e3aba2c1ce1055a04b70b26e86c28d5eada82 (patch)
treefe76fa1741b5d55d2ac1a24b69f270e3bc836d0d /net
parentfca9ee21e9777c8e0c59660a6af8e4b10f93b968 (diff)
downloadlinux-stable-9a5e3aba2c1ce1055a04b70b26e86c28d5eada82.tar.gz
linux-stable-9a5e3aba2c1ce1055a04b70b26e86c28d5eada82.tar.bz2
linux-stable-9a5e3aba2c1ce1055a04b70b26e86c28d5eada82.zip
net/x25: Fix null-ptr-deref in x25_disconnect
commit 8999dc89497ab1c80d0718828e838c7cd5f6bffe upstream. We should check null before do x25_neigh_put in x25_disconnect, otherwise may cause null-ptr-deref like this: #include <sys/socket.h> #include <linux/x25.h> int main() { int sck_x25; sck_x25 = socket(AF_X25, SOCK_SEQPACKET, 0); close(sck_x25); return 0; } BUG: kernel NULL pointer dereference, address: 00000000000000d8 CPU: 0 PID: 4817 Comm: t2 Not tainted 5.7.0-rc3+ #159 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.9.3- RIP: 0010:x25_disconnect+0x91/0xe0 Call Trace: x25_release+0x18a/0x1b0 __sock_release+0x3d/0xc0 sock_close+0x13/0x20 __fput+0x107/0x270 ____fput+0x9/0x10 task_work_run+0x6d/0xb0 exit_to_usermode_loop+0x102/0x110 do_syscall_64+0x23c/0x260 entry_SYSCALL_64_after_hwframe+0x49/0xb3 Reported-by: syzbot+6db548b615e5aeefdce2@syzkaller.appspotmail.com Fixes: 4becb7ee5b3d ("net/x25: Fix x25_neigh refcnt leak when x25 disconnect") Signed-off-by: YueHaibing <yuehaibing@huawei.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'net')
-rw-r--r--net/x25/x25_subr.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/net/x25/x25_subr.c b/net/x25/x25_subr.c
index d34a874177d5..f3d34582581b 100644
--- a/net/x25/x25_subr.c
+++ b/net/x25/x25_subr.c
@@ -362,10 +362,12 @@ void x25_disconnect(struct sock *sk, int reason, unsigned char cause,
sk->sk_state_change(sk);
sock_set_flag(sk, SOCK_DEAD);
}
- read_lock_bh(&x25_list_lock);
- x25_neigh_put(x25->neighbour);
- x25->neighbour = NULL;
- read_unlock_bh(&x25_list_lock);
+ if (x25->neighbour) {
+ read_lock_bh(&x25_list_lock);
+ x25_neigh_put(x25->neighbour);
+ x25->neighbour = NULL;
+ read_unlock_bh(&x25_list_lock);
+ }
}
/*