Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fdd36abd authored by David Howells's avatar David Howells Committed by Greg Kroah-Hartman
Browse files

rxrpc: Fix net namespace cleanup



[ Upstream commit b13023421b5179413421333f602850914f6a7ad8 ]

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: 2baec2c3 ("rxrpc: Support network namespacing")
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent a976384b
Loading
Loading
Loading
Loading
+16 −16
Original line number Original line Diff line number Diff line
@@ -701,13 +701,12 @@ void rxrpc_destroy_all_calls(struct rxrpc_net *rxnet)


	_enter("");
	_enter("");


	if (list_empty(&rxnet->calls))
	if (!list_empty(&rxnet->calls)) {
		return;

		write_lock(&rxnet->call_lock);
		write_lock(&rxnet->call_lock);


		while (!list_empty(&rxnet->calls)) {
		while (!list_empty(&rxnet->calls)) {
		call = list_entry(rxnet->calls.next, struct rxrpc_call, link);
			call = list_entry(rxnet->calls.next,
					  struct rxrpc_call, link);
			_debug("Zapping call %p", call);
			_debug("Zapping call %p", call);


			rxrpc_see_call(call);
			rxrpc_see_call(call);
@@ -724,6 +723,7 @@ void rxrpc_destroy_all_calls(struct rxrpc_net *rxnet)
		}
		}


		write_unlock(&rxnet->call_lock);
		write_unlock(&rxnet->call_lock);
	}


	atomic_dec(&rxnet->nr_calls);
	atomic_dec(&rxnet->nr_calls);
	wait_var_event(&rxnet->nr_calls, !atomic_read(&rxnet->nr_calls));
	wait_var_event(&rxnet->nr_calls, !atomic_read(&rxnet->nr_calls));