]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
rxrpc: Fix net namespace cleanup
authorDavid Howells <dhowells@redhat.com>
Tue, 30 Apr 2019 07:34:08 +0000 (08:34 +0100)
committerDavid S. Miller <davem@davemloft.net>
Tue, 30 Apr 2019 14:50:50 +0000 (10:50 -0400)
commitb13023421b5179413421333f602850914f6a7ad8
tree83cf6ecb7938b0b73b5d76a960a943a17737d805
parentb145745fc8d15cf9d45a5c7a8f5dbc4862e17cf2
rxrpc: Fix net namespace cleanup

In rxrpc_destroy_all_calls(), there are two phases: (1) make sure the
->calls list is empty, emitting error messages if not, and (2) wait for the
RCU cleanup to happen on outstanding calls (ie. ->nr_calls becomes 0).

To avoid taking the call_lock, the function prechecks ->calls and if empty,
it returns to avoid taking the lock - this is wrong, however: it still
needs to go and do the second phase and wait for ->nr_calls to become 0.

Without this, the rxrpc_net struct may get deallocated before we get to the
RCU cleanup for the last calls.  This can lead to:

  Slab corruption (Not tainted): kmalloc-16k start=ffff88802b178000, len=16384
  050: 6b 6b 6b 6b 6b 6b 6b 6b 61 6b 6b 6b 6b 6b 6b 6b  kkkkkkkkakkkkkkk

Note the "61" at offset 0x58.  This corresponds to the ->nr_calls member of
struct rxrpc_net (which is >9k in size, and thus allocated out of the 16k
slab).

Fix this by flipping the condition on the if-statement, putting the locked
section inside the if-body and dropping the return from there.  The
function will then always go on to wait for the RCU cleanup on outstanding
calls.

Fixes: 2baec2c3f854 ("rxrpc: Support network namespacing")
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/rxrpc/call_object.c