linux-stable/net/sunrpc
minoura makoto 2ee0be3fa1 SUNRPC: ensure the matching upcall is in-flight upon downcall
[ Upstream commit b18cba09e3 ]

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-12 12:00:29 +01:00
..
auth_gss SUNRPC: ensure the matching upcall is in-flight upon downcall 2023-01-12 12:00:29 +01:00
xprtrdma xprtrdma: Fix regbuf data not freed in rpcrdma_req_create() 2022-12-31 13:26:09 +01:00
Kconfig SUNRPC: remove RC4-HMAC-MD5 support from KerberosV 2020-09-11 14:39:15 +10:00
Makefile sunrpc: Create a sunrpc directory under /sys/kernel/ 2021-07-08 14:03:23 -04:00
addr.c nfsd: don't alloc under spinlock in rpc_parse_scope_id 2021-09-21 17:51:47 -04:00
auth.c NFS client updates for Linux 5.20 2022-08-10 14:04:32 -07:00
auth_null.c
auth_unix.c SUNRPC: Fix unx_lookup_cred() allocation 2022-03-22 15:52:55 -04:00
backchannel_rqst.c NFS client updates for Linux 5.20 2022-08-10 14:04:32 -07:00
cache.c SUNRPC: Cache deferral injection 2022-05-19 12:25:38 -04:00
clnt.c SUNRPC: Fix missing release socket in rpc_sockname() 2022-12-31 13:26:09 +01:00
debugfs.c SUNRPC: Cache deferral injection 2022-05-19 12:25:38 -04:00
fail.h SUNRPC: Cache deferral injection 2022-05-19 12:25:38 -04:00
netns.h
rpc_pipe.c fs: allocate inode by using alloc_inode_sb() 2022-03-22 15:57:03 -07:00
rpcb_clnt.c SUNRPC: Make the rpciod and xprtiod slab allocation modes consistent 2022-03-22 15:52:55 -04:00
sched.c SUNRPC: Fix an RPC/RDMA performance regression 2022-07-10 19:00:53 -04:00
socklib.c SUNRPC: Move the call to xprt_send_pagedata() out of xprt_sock_sendmsg() 2022-04-07 16:20:01 -04:00
socklib.h SUNRPC: Refactor xs_sendpages() 2020-03-16 12:04:33 -04:00
stats.c proc: remove PDE_DATA() completely 2022-01-22 08:33:37 +02:00
sunrpc.h treewide: Replace GPLv2 boilerplate/reference with SPDX - gpl-2.0_149.RULE 2022-06-10 14:51:35 +02:00
sunrpc_syms.c sunrpc: add IDs to multipath 2021-07-08 14:03:23 -04:00
svc.c SUNRPC: Use RMW bitops in single-threaded hot paths 2022-05-23 11:06:29 -04:00
svc_xprt.c SUNRPC: Expand the svc_alloc_arg_err tracepoint 2022-07-29 20:08:56 -04:00
svcauth.c SUNRPC: Teach server to recognize RPC_AUTH_TLS 2022-02-28 10:26:40 -05:00
svcauth_unix.c SUNRPC: Teach server to recognize RPC_AUTH_TLS 2022-02-28 10:26:40 -05:00
svcsock.c NFSD 5.19 Release Notes 2022-05-26 20:52:24 -07:00
sysctl.c net/sunrpc: fix useless comparison in proc_do_xprt() 2020-11-08 16:28:25 -05:00
sysfs.c SUNRPC: Fix null-ptr-deref when xps sysfs alloc failed 2022-11-10 18:17:15 +01:00
sysfs.h SUNRPC: take a xprt offline using sysfs 2021-07-08 14:03:24 -04:00
timer.c
xdr.c SUNRPC: Remove xdr_align_data() and xdr_expand_hole() 2022-07-23 15:38:29 -04:00
xprt.c SUNRPC: Fix call completion races with call_decode() 2022-09-01 10:40:37 -04:00
xprtmultipath.c SUNRPC export xprt_iter_rewind function 2022-07-25 10:06:04 -04:00
xprtsock.c SUNRPC: Don't reuse bvec on retransmission of the request 2022-07-27 16:26:17 -04:00