Skip to content

Commit 2bad90e

Browse files
YueHaibinggregkh
YueHaibing
authored andcommitted
net/x25: Fix null-ptr-deref in x25_disconnect
commit 8999dc8 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: [email protected] Fixes: 4becb7e ("net/x25: Fix x25_neigh refcnt leak when x25 disconnect") Signed-off-by: YueHaibing <[email protected]> Signed-off-by: David S. Miller <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 923b981 commit 2bad90e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

net/x25/x25_subr.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,12 @@ void x25_disconnect(struct sock *sk, int reason, unsigned char cause,
363363
x25->neighbour = NULL;
364364
read_unlock_bh(&x25_list_lock);
365365
}
366-
read_lock_bh(&x25_list_lock);
367-
x25_neigh_put(x25->neighbour);
368-
x25->neighbour = NULL;
369-
read_unlock_bh(&x25_list_lock);
366+
if (x25->neighbour) {
367+
read_lock_bh(&x25_list_lock);
368+
x25_neigh_put(x25->neighbour);
369+
x25->neighbour = NULL;
370+
read_unlock_bh(&x25_list_lock);
371+
}
370372
}
371373

372374
/*

0 commit comments

Comments
 (0)