Skip to content

Commit 052a34f

Browse files
Olga Kornievskaiagregkh
Olga Kornievskaia
authored andcommitted
nfsd: fix management of listener transports
commit d093c90 upstream. Currently, when no active threads are running, a root user using nfsdctl command can try to remove a particular listener from the list of previously added ones, then start the server by increasing the number of threads, it leads to the following problem: [ 158.835354] refcount_t: addition on 0; use-after-free. [ 158.835603] WARNING: CPU: 2 PID: 9145 at lib/refcount.c:25 refcount_warn_saturate+0x160/0x1a0 [ 158.836017] Modules linked in: rpcrdma rdma_cm iw_cm ib_cm ib_core nfsd auth_rpcgss nfs_acl lockd grace overlay isofs uinput snd_seq_dummy snd_hrtimer nft_fib_inet nft_fib_ipv4 nft_fib_ipv6 nft_fib nft_reject_inet nf_reject_ipv4 nf_reject_ipv6 nft_reject nft_ct nft_chain_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 rfkill ip_set nf_tables qrtr sunrpc vfat fat uvcvideo videobuf2_vmalloc videobuf2_memops uvc videobuf2_v4l2 videodev videobuf2_common snd_hda_codec_generic mc e1000e snd_hda_intel snd_intel_dspcfg snd_hda_codec snd_hda_core snd_hwdep snd_seq snd_seq_device snd_pcm snd_timer snd soundcore sg loop dm_multipath dm_mod nfnetlink vsock_loopback vmw_vsock_virtio_transport_common vmw_vsock_vmci_transport vmw_vmci vsock xfs libcrc32c crct10dif_ce ghash_ce vmwgfx sha2_ce sha256_arm64 sr_mod sha1_ce cdrom nvme drm_client_lib drm_ttm_helper ttm nvme_core drm_kms_helper nvme_auth drm fuse [ 158.840093] CPU: 2 UID: 0 PID: 9145 Comm: nfsd Kdump: loaded Tainted: G B W 6.13.0-rc6+ #7 [ 158.840624] Tainted: [B]=BAD_PAGE, [W]=WARN [ 158.840802] Hardware name: VMware, Inc. VMware20,1/VBSA, BIOS VMW201.00V.24006586.BA64.2406042154 06/04/2024 [ 158.841220] pstate: 61400005 (nZCv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--) [ 158.841563] pc : refcount_warn_saturate+0x160/0x1a0 [ 158.841780] lr : refcount_warn_saturate+0x160/0x1a0 [ 158.842000] sp : ffff800089be7d80 [ 158.842147] x29: ffff800089be7d80 x28: ffff00008e68c148 x27: ffff00008e68c148 [ 158.842492] x26: ffff0002e3b5c000 x25: ffff600011cd1829 x24: ffff00008653c010 [ 158.842832] x23: ffff00008653c000 x22: 1fffe00011cd1829 x21: ffff00008653c028 [ 158.843175] x20: 0000000000000002 x19: ffff00008653c010 x18: 0000000000000000 [ 158.843505] x17: 0000000000000000 x16: 0000000000000000 x15: 0000000000000000 [ 158.843836] x14: 0000000000000000 x13: 0000000000000001 x12: ffff600050a26493 [ 158.844143] x11: 1fffe00050a26492 x10: ffff600050a26492 x9 : dfff800000000000 [ 158.844475] x8 : 00009fffaf5d9b6e x7 : ffff000285132493 x6 : 0000000000000001 [ 158.844823] x5 : ffff000285132490 x4 : ffff600050a26493 x3 : ffff8000805e72bc [ 158.845174] x2 : 0000000000000000 x1 : 0000000000000000 x0 : ffff000098588000 [ 158.845528] Call trace: [ 158.845658] refcount_warn_saturate+0x160/0x1a0 (P) [ 158.845894] svc_recv+0x58c/0x680 [sunrpc] [ 158.846183] nfsd+0x1fc/0x348 [nfsd] [ 158.846390] kthread+0x274/0x2f8 [ 158.846546] ret_from_fork+0x10/0x20 [ 158.846714] ---[ end trace 0000000000000000 ]--- nfsd_nl_listener_set_doit() would manipulate the list of transports of server's sv_permsocks and close the specified listener but the other list of transports (server's sp_xprts list) would not be changed leading to the problem above. Instead, determined if the nfsdctl is trying to remove a listener, in which case, delete all the existing listener transports and re-create all-but-the-removed ones. Fixes: 16a4711 ("NFSD: add listener-{set,get} netlink command") Signed-off-by: Olga Kornievskaia <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Cc: [email protected] Signed-off-by: Chuck Lever <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 63b91c8 commit 052a34f

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

