android_kernel_motorola_sm6225/net/sunrpc
minoura makoto 4916a52341 SUNRPC: ensure the matching upcall is in-flight upon downcall
[ Upstream commit b18cba09e374637a0a3759d856a6bca94c133952 ]

Commit 9130b8dbc6 ("SUNRPC: allow for upcalls for the same uid
but different gss service") introduced `auth` argument to
__gss_find_upcall(), but in gss_pipe_downcall() it was left as NULL
since it (and auth->service) was not (yet) determined.

When multiple upcalls with the same uid and different service are
ongoing, it could happen that __gss_find_upcall(), which returns the
first match found in the pipe->in_downcall list, could not find the
correct gss_msg corresponding to the downcall we are looking for.
Moreover, it might return a msg which is not sent to rpc.gssd yet.

We could see mount.nfs process hung in D state with multiple mount.nfs
are executed in parallel.  The call trace below is of CentOS 7.9
kernel-3.10.0-1160.24.1.el7.x86_64 but we observed the same hang w/
elrepo kernel-ml-6.0.7-1.el7.

PID: 71258  TASK: ffff91ebd4be0000  CPU: 36  COMMAND: "mount.nfs"
 #0 [ffff9203ca3234f8] __schedule at ffffffffa3b8899f
 #1 [ffff9203ca323580] schedule at ffffffffa3b88eb9
 #2 [ffff9203ca323590] gss_cred_init at ffffffffc0355818 [auth_rpcgss]
 #3 [ffff9203ca323658] rpcauth_lookup_credcache at ffffffffc0421ebc
[sunrpc]
 #4 [ffff9203ca3236d8] gss_lookup_cred at ffffffffc0353633 [auth_rpcgss]
 #5 [ffff9203ca3236e8] rpcauth_lookupcred at ffffffffc0421581 [sunrpc]
 #6 [ffff9203ca323740] rpcauth_refreshcred at ffffffffc04223d3 [sunrpc]
 #7 [ffff9203ca3237a0] call_refresh at ffffffffc04103dc [sunrpc]
 #8 [ffff9203ca3237b8] __rpc_execute at ffffffffc041e1c9 [sunrpc]
 #9 [ffff9203ca323820] rpc_execute at ffffffffc0420a48 [sunrpc]

The scenario is like this. Let's say there are two upcalls for
services A and B, A -> B in pipe->in_downcall, B -> A in pipe->pipe.

When rpc.gssd reads pipe to get the upcall msg corresponding to
service B from pipe->pipe and then writes the response, in
gss_pipe_downcall the msg corresponding to service A will be picked
because only uid is used to find the msg and it is before the one for
B in pipe->in_downcall.  And the process waiting for the msg
corresponding to service A will be woken up.

Actual scheduing of that process might be after rpc.gssd processes the
next msg.  In rpc_pipe_generic_upcall it clears msg->errno (for A).
The process is scheduled to see gss_msg->ctx == NULL and
gss_msg->msg.errno == 0, therefore it cannot break the loop in
gss_create_upcall and is never woken up after that.

This patch adds a simple check to ensure that a msg which is not
sent to rpc.gssd yet is not chosen as the matching upcall upon
receiving a downcall.

Signed-off-by: minoura makoto <minoura@valinux.co.jp>
Signed-off-by: Hiroshi Shimamoto <h-shimamoto@nec.com>
Tested-by: Hiroshi Shimamoto <h-shimamoto@nec.com>
Cc: Trond Myklebust <trondmy@hammerspace.com>
Fixes: 9130b8dbc6 ("SUNRPC: allow for upcalls for same uid but different gss service")
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-01-18 11:30:49 +01:00
..
auth_gss SUNRPC: ensure the matching upcall is in-flight upon downcall 2023-01-18 11:30:49 +01:00
xprtrdma xprtrdma: fix incorrect header size calculations 2022-06-25 11:49:18 +02:00
addr.c net: sunrpc: interpret the return value of kstrtou32 correctly 2021-01-19 18:22:38 +01:00
auth.c sunrpc: kstrtoul() can also return -ERANGE 2018-07-31 12:53:40 -04:00
auth_generic.c SUNRPC: Fix a bogus get/put in generic_key_to_expire() 2018-12-01 09:37:33 +01:00
auth_null.c net/sunrpc: Make rpc_auth_create_args a const 2018-07-30 13:19:41 -04:00
auth_unix.c net/sunrpc: Make rpc_auth_create_args a const 2018-07-30 13:19:41 -04:00
backchannel_rqst.c SUNRPC: Reinitialise the backchannel request buffers before reuse 2022-08-25 11:15:37 +02:00
cache.c sunrpc: fix crash when cache_head become valid before update 2019-12-17 20:35:52 +01:00
clnt.c SUNRPC: Fix missing release socket in rpc_sockname() 2023-01-18 11:30:15 +01:00
debugfs.c net: Use octal not symbolic permissions 2018-03-26 12:07:48 -04:00
Kconfig IB: Revert "remove redundant INFINIBAND kconfig dependencies" 2018-05-28 10:40:16 -06:00
Makefile
netns.h
rpc_pipe.c sunrpc: fixed rollback in rpc_gssd_dummy_populate() 2020-06-30 23:17:18 -04:00
rpcb_clnt.c SUNRPC: stop printk reading past end of string 2020-09-23 12:10:58 +02:00
sched.c SUNRPC/call_alloc: async tasks mustn't block waiting for memory 2022-04-15 14:15:03 +02:00
socklib.c
stats.c sunrpc: whitespace fixes 2018-07-31 12:53:40 -04:00
sunrpc.h sunrpc: whitespace fixes 2018-07-31 12:53:40 -04:00
sunrpc_syms.c net: Drop pernet_operations::async 2018-03-27 13:18:09 -04:00
svc.c SUNRPC/nfs: Fix return value for nfs4_callback_compound() 2021-09-22 11:47:47 +02:00
svc_xprt.c NFSD: Repair misuse of sv_lock in 5.10.16-rt30. 2021-03-24 11:07:33 +01:00
svcauth.c
svcauth_unix.c
svcsock.c svcrdma: Fix leak of svc_rdma_recv_ctxt objects 2020-05-02 17:25:52 +02:00
sysctl.c
timer.c
xdr.c SUNRPC: Fix READ_PLUS crasher 2022-07-07 17:35:09 +02:00
xprt.c SUNRPC: use _bh spinlocking on ->transport_lock 2022-09-15 12:17:06 +02:00
xprtmultipath.c
xprtsock.c Revert "SUNRPC: attempt AF_LOCAL connect on setup" 2022-05-12 12:20:24 +02:00