android_kernel_motorola_sm6225/net/rxrpc
David Howells 4a3a78b791 rxrpc: Fix listen() setting the bar too high for the prealloc rings
[ Upstream commit 88e22159750b0d55793302eeed8ee603f5c1a95c ]

AF_RXRPC's listen() handler lets you set the backlog up to 32 (if you bump
up the sysctl), but whilst the preallocation circular buffers have 32 slots
in them, one of them has to be a dead slot because we're using CIRC_CNT().

This means that listen(rxrpc_sock, 32) will cause an oops when the socket
is closed because rxrpc_service_prealloc_one() allocated one too many calls
and rxrpc_discard_prealloc() won't then be able to get rid of them because
it'll think the ring is empty.  rxrpc_release_calls_on_socket() then tries
to abort them, but oopses because call->peer isn't yet set.

Fix this by setting the maximum backlog to RXRPC_BACKLOG_MAX - 1 to match
the ring capacity.

 BUG: kernel NULL pointer dereference, address: 0000000000000086
 ...
 RIP: 0010:rxrpc_send_abort_packet+0x73/0x240 [rxrpc]
 Call Trace:
  <TASK>
  ? __wake_up_common_lock+0x7a/0x90
  ? rxrpc_notify_socket+0x8e/0x140 [rxrpc]
  ? rxrpc_abort_call+0x4c/0x60 [rxrpc]
  rxrpc_release_calls_on_socket+0x107/0x1a0 [rxrpc]
  rxrpc_release+0xc9/0x1c0 [rxrpc]
  __sock_release+0x37/0xa0
  sock_close+0x11/0x20
  __fput+0x89/0x240
  task_work_run+0x59/0x90
  do_exit+0x319/0xaa0

Fixes: 00e907127e ("rxrpc: Preallocate peers, conns and calls for incoming service requests")
Reported-by: Marc Dionne <marc.dionne@auristor.com>
Signed-off-by: David Howells <dhowells@redhat.com>
cc: linux-afs@lists.infradead.org
Link: https://lists.infradead.org/pipermail/linux-afs/2022-March/005079.html
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-06-14 16:59:23 +02:00
..
af_rxrpc.c rxrpc: Fix deadlock around release of dst cached on udp tunnel 2021-02-10 09:21:06 +01:00
ar-internal.h
call_accept.c rxrpc: Fix memory leak in rxrpc_lookup_local 2021-02-03 23:23:26 +01:00
call_event.c
call_object.c
conn_client.c
conn_event.c
conn_object.c
conn_service.c
input.c
insecure.c
Kconfig
key.c rxrpc: Fix handling of an unsupported token type in rxrpc_read() 2021-01-23 15:49:56 +01:00
local_event.c
local_object.c
Makefile
misc.c
net_ns.c rxrpc: Restore removed timer deletion 2022-04-27 13:39:42 +02:00
output.c
peer_event.c
peer_object.c rxrpc: Fix rxrpc_local leak in rxrpc_lookup_peer() 2021-12-08 08:50:13 +01:00
proc.c
protocol.h
recvmsg.c
rxkad.c
security.c
sendmsg.c rxrpc: Return an error to sendmsg if call failed 2022-06-14 16:59:17 +02:00
skbuff.c
sysctl.c rxrpc: Fix listen() setting the bar too high for the prealloc rings 2022-06-14 16:59:23 +02:00
utils.c