fs/nfsd/nfsctl.c

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,6 +1959,7 @@ int nfsd_nl_listener_set_doit(struct sk_buff *skb, struct genl_info *info)
19591959
struct svc_serv *serv;
19601960
LIST_HEAD(permsocks);
19611961
struct nfsd_net *nn;
1962+
bool delete = false;
19621963
int err, rem;
19631964

19641965
mutex_lock(&nfsd_mutex);
@@ -2019,34 +2020,28 @@ int nfsd_nl_listener_set_doit(struct sk_buff *skb, struct genl_info *info)
20192020
}
20202021
}
20212022

2022-
/* For now, no removing old sockets while server is running */
2023-
if (serv->sv_nrthreads && !list_empty(&permsocks)) {
2023+
/*
2024+
* If there are listener transports remaining on the permsocks list,
2025+
* it means we were asked to remove a listener.
2026+
*/
2027+
if (!list_empty(&permsocks)) {
20242028
list_splice_init(&permsocks, &serv->sv_permsocks);
2025-
spin_unlock_bh(&serv->sv_lock);
2026-
err = -EBUSY;
2027-
goto out_unlock_mtx;
2029+
delete = true;
20282030
}
2031+
spin_unlock_bh(&serv->sv_lock);
20292032

2030-
/* Close the remaining sockets on the permsocks list */
2031-
while (!list_empty(&permsocks)) {
2032-
xprt = list_first_entry(&permsocks, struct svc_xprt, xpt_list);
2033-
list_move(&xprt->xpt_list, &serv->sv_permsocks);
2034-
2035-
/*
2036-
* Newly-created sockets are born with the BUSY bit set. Clear
2037-
* it if there are no threads, since nothing can pick it up
2038-
* in that case.
2039-
*/
2040-
if (!serv->sv_nrthreads)
2041-
clear_bit(XPT_BUSY, &xprt->xpt_flags);
2042-
2043-
set_bit(XPT_CLOSE, &xprt->xpt_flags);
2044-
spin_unlock_bh(&serv->sv_lock);
2045-
svc_xprt_close(xprt);
2046-
spin_lock_bh(&serv->sv_lock);
2033+
/* Do not remove listeners while there are active threads. */
2034+
if (serv->sv_nrthreads) {
2035+
err = -EBUSY;
2036+
goto out_unlock_mtx;
20472037
}
20482038

2049-
spin_unlock_bh(&serv->sv_lock);
2039+
/*
2040+
* Since we can't delete an arbitrary llist entry, destroy the
2041+
* remaining listeners and recreate the list.
2042+
*/
2043+
if (delete)
2044+
svc_xprt_destroy_all(serv, net);
20502045

20512046
/* walk list of addrs again, open any that still don't exist */
20522047
nlmsg_for_each_attr(attr, info->nlhdr, GENL_HDRLEN, rem) {
@@ -2073,6 +2068,9 @@ int nfsd_nl_listener_set_doit(struct sk_buff *skb, struct genl_info *info)
20732068

20742069
xprt = svc_find_listener(serv, xcl_name, net, sa);
20752070
if (xprt) {
2071+
if (delete)
2072+
WARN_ONCE(1, "Transport type=%s already exists\n",
2073+
xcl_name);
20762074
svc_xprt_put(xprt);
20772075
continue;
20782076
}

0 commit comments

Comments
 (0)