tipc: fix a null pointer deref on error path
Subsystems (3)
PATCH v2 1/1 tipc: fix a null pointer deref on error path
In tipc_topsrv_kern_subscr() when s->tipc_conn_new() fails we call tipc_close_conn() to clean up, but in this case calling conn_put() is just enough.
This fixes the folllowing crash:
kasan: GPF could be caused by NULL-ptr deref or user memory access
general protection fault: 0000 [#1] SMP KASAN
Dumping ftrace buffer:
(ftrace buffer empty)
Modules linked in:
CPU: 0 PID: 3085 Comm: syzkaller064164 Not tainted 4.15.0-rc1+ #137
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
task: 00000000c24413a5 task.stack: 000000005e8160b5
RIP: 0010:__lock_acquire+0xd55/0x47f0 kernel/locking/lockdep.c:3378
RSP: 0018:ffff8801cb5474a8 EFLAGS: 00010002
RAX: dffffc0000000000 RBX: 0000000000000000 RCX: 0000000000000000
RDX: 0000000000000004 RSI: 0000000000000000 RDI: ffffffff85ecb400
RBP: ffff8801cb547830 R08: 0000000000000001 R09: 0000000000000000
R10: 0000000000000000 R11: ffffffff87489d60 R12: ffff8801cd2980c0
R13: 0000000000000000 R14: 0000000000000001 R15: 0000000000000020
FS: 00000000014ee880(0000) GS:ffff8801db400000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007ffee2426e40 CR3: 00000001cb85a000 CR4: 00000000001406f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
lock_acquire+0x1d5/0x580 kernel/locking/lockdep.c:4004
__raw_spin_lock_bh include/linux/spinlock_api_smp.h:135 [inline]
_raw_spin_lock_bh+0x31/0x40 kernel/locking/spinlock.c:175
spin_lock_bh include/linux/spinlock.h:320 [inline]
tipc_subscrb_subscrp_delete+0x8f/0x470 net/tipc/subscr.c:201
tipc_subscrb_delete net/tipc/subscr.c:238 [inline]
tipc_subscrb_release_cb+0x17/0x30 net/tipc/subscr.c:316
tipc_close_conn+0x171/0x270 net/tipc/server.c:204
tipc_topsrv_kern_subscr+0x724/0x810 net/tipc/server.c:514
tipc_group_create+0x702/0x9c0 net/tipc/group.c:184
tipc_sk_join net/tipc/socket.c:2747 [inline]
tipc_setsockopt+0x249/0xc10 net/tipc/socket.c:2861
SYSC_setsockopt net/socket.c:1851 [inline]
SyS_setsockopt+0x189/0x360 net/socket.c:1830
entry_SYSCALL_64_fastpath+0x1f/0x96--- net/tipc/server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/tipc/server.c +1 -1
@@ -511,7 +511,7 @@ bool tipc_topsrv_kern_subscr(struct net *net, u32 port, u32 type, s = con->server; scbr = s->tipc_conn_new (*conid);if (!scbr) { -tipc_close_conn (con); +conn_put (con);return false; }
Signature · 1 line
2.13.0
David Miller
maintainerFrom: Cong Wang <[email protected]>
Date: Mon, 4 Dec 2017 10:31:43 -0800
Quoted 5 lines
In
tipc_topsrv_kern_subscr()whens->tipc_conn_new()fails we calltipc_close_conn()to clean up, but in this case callingconn_put()is just enough.This fixes the folllowing crash:
...
Quoted 5 lines
Fixes 14c04493cb77 ("tipc: add ability to order and receive topology events in driver")Reported-by syzbot <[email protected]>Cc Jon Maloy <[email protected]>Cc Ying Xue <[email protected]>Signed-off-by Cong Wang <[email protected]>
...
Quoted 12 lines
net/tipc/server.c +1
-1@@ -511,7 +511,7 @@ bool tipc_topsrv_kern_subscr(struct net *net, u32 port, u32 type, s = con->server; scbr = s->tipc_conn_new (*conid);if (!scbr) { -tipc_close_conn (con); +conn_put (con);return false; }Signature · 1 line
2.13.0
It looks like tipc_accept_from_sock() has a similar problem? The tipc_close_conn() will get invoked indirectly from the sock_release() path right?
Quoted 24 lines · David Miller
From: Cong Wang <[email protected]>
Date: Mon, 4 Dec 2017 10:31:43 -0800Quoted 5 lines
In
tipc_topsrv_kern_subscr()whens->tipc_conn_new()fails we calltipc_close_conn()to clean up, but in this case callingconn_put()is just enough.This fixes the folllowing crash:
...
Quoted 5 lines
Fixes 14c04493cb77 ("tipc: add ability to order and receive topology events in driver")Reported-by syzbot <[email protected]>Cc Jon Maloy <[email protected]>Cc Ying Xue <[email protected]>Signed-off-by Cong Wang <[email protected]>...
Quoted 9 lines
net/tipc/server.c +1
-1@@ -511,7 +511,7 @@ bool tipc_topsrv_kern_subscr(struct net *net, u32 port, u32 type, s = con->server; scbr = s->tipc_conn_new (*conid);if (!scbr) { -tipc_close_conn (con); +conn_put (con);return false; }
Quoted 7 lines
Quoted 3 lines
--
2.13.0It looks like
tipc_accept_from_sock()has a similar problem? Thetipc_close_conn()will get invoked indirectly from thesock_release()path right?
Not sure, the sock_release() in tipc_accept_from_sock() is for kernel_accept(), not for tipc_alloc_conn(). Or maybe it is hiding deep in the call chain that I miss?
Quoted 9 lines · Cong Wang
Quoted 4 lines · David Miller
It looks like
tipc_accept_from_sock()has a similar problem? Thetipc_close_conn()will get invoked indirectly from thesock_release()path right?Not sure, the
sock_release()intipc_accept_from_sock()is forkernel_accept(), not fortipc_alloc_conn(). Or maybe it is hiding deep in the call chain that I miss?
I see:
tipc_release() -> tipc_sk_leave() -> tipc_group_delete() -> tipc_topsrv_kern_unsubscr() -> tipc_close_conn()
Seems on this path we do need to skip NULL too.
Quoted 37 lines
-----Original Message-----
From: [email protected] [mailto:netdev- [email protected]] On Behalf Of David Miller
Sent: Monday, December 04, 2017 13:57
To: [email protected]
Cc: [email protected]; [email protected]; Jon Maloy <[email protected]>; Ying Xue <[email protected]>
Subject: Re: [Patch net v2] tipc: fix a null pointer deref on error pathFrom: Cong Wang <[email protected]>
Date: Mon, 4 Dec 2017 10:31:43 -0800Quoted 5 lines
In
tipc_topsrv_kern_subscr()whens->tipc_conn_new()fails we calltipc_close_conn()to clean up, but in this case callingconn_put()is just enough.This fixes the folllowing crash:
...
Quoted 6 lines
Fixes 14c04493cb77 ("tipc: add ability to order and receive topologyevents in driver")
Reported-by syzbot <[email protected]>Cc Jon Maloy <[email protected]>Cc Ying Xue <[email protected]>Signed-off-by Cong Wang <[email protected]>...
Review bool tipc_topsrv_kern_subscr(struct net *net, u32
Quoted 1 line
(quoted diff) +0
-0@@ -511,7 +511,7 @@ bool tipc_topsrv_kern_subscr(struct net *net, u32port, u32 type,
Quoted 8 lines
net/tipc/server.c +1
-1s = con->server; scbr = s->tipc_conn_new (*conid);if (!scbr) { -tipc_close_conn (con); +conn_put (con);return false; }
Quoted 7 lines
Quoted 3 lines
--
2.13.0It looks like
tipc_accept_from_sock()has a similar problem? Thetipc_close_conn()will get invoked indirectly from thesock_release()path right?
No, it doesn't. There will be a 'leaked' conn instance which will remain in the reference table until it is flushed during module removal. We'll fix this in a separate patch. Cong's fix is correct.
///jon
David Miller
maintainerFrom: Cong Wang <[email protected]>
Date: Mon, 4 Dec 2017 11:23:13 -0800
Quoted 33 lines · David Miller
Quoted 24 lines
From: Cong Wang <[email protected]>
Date: Mon, 4 Dec 2017 10:31:43 -0800Quoted 5 lines
In
tipc_topsrv_kern_subscr()whens->tipc_conn_new()fails we calltipc_close_conn()to clean up, but in this case callingconn_put()is just enough.This fixes the folllowing crash:
...
Quoted 5 lines
Fixes 14c04493cb77 ("tipc: add ability to order and receive topology events in driver")Reported-by syzbot <[email protected]>Cc Jon Maloy <[email protected]>Cc Ying Xue <[email protected]>Signed-off-by Cong Wang <[email protected]>...
Quoted 9 lines
net/tipc/server.c +1
-1@@ -511,7 +511,7 @@ bool tipc_topsrv_kern_subscr(struct net *net, u32 port, u32 type, s = con->server; scbr = s->tipc_conn_new (*conid);if (!scbr) { -tipc_close_conn (con); +conn_put (con);return false; }Quoted 7 lines
Quoted 3 lines
--
2.13.0It looks like
tipc_accept_from_sock()has a similar problem? Thetipc_close_conn()will get invoked indirectly from thesock_release()path right?
Quoted 3 lines
Not sure, the
sock_release()intipc_accept_from_sock()is forkernel_accept(), not fortipc_alloc_conn(). Or maybe it is hiding deep in the call chain that I miss?
I guess I'm trying to figure out where 'newcon' is released when the call to s->tipc_conn_new() on it fails.
It looks similar to the situation you are fixing here, which is why I am mentioning it.
Quoted 24 lines
-----Original Message-----
From: Cong Wang [mailto:[email protected]]
Sent: Monday, December 04, 2017 14:41
To: David Miller <[email protected]>
Cc: Linux Kernel Network Developers <[email protected]>; tipc- [email protected]; Jon Maloy <[email protected]>; Ying Xue <[email protected]>
Subject: Re: [Patch net v2] tipc: fix a null pointer deref on error pathQuoted 1 line · Cong Wang
On Mon, Dec 4, 2017 at 10:57 AM, David Miller <[email protected]>
Quoted 8 lines · wrote:
Quoted 4 lines
It looks like
tipc_accept_from_sock()has a similar problem? Thetipc_close_conn()will get invoked indirectly from thesock_release()path right?Not sure, the
sock_release()intipc_accept_from_sock()is forkernel_accept(), not fortipc_alloc_conn(). Or maybe it is hiding deep in the call chain that I miss?
Quoted 6 lines
I see:
tipc_release()->tipc_sk_leave()->tipc_group_delete()->tipc_topsrv_kern_unsubscr()->tipc_close_conn()Seems on this path we do need to skip NULL too.
You are right. The right solution is to just call conn_put() twice here.
I already have a patch ready for this, but it is part of a series that needs more review. I should probably post it separately...
///jon
Quoted 43 lines
-----Original Message-----
From: [email protected] [mailto:netdev- [email protected]] On Behalf Of Jon Maloy
Sent: Monday, December 04, 2017 14:50
To: Cong Wang <[email protected]>; David Miller <[email protected]>
Cc: Linux Kernel Network Developers <[email protected]>; tipc- [email protected]; Ying Xue <[email protected]>
Subject: RE: [Patch net v2] tipc: fix a null pointer deref on error pathQuoted 11 lines
-----Original Message-----
From: Cong Wang [mailto:[email protected]]
Sent: Monday, December 04, 2017 14:41
To: David Miller <[email protected]>
Cc: Linux Kernel Network Developers <[email protected]>; tipc- [email protected]; Jon Maloy <[email protected]>; Ying Xue <[email protected]>
Subject: Re: [Patch net v2] tipc: fix a null pointer deref on error pathOn Mon, Dec 4, 2017 at 11:23 AM, Cong Wang
Quoted 17 lines
Quoted 1 line · wrote:
On Mon, Dec 4, 2017 at 10:57 AM, David Miller <[email protected]>
Quoted 8 lines · wrote:
Quoted 4 lines
It looks like
tipc_accept_from_sock()has a similar problem? Thetipc_close_conn()will get invoked indirectly from thesock_release()path right?Not sure, the
sock_release()intipc_accept_from_sock()is forkernel_accept(), not fortipc_alloc_conn(). Or maybe it is hiding deep in the call chain that I miss?I see:
tipc_release()->tipc_sk_leave()->tipc_group_delete()->tipc_topsrv_kern_unsubscr()->tipc_close_conn()
Quoted 6 lines
Quoted 1 line
Seems on this path we do need to skip NULL too.
You are right. The right solution is to just call
conn_put()twice here. I already have a patch ready for this, but it is part of a series that needs more review.
I should probably post it separately...
Well, calling conn_put() twice was ok in my series, but in the current upstream version it is not enough. I will find a different short term solution.
///jon
Quoted 2 lines
///jon
Quoted 9 lines · Jon Maloy
Quoted 5 lines
You are right. The right solution is to just call
conn_put()twice here. I already have a patch ready for this, but it is part of a series that needs more review.
I should probably post it separately...Well, calling
conn_put()twice was ok in my series, but in the current upstream version it is not enough. I will find a different short term solution.
IMHO, for tipc_topsrv_kern_subscr() my v2 patch is more correct, and for tipc_accept_from_sock(), v1 is needed too.
Of course v1 could fix both, but still v2 is better than v1 if we only consider tipc_topsrv_kern_subscr() case. So this depends if we want to consider these 2 paths as 2 cases or 1 case. _I think_ it is better to consider them separately since we already v2 is best fix for tipc_topsrv_kern_subscr(), while still not sure what is the best for tipc_accept_from_sock().
Quoted 19 lines
-----Original Message-----
From: Cong Wang [mailto:[email protected]]
Sent: Monday, December 04, 2017 17:34
To: Jon Maloy <[email protected]>
Cc: David Miller <[email protected]>; Linux Kernel Network Developers <[email protected]>; [email protected]; Ying Xue <[email protected]>
Subject: Re: [Patch net v2] tipc: fix a null pointer deref on error pathQuoted 6 lines · Jon Maloy
Quoted 5 lines
You are right. The right solution is to just call
conn_put()twice here. I already have a patch ready for this, but it is part of a series that needs more review.
I should probably post it separately...
Quoted 7 lines
Quoted 1 line
Well, calling
conn_put()twice was ok in my series, but in the currentupstream version it is not enough.
Quoted 2 lines
I will find a different short term solution.
IMHO, for
tipc_topsrv_kern_subscr()my v2 patch is more correct, and fortipc_accept_from_sock(), v1 is needed too.
Absolutely. I already acked v2, but maybe I wasn't clear enough about that.
What I was referring to above was tipc_kern_unsubscr(), where you also, correctly, identified a problem. That problem is reduced, but not totally eliminated by your v1, so I am ok with that one too for now. We have a fully safe solution for this in the pipe.
Quoted 6 lines
Of course v1 could fix both, but still v2 is better than v1 if we only consider
tipc_topsrv_kern_subscr()case. So this depends if we want to consider these 2 paths as 2 cases or 1 case. _Ithink_it is better to consider them separately since we already v2 is best fix fortipc_topsrv_kern_subscr(), while still not sure what is the best fortipc_accept_from_sock().
The tipc_accept_from_sock() problem is as far as I can see totally analogous to the tipc_kern_subscr() one, and requires the same solution. This is what my patch is providing.
BR
///jon
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
David Miller
maintainerFrom: Cong Wang <[email protected]>
Date: Mon, 4 Dec 2017 10:31:43 -0800
Quoted 5 lines
In
tipc_topsrv_kern_subscr()whens->tipc_conn_new()fails we calltipc_close_conn()to clean up, but in this case callingconn_put()is just enough.This fixes the folllowing crash:
...
Quoted 5 lines
Fixes 14c04493cb77 ("tipc: add ability to order and receive topology events in driver")Reported-by syzbot <[email protected]>Cc Jon Maloy <[email protected]>Cc Ying Xue <[email protected]>Signed-off-by Cong Wang <[email protected]>
Applied and queued up for -stable.