From nobody Sat Sep 26 23:02:48 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24487377558; Fri, 28 Aug 2026 16:37:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787935068; cv=none; b=nfpkRzvLdBegLCFxKipOvz5ceMONV8fEdM+Kamzt+rsPA+yNeJ1IdUTZn2y60kP4lMKWohpTRwiyKbTow4iyfTw5EWjGvTr39lQ63cWVIn9mA+oRMtnxeEqnik9V31PzEm/WuN+Y44Kfx3Rcw6IGYFIQncxsiRgZZ9CUtme+QVw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787935068; c=relaxed/simple; bh=tRmgxww+rxzTihIU6XxzVA4+qqOxvEdXskaEQAJ+8Pg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Cvf33Y7fVQm8Vj4x2NTA8W5xZeiDOvvbT3gitREpXblXrbM5+22zoydLfbGe/ZN6m4zflPiMObjsm28El56h3Z81eTbgYhMvvXKXVOZz7gs7nrT5pormwKTSUuRJ1J5HNFSWCJ69PUiTlv8uZfUmd1sfVW+g0Gnap9B6hF/KQQA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Pj9R9azD; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Pj9R9azD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BCF71F00A3D; Fri, 28 Aug 2026 16:37:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787935066; bh=pL3XeMVN1EzXKRu842hzSRvAUH5WEX0PtRHjn0sU1pg=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=Pj9R9azDTzzrP1KJrFA+4ykbFdhQEbvuz4ipsqHyMrKeCKat6BY1Ko8osRoItyigo 1UH3aDIm4et/dfMwWVOcOI+k1O6/zCKfZFt8y4sXcdNX+KVAUQgy7yPMyrOFLhcWv1 g7JKdAkihnOKR6ShG6RQ24EnDL/nLHh+LUy5tFzGyFdAGHctZz3UF2qFqqfNqx55t6 y+0w9HAvfUTeB4ZhjDE/M5Tc2BVPRtI7eV+Oq7g+1QKSQAE2V46i84IhNVCCAPfaOH NSY+AzHgZXzd5M49cGEqR+ZYclEoH1cMXXh5Gi/Gu6olkxYKoA2HjRMDQ4v+Jqnc+g IWd/h7k8kECIg== From: Jeff Layton Date: Fri, 28 Aug 2026 12:37:31 -0400 Subject: [PATCH v3 01/14] NFSD: cap the number of listeners accepted in listener_set Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260828-nfsd-nl-hang-v3-1-55026685c75d@kernel.org> References: <20260828-nfsd-nl-hang-v3-0-55026685c75d@kernel.org> In-Reply-To: <20260828-nfsd-nl-hang-v3-0-55026685c75d@kernel.org> To: Chuck Lever , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: Slawomir Stepien , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Trond Myklebust , linux-kselftest@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2930; i=jlayton@kernel.org; h=from:subject:message-id; bh=tRmgxww+rxzTihIU6XxzVA4+qqOxvEdXskaEQAJ+8Pg=; b=owEBbQKS/ZANAwAKAQAOaEEZVoIVAcsmYgBqkblUIzSNyeqZzNscZsInYOUudHQlI9k7WbpIG xf3hhfVlXeJAjMEAAEKAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCapG5VAAKCRAADmhBGVaC FcEFEADGCBfjmy6pZYyI30IPfmkHH+JOExxOC0g+EbyXlPslIWziP9VyYoSRa7V5Ip7QYZWTlOG dhWEBC+UeOqc/hCz90emMCNrfdmzaYUrAo6kMzIi6pGO0Q1ChPONyZsZWh7ZSbD+Q302hUfasPE OCfnmxKvezEykNZs1foKiaVgAoWB47eTr7gY82v/RhYoGgJ2GgkPh0HAZ9Gaql2255UHQUIVs1n 0wWp6uhYbKj5lXwPhBSGGQ4S3OMUmuc8r9LpEpxa/HzrZUR8jOZbjubLqTcyfV7qUhXrHSWPmp4 OcHSL1xqW2Nab3wOFZvBMp1t62RGsO9iXQWFQ/jhy/3gOzuW/D1dOShEbdSeYBDu+pYcucrKx4q oTthHJELzgVCIWAsxBrxdT5ZyptqLBtIQae3A2+X6OV0WpLwARMfjVbEmJ6qKfXJdrt2aaC0DxN pPHxutz424I8mMB81crrt0tkoQKuPJYf/qlpGZPhQXZOEvQrM0NxCyQAH6BDCwQwqZ8G1bML1yC WYVR5+8FrLeAbkZnbmYqjsCgGqgHc9sCLkxmqUNiXvKSeGsdOMFMCiXWbzjW31N2SHXkHtpYeB1 kIgpVK04D27lcOxO0wBA7cRMbg2rzhZr+Zpx02RGe44G/0W6Wz8sraZ/zrxZYmqJOWOfunMw/qC NZM62MZ30YkdBIg== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 nfsd_nl_listener_set_doit() matches each requested listener against the existing set. The nested loop that does this is O(N * M), where N is the requested count and M is the existing count. The loop runs under sv_lock with bottom halves disabled. A userland request with a very large listener list can therefore spin in atomic context for a long time. Reject a request that carries more than NFSD_NL_LISTENER_MAX (1024) entries. The check goes in nfsd_nl_validate_listeners(), before the code takes any lock. The limit is far above any realistic configuration. This patch does not cap M. Only the message size bounded N; real sockets bound M. A listener_set result set is the requested set, so that path also holds M at the cap, but __write_ports_addxprt() adds two listeners per call and removes none, so repeated calls can push M past it. The worst case under sv_lock is therefore 1024 * M, plus 1024 nla_parse_nested() calls. Both interfaces require CAP_NET_ADMIN. Fixes: 16a471177496 ("NFSD: add listener-{set,get} netlink command") Assisted-by: LLM Signed-off-by: Jeff Layton --- fs/nfsd/nfsctl.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c index 5331b89c4281..b6f4d66f612a 100644 --- a/fs/nfsd/nfsctl.c +++ b/fs/nfsd/nfsctl.c @@ -1995,21 +1995,22 @@ int nfsd_nl_version_get_doit(struct sk_buff *skb, s= truct genl_info *info) return err; } =20 +/* Upper bound on the number of listeners a single request may carry. */ +#define NFSD_NL_LISTENER_MAX 1024 + /** * nfsd_nl_validate_listeners - sanity-check the listener list from userla= nd * @info: netlink metadata and command arguments * - * Walk every NFSD_A_SERVER_SOCK_ADDR attribute and confirm that each entry - * is well-formed: it parses against the policy, carries both an address a= nd - * a transport name, and the address is long enough for its family. Doing - * this up front lets the callers below assume every entry is valid and - * guarantees we make no changes when the request is malformed. + * Walk every NFSD_A_SERVER_SOCK_ADDR attribute and confirm that the list = is + * not oversized and that each entry is well-formed. * * Return: 0 if every entry is valid, or a negative errno otherwise. */ static int nfsd_nl_validate_listeners(struct genl_info *info) { const struct nlattr *attr; + unsigned int count =3D 0; int rem; =20 nlmsg_for_each_attr_type(attr, NFSD_A_SERVER_SOCK_ADDR, info->nlhdr, @@ -2018,6 +2019,11 @@ static int nfsd_nl_validate_listeners(struct genl_in= fo *info) struct sockaddr *sa; int err; =20 + if (++count > NFSD_NL_LISTENER_MAX) { + NL_SET_ERR_MSG(info->extack, "too many listeners"); + return -E2BIG; + } + err =3D nla_parse_nested(tb, NFSD_A_SOCK_MAX, attr, nfsd_sock_nl_policy, info->extack); if (err < 0) --=20 2.55.0 From nobody Sat Sep 26 23:02:48 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 218903932FA; Fri, 28 Aug 2026 16:37:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787935070; cv=none; b=o2H5sxyeucw6ywcffOLB0lWZTimB3Dh6RT/A8fNdkH3i92JNTtzSlpcjD+m7ZestVNxH5YELSI8ll9nJYBHkjbv1btWIk+QyZgYNgYKPjHQJ0thYtpwxRZxBdC/JHov7zZAthQOvVXLhxNeiFEvcxYFAxdc7IdLXmY4QAfmDJhk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787935070; c=relaxed/simple; bh=aJetiop332TzGMjtNxCwp2osCzOlN1SMdSvmKASa+aI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Uy4GjlaN2WUHJoSRbhhOuHX2cp43Zvv3BYU735LgTkWvnjEyJ/A8XhcnFJRPti6bsz+jOLrWj0VfV1SND1bE11C+PgMkVUq+TTTH91yPTGYTg/niUw1rZB+CTJ6sMJnLf9hk5lHZMvNEeN+wq0QBx29r5D3FXm8bt6WGKqBigAA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ljUOfsfA; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ljUOfsfA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F25581F000E9; Fri, 28 Aug 2026 16:37:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787935068; bh=f7DIO5UFdyzmop+0FickQyJR+upbMPxvd7WYzoH5UvM=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=ljUOfsfAfBRR6ZCVhGU5c88WgatmyOwaDNfeGJh3Rkn8RjINg51BC001MuqwgrmEe qW9sEjUi72nO4ilolSkXv2LF/SNnkxuq1iWfPrX43HYLZHtquPXrYR/4nry1glZAw/ 426BdCqnLpk25gISMdfQYgSftqIm3R6CJagLe9Rn5QSmKxMCxrRtLcRwzIetBSui70 +jlLTADB7YJmSRLxeBowyPgTBrxFkFXEwDqbX2Pvq7fjtlMO1UKQ760STEcFtIrOco 1ki5XjiI/6JHUU7X0pog/p5XayzhPqY1yjEjypAsQxGIXyrAh+lK9dEY/cwopvlWm4 2lswT4lknaFwg== From: Jeff Layton Date: Fri, 28 Aug 2026 12:37:32 -0400 Subject: [PATCH v3 02/14] NFSD: validate transport name in listener_set before serv creation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260828-nfsd-nl-hang-v3-2-55026685c75d@kernel.org> References: <20260828-nfsd-nl-hang-v3-0-55026685c75d@kernel.org> In-Reply-To: <20260828-nfsd-nl-hang-v3-0-55026685c75d@kernel.org> To: Chuck Lever , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: Slawomir Stepien , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Trond Myklebust , linux-kselftest@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2761; i=jlayton@kernel.org; h=from:subject:message-id; bh=aJetiop332TzGMjtNxCwp2osCzOlN1SMdSvmKASa+aI=; b=owEBbQKS/ZANAwAKAQAOaEEZVoIVAcsmYgBqkblU7ipDBR9hOHCBw4J3hHZKeSediS87zPMNB ECizBuP8r6JAjMEAAEKAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCapG5VAAKCRAADmhBGVaC FfUYEADUjJjbSWHOdtHJlppRBlsFrh+hg7vLLU5wqjzVhOgWcKenRqsfmwHGoiOEcPNMN+socBH AGqy5C5eWvwBeqNUZyMLkJTvxGSavUR8O1eEtj/NA5ybsOGCHebwhW2aRAw2QxzXJcHU2lq9ikr 6GasDNLUQ9zV6RpsnEGM8K72NCopXM6DUQvseiHftBEHg+2X0TLLiQJTeC9AiRHd5FVJnPPElYb lxxPqfiAsI1Mgv8I+V376PM9wMvlvyOJ7e70ff17MVg76qQWh9VNmIjZtxOUJvzkC8tnhZSjC1N jzvh7HhbHbPiLW3If1WBwr4m3FGSaLZCkvpEcjqE0BxhKn72316C3isJ692w6ML5aihvNSQd5yG gIiEzMvhAlcPCptimNat07I8XrD3u0pMAbszstnw8IgoCsgI00380osrEUCxlC1DguyrhptPAGY TEtYyb3N1IA3zTsXTzPQthCmGfCxZzbrfeDaKVN8J8Tu7UlXyttSxou8R8CqwzVpWsOa/3gqAks bRp9FyQ4D3FvEXKDX3O9l4SzOQl/oxeFDl6FkWV5CE6qUYfdyKc3Z/PgLrNN8MEiolscqI4xOLz dbS+0BlGierXWEaLCsODvpNSNXGHkO6Tq0W4ag4m3my2mLY7ClV6eHe5wjHtgVpMeCUrqr+QEyW Daonu5qrlLmWVtw== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 nfsd_nl_listener_set_doit() holds nfsd_mutex for the whole listener teardown and rebuild. The code checks NFSD_A_SOCK_TRANSPORT_NAME for presence only, and not for content. An arbitrary name therefore reaches svc_xprt_create_from_sa(). There, a name that matches no registered class calls request_module("svc%s", name). That call is a TASK_KILLABLE usermode helper upcall, and it runs under nfsd_mutex. Check the name against the classes that NFSD can create: tcp, udp and rdma. The check goes in nfsd_nl_validate_listeners(), which runs before the code takes nfsd_mutex. The rejection names the offending attribute through extack, since -EPROTONOSUPPORT on its own does not say which entry carried the bad name. This narrows the upcall. It does not remove it. NFSD accepts "rdma" without a condition, so on a kernel that does not build svcrdma the name still reaches request_module("svcrdma") under nfsd_mutex. That is necessary for the modular case, where the autoload is legitimate. Fixes: 16a471177496 ("NFSD: add listener-{set,get} netlink command") Assisted-by: LLM Link: https://syzkaller.appspot.com/bug?extid=3Dc7eae0eb80858a2dba0f Signed-off-by: Jeff Layton --- fs/nfsd/nfsctl.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c index b6f4d66f612a..d8135f38e69f 100644 --- a/fs/nfsd/nfsctl.c +++ b/fs/nfsd/nfsctl.c @@ -1995,6 +1995,23 @@ int nfsd_nl_version_get_doit(struct sk_buff *skb, st= ruct genl_info *info) return err; } =20 +/* + * Transport classes NFSD knows how to instantiate. Vetting the name here + * keeps a bogus string from reaching svc_xprt_create_from_sa(), where an + * unknown name triggers a request_module("svc%s", name) upcall under + * nfsd_mutex. + */ +static bool nfsd_nl_transport_supported(const char *name) +{ + static const char * const supported[] =3D { "tcp", "udp", "rdma" }; + int i; + + for (i =3D 0; i < ARRAY_SIZE(supported); i++) + if (!strcmp(name, supported[i])) + return true; + return false; +} + /* Upper bound on the number of listeners a single request may carry. */ #define NFSD_NL_LISTENER_MAX 1024 =20 @@ -2032,6 +2049,13 @@ static int nfsd_nl_validate_listeners(struct genl_in= fo *info) if (!tb[NFSD_A_SOCK_ADDR] || !tb[NFSD_A_SOCK_TRANSPORT_NAME]) return -EINVAL; =20 + if (!nfsd_nl_transport_supported(nla_data(tb[NFSD_A_SOCK_TRANSPORT_NAME]= ))) { + NL_SET_ERR_MSG_ATTR(info->extack, + tb[NFSD_A_SOCK_TRANSPORT_NAME], + "unsupported transport name"); + return -EPROTONOSUPPORT; + } + sa =3D nla_data(tb[NFSD_A_SOCK_ADDR]); if (nla_len(tb[NFSD_A_SOCK_ADDR]) < sizeof(sa->sa_family)) return -EINVAL; --=20 2.55.0 From nobody Sat Sep 26 23:02:48 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82AC338DC52; Fri, 28 Aug 2026 16:37:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787935071; cv=none; b=P450CogYyNLCHuMbDUXlddzDWdW5jP0SIKvIidr0jd2wpMOdhMJ32mI/7E42kePs/I7CaXFtzlDQaBqNP79T16kDusFYwMSoTgldL6fByTbdE+DtmITQ6S1ljotFgkXjYokpsaTjbGMBU+Z7qaTQRddvdmCDgDn2gx9fk6G14wU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787935071; c=relaxed/simple; bh=0/b63pHsH99q59pHXxgWpdCiis0fT0wFTjXendozs0s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ltxpDxMQ9xUQlDTD6njjjrLt/EPlCEsDl6uiSsU0bLHedtVFNIH3LDwhDZ8Xxl28KE4OEtnKJS1Ptrg5BwB7O1X7OF4/0EyB4ivYmJLlsHllKwzI9Y7UWFIvZ73uxsw0PA9HYuXVFAeVxxosSuUWNftaWqozbb2CJTSKttCheKQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EecOYMky; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EecOYMky" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4B901F00A3D; Fri, 28 Aug 2026 16:37:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787935070; bh=yBYuY0qF5cKQRzExECF4YXQMQy4ClFSSmJFRGPrU+CQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=EecOYMky7iDMtCaMk7yWVpPRVh9hVl5RaRI/k0GZTuFPqAIiOMBwp+D4lVlQAIcqu QhIW798nX9/sKvoJZWdAFzvNoIRvQMpIvSC2DSQgrrptF85g7yRFke8iJoYJAt5H82 HOvYphUN3Py2kDE7thUDTd/IWzBoIJe+Fqwrar9RxyPcPoKMcY1DeEgCGonzWudvMc lxpaCNu9t/XjRXhNPvJaOIII9/r6IW8hJCSJX+8B7lxQfWCFf1adOpjRTDuLpEkODm LC4mwsWTRarSrDIHGDGd2aMRblWGz4auauvwID3wQQQXWiDDEUZaHCPzgSi1NgNAIs X0VYfUkF+U9Vw== From: Jeff Layton Date: Fri, 28 Aug 2026 12:37:33 -0400 Subject: [PATCH v3 03/14] SUNRPC: keep the first error in svc_register() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260828-nfsd-nl-hang-v3-3-55026685c75d@kernel.org> References: <20260828-nfsd-nl-hang-v3-0-55026685c75d@kernel.org> In-Reply-To: <20260828-nfsd-nl-hang-v3-0-55026685c75d@kernel.org> To: Chuck Lever , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: Slawomir Stepien , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Trond Myklebust , linux-kselftest@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1206; i=jlayton@kernel.org; h=from:subject:message-id; bh=0/b63pHsH99q59pHXxgWpdCiis0fT0wFTjXendozs0s=; b=owEBbQKS/ZANAwAKAQAOaEEZVoIVAcsmYgBqkblUvEmFdS94dVuTXCNOUtAs56USDL2OGxbpe /64bYD1kBuJAjMEAAEKAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCapG5VAAKCRAADmhBGVaC FWgYEACccaQGhvRELt+7BtoJgnHmtUHra93CFjuqhYVs8DWbI3nU0wCJGUOMcKmN1iSVj0vh+xZ saVsWWaykCacCxZb6HcBfmXiUzsNnq6G9RbRk6bjdbIsiGlZutrxJSBi0+aXxilcU9cQPTYvZo7 ZYo93zcQm5JD8GH5fOssixKhO78GEUz82VS75mTBp9CBvywCdbPva9dqevIF9C10BqHN/080wJK /gHFjqRQAgn8jc9Km6hKRcqxIx5vx5u7WfJRThOlfpFTNWs/7wLqxEytXoK/DhwbJSFvet5IoGz cNsin/UrUwsZUKd6nyZYfGwMNk9aExQc+GvkDM2Wu/rl9vcbmFNbBJtTOb8pfQoh9Y/iR8ThjMY X8upl5R3VSFxJlG2ofxJ4riZiiwDyNcfUGzdu1BCiRSA0XZqtOWpEqQP9WIYAYoVbZuk8Iuc9oa nAXn9RV08W2Ks6k3pqp1tSv/lX21lZxMyYPbVv4dsVOnQM4zh+ZSkKjUEhQ4vi9qwxO6hucqdnc qZhtP+4ULhnI/YnSwDXGVsVw+nefxHn1McB16PlLkyTTISjPXJD89Rf9pfrT0oEBLjTtJOhu/d7 Csd6SRBf6geWb++VmfEhKNLuqQ3rwLP2vKWiP7gg2HJNDgHOVAC8Bkc4cArHAOSLiOalDuWmyq2 nKeKumSP7QhelPA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 svc_register() assigns every pg_rpcbind_set() result to the same "error" variable and returns the last one, so a later result erases an earlier failure. Keep the first error instead of the last. Fixes: 642ee6b209c2 ("SUNRPC: Allow further customisation of RPC program re= gistration") Assisted-by: LLM Signed-off-by: Jeff Layton --- net/sunrpc/svc.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c index 8297bad2b177..4f402bbf97ba 100644 --- a/net/sunrpc/svc.c +++ b/net/sunrpc/svc.c @@ -1208,13 +1208,16 @@ int svc_register(const struct svc_serv *serv, struc= t net *net, struct svc_program *progp =3D &serv->sv_programs[p]; =20 for (i =3D 0; i < progp->pg_nvers; i++) { + int ret; =20 - error =3D progp->pg_rpcbind_set(net, progp, i, + ret =3D progp->pg_rpcbind_set(net, progp, i, family, proto, port); - if (error < 0) { + if (ret < 0) { printk(KERN_WARNING "svc: failed to register " "%sv%u RPC service (errno %d).\n", - progp->pg_name, i, -error); + progp->pg_name, i, -ret); + if (!error) + error =3D ret; break; } } --=20 2.55.0 From nobody Sat Sep 26 23:02:48 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3365C3A901C; Fri, 28 Aug 2026 16:37:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787935073; cv=none; b=XPto/b1i7AZMrYYxVCr2C6CU9hMZc2Z3Y52JdjBp2R/zlDJqzRMEQiCZz4bm7mtUmioUKsBGrBaZRFbJ9z6698GUkqYkDY426cMosKVjqMXaH2IXARbW7fS12ZaIG0U76FOe23YanvcXU7WCStuRNxfhFOo1sXKUBbXLcsNSfZw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787935073; c=relaxed/simple; bh=hTif5dKJuoIIsVz4dAaSFnhZxibEnCpGcJ3SqDcakyA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Kgv4uVVj9U5fmnP8EFo08L26BHwjjlu5vLeTMKtd87tmH+o0lYmoiXotTvWrfAdA2YuSC9Dv8l5HEtjrsNLUneyD42J63wIIKVNzITessrB9Pz+07ZyL8IxYPyYhjqMycKH0MSxplYhaxcCphNF5LVaJ+5MS1+PRmEOitn0yVnk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kulLswQ1; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kulLswQ1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56B1A1F00AC4; Fri, 28 Aug 2026 16:37:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787935071; bh=NJ+06JLg+zozGY40HFLsiWKPGrZUTJWkSToQO3R8seU=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=kulLswQ1HCI+8UWo+7s+WEpdrQFJd2KELh0d4kHhzJWttyrzbQAjrMq1SIU9yAUPY p31W6akUg002vmgc5Bu8K2ZWiQt0vOwL1b9d5U9CGk2ZR8AVbWBqn0v+rXTOY5xVPq e9l4XWZ5FACSwWSXzptyeTOYbFlsH7rWGpWTZMFxzjEREcD2FNylf2ZHcrZpbyi7QF Snj4G0zsqsNuHkX/OKH3fd2f6tksV0fC7aUG26f2EOfaAoAtcyMhiEw2jgcCxOlY4k nQV4cYbSnCquV3qoWOqHofU4u2iisKOzG+wUhmWOXkf1mIqm/TwrkJIE1/mGio8tCX vI23FMB+E3VPw== From: Jeff Layton Date: Fri, 28 Aug 2026 12:37:34 -0400 Subject: [PATCH v3 04/14] SUNRPC: bound the local rpcbind client timeout to 1s Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260828-nfsd-nl-hang-v3-4-55026685c75d@kernel.org> References: <20260828-nfsd-nl-hang-v3-0-55026685c75d@kernel.org> In-Reply-To: <20260828-nfsd-nl-hang-v3-0-55026685c75d@kernel.org> To: Chuck Lever , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: Slawomir Stepien , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Trond Myklebust , linux-kselftest@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2890; i=jlayton@kernel.org; h=from:subject:message-id; bh=hTif5dKJuoIIsVz4dAaSFnhZxibEnCpGcJ3SqDcakyA=; b=owEBbQKS/ZANAwAKAQAOaEEZVoIVAcsmYgBqkblUHDqjYv6PZAnEvjHX5MjO5HoX569RBOwNl niJVzhrF16JAjMEAAEKAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCapG5VAAKCRAADmhBGVaC FUZRD/wPBHnDAJHVFDaJhF9bpYcgtqHGvbsHw/7LH8H+B+HyqlMDV8osflcyINFKskP9+LR+/Za XPKowz9396b4DiNFHd/CVpvjWC3QdpXJaV8kvzAQMOHvvOAIZLATS2so9JIzL3abAogwXOyfff3 xx0ak/2TXRfhP4jihSAAE7Jovch8LTO1Od8giK9wZk81kuK1clMBrOE3rt8fisD2Ju4kHAYJsB+ ovgrQm+mVFQoMzAAB95AyM0u2ieaPocJs0vTkDicFtrEEUnDbqLecM8z/mEKT/LN2PKwuM1DoIL Ytj2KWCO0U1lflPRxiG9yH4D5pXFaFbH64oe2uUaJ8pk8lYL/S9+j1lYEJyfxQ0PJpU7l2+Mo9Q ScWkOFCIlz5Yg1s2JQ7MRK8IEpL4nMf9hKGZdkgavzEVql/SY6IVBKX/vT1t0tIoHpGQMoSOxsQ +90cYkztof7gWvfr9xoxQkn7RFI7hwfCvxOl7vX/j6RT3Ml26KYfesRUo+BrtN2YM/5mhbnzYZ9 tReyiYDweUa8f3rOQJuqfYAG+YsQt7D2YYuiVLBXoSQ2FzxY5Fm81vG0M9Gv3b2PHmByp7d5/at 2o6CZ3dRLttQ9xp1Xw3Klz9yHG91g4gHnRi2ljxDxN6Vy4mbhhq0Un6w6LEqQdRAg9mATMedXFE 6YbdHWSa57BCxYQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 The kernel's local rpcbind client uses the transport defaults: a 10s major timeout for AF_LOCAL, and 60s for the loopback TCP fallback. xprt_calc_majortimeo() returns to_initval when to_increment is 0. Those calls are synchronous, and they run under nfsd_mutex. One operation makes several of them. rpcb_create_local() tries up to three client creations, and svc_register() sends one call for each program and version. A local rpcbind that accepts the connection but never replies stalls every one of these calls. The accumulated hold is long enough to trip the hung-task watchdog on other NFSD netlink operations. The holder itself waits killably and escapes the watchdog: INFO: task hung in nfsd_nl_cache_flush_doit The local rpcbind is on loopback or on an AF_LOCAL socket, and it answers in microseconds. Bound its client to one attempt of 1s. This shortens the stall. It does not remove the stall, and it is not free. Registration stays synchronous and stays fatal. An rpcb_create_local() failure aborts nfsd_create_serv() through svc_bind(), and an svc_register() failure makes svc_setup_socket() fail. An rpcbind that is merely slow to be scheduled can therefore now fail server startup, where it succeeded before. The real fix is to make the registration asynchronous. Assisted-by: LLM Link: https://syzkaller.appspot.com/bug?extid=3Dc7eae0eb80858a2dba0f Signed-off-by: Jeff Layton --- net/sunrpc/rpcb_clnt.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/net/sunrpc/rpcb_clnt.c b/net/sunrpc/rpcb_clnt.c index 6aa372188c86..0aa376b82a52 100644 --- a/net/sunrpc/rpcb_clnt.c +++ b/net/sunrpc/rpcb_clnt.c @@ -221,6 +221,16 @@ static void rpcb_set_local(struct net *net, struct rpc= _clnt *clnt, # define SUN_LEN(ptr) (offsetof(struct sockaddr_un, sun_path) \ + 1 + strlen((ptr)->sun_path + 1)) =20 +/* + * The kernel's rpcbind client talks only to the local rpcbind, over loopb= ack + * or a local AF_LOCAL socket, where a healthy rpcbind answers in microsec= onds. + */ +static const struct rpc_timeout rpcb_local_timeout =3D { + .to_initval =3D 1 * HZ, + .to_maxval =3D 1 * HZ, + .to_retries =3D 0, +}; + /* * Returns zero on success, otherwise a negative errno value * is returned. @@ -238,6 +248,7 @@ static int rpcb_create_af_local(struct net *net, .version =3D RPCBVERS_2, .authflavor =3D RPC_AUTH_NULL, .cred =3D current_cred(), + .timeout =3D &rpcb_local_timeout, /* * We turn off the idle timeout to prevent the kernel * from automatically disconnecting the socket. @@ -312,6 +323,7 @@ static int rpcb_create_local_net(struct net *net) .version =3D RPCBVERS_2, .authflavor =3D RPC_AUTH_UNIX, .cred =3D current_cred(), + .timeout =3D &rpcb_local_timeout, .flags =3D RPC_CLNT_CREATE_NOPING, }; struct rpc_clnt *clnt, *clnt4; --=20 2.55.0 From nobody Sat Sep 26 23:02:48 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8ED6B3B389E; Fri, 28 Aug 2026 16:37:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787935074; cv=none; b=oIdXUUwZR5BY40r/7UyGzvGQGb8TP56noXtl8lX2FxT0AycXzkW6aeYpol0Wo/xqSLQdfqFkzOwNz0hR8nOuhbFETz8pus/AVChtalptTR1aYMsEJapgFSFJAz3AaOMFW25Gh0qrIU3Nq8x8rEpB+AUrB0pihNOm6ZGZGNt8dWw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787935074; c=relaxed/simple; bh=V+wvIGsJlzSDNv4WKj3Vpj9Bw7A+dysnBkXbj7sTYeg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ll2F40t4+rBt9sSallnG/kBfTIJPcof9FUH/yDhy6qDvK44rBvKBBIxNXUmDpaH2nNGMIpprnvVKXR2OOwzFjjapqSNJqRNOF6luLNJfp8DhSWp9oWQTiLOzYZNSxzXim+haKuE57KRym9SSpNwHujM89RN5CwaAbG9dCPj+IAI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DVOOwJxE; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DVOOwJxE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08B061F000E9; Fri, 28 Aug 2026 16:37:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787935073; bh=dtpz+uXivVuZd9+O4vrtoCG96NBwe0+gdme3nSBwjT8=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=DVOOwJxEwPyPFVNHqFo6WPJc7doWCYfTuPiVsoN07toqemsRdr5C+5bS7Nfke5W+D nIgx1aqFPgcDc/Z7LlmoQzW3WzrHC5V4ErwgNb9jsoduqoEk5hErUwmZv1hksHJDga m+BBzv/qxd3hrZT18203L2ng6aHi0uzejChAxdqsnuGhQyKoExpzKbVu9KRfieIh5T AJGTqeWwiDurepdmk0tWZIvDXrLHshOaT96bZyGvCoNa6dvvZcCxxNxwu6Y+8yFKTr g7FHEZPp9kzshSB23SN9H984vivLiylGTvgdfzwE4Gqtsg+Ng7cw9sTIrhXiE1nkVW buY9lM3pB6Hyw== From: Jeff Layton Date: Fri, 28 Aug 2026 12:37:35 -0400 Subject: [PATCH v3 05/14] NFSD: report listener creation failures through extack Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260828-nfsd-nl-hang-v3-5-55026685c75d@kernel.org> References: <20260828-nfsd-nl-hang-v3-0-55026685c75d@kernel.org> In-Reply-To: <20260828-nfsd-nl-hang-v3-0-55026685c75d@kernel.org> To: Chuck Lever , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: Slawomir Stepien , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Trond Myklebust , linux-kselftest@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2186; i=jlayton@kernel.org; h=from:subject:message-id; bh=V+wvIGsJlzSDNv4WKj3Vpj9Bw7A+dysnBkXbj7sTYeg=; b=kA0DAAoBAA5oQRlWghUByyZiAGqRuVXIkhKLjoVK2Xf8t97Nob429skz7qEVJf+VzuQ/ACxBc IkCMwQAAQoAHRYhBEvA17JEcbKhhOr10wAOaEEZVoIVBQJqkblVAAoJEAAOaEEZVoIVEKsP/3hp HMShPkUd7LRnvHya7w9OlIts1azmUNvymC/6Bo8UF4h6ku8lEOd5wVQotYujAUO7mpvWJT4QRum sskrv7sSRFY+AXtf+0wUpZI2+Y2eKUChpLQc/xTenweOpo7As6iZJsRqG2ZukebqptbpjDM2qPY Hgtv6095Lcy+bvkca4PStU/hTpk0/0Y7BcJD9jB6bcHo9JzkXoveT1xdQ8VHPgw0syrRKrUtt16 nJw5M68NfifzuuFHSjOIgc1jZAnGNeGa//2jq4+atT64IIHeZEnvyPbQ+8Y3UyGlv3FS/yXZhdQ UvsM77j7Lw2DvRJlebx7WyX1QaLimZRsqzJdQC3G/kgXmFp4Ghn0P9pJNpAYeuaAC6a5rhQ5BRQ BZKxv3dj1xHN+Tdtnw2PStP3ut3yLdaRaGVnnwlq833y+lkcotGN1QKL7GiIdLmuhd8twZiJdGv hyKQOy4jptNMNsYG6yme7iMZ6XFNaquMc0Z7x/j2CSFARr/r1B1JsmimtrJqew4mlJ2/03/s8Cm Sx/J5au1C0gMlJjdOlGdrOSG9IBWNIaauhReOcWnOKcpO9Pbo4v22P6sKHxkMLKAl8rvu737Y/q /74jonzh0MGdfoL+HRZQIvmvtsB+2PIxOr8KN4KlQWOMdYW9XU2GWtWbmum+edm4GxlD7boQ3Ws Kj+Iz X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 nfsd_nl_listener_set_doit() returns the raw errno from svc_xprt_create_from_sa() and sets no extack. A failed LISTENER_SET therefore tells userland only "Address already in use", or whatever else the transport returned. It never tells userland which entry failed. Record the attribute and the transport name of the entry whose errno the call returns, and report both after the loop. NL_SET_BAD_ATTR() names the entry, which the message alone cannot do: a request can carry several entries with the same transport name. The rejections in nfsd_nl_validate_listeners() other than -E2BIG and the unsupported transport name still carry no extack. This patch does not change them. Assisted-by: LLM Signed-off-by: Jeff Layton --- fs/nfsd/nfsctl.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c index d8135f38e69f..6cbdcee4b733 100644 --- a/fs/nfsd/nfsctl.c +++ b/fs/nfsd/nfsctl.c @@ -2089,7 +2089,9 @@ static int nfsd_nl_validate_listeners(struct genl_inf= o *info) int nfsd_nl_listener_set_doit(struct sk_buff *skb, struct genl_info *info) { struct net *net =3D genl_info_net(info); + const struct nlattr *bad_attr =3D NULL; struct svc_xprt *xprt, *tmp; + const char *bad_xprt =3D NULL; const struct nlattr *attr; struct svc_serv *serv; LIST_HEAD(permsocks); @@ -2208,8 +2210,22 @@ int nfsd_nl_listener_set_doit(struct sk_buff *skb, s= truct genl_info *info) ret =3D svc_xprt_create_from_sa(serv, xcl_name, net, sa, 0, current_cred()); /* always save the latest error */ - if (ret < 0) + if (ret < 0) { + bad_attr =3D attr; + bad_xprt =3D xcl_name; err =3D ret; + } + } + + /* + * The ack carries the errno of the last entry that failed. Point at + * that entry as well, since several entries can share a transport + * name and the errno alone cannot tell them apart. + */ + if (err) { + NL_SET_BAD_ATTR(info->extack, bad_attr); + NL_SET_ERR_MSG_FMT(info->extack, "cannot create %s listener", + bad_xprt); } =20 if (!serv->sv_nrthreads && list_empty(&nn->nfsd_serv->sv_permsocks)) --=20 2.55.0 From nobody Sat Sep 26 23:02:48 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 84F6B43B492; Fri, 28 Aug 2026 16:37:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787935077; cv=none; b=DA+EUKbn2YLqqy1RELUzy0mwM/++JdII2X8QrtQhKjIO7+5947a9tLvffomCFk1pl581mEXJC3P4QS6LoBwJrYL7T2I8R5Byhz676OII4PueoE0VyrCB/wPLynU7rP5nA/6MfwH3Xr4BlCTH+GnRdSPSdIcUhzkdmKev2ety0ms= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787935077; c=relaxed/simple; bh=VtI7n2HnvBxWtHxpVK+v8l92gp2bSc/EpIOPY1kBF3k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dZ4tNJaQkIOIICOcZ2cJkD1G3YlFPdGcZ4KvwJl0Zwd4Y8AA1ZXGWmneKTyfix1kn9gdlmA8m1mYAo+SHovx4PaAH+Yj7kPvc+1NnUC5TybZ2SKbmMuyCaIbZp+u6rKyYLO7TO7218Z6zgHhN1TjSjDmpIPO9mBpgUXJrzU1LeQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hprgfaMq; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hprgfaMq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AECB61F00A3D; Fri, 28 Aug 2026 16:37:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787935075; bh=fAEisYK/B9Nm+vH/z1au7xtnCnKTcCwdV0WAKPK4Obg=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=hprgfaMqiMGnaJighb+wX7cpNBnEH/Lc0OXKLMB4OTA8df0o91ixDcbO4yi8SojgK JgvHAYpTu2N6D/T08SBZiMHuuCDJJqF0VoS3dSI1deF0GV07iJWmakNd8tjMUCuhcV 9y0Gd2iAL0Lz2g+YIlFUic1aUNWMIO8x46gHtJ6RxKALjzR5UPnaC6no7FItGLQFdv YrWlhJWrRYkzpasS5zjVqm399P20nHk2hg1Rc4ZIZO0BIT2p/7m3zi9yBCxJtBrGY3 VmnwDdiJg6AyAmGYYHWG/VXnPAqQE4r+D7arDh8/aadjOfzUryWoy7OYl0UaAZLnnY 6Fjjisxb232yg== From: Jeff Layton Date: Fri, 28 Aug 2026 12:37:36 -0400 Subject: [PATCH v3 06/14] SUNRPC: report local rpcbind calls that get no answer Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260828-nfsd-nl-hang-v3-6-55026685c75d@kernel.org> References: <20260828-nfsd-nl-hang-v3-0-55026685c75d@kernel.org> In-Reply-To: <20260828-nfsd-nl-hang-v3-0-55026685c75d@kernel.org> To: Chuck Lever , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: Slawomir Stepien , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Trond Myklebust , linux-kselftest@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=8220; i=jlayton@kernel.org; h=from:subject:message-id; bh=VtI7n2HnvBxWtHxpVK+v8l92gp2bSc/EpIOPY1kBF3k=; b=owEBbQKS/ZANAwAKAQAOaEEZVoIVAcsmYgBqkblVhlWGJWQ9EqXh2MPrGVJKU9Y8VkKCLCODM R8QtnuUgv+JAjMEAAEKAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCapG5VQAKCRAADmhBGVaC FWKCD/99a1BDrKpM5+mfJM3ErlDkSc2l+XvBPoTmXuFcwl6Pv0brOf4LBt+QW778kOf0aWV/wz0 xAsznfHz9Sq1IRvOqw6Tdmd/Un0RrXrA8MpwxfiUoan993+0Kykt55+qR5ZVxFlHcE9RSLTNjMB x5/sxAedF2JMxpI2Wlg11ykyBfANir9epuYdl3QH2E8ddIQTPXILrsA/YwHjtethM40WGb7tSoq 6987YOue4UbfxUkbIrzJVhTrmBB6b+tHt+ZH7RtF6MGsPt05483llTdFZr5yzIFfpQHRLzHXrbo fWxa5G6qXjCSV/AWc98tLUEDb0fEfS5a4/+bCMq5lnI5YLSFfyL5kShQSRNmh/qqWH5AJBz6WzS xYmY1QcEGYa+dc0junmq4LVplXV74WqXBoVHJousV084jhyfE/aTbxPfRVS6E1Fo4lgAe9hxYX8 pWJIIOWtsC3rUUXB3N0xNJ/BY3kvB+sBM0eXs5FO2qX/SExQ4dFff/g5pVba84RgBgEx1jJnj4d qJCpxC8rvg7hFQn+Zq6PeQVgZb/w6PCCtdFdJJRvd2BJPjsVbaN8c5cRa1A3epnr+KQwR53umj6 AsQB9i7woBLQJIA9uuOP1QU3aXbJ8So/aGXVRYbl20ETCi0rgXmp+lhDNG8Lzpj1dikk6DMw1OR UEnyga6x1a6NfuQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 A caller that creates many listeners in one operation calls svc_register() once for each of them. Every call waits for the local rpcbind on its own, so a rpcbind that never answers costs the caller one timeout per listener. The caller has no way to learn that the first call already failed. An rpcbind failure can occur one of two ways: either rpcbind fails to respond, or it can respond with -EACCES to indicate that the user doesn't own the current record. Give the first case its own errno. rpcb_register_call() returns -ENAVAIL when the call got no answer, and the existing -EACCES continues to mean a FALSE reply. svc_generic_rpcbind_set() has to let -ENAVAIL past vs_rpcb_optnl, since it is not a refusal. svc_register() applies vs_rpcb_optnl to it instead, so a v4-only server still creates its listeners, and then keeps a running total in serv->sv_rpcb_failures. -ENAVAIL never escapes svc_register(). svc_rpcb_failure_count() reports the total. A caller reads the count before it starts and compares as it goes to determine if there have been errors. The users of this infrastructure will be added in later patches. Assisted-by: LLM Signed-off-by: Jeff Layton --- include/linux/sunrpc/clnt.h | 3 ++- include/linux/sunrpc/svc.h | 7 +++++-- net/sunrpc/rpcb_clnt.c | 10 +++++++--- net/sunrpc/svc.c | 42 +++++++++++++++++++++++++++++++++++++++++- 4 files changed, 55 insertions(+), 7 deletions(-) diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h index 3c2b8c355ab3..30344c0d6a9d 100644 --- a/include/linux/sunrpc/clnt.h +++ b/include/linux/sunrpc/clnt.h @@ -199,7 +199,8 @@ struct rpc_xprt *rpc_task_get_xprt(struct rpc_clnt *cln= t, =20 int rpcb_create_local(struct net *); void rpcb_put_local(struct net *); -int rpcb_register(struct net *, u32, u32, int, unsigned short); +int rpcb_register(struct net *net, u32 prog, u32 vers, int prot, + unsigned short port); int rpcb_v4_register(struct net *net, const u32 program, const u32 version, const struct sockaddr *address, diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h index 2db1b9ec5658..5fa9417e034d 100644 --- a/include/linux/sunrpc/svc.h +++ b/include/linux/sunrpc/svc.h @@ -78,6 +78,7 @@ struct svc_serv { unsigned int sv_max_payload; /* datagram payload size */ unsigned int sv_max_mesg; /* max_payload + 1 page for overheads */ unsigned int sv_xdrsize; /* XDR buffer size */ + atomic_t sv_rpcb_failures; /* unanswered rpcbind calls */ struct list_head sv_permsocks; /* all permanent sockets */ struct list_head sv_tempsocks; /* all temporary sockets */ int sv_tmpcnt; /* count of temporary "valid" sockets */ @@ -451,6 +452,7 @@ int sunrpc_set_pool_mode(const char *val); int sunrpc_get_pool_mode(char *val, size_t size); void svc_rpcb_cleanup(struct svc_serv *serv, struct net *net); int svc_bind(struct svc_serv *serv, struct net *net); +unsigned int svc_rpcb_failure_count(struct svc_serv *serv); struct svc_serv *svc_create(struct svc_program *, unsigned int, int (*threadfn)(void *data)); bool svc_rqst_replace_page(struct svc_rqst *rqstp, @@ -471,8 +473,9 @@ unsigned int svc_serv_maxthreads(const struct svc_se= rv *serv); int svc_pool_stats_open(struct svc_info *si, struct file *file); void svc_process(struct svc_rqst *rqstp); void svc_process_bc(struct rpc_rqst *req, struct svc_rqst *rqstp); -int svc_register(const struct svc_serv *, struct net *, const int, - const unsigned short, const unsigned short); +int svc_register(struct svc_serv *serv, struct net *net, + const int family, const unsigned short proto, + const unsigned short port); =20 void svc_wake_up(struct svc_serv *); void svc_reserve(struct svc_rqst *rqstp, int space); diff --git a/net/sunrpc/rpcb_clnt.c b/net/sunrpc/rpcb_clnt.c index 0aa376b82a52..c680137f0fca 100644 --- a/net/sunrpc/rpcb_clnt.c +++ b/net/sunrpc/rpcb_clnt.c @@ -412,7 +412,8 @@ static struct rpc_clnt *rpcb_create(struct net *net, co= nst char *nodename, return rpc_create(&args); } =20 -static int rpcb_register_call(struct sunrpc_net *sn, struct rpc_clnt *clnt= , struct rpc_message *msg, bool is_set) +static int rpcb_register_call(struct sunrpc_net *sn, struct rpc_clnt *clnt, + struct rpc_message *msg, bool is_set) { int flags =3D RPC_TASK_NOCONNECT; int error, result =3D 0; @@ -422,8 +423,10 @@ static int rpcb_register_call(struct sunrpc_net *sn, s= truct rpc_clnt *clnt, stru msg->rpc_resp =3D &result; =20 error =3D rpc_call_sync(clnt, msg, flags); - if (error < 0) + if (error =3D=3D -EPROTONOSUPPORT) return error; + if (error < 0) + return -ENAVAIL; =20 if (!result) return -EACCES; @@ -463,7 +466,8 @@ static int rpcb_register_call(struct sunrpc_net *sn, st= ruct rpc_clnt *clnt, stru * IN6ADDR_ANY (ie available for all AF_INET and AF_INET6 * addresses). */ -int rpcb_register(struct net *net, u32 prog, u32 vers, int prot, unsigned = short port) +int rpcb_register(struct net *net, u32 prog, u32 vers, int prot, + unsigned short port) { struct rpcbind_args map =3D { .r_prog =3D prog, diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c index 4f402bbf97ba..54f8e8b0bf28 100644 --- a/net/sunrpc/svc.c +++ b/net/sunrpc/svc.c @@ -1179,10 +1179,40 @@ int svc_generic_rpcbind_set(struct net *net, error =3D svc_rpcbind_set_version(net, progp, version, family, proto, port); =20 + /* -ENAVAIL is not a refusal, so vs_rpcb_optnl must not swallow it. */ + if (error =3D=3D -ENAVAIL) + return error; + return (vers->vs_rpcb_optnl) ? 0 : error; } EXPORT_SYMBOL_GPL(svc_generic_rpcbind_set); =20 +/** + * svc_rpcb_failure_count - local rpcbind calls for @serv that got no answ= er + * @serv: RPC service to query + * + * svc_register() adds one for each of its calls that got no answer. A rep= ly + * that refuses one entry does not count, because rpcbind answered and the + * next entry may still succeed. + * + * The count is kept per serv rather than per net. The local rpcbind client + * is per-net and lockd shares it, but a count that another service can mo= ve + * says nothing about this serv's own calls. + * + * This is for callers that cannot see the svc_register() return, because a + * transport class sits in between. Such a caller reads the count before it + * starts and compares as it goes, so there is no state to reset between + * operations. The count never resets, and callers must not attach meaning + * to the value itself. + * + * Return: the number of unanswered calls since this serv was created. + */ +unsigned int svc_rpcb_failure_count(struct svc_serv *serv) +{ + return atomic_read(&serv->sv_rpcb_failures); +} +EXPORT_SYMBOL_GPL(svc_rpcb_failure_count); + /** * svc_register - register an RPC service with the local portmapper * @serv: svc_serv struct for the service to register @@ -1193,10 +1223,11 @@ EXPORT_SYMBOL_GPL(svc_generic_rpcbind_set); * * Service is registered for any address in the passed-in protocol family */ -int svc_register(const struct svc_serv *serv, struct net *net, +int svc_register(struct svc_serv *serv, struct net *net, const int family, const unsigned short proto, const unsigned short port) { + bool noanswer =3D false; unsigned int p, i; int error =3D 0; =20 @@ -1208,10 +1239,16 @@ int svc_register(const struct svc_serv *serv, struc= t net *net, struct svc_program *progp =3D &serv->sv_programs[p]; =20 for (i =3D 0; i < progp->pg_nvers; i++) { + const struct svc_version *vers =3D progp->pg_vers[i]; int ret; =20 ret =3D progp->pg_rpcbind_set(net, progp, i, family, proto, port); + if (ret =3D=3D -ENAVAIL) { + noanswer =3D true; + ret =3D (vers && vers->vs_rpcb_optnl) ? + 0 : -ETIMEDOUT; + } if (ret < 0) { printk(KERN_WARNING "svc: failed to register " "%sv%u RPC service (errno %d).\n", @@ -1223,6 +1260,9 @@ int svc_register(const struct svc_serv *serv, struct = net *net, } } =20 + if (noanswer) + atomic_inc(&serv->sv_rpcb_failures); + return error; } =20 --=20 2.55.0 From nobody Sat Sep 26 23:02:48 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A2494534A7; Fri, 28 Aug 2026 16:37:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787935078; cv=none; b=eVSK62y98i0YzeFqKQdhFBlgQ+3Y1f7DW1nD/zB0isUjnf1y1tmL9RwlLtnVy2uyWnQTfZpZKiyQ/iUNyh3+jLqEwnCq+hkzknG9ZsfC73Ozxt2gf/8CBWq0mKPTb5lif6j9YWobLi/NYsT0XS2GY3j8NCEhmZTt/m3xeYDkfr0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787935078; c=relaxed/simple; bh=iBISyt3zCPwOU6LhEil5+ZXak53MIzcx4tHXZSTAl18=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jW0DroESnpschAy19LqUXs/n9w2mHvKJIs9OztkHR9r6B+wopNanT6NhPzr1c+nqQFfuOxuybPCecIz1qx6AI1qDJStb4tzUB6nmYhKjW+7jY33SLKR4l/NNd0xHo+LUhNeYw0PMKXvYKn6XUIyf93g/h4uinRRmJalcsXVYhxM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fHOD29UF; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fHOD29UF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 611231F00A3F; Fri, 28 Aug 2026 16:37:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787935076; bh=p4VaHOgmeNFMziXpqxvwDBqmcVr4dEvVqtOV2sYB+yY=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=fHOD29UFj4s/cNiCiPTgSw0uWqqqD1ee9xX/a6A32/fmANJQ7SacguFI4SI5UwJiv wh8ommnFswfOSOgUfR7oFVGu2gcLO0CY8egy3sRmSoH1KpjagPyff57+og/21cjypN BPclDR0kM3s64A40TRA10ueifZFPxCYABgFG6+FGap5WOiEQ+Qap3On5/w8FqKmaYy MKDZ9lQ137ng+Opm5u8brzhczW6MAMuoYqBNXGLClLg9KYSkGgntOxRtEPDSpdYc8X cCtprGnr1JOkAU9yR6HWwIaz2vmLJ828YjG8k3+4vbCEbD337e5twCvhJhjp1XJLQa 2iRtF17VxuI/w== From: Jeff Layton Date: Fri, 28 Aug 2026 12:37:37 -0400 Subject: [PATCH v3 07/14] SUNRPC: stop svc_register() once rpcbind stops answering Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260828-nfsd-nl-hang-v3-7-55026685c75d@kernel.org> References: <20260828-nfsd-nl-hang-v3-0-55026685c75d@kernel.org> In-Reply-To: <20260828-nfsd-nl-hang-v3-0-55026685c75d@kernel.org> To: Chuck Lever , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: Slawomir Stepien , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Trond Myklebust , linux-kselftest@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=931; i=jlayton@kernel.org; h=from:subject:message-id; bh=iBISyt3zCPwOU6LhEil5+ZXak53MIzcx4tHXZSTAl18=; b=owEBbQKS/ZANAwAKAQAOaEEZVoIVAcsmYgBqkblVlWDOGbDKEE0DrYizTKFH8DxyCPM9XY2OK QcY1YE1iNmJAjMEAAEKAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCapG5VQAKCRAADmhBGVaC FSEnD/4utauLkgitX1LWSsTq11DqkDEAZgmizCQkzQSaL1T7KMG+KBO3B/pHMSP9/K68RimkQ7/ jgv1iBk7vxvI1AH3uuC3QmI7z5zRRRArS6YWBR0nLbnQ9M437bsYHo37PbEWGu8hXxSmcwBV60k mxWSvPa02v+QR46q0YRiaZpFFq3B8ORdSp+O1XvpT5OwnAKnPmSm20O+h8tStWYPfYnkjLZ/M7b bIEllrMCKR6QQbcnYkFECpGODER+AFtDn1GIHoPJUlZpnUylbI8XTssOXB4E1yKkzvOlUC/1HFE 4DiJ0NdmxlUYWIJ/g+nHuC/IaYayju46ovYZU3DKUB+6dtqdwy7Mn7g0zyzADLXFWFW6Un5HnLL 6dYEQwpF802KebFeXGu2WX6xEfThnuNLosJ4ZQiuQ5lHPUWQ/sxQ0jbGlFbB95E4Nnt7JCBsCVw vZ0QVEan9TNJwwuM3+5IoXCRjYaMBWbDsD2B2mrWt0KcfvWdXF85BhFTTBod8i+1wsE/5FOnDhN dmOdJ3MsPACUknKyeCfwg4n3LP9pTu/F4WGhp/7kVLPFgCQ3pHJcYsgcAJpCRU3g0LgvhW8Goxn i8nYiWatrfztxwzia7EhDCJG9AmVMyvbFfJdMvzQ0O4T76HdsPDEb3UcWN0FiTAoAsYzG9Rl3Ua d5BYhaqjkz8kw7g== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 svc_register() walks every program and every version. The break on error leaves the version loop only, so a program whose call to the local rpcbind timed out is followed by the next program timing out in the same way. With the 1s bound on the local rpcbind client, an nfsd serv pays 2s for that, once for nfsd and once for nfsacl. Stop the program loop too, but only when the call got no answer. Assisted-by: LLM Signed-off-by: Jeff Layton --- net/sunrpc/svc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c index 54f8e8b0bf28..e437e99a0b36 100644 --- a/net/sunrpc/svc.c +++ b/net/sunrpc/svc.c @@ -1258,6 +1258,10 @@ int svc_register(struct svc_serv *serv, struct net *= net, break; } } + + /* Give up on trying to register anything if it didn't respond */ + if (noanswer) + break; } =20 if (noanswer) --=20 2.55.0 From nobody Sat Sep 26 23:02:48 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D014F391E5F; Fri, 28 Aug 2026 16:37:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787935080; cv=none; b=Lg1M7iRThkUlX2VBgVoPvilkQG3EKiEjeqGlnJ55pelRAaca1TguIzqNviyWJA+O7vMXHMBBAa4ZyEcwvgmfAEVrIpguJKyXIJXXk+cotjeBWwiw7Gor2m9EsxqY71pVRaeejDGW2dyLTcRDUIf0ew/PEHxKZweGJgU+PAp+fTQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787935080; c=relaxed/simple; bh=RTcXp/XwAZK07kmKnoyjWTw0KieKZtAuYzEGLVY+5hg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZQuoOqasUhSXJeJk1do8eELW4De20Px60SvEpJypndQ0ocsccfbnVJXvMRnq+7X57fUL5HW5VuGDzS6w/PH8NSAtNwTpCrhwtR4FiBnpoChpdEd7gkGLvl9jqoLb/sKUMZ5zac3/7h+7ZiUFi6TLGcwWjmN+9mj+NNMfnIhJuNs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CDClmfhd; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CDClmfhd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 136CC1F00A3D; Fri, 28 Aug 2026 16:37:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787935078; bh=9tzxYlwQuDAnUqvOPKUuPXDIwe1U2jXuBsgT+odNOh0=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=CDClmfhdZge0uVfCkcidYTYSHaDxdklfmzihKZOFrZg9A4ybwLbx2CnSAfJaTSqMf XNYWBm8NPWuNYCk2eiM0d7rKz7Crd+c0cV9tHwtde8PQB0ATMosl2LfvWJH4X6AWVA n2Bhw2OFUqKlPLiwtEktDf5SyTA3R3BKns9O4Svxxn8VlANjDGED1s87/F01dWorm1 hulerlZghuBYnTu+f0CVKgUeSyXvoWGuymjnJ+OrQLTKFm0H/e0D/+YkOS5aJqBj4/ R3YvSHwaC7pQlwB6RByfWYUu1xjBKiu8Ng/tnSqgh8D0WQaKZWed2NLINQ0bJPc1x6 JWuxUtIA00dQg== From: Jeff Layton Date: Fri, 28 Aug 2026 12:37:38 -0400 Subject: [PATCH v3 08/14] SUNRPC: stop the svc_unregister() sweep once rpcbind stops answering Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260828-nfsd-nl-hang-v3-8-55026685c75d@kernel.org> References: <20260828-nfsd-nl-hang-v3-0-55026685c75d@kernel.org> In-Reply-To: <20260828-nfsd-nl-hang-v3-0-55026685c75d@kernel.org> To: Chuck Lever , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: Slawomir Stepien , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Trond Myklebust , linux-kselftest@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1962; i=jlayton@kernel.org; h=from:subject:message-id; bh=RTcXp/XwAZK07kmKnoyjWTw0KieKZtAuYzEGLVY+5hg=; b=owEBbQKS/ZANAwAKAQAOaEEZVoIVAcsmYgBqkblVpeN/m4T8mawarXPaJ+9twWQfrc3Fv+NF0 ZupgQepKpeJAjMEAAEKAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCapG5VQAKCRAADmhBGVaC Ff2gEADHQSmcM5qBfnyufH2X3MvUVJcj3F0VAnFdOZNaeR3Y6tThV6ZDrPU3rivkcoYmtd+lncP JsyUVY9RGEm4yOeJAsuHk27zyCGoKa/RIIwDNZRzYFA5fjkCOxOrR1WOE+by1Zsh/7r7rpcEBSu kMvC+uCjT84aAkd5XfDMeBT8nlfGA9x7jii2Br9P876g9VFNBuogVaANHkjn2do7x79heX5WH8b iw38M2Stzr/t+Wg//FaI1a6HMhMNMflQK9U2LYA9n7CXBVKURXWBkluBGBW4vKTH1hNM/7rd7XQ I5s/gX37Q5G2tiYC6aVwaiLs6gJQpc24VDGKHwaZhc/Dh2SF/+3j7CLIn4F1TlCVfgMMdjKXgW1 tAItZPn/fkV/Xiv41/9zqMzZqQC72XWLddNU2ouNdWFinPHKvG2gOcZsU1btP9Qa/t6gZW4q5lQ dymMb3e6EigqHridK9HOHpl1LO9PBZF4VuhBSgalJxPxGdRhAWZC2ZOfZlNA26ypdKBMNZ7Bu7q naTxWv7BYDCDDsvKtzNxhUrA9Sq+C7LErOJkzOozYYJXsJ5X6buehSHUQ7DWqCUsE589IL6cIpf msX14HFHiObusWDVTBdZHgAhVJMZriKUy4Rt1l9zqzwo36k8RK22WnrIVkR0QZ5LfZPMl00ubTv TAORfokPVxY/9UA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 svc_unregister() clears the rpcbind entry for every non-hidden program and version. svc_rpcb_setup() runs it to drop stale entries when a serv binds, and svc_rpcb_cleanup() runs it when one goes away. An nfsd serv with v3 and v4 enabled sweeps four or five entries, so a local rpcbind that never replies costs that many timeouts, twice per NFSD_CMD_LISTENER_SET, all under nfsd_mutex. Give up after the first call that gets no answer. Assisted-by: LLM Signed-off-by: Jeff Layton --- net/sunrpc/svc.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c index e437e99a0b36..bccaeb8dfba8 100644 --- a/net/sunrpc/svc.c +++ b/net/sunrpc/svc.c @@ -1277,8 +1277,8 @@ int svc_register(struct svc_serv *serv, struct net *n= et, * any "inet6" entries anyway. So a PMAP_UNSET should be sufficient * in this case to clear all existing entries for [program, version]. */ -static void __svc_unregister(struct net *net, const u32 program, const u32= version, - const char *progname) +static int __svc_unregister(struct net *net, const u32 program, const u32 = version, + const char *progname) { int error; =20 @@ -1292,6 +1292,7 @@ static void __svc_unregister(struct net *net, const u= 32 program, const u32 versi error =3D rpcb_register(net, program, version, 0, 0); =20 trace_svc_unregister(progname, version, error); + return error; } =20 /* @@ -1318,10 +1319,13 @@ static void svc_unregister(const struct svc_serv *s= erv, struct net *net) continue; if (progp->pg_vers[i]->vs_hidden) continue; - __svc_unregister(net, progp->pg_prog, i, progp->pg_name); + if (__svc_unregister(net, progp->pg_prog, i, + progp->pg_name) =3D=3D -ENAVAIL) + goto out; } } =20 +out: rcu_read_lock(); sighand =3D rcu_dereference(current->sighand); spin_lock_irqsave(&sighand->siglock, flags); --=20 2.55.0 From nobody Sat Sep 26 23:02:48 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A87EA34EEF3; Fri, 28 Aug 2026 16:38:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787935081; cv=none; b=nG/8LkdUbl8pvdeC1hoeE5OippnK2sB7a4HGKhSAoqRaTF7Kl5s+iieuL2GDqDgAidOIc0WxD4a/CvxDq2KJns7+Z0D7L1oLDwQNrFLr9R16/zbasH2B26p7np3+Qk+afJ3u3be9ypMhpmWfzepUx5UhIfPrJHWwU87F4uUSrj0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787935081; c=relaxed/simple; bh=FKA2BkMlz5ELGl32gDJPPbAwvFf5JVXLuMfqgnUQM9U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nnyrkixH0nt07MMypRupqa9X/oV7pyxzous5xCxLbyl30lprIftZvxI1pLT/ZGHW0kqOlH9aZ/w/xstW6ynzze8EQC9KPXy2y6zB6O0xWPr1hkkQLXCmxnd3CLzyak7x4yMpVPblnnr6J6PwIYtY+0zYdAv+zIJPTEapwpry55c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GmD92sjC; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GmD92sjC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9D491F000E9; Fri, 28 Aug 2026 16:37:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787935080; bh=ockaZEjuUu+8Z8u8Q0PDF9tkO0ak/zH6aUQtKJaJl5Q=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=GmD92sjCCLSPWkad7nMFxt8FkqgrlZy+DjXLH5d1gHKx3/BuilFRBvOm38/EfbEC2 LjNqPMRkrZGOsmOLfqUlE4k/f/8oA0X/yGyyzYd/3nlQGNTJoJG+i9G+dVB7jG3RZD 8kavgTmwjrg8hHVrnI0GuOXI5LwGb9+MNahZP0JANK+iMecbsEQc+WbAhB/491SFZr L+pdJNu2L9sfelqYsZ7j3wrQs8YxygkE/VwkRKpYpbAHohf8DngzvtqTzQATH3wypn UqWvvkhA2qi+vzM4MbLYZPXifvAMbwEDat44WugSn7kJz0S0Rm1eEXcEsSgm3l3oAm e9pEWfoLYVgDA== From: Jeff Layton Date: Fri, 28 Aug 2026 12:37:39 -0400 Subject: [PATCH v3 09/14] SUNRPC: stop unregistering listeners once rpcbind stops answering Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260828-nfsd-nl-hang-v3-9-55026685c75d@kernel.org> References: <20260828-nfsd-nl-hang-v3-0-55026685c75d@kernel.org> In-Reply-To: <20260828-nfsd-nl-hang-v3-0-55026685c75d@kernel.org> To: Chuck Lever , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: Slawomir Stepien , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Trond Myklebust , linux-kselftest@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2044; i=jlayton@kernel.org; h=from:subject:message-id; bh=FKA2BkMlz5ELGl32gDJPPbAwvFf5JVXLuMfqgnUQM9U=; b=owEBbQKS/ZANAwAKAQAOaEEZVoIVAcsmYgBqkblWCAym/muah0F6vWM8YgSIL5RD8Q85pSga3 +oBcgjcOIWJAjMEAAEKAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCapG5VgAKCRAADmhBGVaC Fe9HEADDlFMqUaSbem32S8QZfH8ZbfhUjcMPLWyFsxE8xMHZ5+exV0yS7Bs7QFIxXS28Xvc13ES wK66Qu0yL5GkXPxxD/0FOHtn69ImcmjLySwg1dIlhqJ65aBKaM6LDq1fnoTp8mYHXvjIWN1w/Zn Sa8A6zFGuJhTQSASgda8oPCC/glqu+rBb9Vdl75/oU+iofviiUf/J+I3sPwIkOilxY7IMTA6/cS ne+uu/26HHpkNfgbw6SYTkib4FHHgnp9Jg1ai5I5Yv+7AZUJyOxrTHLiS7ZBQoU+7FAK5DG28Po L6L/u87lKnNHlx5KmPvH04CikXsfT58i1MjDzqA2Y61wAi6iEFfnKrtPEeGTDVo4CKyL0Z90jMa 7y3hGMKeDC0JlOOkWqlld/cMx21uArVCM5tn+cSjX/xh47IhGvWTEeKNymWt6YtFy1cVSXjymp1 /5gX107k3fBtlVKMLsSHF6g1pDeOndnOtydD6X2Qe/eJ0JIR/iSb+cGTfp+hiIwguyKv0nQbGuw 97cfkLgKzoggR0zlE4CVnFQIMGOwxk7ppeYPdSFhqlsKPcLsDJOSQISkGzxGd+jFhZEbYLzooP2 bMqxfFeEvdtK8WabsULXrQwcC7jCgtcQ1VxCXJEh1b5nlIku4QNlNa82k2Tv1OtYxtU8+CwFV3c ZqqYhcbuttwYhbg== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 svc_delete_xprt() unregisters each listener it destroys. One NFSD_CMD_LISTENER_SET that removes listeners therefore pays one local rpcbind timeout for each of them, under nfsd_mutex, on top of the one the create loop already bounds. One failure is enough to know that the rest of the teardown will not fare better. When the call gets no answer, clear XPT_RPCB_UNREG on every remaining transport in the same net. Assisted-by: LLM Signed-off-by: Jeff Layton --- net/sunrpc/svc_xprt.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c index 40040af588fb..7e471c92f23a 100644 --- a/net/sunrpc/svc_xprt.c +++ b/net/sunrpc/svc_xprt.c @@ -1101,6 +1101,22 @@ static void call_xpt_users(struct svc_xprt *xprt) spin_unlock(&xprt->xpt_lock); } =20 +/* + * If rpcbind stops answering, every listener still to be destroyed would + * only wait out the same timeout again. Drop the flag on all of the + * remaining listeners. + */ +static void svc_xprt_clear_rpcb_unreg(struct svc_serv *serv, struct net *n= et) +{ + struct svc_xprt *xprt; + + spin_lock_bh(&serv->sv_lock); + list_for_each_entry(xprt, &serv->sv_permsocks, xpt_list) + if (xprt->xpt_net =3D=3D net) + clear_bit(XPT_RPCB_UNREG, &xprt->xpt_flags); + spin_unlock_bh(&serv->sv_lock); +} + /* * Remove a dead transport */ @@ -1115,11 +1131,15 @@ static void svc_delete_xprt(struct svc_xprt *xprt) struct svc_sock *svsk =3D container_of(xprt, struct svc_sock, sk_xprt); struct socket *sock =3D svsk->sk_sock; + unsigned int failures =3D svc_rpcb_failure_count(serv); =20 if (svc_register(serv, xprt->xpt_net, sock->sk->sk_family, sock->sk->sk_protocol, 0) < 0) pr_warn("failed to unregister %s with rpcbind\n", xprt->xpt_class->xcl_name); + + if (svc_rpcb_failure_count(serv) !=3D failures) + svc_xprt_clear_rpcb_unreg(serv, xprt->xpt_net); } =20 if (test_and_set_bit(XPT_DEAD, &xprt->xpt_flags)) --=20 2.55.0 From nobody Sat Sep 26 23:02:48 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 44C1A471D1A; Fri, 28 Aug 2026 16:38:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787935083; cv=none; b=jrqIhdsn0W+BrZDO0xTu1LPIVdCdkdA199uMfbOnEHht6Zm+XXCiEF1pRsBq1AsjLB140lOFIGkK36GZVW/mG1JUmvwSwnFbYwJmgYkuTlAdcRV/LLNQsTxDEmVqZVbkL8Ygo0c8kDX1dQRxyqnLdHmvBPQaj6SJwWJiB/UmCAs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787935083; c=relaxed/simple; bh=2x7B3PwxP/3BtOylSFXw7RWPlE8nh0dtG6olsUilqDg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=J5xnVsycTjA8aY5awJDfigxDU7hwePuwppreWKNSS+1mvl2nOGRjQFU+sAUhlFsptCYTSDVche3t/Q8CqyDB2ha3NcT5kqKEKdePczG72Pm+FzDWUjECpo2/3Cv1Z/+KBDdevNmtGbvhbhWUw6fjcGfMZr6+lBybDmwLwqOmbIM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NYXwcTFM; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NYXwcTFM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70B3E1F00A3E; Fri, 28 Aug 2026 16:38:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787935081; bh=GtpcXXZ0zNpjKNHNu83pEcU/aeQP2umwafmS+/+dV3c=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=NYXwcTFMSXbZowLS700IDufTexXFxARuubDvpfSM6xuX7BjoUE8Er1lxUUFNOP+nv Jzzpj46sC0Tkw29iVkeibmIF7eAq0AtTX/mVnyOEcTxg6uWymB/NDLPfBhrg4U0TpE EvqblPcjHZI+uZoyWsDavXMB62wdFcc94/DVU4NEZ8iVu5ndn78GRhEfA/hqfXISZz DiAhTFy70IOB5KVYHLyYptY5jDq9Wc8GNP4e/FB2oeR5d/q4fi15GyCLkNSEmwA1M+ MDUDTCJ2XhtBZOzSOzQbcnY/X/PKO+fkdNSYRxjVhY3hZDPyAlPjUZieAs7G5H/EIW hwqs7QHNPEfeQ== From: Jeff Layton Date: Fri, 28 Aug 2026 12:37:40 -0400 Subject: [PATCH v3 10/14] NFSD: stop registering with rpcbind after a failure in listener_set Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260828-nfsd-nl-hang-v3-10-55026685c75d@kernel.org> References: <20260828-nfsd-nl-hang-v3-0-55026685c75d@kernel.org> In-Reply-To: <20260828-nfsd-nl-hang-v3-0-55026685c75d@kernel.org> To: Chuck Lever , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: Slawomir Stepien , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Trond Myklebust , linux-kselftest@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4092; i=jlayton@kernel.org; h=from:subject:message-id; bh=2x7B3PwxP/3BtOylSFXw7RWPlE8nh0dtG6olsUilqDg=; b=owEBbQKS/ZANAwAKAQAOaEEZVoIVAcsmYgBqkblWvWslR176ZcPHGh8CmTK6uBbHSOuLhIslb 3vX+OKsyQWJAjMEAAEKAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCapG5VgAKCRAADmhBGVaC FTG7D/4/85uR0o1M4S1H1u1Uu+I+M6YuzikKn5LJ/Et6VgTTA+YWILARJfRWlfm00Bu45KQppw1 P+9NtGD97zdEsMxDnJAzoeSOkbEtUC+H0rMOuQJTX8fwyTI+MtFFXXVOUcXNCN2Zl1gZoqGQ+ko V5LIyeknyaXWjrJqPYIGg3rbphCShgDLf3qq/lKIoGJO0ZXz25QWZV7P+IC/cUysF/CKVi8vBb2 ARwb8NRqimmDlgo4aOrRk9WHRcirtDqcLjRFTwsN5LWohTRPnVsqaaHlKieCQEW92pTT/yDgIFc K7hONWclmLVnNeaHE0P8+TzQRuh8dLJ5mc0oxwV06oAvF9cHwTnkh7xQROsK5lF31isZ5ZBOh3A nXlAmATLTbozK42CIGEIDwDw9LSBI+vh9DJrvt7QiPXNVwOMWnQYEDwRjG3FiojkKI8ED/2HbCB L1g+KAAzqUwxUU0aOzxZt1K3Cmiti5jZpfY7NST1SNfI6gJn1yQCtnQNxKJ/mEyDpQlKy1fgW4h bc8tyQBBvpznXLPLNy0pOgt0ah33wB7CcZtdW9qy1rg2fl66XYZANLpnAdWG4IYelzAQWE7vAhv qgZmPDKMSPp6qM1RnKmTf/YE3p04aMhClLBSaxdqDCwqWDwHwxvq/MK9rojkjxL0WY4l4kqq10U nqWHrqWpJStmNRg== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 nfsd_nl_listener_set_doit() calls svc_xprt_create_from_sa() once for each requested listener and passes flags of 0, so every listener registers with rpcbind on its own. A rpcbind that accepts the connection and never replies therefore costs one timeout for each entry. With the cap of 1024 entries the request can hold nfsd_mutex for about 34 minutes, which is roughly 17 times the hung-task threshold. One failure is enough to know that the next call will not fare better. Read svc_rpcb_failure_count() before the create loop, and pass SVC_SOCK_ANONYMOUS for the rest of the request once the count moves. The entry that moves the count has already paid the timeout, and with v3 enabled svc_register() turns that into -ETIMEDOUT and no listener. Nothing marks it out from the rest of the request, and a retry of the request would fail it again, so retry it with SVC_SOCK_ANONYMOUS rather than leave the set permanently short of whichever entry went first. A silent rpcbind therefore no longer fails an entry. Report it as its own condition in the ack, instead of appending it to whatever unrelated error the last failing entry had. Fixes: 16a471177496 ("NFSD: add listener-{set,get} netlink command") Assisted-by: LLM Link: https://syzkaller.appspot.com/bug?extid=3Dc7eae0eb80858a2dba0f Suggested-by: Olga Kornievskaia Signed-off-by: Jeff Layton --- fs/nfsd/nfsctl.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c index 6cbdcee4b733..2256c53277b8 100644 --- a/fs/nfsd/nfsctl.c +++ b/fs/nfsd/nfsctl.c @@ -2092,7 +2092,9 @@ int nfsd_nl_listener_set_doit(struct sk_buff *skb, st= ruct genl_info *info) const struct nlattr *bad_attr =3D NULL; struct svc_xprt *xprt, *tmp; const char *bad_xprt =3D NULL; + unsigned int rpcb_failures; const struct nlattr *attr; + bool skipped_rpcb =3D false; struct svc_serv *serv; LIST_HEAD(permsocks); struct nfsd_net *nn; @@ -2182,13 +2184,15 @@ int nfsd_nl_listener_set_doit(struct sk_buff *skb, = struct genl_info *info) if (delete) svc_xprt_destroy_all(serv, net, false); =20 + rpcb_failures =3D svc_rpcb_failure_count(serv); + /* walk list of addrs again, open any that still don't exist */ nlmsg_for_each_attr_type(attr, NFSD_A_SERVER_SOCK_ADDR, info->nlhdr, GENL_HDRLEN, rem) { struct nlattr *tb[NFSD_A_SOCK_MAX + 1]; const char *xcl_name; struct sockaddr *sa; - int ret; + int flags, ret; =20 /* validated up front in nfsd_nl_validate_listeners() */ if (nla_parse_nested(tb, NFSD_A_SOCK_MAX, attr, @@ -2207,8 +2211,20 @@ int nfsd_nl_listener_set_doit(struct sk_buff *skb, s= truct genl_info *info) continue; } =20 - ret =3D svc_xprt_create_from_sa(serv, xcl_name, net, sa, 0, + flags =3D skipped_rpcb ? SVC_SOCK_ANONYMOUS : 0; + ret =3D svc_xprt_create_from_sa(serv, xcl_name, net, sa, flags, current_cred()); + + if (!skipped_rpcb && + svc_rpcb_failure_count(serv) !=3D rpcb_failures) { + skipped_rpcb =3D true; + if (ret < 0) + ret =3D svc_xprt_create_from_sa(serv, xcl_name, + net, sa, + SVC_SOCK_ANONYMOUS, + current_cred()); + } + /* always save the latest error */ if (ret < 0) { bad_attr =3D attr; @@ -2224,8 +2240,17 @@ int nfsd_nl_listener_set_doit(struct sk_buff *skb, s= truct genl_info *info) */ if (err) { NL_SET_BAD_ATTR(info->extack, bad_attr); - NL_SET_ERR_MSG_FMT(info->extack, "cannot create %s listener", - bad_xprt); + if (skipped_rpcb) + NL_SET_ERR_MSG_FMT(info->extack, + "cannot create %s listener; rpcbind did not answer", + bad_xprt); + else + NL_SET_ERR_MSG_FMT(info->extack, + "cannot create %s listener", + bad_xprt); + } else if (skipped_rpcb) { + NL_SET_ERR_MSG(info->extack, + "rpcbind did not answer, some listeners are not registered"); } =20 if (!serv->sv_nrthreads && list_empty(&nn->nfsd_serv->sv_permsocks)) --=20 2.55.0 From nobody Sat Sep 26 23:02:48 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E436038D018; Fri, 28 Aug 2026 16:38:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787935086; cv=none; b=NomQ70/6VSfJYnVEinxBjOPD8V7xZE4ZPhbrMeI4MG9fELiHdKildLOt+Txwj1Smtkp6hsL9osXC18hS5BeI+skSaP6z9fkjVXJvFN0hr8y6Sii2KxLjHRB47mGzYXRY+tpVLviPxhS+DcdEaJIXSW86MdiW18+CInIAQ2ErfBM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787935086; c=relaxed/simple; bh=qKb2bweuqy9GehslCZtN22n6bjX8AkfXkJJ9gCHcsS8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DDOieBvXVwdj+/hFxaMxpMn9Tg0vyYf99UR/Uc2v11vQ0625gD1MwnEWn75NCtwPhVncLwNJTYczGkErxmRAvWukolpxqbFn0pRRWxhr2OQE5qLyGwO3KHtJSl1gdE7ZmBZ1vKz/Tx7CTHOCCFVnk5VmGV8KdLV+fAvB23mwtqY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jsIzpoFN; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jsIzpoFN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23B0E1F000E9; Fri, 28 Aug 2026 16:38:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787935083; bh=Ww9aE1CgZAnMjvFIp83svlEAgt5oJyxEdaaWiGYit60=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=jsIzpoFNDtJVF+fxdyVg1jhDTjnZDMNbikZlOniWNObUt6sAW1awhoLDnmRRrVslm ZwYa0Fdtjz8kNwjlvES8TR82G8fczAWZQjMhtpfcJCIiaL8D2DKqdZm2/IImL5lyFx yzo/s/w1Xy7u3yWmzURTzJYMYteb2qNThXy/XA7Eduk6vCc02syLEQ9qahthoI5Nlp EstdnpA9KleMGkd9eOrSmRWFHMjdwyT/2pa/OkhNcuDnMOgzRud8VncCSkj/f1wSAf hdvEuWVa3y5U32Hx96qirrui6WNJQYx1Lck0fZUqP2hSc1zz4QkeSM0smDYAjwKkg7 fSJN8b9te17wA== From: Jeff Layton Date: Fri, 28 Aug 2026 12:37:41 -0400 Subject: [PATCH v3 11/14] selftests/nfsd: exercise listener_set request validation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260828-nfsd-nl-hang-v3-11-55026685c75d@kernel.org> References: <20260828-nfsd-nl-hang-v3-0-55026685c75d@kernel.org> In-Reply-To: <20260828-nfsd-nl-hang-v3-0-55026685c75d@kernel.org> To: Chuck Lever , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: Slawomir Stepien , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Trond Myklebust , linux-kselftest@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=19166; i=jlayton@kernel.org; h=from:subject:message-id; bh=qKb2bweuqy9GehslCZtN22n6bjX8AkfXkJJ9gCHcsS8=; b=owEBbQKS/ZANAwAKAQAOaEEZVoIVAcsmYgBqkblW4jUb8elHISBYE3l121Lb5i0efJsnZZRNp 4PMC8OyEGOJAjMEAAEKAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCapG5VgAKCRAADmhBGVaC FSoqD/0fVfz0lzGjcB2/o9azQjLhKxUHQLozCbruNeqL+EzeenVrAIuyaqrIhBhsyVjuWfWzpUe sCcI3iUOd0pSPZgtB70nIXAgSMuiNx4U4jroaS9vkPq0EaxzQveMykmPboJQK3lZo15n9h1RCUO 2VSOvFbwIn2I4Xa2L+rmgU6B5qgb0Jr2bc57hArWaodtCZGco3zjm/kDBCAymOPgYuTJdxgEmf7 lA5iveR2Hc/MgIHsn2n2dYDQtdpAkHmWweVr+eDHj0IB7yKna3FvlDVxPPNFu59S9/HaFA4/8wN LfUQnuSzymqsDC14fXO38LAUneS3E+CCqdAKK4JN0bR2H+gnpZaC+0OYVGU8n3Y8D1fTzV298xq 6uGTFbpsYSz0IiiaFE5dR9I6mIGTIMzNcPzsqBmGVzTe3E5eUlV/CLQ2MU7d6uVhUpA0UJ8OY6p auK3wxzq+BeHiaU/qmwH6v14OdgjkGGgEByOoWJq5nb3R0fCEZc1/vLvdSk7gNO9cYqfB6OHiqC NtWOBmjbWI3EaUXBRjvAu5lKSMxEks8zFRcQFJNDzErT5hvRTFHR+/4RYK6jnXoWKPoEOCqg60j 3EnbILaIO0VcCPtN0IohhGaxSzgGGduW1JYlJp1PGLF2Uby3y+KjluivdfZ9L6O72dBjxwB5MsU 7I03bDY3qnhLaFA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Add regression tests for the NFSD_CMD_LISTENER_SET checks that nfsd_nl_validate_listeners() runs before the code takes nfsd_mutex. The tests cover a bad transport name, an absent transport name, a missing address, a truncated or unsupported sockaddr, a bad address family, a malformed entry behind a well-formed one, and more than NFSD_NL_LISTENER_MAX entries. One more test sends a LISTENER_GET to an empty netns. None of these requests reach nfsd_create_serv(), so nothing here creates a serv or registers with rpcbind. The tests that do need a serv come next, with a stub. The tests use kselftest_harness.h, so each test runs in its own net and mount namespace. /run is masked there. unix_find_bsd() resolves by inode and takes no struct net, so a connect to "/var/run/rpcbind.sock" from this netns would otherwise reach the rpcbind on the host. svc_rpcb_setup() opens with a call to svc_unregister(), which would then clear the host's nfsd registrations. The config fragment must therefore cover the fixture as well as nfsd: NAMESPACES and NET_NS for the unshare(), SHMEM and TMPFS for the mask, and UNIX for the AF_LOCAL rpcbind client. Without them, every test skips. Add the new directory to the NFSD MAINTAINERS entry, which does not cover tools/testing/selftests/ today. Assisted-by: LLM Signed-off-by: Jeff Layton --- MAINTAINERS | 1 + tools/testing/selftests/Makefile | 1 + tools/testing/selftests/nfsd/.gitignore | 1 + tools/testing/selftests/nfsd/Makefile | 6 + tools/testing/selftests/nfsd/config | 8 + .../testing/selftests/nfsd/nfsd_netlink_listener.c | 488 +++++++++++++++++= ++++ tools/testing/selftests/nfsd/settings | 1 + 7 files changed, 506 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index be63cb3844db..9d97df56cad6 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14163,6 +14163,7 @@ F: include/uapi/linux/nfsd/ F: include/uapi/linux/sunrpc/ F: net/sunrpc/ F: tools/net/sunrpc/ +F: tools/testing/selftests/nfsd/ =20 KERNEL NFSD BLOCK and SCSI LAYOUT DRIVER R: Christoph Hellwig diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Mak= efile index c62642302c84..edaf3c932011 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -89,6 +89,7 @@ TARGETS +=3D net/packetdrill TARGETS +=3D net/ppp TARGETS +=3D net/rds TARGETS +=3D net/tcp_ao +TARGETS +=3D nfsd TARGETS +=3D nolibc TARGETS +=3D pci_endpoint TARGETS +=3D pcie_bwctrl diff --git a/tools/testing/selftests/nfsd/.gitignore b/tools/testing/selfte= sts/nfsd/.gitignore new file mode 100644 index 000000000000..19e6dec04d8e --- /dev/null +++ b/tools/testing/selftests/nfsd/.gitignore @@ -0,0 +1 @@ +nfsd_netlink_listener diff --git a/tools/testing/selftests/nfsd/Makefile b/tools/testing/selftest= s/nfsd/Makefile new file mode 100644 index 000000000000..15ac65549d25 --- /dev/null +++ b/tools/testing/selftests/nfsd/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 +CFLAGS +=3D $(KHDR_INCLUDES) -Wall + +TEST_GEN_PROGS :=3D nfsd_netlink_listener + +include ../lib.mk diff --git a/tools/testing/selftests/nfsd/config b/tools/testing/selftests/= nfsd/config new file mode 100644 index 000000000000..ab84523fbedf --- /dev/null +++ b/tools/testing/selftests/nfsd/config @@ -0,0 +1,8 @@ +CONFIG_NAMESPACES=3Dy +CONFIG_NET_NS=3Dy +CONFIG_SHMEM=3Dy +CONFIG_TMPFS=3Dy +CONFIG_UNIX=3Dy +CONFIG_IPV6=3Dy +CONFIG_NFSD=3Dy +CONFIG_NFSD_V4=3Dy diff --git a/tools/testing/selftests/nfsd/nfsd_netlink_listener.c b/tools/t= esting/selftests/nfsd/nfsd_netlink_listener.c new file mode 100644 index 000000000000..ae28c224255f --- /dev/null +++ b/tools/testing/selftests/nfsd/nfsd_netlink_listener.c @@ -0,0 +1,488 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Regression tests for the NFSD generic-netlink listener interface + * (NFSD_CMD_LISTENER_SET / NFSD_CMD_LISTENER_GET). + * + * These cover the request validation that nfsd_nl_validate_listeners() do= es + * before nfsd_mutex is taken: bad or absent transport name, missing addre= ss, + * truncated or unsupported sockaddr, oversized list. None of them reach + * nfsd_create_serv(), so nothing here creates a serv or talks to rpcbind. + * + * Each test runs in its own private net + mount namespace (unshare in + * FIXTURE_SETUP). /run is masked there: a pathname AF_LOCAL connect is not + * scoped by the network namespace, since unix_find_bsd() resolves by inode + * and takes no struct net, so the kernel's rpcbind client would otherwise= be + * able to reach the rpcbind running on the host. + */ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../kselftest_harness.h" + +/* NFSD generic-netlink constants (from linux/nfsd_netlink.h). */ +#define NFSD_FAMILY_NAME "nfsd" +#define NFSD_CMD_LISTENER_SET 6 +#define NFSD_CMD_LISTENER_GET 7 +#define NFSD_A_SERVER_SOCK_ADDR 1 /* per-listener nest */ +#define NFSD_A_SOCK_ADDR 1 /* inside the nest */ +#define NFSD_A_SOCK_TRANSPORT_NAME 2 /* inside the nest */ + +#define NLA_ALIGN4(len) (((len) + 3) & ~3) +#define TEST_PORT 20049 +#define MAX_LISTENERS 8 +#define RECV_TIMEO_SEC 30 + +static int nfsd_family; /* set per-test in FIXTURE_SETUP */ + +static void die(const char *msg) +{ + perror(msg); + exit(1); +} + +/* ------------------- minimal generic-netlink plumbing ------------------= - */ + +static int genl_open(void) +{ + struct sockaddr_nl sa =3D { .nl_family =3D AF_NETLINK }; + struct timeval tv =3D { .tv_sec =3D RECV_TIMEO_SEC }; + int fd =3D socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC); + + if (fd < 0) + die("socket(NETLINK_GENERIC)"); + if (bind(fd, (void *)&sa, sizeof(sa)) < 0) + die("bind(netlink)"); + setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); + return fd; +} + +/* Append an attribute at @off; return the new (aligned) offset. */ +static int put_attr(char *buf, int off, uint16_t type, + const void *data, int len) +{ + struct nlattr *na =3D (void *)(buf + off); + + na->nla_type =3D type; + na->nla_len =3D NLA_HDRLEN + len; + if (len) + memcpy(buf + off + NLA_HDRLEN, data, len); + return off + NLA_ALIGN4(NLA_HDRLEN + len); +} + +/* Build a genl message header into @buf; return the offset past it. */ +static int genl_hdr(char *buf, uint16_t type, uint16_t flags, uint8_t cmd) +{ + struct nlmsghdr *nlh =3D (void *)buf; + struct genlmsghdr *gnl =3D (void *)(buf + NLMSG_HDRLEN); + + memset(buf, 0, NLMSG_HDRLEN + GENL_HDRLEN); + nlh->nlmsg_type =3D type; + nlh->nlmsg_flags =3D flags; + nlh->nlmsg_seq =3D 1; + gnl->cmd =3D cmd; + gnl->version =3D 1; + return NLMSG_HDRLEN + GENL_HDRLEN; +} + +/* Send an nfsd command with an ACK; return the ACK errno (<=3D 0). */ +static int genl_request(uint8_t cmd, const char *attrs, int attrs_len) +{ + char buf[1 << 20], rbuf[4096]; + struct nlmsghdr *nlh =3D (void *)buf; + int fd =3D genl_open(); + int off, n, ret; + + off =3D genl_hdr(buf, nfsd_family, NLM_F_REQUEST | NLM_F_ACK, cmd); + if (attrs_len) { + memcpy(buf + off, attrs, attrs_len); + off +=3D attrs_len; + } + nlh->nlmsg_len =3D off; + + if (send(fd, buf, off, 0) < 0) + die("send(genl)"); + + n =3D recv(fd, rbuf, sizeof(rbuf), 0); + if (n < 0) + ret =3D (errno =3D=3D EAGAIN || errno =3D=3D EWOULDBLOCK) ? -ETIMEDOUT := -errno; + else if (((struct nlmsghdr *)rbuf)->nlmsg_type =3D=3D NLMSG_ERROR) + ret =3D ((struct nlmsgerr *)NLMSG_DATA(rbuf))->error; + else + ret =3D 0; + close(fd); + return ret; +} + +/* Send a command and return the full reply message; -errno on failure. */ +static int genl_request_reply(uint8_t cmd, char *rbuf, size_t rlen) +{ + char buf[256]; + struct nlmsghdr *nlh =3D (void *)buf; + int fd =3D genl_open(); + int off, n, ret; + + off =3D genl_hdr(buf, nfsd_family, NLM_F_REQUEST, cmd); + nlh->nlmsg_len =3D off; + + if (send(fd, buf, off, 0) < 0) + die("send(genl reply)"); + + n =3D recv(fd, rbuf, rlen, 0); + if (n < 0) + ret =3D (errno =3D=3D EAGAIN || errno =3D=3D EWOULDBLOCK) ? -ETIMEDOUT := -errno; + else if (((struct nlmsghdr *)rbuf)->nlmsg_type =3D=3D NLMSG_ERROR) + ret =3D ((struct nlmsgerr *)NLMSG_DATA(rbuf))->error; + else + ret =3D n; + close(fd); + return ret; +} + +/* Resolve the "nfsd" genl family id; -1 if not registered. */ +static int genl_resolve_nfsd(void) +{ + char buf[1024], rbuf[4096]; + struct nlmsghdr *nlh =3D (void *)buf; + struct nlmsghdr *rh =3D (void *)rbuf; + struct nlattr *na; + int fd, off, left, id =3D -1; + + fd =3D genl_open(); + off =3D genl_hdr(buf, GENL_ID_CTRL, NLM_F_REQUEST, CTRL_CMD_GETFAMILY); + off =3D put_attr(buf, off, CTRL_ATTR_FAMILY_NAME, + NFSD_FAMILY_NAME, sizeof(NFSD_FAMILY_NAME)); + nlh->nlmsg_len =3D off; + + if (send(fd, buf, off, 0) < 0) + die("send(GETFAMILY)"); + if (recv(fd, rbuf, sizeof(rbuf), 0) < 0) + die("recv(GETFAMILY)"); + close(fd); + + if (rh->nlmsg_type =3D=3D NLMSG_ERROR) + return -1; + + na =3D (void *)((char *)NLMSG_DATA(rh) + GENL_HDRLEN); + left =3D rh->nlmsg_len - NLMSG_HDRLEN - GENL_HDRLEN; + while (left >=3D (int)NLA_HDRLEN) { + if (na->nla_type =3D=3D CTRL_ATTR_FAMILY_ID) { + id =3D *(uint16_t *)((char *)na + NLA_HDRLEN); + break; + } + left -=3D NLA_ALIGN4(na->nla_len); + na =3D (void *)((char *)na + NLA_ALIGN4(na->nla_len)); + } + return id; +} + +/* ------------------- listener request builders ------------------- */ + +/* Fine-grained control for negative tests: any field can be omitted/malfo= rmed. */ +struct raw_listener { + const char *xprt; /* NULL -> omit NFSD_A_SOCK_TRANSPORT_NAME */ + int emit_addr; /* 0 -> omit NFSD_A_SOCK_ADDR */ + const void *addr; + int addr_len; /* bytes to emit for NFSD_A_SOCK_ADDR */ +}; + +static int put_raw_listener(char *buf, int off, const struct raw_listener = *r) +{ + struct nlattr *nest =3D (void *)(buf + off); + int inner =3D off + NLA_HDRLEN; + + if (r->emit_addr) + inner =3D put_attr(buf, inner, NFSD_A_SOCK_ADDR, r->addr, r->addr_len); + if (r->xprt) + inner =3D put_attr(buf, inner, NFSD_A_SOCK_TRANSPORT_NAME, + r->xprt, strlen(r->xprt) + 1); + nest->nla_type =3D NFSD_A_SERVER_SOCK_ADDR | NLA_F_NESTED; + nest->nla_len =3D inner - off; + return off + NLA_ALIGN4(nest->nla_len); +} + +/* Well-formed loopback listener for @family (AF_INET or AF_INET6). */ +static int put_listener_af(char *buf, int off, const char *xprt, int famil= y, + uint16_t port) +{ + struct sockaddr_storage ss =3D {0}; + struct raw_listener r =3D { .xprt =3D xprt, .emit_addr =3D 1, .addr =3D &= ss }; + + if (family =3D=3D AF_INET6) { + struct sockaddr_in6 *s6 =3D (void *)&ss; + + s6->sin6_family =3D AF_INET6; + s6->sin6_port =3D htons(port); + s6->sin6_addr =3D in6addr_loopback; + r.addr_len =3D sizeof(*s6); + } else { + struct sockaddr_in *s4 =3D (void *)&ss; + + s4->sin_family =3D AF_INET; + s4->sin_port =3D htons(port); + s4->sin_addr.s_addr =3D htonl(INADDR_LOOPBACK); + r.addr_len =3D sizeof(*s4); + } + return put_raw_listener(buf, off, &r); +} + +static int put_listener(char *buf, int off, const char *xprt, uint16_t por= t) +{ + return put_listener_af(buf, off, xprt, AF_INET, port); +} + +/* ------------------- LISTENER_GET parsing ------------------- */ + +struct listener_ent { + char xprt[16]; + int family; + uint16_t port; + struct in_addr a4; + struct in6_addr a6; +}; + +static int parse_listener_get(const char *rbuf, int len, + struct listener_ent *out, int max) +{ + const struct nlmsghdr *nlh =3D (const void *)rbuf; + const struct nlattr *na; + int left, count =3D 0; + + (void)len; + na =3D (const void *)(rbuf + NLMSG_HDRLEN + GENL_HDRLEN); + left =3D nlh->nlmsg_len - NLMSG_HDRLEN - GENL_HDRLEN; + + while (left >=3D (int)NLA_HDRLEN) { + int alen =3D na->nla_len; + + if ((na->nla_type & NLA_TYPE_MASK) =3D=3D NFSD_A_SERVER_SOCK_ADDR && + count < max) { + const struct nlattr *in =3D (const void *)((char *)na + NLA_HDRLEN); + int ileft =3D alen - NLA_HDRLEN; + struct listener_ent *e =3D &out[count]; + + memset(e, 0, sizeof(*e)); + while (ileft >=3D (int)NLA_HDRLEN) { + const void *d =3D (const char *)in + NLA_HDRLEN; + int t =3D in->nla_type & NLA_TYPE_MASK; + + if (t =3D=3D NFSD_A_SOCK_TRANSPORT_NAME) { + strncpy(e->xprt, d, sizeof(e->xprt) - 1); + } else if (t =3D=3D NFSD_A_SOCK_ADDR) { + const struct sockaddr_storage *ss =3D d; + + e->family =3D ss->ss_family; + if (ss->ss_family =3D=3D AF_INET) { + const struct sockaddr_in *s =3D d; + + e->a4 =3D s->sin_addr; + e->port =3D ntohs(s->sin_port); + } else if (ss->ss_family =3D=3D AF_INET6) { + const struct sockaddr_in6 *s =3D d; + + e->a6 =3D s->sin6_addr; + e->port =3D ntohs(s->sin6_port); + } + } + ileft -=3D NLA_ALIGN4(in->nla_len); + in =3D (const void *)((char *)in + NLA_ALIGN4(in->nla_len)); + } + count++; + } + left -=3D NLA_ALIGN4(alen); + na =3D (const void *)((char *)na + NLA_ALIGN4(alen)); + } + return count; +} + +/* ------------------- convenience wrappers ------------------- */ + +static int listener_set(const char *attrs, int len) +{ + return genl_request(NFSD_CMD_LISTENER_SET, attrs, len); +} + +/* Fetch the current listeners; returns count (>=3D0) or -errno. */ +static int listener_get(struct listener_ent *out, int max) +{ + char rbuf[8192]; + int n =3D genl_request_reply(NFSD_CMD_LISTENER_GET, rbuf, sizeof(rbuf)); + + if (n < 0) + return n; + return parse_listener_get(rbuf, n, out, max); +} + +/* --------------------------- fixture --------------------------- */ + +FIXTURE(nfsd_listener) { + int placeholder; +}; + +FIXTURE_SETUP(nfsd_listener) +{ + struct ifreq ifr =3D {0}; + struct stat st; + int s; + + if (geteuid() !=3D 0) + SKIP(return, "must be run as root"); + if (unshare(CLONE_NEWNET | CLONE_NEWNS) < 0) + SKIP(return, "unshare(NEWNET|NEWNS): %s", strerror(errno)); + if (mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL) < 0) + SKIP(return, "mount(/ private): %s", strerror(errno)); + + /* + * Keep the kernel's rpcbind client inside this namespace. The + * abstract socket it tries first is per-netns, but the + * "/var/run/rpcbind.sock" fallback is not, so hide the path. + */ + if (mount("tmpfs", "/run", "tmpfs", 0, NULL) < 0) + SKIP(return, "mount(tmpfs on /run): %s", strerror(errno)); + if (lstat("/var/run", &st) =3D=3D 0 && S_ISDIR(st.st_mode) && + mount("tmpfs", "/var/run", "tmpfs", 0, NULL) < 0) + SKIP(return, "mount(tmpfs on /var/run): %s", strerror(errno)); + + /* Bring loopback up so listener binds (127.0.0.1 / ::1) work. */ + s =3D socket(AF_INET, SOCK_DGRAM, 0); + ASSERT_GE(s, 0); + strcpy(ifr.ifr_name, "lo"); + ASSERT_EQ(0, ioctl(s, SIOCGIFFLAGS, &ifr)); + ifr.ifr_flags |=3D IFF_UP | IFF_RUNNING; + ASSERT_EQ(0, ioctl(s, SIOCSIFFLAGS, &ifr)); + close(s); + + nfsd_family =3D genl_resolve_nfsd(); + if (nfsd_family < 0) + SKIP(return, "nfsd genl family not found (modprobe nfsd?)"); +} + +FIXTURE_TEARDOWN(nfsd_listener) +{ +} + +/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D validat= ion / negative =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D */ + +TEST_F(nfsd_listener, val_too_many) +{ + static char attrs[1 << 20]; + int i, off =3D 0; + + for (i =3D 0; i < 1025; i++) /* > NFSD_NL_LISTENER_MAX (1024) */ + off =3D put_listener(attrs, off, "udp", TEST_PORT); + EXPECT_EQ(-E2BIG, listener_set(attrs, off)); +} + +TEST_F(nfsd_listener, val_missing_addr) +{ + char attrs[64]; + struct raw_listener r =3D { .xprt =3D "tcp", .emit_addr =3D 0 }; + int off =3D put_raw_listener(attrs, 0, &r); + + EXPECT_EQ(-EINVAL, listener_set(attrs, off)); +} + +TEST_F(nfsd_listener, val_missing_transport) +{ + struct sockaddr_in s4 =3D { .sin_family =3D AF_INET, .sin_port =3D htons(= TEST_PORT) }; + struct raw_listener r =3D { .xprt =3D NULL, .emit_addr =3D 1, + .addr =3D &s4, .addr_len =3D sizeof(s4) }; + char attrs[64]; + int off =3D put_raw_listener(attrs, 0, &r); + + EXPECT_EQ(-EINVAL, listener_set(attrs, off)); +} + +/* + * A name matching no transport class must be refused before nfsd_mutex is + * taken, so it never reaches svc_xprt_create_from_sa() and its + * request_module("svc%s", name) upcall. + */ +TEST_F(nfsd_listener, val_bad_transport) +{ + char attrs[64]; + int off =3D put_listener(attrs, 0, "bogus_xprt", TEST_PORT); + + EXPECT_EQ(-EPROTONOSUPPORT, listener_set(attrs, off)); +} + +TEST_F(nfsd_listener, val_addr_too_short) +{ + unsigned char tiny =3D 0; + struct raw_listener r =3D { .xprt =3D "tcp", .emit_addr =3D 1, + .addr =3D &tiny, .addr_len =3D 1 }; + char attrs[64]; + int off =3D put_raw_listener(attrs, 0, &r); + + EXPECT_EQ(-EINVAL, listener_set(attrs, off)); +} + +TEST_F(nfsd_listener, val_inet_short) +{ + struct sockaddr_in s4 =3D { .sin_family =3D AF_INET, .sin_port =3D htons(= TEST_PORT) }; + struct raw_listener r =3D { .xprt =3D "tcp", .emit_addr =3D 1, .addr =3D = &s4, + .addr_len =3D sizeof(sa_family_t) + 2 }; + char attrs[64]; + int off =3D put_raw_listener(attrs, 0, &r); + + EXPECT_EQ(-EINVAL, listener_set(attrs, off)); +} + +TEST_F(nfsd_listener, val_inet6_short) +{ + struct sockaddr_in6 s6 =3D { .sin6_family =3D AF_INET6, .sin6_port =3D ht= ons(TEST_PORT) }; + struct raw_listener r =3D { .xprt =3D "tcp", .emit_addr =3D 1, .addr =3D = &s6, + .addr_len =3D sizeof(struct sockaddr_in) }; + char attrs[64]; + int off =3D put_raw_listener(attrs, 0, &r); + + EXPECT_EQ(-EINVAL, listener_set(attrs, off)); +} + +TEST_F(nfsd_listener, val_bad_family) +{ + struct sockaddr_storage ss =3D { .ss_family =3D AF_UNIX }; + struct raw_listener r =3D { .xprt =3D "tcp", .emit_addr =3D 1, .addr =3D = &ss, + .addr_len =3D sizeof(struct sockaddr_in) }; + char attrs[64]; + int off =3D put_raw_listener(attrs, 0, &r); + + EXPECT_EQ(-EAFNOSUPPORT, listener_set(attrs, off)); +} + +TEST_F(nfsd_listener, val_second_entry_bad) +{ + struct sockaddr_storage ss =3D { .ss_family =3D AF_UNIX }; + struct raw_listener bad =3D { .xprt =3D "tcp", .emit_addr =3D 1, .addr = =3D &ss, + .addr_len =3D sizeof(struct sockaddr_in) }; + char attrs[128]; + int off =3D put_listener(attrs, 0, "tcp", TEST_PORT); + + off =3D put_raw_listener(attrs, off, &bad); + /* The whole request is rejected during validation; nothing applied. */ + EXPECT_EQ(-EAFNOSUPPORT, listener_set(attrs, off)); +} + +/* LISTENER_GET with no serv in this netns returns an empty list. */ +TEST_F(nfsd_listener, func_get_empty) +{ + struct listener_ent got[MAX_LISTENERS]; + + EXPECT_EQ(0, listener_get(got, MAX_LISTENERS)); +} + +TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/nfsd/settings b/tools/testing/selftest= s/nfsd/settings new file mode 100644 index 000000000000..6091b45d226b --- /dev/null +++ b/tools/testing/selftests/nfsd/settings @@ -0,0 +1 @@ +timeout=3D120 --=20 2.55.0 From nobody Sat Sep 26 23:02:48 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 91B57472F7D; Fri, 28 Aug 2026 16:38:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787935087; cv=none; b=iFFVEaNsZ4fY3fQr2k4ybe8/Touee//16kh0gXCJ0ow7D+jDW2hOXWMFwh8bCgi8VLEr2jOW1vnD9+aUsxURxE4O8yyEu0xW4rsdP0kyUG7K1XAgWRRWH78inNX824XH+MXQ0zrcDTr1XVkNCx/ioLGwkO2t7tDCL1CYnk3iygc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787935087; c=relaxed/simple; bh=th48vMrVvf58O7nk4N1WnDhM2y9ibVFDXAp4BTCNaHc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=H5DJxHh6NPJxGWWm/0DvZ8dgA0q85gBKvsrniXC156iFvvZWvmiyV622Kmkq3bNpE8jtZKerYujOrYJJOkLu5gJoNW3slbEZn7Shom0zA8LqUxPZnnpbxBuqhQtMeP3o2cz8MrNG7TcjVKQI0mIcCUivC2XxSlZ9HAND5yZes7s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZAst78ME; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZAst78ME" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBA961F00A3D; Fri, 28 Aug 2026 16:38:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787935085; bh=0wHkz9gKCDlM8SccDujfwP2D/PQWOv/mcr4bCZIAihY=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=ZAst78MEiibyB31LqLHpKJ6BHjqKtvVMeQH9+QK6J1bJE1gv5OcvEiDmVYn1H46sP ABNneFQtL6oR8oc49J/fKyUzhTqn7QwXZCsgvH+5SvxQJFpxHteV2rQBvdFP98xR1b QHkHEJZH8kPr4XLR7Z0HfVVyAe299rRUg3gYnA98dRsG/24DOugQI3hLjSk0y3re8p rdLXucvPfDke3Bo/qNpQuBdYzqblDggOP7WncwVbyhflnfNQkVWo+mvNKiAfj9ykIa YFarrSXUvNxmrqFuxJF/gB73T8nKJ7wkxCiNneNcc3yWi9NkMVE5oNGx2OC/W/dFgs BqKeEM9NZjMOA== From: Jeff Layton Date: Fri, 28 Aug 2026 12:37:42 -0400 Subject: [PATCH v3 12/14] selftests/nfsd: add a per-netns rpcbind stub and the listener round-trips Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260828-nfsd-nl-hang-v3-12-55026685c75d@kernel.org> References: <20260828-nfsd-nl-hang-v3-0-55026685c75d@kernel.org> In-Reply-To: <20260828-nfsd-nl-hang-v3-0-55026685c75d@kernel.org> To: Chuck Lever , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: Slawomir Stepien , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Trond Myklebust , linux-kselftest@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=30213; i=jlayton@kernel.org; h=from:subject:message-id; bh=th48vMrVvf58O7nk4N1WnDhM2y9ibVFDXAp4BTCNaHc=; b=owEBbQKS/ZANAwAKAQAOaEEZVoIVAcsmYgBqkblWHJ5lTPc7EVys7uN0sDruLYS3La5iyAghl 6pVsCnU6Q6JAjMEAAEKAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCapG5VgAKCRAADmhBGVaC FZhMEACPENM6GoXOGAntehyudWhHR7zrWeNwQsOY6VjMOkosZTCkJhI/ZBlY/AmSybyk2E6w1P0 I7n6z/O9K+YUwcrL98b4HC3YJmSK+xK6Sxw7sD/bodpIQ981z5M1jzKIlWJ2sIcxW6k1x75eXrm zWGKOUnoSBT49ltbPpZcsTt/S7JNtnaMCaV6ms8h1fUBOWTrFcp/zd4xZj+wnd1ckMCyH0DtzCu JZisys2LtH5XhyPbZB5dX3MiqtqGbatJ3+kYwsF6Jwnxvrxyw1Yjd+SD1KMadur3vtkxyk7VSNj Vncaf7REWIq63cstU1HOa5C8btiyk33inphwpJywLjeckHli9YYywZ542C8iF8esPv7SAHLD2te jHBFcRG68jn+e2MzkgYbaJwxPEiwTXMU/XquR8i2YNtz/FObPaXXK8ZDNg5XRIa3jG2gKFLX+u7 WrPp+yQPVnhyLkskW639ek53srFbEKS+a0Bfx/u+IchwYdR3+KybbuBjhzEFyilSXyp2i5L7SCv OUplNwRoYq1paTaFNk4aKwya0ZcGxDSaNGn7O6wcOk/9C3ViZCJvtsMBqUknFTeCZZBgPHEu+Wz 7o2Ohjk3xDDBP9hPuGcFJckH5Ju/npx2sKz/b6UnCFAa1yTD2i+QbLkOsyy2Qz5lzA2IKDIJvhd t/j+Pxk4CEi3wvA== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 The creation of a listener registers with rpcbind. svc_xprt_create_from_sa() passes flags of 0, so pmap_register is true in svc_setup_socket(). A fresh netns has no rpcbind. Every registration therefore waits out the local rpcbind timeout, once for each program and version, and the registration failure then takes the listener down. The host's rpcbind is not an option either. svc_rpcb_setup() opens with a call to svc_unregister(), which would clear the host's nfsd entries. Serve rpcbind from inside the namespace instead. The abstract AF_LOCAL name that the kernel tries first is per-netns, because unix_find_abstract() takes a struct net. Bind "\0/run/rpcbind.sock" and fork a minimal responder: - the responder never decodes arguments. The NULL procedure gets an empty success, and SET and UNSET get TRUE. - the responder answers RPCBVERS_4 as well as RPCBVERS_2. A v4 refusal makes __svc_rpcb_register6() return -EAFNOSUPPORT, which would leave every IPv6 listener unregistered. - the responder counts accepted connections and received calls in a page that it shares with the test, and reads its mode from that page on every call. The mode lives there rather than in the child so that a test can change it with a serv already up: killing and restarting the stub would close the connection the kernel holds, and rpcb_register_call() issues UNSET over AF_LOCAL with RPC_TASK_NOCONNECT, so the next call would fail at once with -ENOTCONN instead of waiting out a timeout. - PR_SET_PDEATHSIG plus an explicit kill in FIXTURE_TEARDOWN make sure that no stub outlives its test. With the stub in place, add the tests that need a serv. These cover the create, add and remove paths and the LISTENER_GET round trips: tcp, udp, several listeners at once, an idempotent re-set, the removal of a subset, the destruction of a serv from an empty list, and IPv6. Two more tests cover the empty-list request and the -EBUSY refusal after THREADS_SET has started threads. The netlink socket asks for NETLINK_EXT_ACK, so that the tests can read the extack message. It also asks for NETLINK_CAP_ACK, so that the kernel does not echo the request back and the TLVs sit at a fixed offset. FIXTURE_TEARDOWN drops whatever a test left running. A listener holds a reference to the netns, and that netns outlives the test process. Threads pin the listeners. Anything left up therefore leaks the namespace. Several of these tests exist to catch a revert, not to describe the interface. The errno alone shows none of them: - val_reject_keeps_listeners. An unknown transport name ends in -EPROTONOSUPPORT either way, because svc_xprt_create_from_sa() returns that error too. The difference is the state that it leaves. Without the up-front check, nfsd_nl_listener_set_doit() has already destroyed the listeners that did not match by the time the name fails. - val_bad_transport. This test now also requires that the stub saw no traffic. A request that reaches svc_xprt_create_from_sa() has run nfsd_create_serv(). svc_bind() then pings rpcbind at client creation and sweeps stale entries with svc_unregister(). Silence at the stub is therefore what shows that the kernel refused the request up front. - val_second_entry_bad. This test now also sends a LISTENER_GET. svc_xprt_create_from_sa() also returns -EAFNOSUPPORT for the bad entry, and the doit keeps the listeners that it did create. The well-formed tcp entry ahead of it would otherwise still be up. - sem_register_refused. This test puts the stub in a mode that answers RPCBPROC_SET with FALSE. rpcb_register_call() turns that answer into -EACCES, svc_register() then fails, and svc_setup_socket() creates no listener. The bare errno does not show that, because a bind can return -EACCES too, so the test reads the listener set back and requires that it is empty. - sem_create_failure_extack. This test squats on the port first, so the listener cannot bind. The extack must then name the transport that failed. - func_empty_destroys. This test uses the connection count. LISTENER_GET replies empty both for a destroyed serv and for a live serv with no permsocks. But only nfsd_destroy_serv() reaches svc_xprt_destroy_all(..., unregister=3Dtrue) -> svc_rpcb_cleanup() -> rpcb_put_local(), which drops the last user and shuts the local client down. The next serv has to connect again. - sem_busy_on_change and sem_busy_on_remove read the listeners back, because -EBUSY says nothing about what the doit did before it returned. find_listener() matches the address as well as the transport, the family and the port. Every listener here is created on loopback, so a reply that names 0.0.0.0 has to fail. Assisted-by: LLM Signed-off-by: Jeff Layton --- .../testing/selftests/nfsd/nfsd_netlink_listener.c | 637 +++++++++++++++++= +++- 1 file changed, 627 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/nfsd/nfsd_netlink_listener.c b/tools/t= esting/selftests/nfsd/nfsd_netlink_listener.c index ae28c224255f..99c320e2f7c2 100644 --- a/tools/testing/selftests/nfsd/nfsd_netlink_listener.c +++ b/tools/testing/selftests/nfsd/nfsd_netlink_listener.c @@ -3,30 +3,41 @@ * Regression tests for the NFSD generic-netlink listener interface * (NFSD_CMD_LISTENER_SET / NFSD_CMD_LISTENER_GET). * - * These cover the request validation that nfsd_nl_validate_listeners() do= es - * before nfsd_mutex is taken: bad or absent transport name, missing addre= ss, - * truncated or unsupported sockaddr, oversized list. None of them reach - * nfsd_create_serv(), so nothing here creates a serv or talks to rpcbind. + * Three groups: + * validation - malformed/abusive LISTENER_SET requests are rejected by + * nfsd_nl_validate_listeners(), before nfsd_mutex is take= n. + * functional - create/add/remove listeners and verify LISTENER_GET + * reflects the set (round-trip of transport + addr:port). + * semantics - once threads are running (THREADS_SET) a listener change + * is refused with -EBUSY. * * Each test runs in its own private net + mount namespace (unshare in * FIXTURE_SETUP). /run is masked there: a pathname AF_LOCAL connect is not * scoped by the network namespace, since unix_find_bsd() resolves by inode * and takes no struct net, so the kernel's rpcbind client would otherwise= be - * able to reach the rpcbind running on the host. + * able to reach the rpcbind running on the host. Anything that creates a + * serv is served by the per-netns rpcbind stub below instead. */ #define _GNU_SOURCE #include +#include #include +#include +#include #include #include #include #include #include +#include #include +#include #include #include #include #include +#include +#include #include #include #include @@ -36,8 +47,10 @@ =20 /* NFSD generic-netlink constants (from linux/nfsd_netlink.h). */ #define NFSD_FAMILY_NAME "nfsd" +#define NFSD_CMD_THREADS_SET 2 #define NFSD_CMD_LISTENER_SET 6 #define NFSD_CMD_LISTENER_GET 7 +#define NFSD_A_SERVER_THREADS 1 #define NFSD_A_SERVER_SOCK_ADDR 1 /* per-listener nest */ #define NFSD_A_SOCK_ADDR 1 /* inside the nest */ #define NFSD_A_SOCK_TRANSPORT_NAME 2 /* inside the nest */ @@ -47,7 +60,10 @@ #define MAX_LISTENERS 8 #define RECV_TIMEO_SEC 30 =20 -static int nfsd_family; /* set per-test in FIXTURE_SETUP */ +static int nfsd_family =3D -1; /* set per-test in FIXTURE_SETUP */ + +/* Extack message from the last genl_request(); empty if there was none. */ +static char last_extack[128]; =20 static void die(const char *msg) { @@ -62,15 +78,50 @@ static int genl_open(void) struct sockaddr_nl sa =3D { .nl_family =3D AF_NETLINK }; struct timeval tv =3D { .tv_sec =3D RECV_TIMEO_SEC }; int fd =3D socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC); + int on =3D 1; =20 if (fd < 0) die("socket(NETLINK_GENERIC)"); if (bind(fd, (void *)&sa, sizeof(sa)) < 0) die("bind(netlink)"); setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); + /* + * Ask for extack, and cap the ack so the request is not echoed back: + * the TLVs then always follow the fixed part of the error message. + */ + setsockopt(fd, SOL_NETLINK, NETLINK_EXT_ACK, &on, sizeof(on)); + setsockopt(fd, SOL_NETLINK, NETLINK_CAP_ACK, &on, sizeof(on)); return fd; } =20 +/* Stash the extack message of an ack, if it carries one. */ +static void parse_extack(const char *rbuf) +{ + const struct nlmsghdr *nlh =3D (const void *)rbuf; + const struct nlattr *na; + int off, left; + + last_extack[0] =3D '\0'; + if (nlh->nlmsg_type !=3D NLMSG_ERROR || + !(nlh->nlmsg_flags & NLM_F_ACK_TLVS)) + return; + + off =3D NLMSG_HDRLEN + NLMSG_ALIGN(sizeof(struct nlmsgerr)); + left =3D nlh->nlmsg_len - off; + na =3D (const void *)(rbuf + off); + + while (left >=3D (int)NLA_HDRLEN) { + if ((na->nla_type & NLA_TYPE_MASK) =3D=3D NLMSGERR_ATTR_MSG) { + strncpy(last_extack, (const char *)na + NLA_HDRLEN, + sizeof(last_extack) - 1); + last_extack[sizeof(last_extack) - 1] =3D '\0'; + return; + } + left -=3D NLA_ALIGN4(na->nla_len); + na =3D (const void *)((const char *)na + NLA_ALIGN4(na->nla_len)); + } +} + /* Append an attribute at @off; return the new (aligned) offset. */ static int put_attr(char *buf, int off, uint16_t type, const void *data, int len) @@ -117,13 +168,16 @@ static int genl_request(uint8_t cmd, const char *attr= s, int attrs_len) if (send(fd, buf, off, 0) < 0) die("send(genl)"); =20 + last_extack[0] =3D '\0'; n =3D recv(fd, rbuf, sizeof(rbuf), 0); - if (n < 0) + if (n < 0) { ret =3D (errno =3D=3D EAGAIN || errno =3D=3D EWOULDBLOCK) ? -ETIMEDOUT := -errno; - else if (((struct nlmsghdr *)rbuf)->nlmsg_type =3D=3D NLMSG_ERROR) + } else if (((struct nlmsghdr *)rbuf)->nlmsg_type =3D=3D NLMSG_ERROR) { ret =3D ((struct nlmsgerr *)NLMSG_DATA(rbuf))->error; - else + parse_extack(rbuf); + } else { ret =3D 0; + } close(fd); return ret; } @@ -327,10 +381,296 @@ static int listener_get(struct listener_ent *out, in= t max) return parse_listener_get(rbuf, n, out, max); } =20 +/* + * Every listener these tests create comes from put_listener_af(), so the + * address is always loopback. Match on it too: without that, a reply that + * gave the right transport and port on the wrong address (0.0.0.0, say) + * would pass. + */ +static struct listener_ent *find_listener(struct listener_ent *e, int n, + const char *xprt, int family, + uint16_t port) +{ + int i; + + for (i =3D 0; i < n; i++) { + if (e[i].family !=3D family || e[i].port !=3D port || + strcmp(e[i].xprt, xprt)) + continue; + if (family =3D=3D AF_INET6) { + if (memcmp(&e[i].a6, &in6addr_loopback, sizeof(e[i].a6))) + continue; + } else if (e[i].a4.s_addr !=3D htonl(INADDR_LOOPBACK)) { + continue; + } + return &e[i]; + } + return NULL; +} + +/* Start (@n > 0) or stop (@n =3D=3D 0) nfsd threads in this netns. */ +static int threads_set(int n) +{ + char attrs[64]; + uint32_t v =3D n; + int off =3D put_attr(attrs, 0, NFSD_A_SERVER_THREADS, &v, sizeof(v)); + + return genl_request(NFSD_CMD_THREADS_SET, attrs, off); +} + +/* ------------------- per-netns local rpcbind stub ------------------- */ + +/* + * Creating a listener registers with rpcbind: nfsd_nl_listener_set_doit() + * passes no SVC_SOCK_ANONYMOUS for the first entry of a request, so + * pmap_register is true in svc_setup_socket(). The fixture's server has v3 + * enabled, and nfsd_version3 does not set vs_rpcb_optnl, so a failure the= re + * comes back out of svc_register() and takes the listener down with it. + * With nothing listening, every attempt first waits out the local rpcbind + * timeout. The abstract AF_LOCAL name the kernel tries first is per-netns + * (unix_find_abstract() takes a struct net), so answer it here and stay o= ut + * of the host's rpcbind. + * + * Arguments are never decoded. The NULL procedure gets an empty success a= nd + * SET/UNSET get TRUE, for both RPCBVERS_2 and RPCBVERS_4. v4 has to be + * answered because __svc_rpcb_register6() turns a v4 refusal into + * -EAFNOSUPPORT, which would leave every IPv6 listener unregistered. + * + * In RPCB_STUB_REFUSE mode SET is answered FALSE instead, which + * rpcb_register_call() reports as -EACCES. UNSET is left alone: only + * svc_unregister() issues it, and it discards the result. + * + * The stub also keeps counters and the mode in a page shared with the tes= t, so + * a test can assert that the kernel never talked to rpcbind at all, or th= at it + * dropped the local rpcbind client and had to reconnect. + * + * The mode lives there rather than in the child so that a test can change= it + * with a serv already up. Killing and restarting the stub would close the + * connection the kernel holds, and rpcb_register_call() issues UNSET over + * AF_LOCAL with RPC_TASK_NOCONNECT, so the next call would fail at once w= ith + * -ENOTCONN instead of waiting out a timeout. + */ +#define RPCB_PROGRAM 100000 +#define RPCB_PROC_NULL 0 +#define RPCB_PROC_SET 1 +#define RPCB_PROC_UNSET 2 +#define RPCB_ABSTRACT_NAME "/run/rpcbind.sock" +#define RPCB_STUB_MAXCONN 4 + +enum { RPCB_STUB_ACCEPT, RPCB_STUB_REFUSE }; + +struct rpcb_stub_stats { + unsigned int conns; /* connections accepted */ + unsigned int calls; /* calls received */ + unsigned int mode; /* RPCB_STUB_*, read on every call */ +}; + +static volatile struct rpcb_stub_stats *rpcb_stats; /* MAP_SHARED */ + +static int rpcb_stats_alloc(void) +{ + void *p =3D mmap(NULL, sizeof(*rpcb_stats), PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANONYMOUS, -1, 0); + + if (p =3D=3D MAP_FAILED) + return -1; + rpcb_stats =3D p; + return 0; +} + +/* + * The stub bumps these before it replies and the kernel waits for that re= ply, + * so whatever a netlink request provoked is visible once it returns. + */ +static int rpcb_calls(void) +{ + return rpcb_stats ? (int)rpcb_stats->calls : 0; +} + +static int rpcb_conns(void) +{ + return rpcb_stats ? (int)rpcb_stats->conns : 0; +} + +/* Takes effect on the stub's next call; the caller has not sent one yet. = */ +static void rpcb_stub_set_mode(int mode) +{ + rpcb_stats->mode =3D mode; +} + +static int rpcb_stub_listen(void) +{ + struct sockaddr_un sun =3D { .sun_family =3D AF_UNIX }; + size_t nlen =3D strlen(RPCB_ABSTRACT_NAME); + socklen_t alen; + int fd; + + /* Abstract names are length-delimited, so the length must match. */ + memcpy(sun.sun_path + 1, RPCB_ABSTRACT_NAME, nlen); + alen =3D offsetof(struct sockaddr_un, sun_path) + 1 + nlen; + + fd =3D socket(AF_UNIX, SOCK_STREAM, 0); + if (fd < 0) + return -1; + if (bind(fd, (struct sockaddr *)&sun, alen) < 0 || + listen(fd, RPCB_STUB_MAXCONN) < 0) { + close(fd); + return -1; + } + return fd; +} + +static int rpcb_stub_read(int fd, void *buf, size_t len) +{ + size_t done =3D 0; + + while (done < len) { + ssize_t n =3D read(fd, (char *)buf + done, len - done); + + if (n <=3D 0) + return -1; + done +=3D n; + } + return 0; +} + +/* Handle one record-marked RPC call. Returns -1 when the peer is done. */ +static int rpcb_stub_call(int fd) +{ + unsigned int len, nrep =3D 6, mode =3D rpcb_stats->mode; + uint32_t mark, call[6], rep[7]; + size_t replen; + + if (rpcb_stub_read(fd, &mark, sizeof(mark))) + return -1; + len =3D ntohl(mark) & 0x7fffffff; + if (len < sizeof(call) || len > 4096) + return -1; + if (rpcb_stub_read(fd, call, sizeof(call))) + return -1; + + /* xid, msg_type, rpcvers, prog, vers, proc; the rest is discarded */ + for (len -=3D sizeof(call); len; ) { + char sink[256]; + unsigned int n =3D len > sizeof(sink) ? sizeof(sink) : len; + + if (rpcb_stub_read(fd, sink, n)) + return -1; + len -=3D n; + } + + if (rpcb_stats) + rpcb_stats->calls++; + + rep[0] =3D call[0]; /* xid */ + rep[1] =3D htonl(1); /* REPLY */ + rep[2] =3D htonl(0); /* MSG_ACCEPTED */ + rep[3] =3D htonl(0); /* verifier flavor AUTH_NULL */ + rep[4] =3D htonl(0); /* verifier length */ + rep[5] =3D htonl(0); /* SUCCESS */ + + if (ntohl(call[3]) !=3D RPCB_PROGRAM) { + rep[5] =3D htonl(1); /* PROG_UNAVAIL */ + } else { + switch (ntohl(call[5])) { + case RPCB_PROC_NULL: + break; + case RPCB_PROC_SET: + rep[6] =3D htonl(mode =3D=3D RPCB_STUB_REFUSE ? 0 : 1); + nrep =3D 7; + break; + case RPCB_PROC_UNSET: + rep[6] =3D htonl(1); /* TRUE */ + nrep =3D 7; + break; + default: + rep[5] =3D htonl(3); /* PROC_UNAVAIL */ + } + } + + replen =3D nrep * sizeof(rep[0]); + mark =3D htonl(0x80000000 | replen); + if (write(fd, &mark, sizeof(mark)) !=3D (ssize_t)sizeof(mark) || + write(fd, rep, replen) !=3D (ssize_t)replen) + return -1; + return 0; +} + +static void rpcb_stub_serve(int lfd) +{ + struct pollfd pfd[1 + RPCB_STUB_MAXCONN]; + nfds_t n =3D 1, i; + + pfd[0].fd =3D lfd; + + for (;;) { + /* stop polling the listener when full, or poll() spins */ + pfd[0].events =3D n < 1 + RPCB_STUB_MAXCONN ? POLLIN : 0; + + if (poll(pfd, n, -1) < 0) + return; + + if (pfd[0].revents & POLLIN) { + int c =3D accept(lfd, NULL, NULL); + + if (c >=3D 0) { + pfd[n].fd =3D c; + pfd[n].events =3D POLLIN; + /* + * poll() ran with the old n, so it did not + * write this revents. The loop below reads it. + */ + pfd[n].revents =3D 0; + n++; + if (rpcb_stats) + rpcb_stats->conns++; + } + } + + for (i =3D 1; i < n; i++) { + if (!(pfd[i].revents & (POLLIN | POLLHUP | POLLERR))) + continue; + if (rpcb_stub_call(pfd[i].fd)) { + close(pfd[i].fd); + pfd[i] =3D pfd[--n]; + } + } + } +} + +/* Returns the stub's pid, or -1. The socket is listening before we fork. = */ +static pid_t rpcb_stub_start(int mode) +{ + int lfd =3D rpcb_stub_listen(); + pid_t pid; + + if (lfd < 0) + return -1; + + rpcb_stats->mode =3D mode; + + pid =3D fork(); + if (pid < 0) { + close(lfd); + return -1; + } + if (pid =3D=3D 0) { + signal(SIGPIPE, SIG_IGN); + prctl(PR_SET_PDEATHSIG, SIGKILL); + if (getppid() =3D=3D 1) /* raced with parent exit */ + _exit(0); + rpcb_stub_serve(lfd); + _exit(0); + } + + close(lfd); + return pid; +} + /* --------------------------- fixture --------------------------- */ =20 FIXTURE(nfsd_listener) { - int placeholder; + pid_t rpcbd; }; =20 FIXTURE_SETUP(nfsd_listener) @@ -369,14 +709,43 @@ FIXTURE_SETUP(nfsd_listener) nfsd_family =3D genl_resolve_nfsd(); if (nfsd_family < 0) SKIP(return, "nfsd genl family not found (modprobe nfsd?)"); + + if (rpcb_stats_alloc() < 0) + SKIP(return, "mmap(rpcbind stub counters): %s", strerror(errno)); + + self->rpcbd =3D rpcb_stub_start(RPCB_STUB_ACCEPT); + if (self->rpcbd < 0) + SKIP(return, "cannot start the rpcbind stub: %s", + strerror(errno)); } =20 FIXTURE_TEARDOWN(nfsd_listener) { + /* + * A listener holds a reference to this netns, which outlives the test + * process, so anything still up leaks it. Threads pin the listeners in + * turn; dropping them destroys the serv and everything under it. + */ + if (nfsd_family >=3D 0 && listener_set(NULL, 0) =3D=3D -EBUSY) + threads_set(0); + + if (self->rpcbd > 0) { + kill(self->rpcbd, SIGKILL); + waitpid(self->rpcbd, NULL, 0); + } + if (rpcb_stats) { + munmap((void *)rpcb_stats, sizeof(*rpcb_stats)); + rpcb_stats =3D NULL; + } } =20 /* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D validat= ion / negative =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D */ =20 +TEST_F(nfsd_listener, val_empty_list_ok) +{ + EXPECT_EQ(0, listener_set(NULL, 0)); +} + TEST_F(nfsd_listener, val_too_many) { static char attrs[1 << 20]; @@ -411,13 +780,21 @@ TEST_F(nfsd_listener, val_missing_transport) * A name matching no transport class must be refused before nfsd_mutex is * taken, so it never reaches svc_xprt_create_from_sa() and its * request_module("svc%s", name) upcall. + * + * The errno cannot show that -- svc_xprt_create_from_sa() returns + * -EPROTONOSUPPORT for an unknown name too. The rpcbind traffic can: + * getting that far means nfsd_create_serv() ran, and svc_bind() pings + * rpcbind at client creation and then sweeps stale entries with + * svc_unregister(). A silent stub is the proof nothing was created. */ TEST_F(nfsd_listener, val_bad_transport) { char attrs[64]; int off =3D put_listener(attrs, 0, "bogus_xprt", TEST_PORT); =20 + ASSERT_EQ(0, rpcb_calls()); EXPECT_EQ(-EPROTONOSUPPORT, listener_set(attrs, off)); + EXPECT_EQ(0, rpcb_calls()); } =20 TEST_F(nfsd_listener, val_addr_too_short) @@ -469,14 +846,49 @@ TEST_F(nfsd_listener, val_second_entry_bad) struct sockaddr_storage ss =3D { .ss_family =3D AF_UNIX }; struct raw_listener bad =3D { .xprt =3D "tcp", .emit_addr =3D 1, .addr = =3D &ss, .addr_len =3D sizeof(struct sockaddr_in) }; + struct listener_ent got[MAX_LISTENERS]; char attrs[128]; int off =3D put_listener(attrs, 0, "tcp", TEST_PORT); =20 off =3D put_raw_listener(attrs, off, &bad); /* The whole request is rejected during validation; nothing applied. */ EXPECT_EQ(-EAFNOSUPPORT, listener_set(attrs, off)); + /* + * Again the errno alone does not say so: svc_xprt_create_from_sa() + * also returns -EAFNOSUPPORT, and the doit keeps the listeners it did + * manage to create, so the well-formed tcp entry ahead of the bad one + * would still be up. + */ + EXPECT_EQ(0, listener_get(got, MAX_LISTENERS)); +} + +/* + * A rejected request must leave the listeners that are already up alone. + * The errno alone does not show that: svc_xprt_create_from_sa() returns + * -EPROTONOSUPPORT for an unknown name too. What differs is how far the + * request gets -- without the check in nfsd_nl_validate_listeners(), + * nfsd_nl_listener_set_doit() has already moved the unmatched tcp listener + * off sv_permsocks and run svc_xprt_destroy_all() on it by the time the + * name fails. + */ +TEST_F(nfsd_listener, val_reject_keeps_listeners) +{ + struct listener_ent got[MAX_LISTENERS]; + char good[64], bad[64]; + int og =3D put_listener(good, 0, "tcp", TEST_PORT); + int ob =3D put_listener(bad, 0, "bogus_xprt", TEST_PORT); + + ASSERT_EQ(0, listener_set(good, og)); + ASSERT_EQ(1, listener_get(got, MAX_LISTENERS)); + + EXPECT_EQ(-EPROTONOSUPPORT, listener_set(bad, ob)); + + ASSERT_EQ(1, listener_get(got, MAX_LISTENERS)); + EXPECT_NE(NULL, find_listener(got, 1, "tcp", AF_INET, TEST_PORT)); } =20 +/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D functio= nal / round-trip =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D */ + /* LISTENER_GET with no serv in this netns returns an empty list. */ TEST_F(nfsd_listener, func_get_empty) { @@ -485,4 +897,209 @@ TEST_F(nfsd_listener, func_get_empty) EXPECT_EQ(0, listener_get(got, MAX_LISTENERS)); } =20 +TEST_F(nfsd_listener, func_create_tcp) +{ + struct listener_ent got[MAX_LISTENERS]; + char attrs[64]; + int off =3D put_listener(attrs, 0, "tcp", TEST_PORT); + + ASSERT_EQ(0, listener_set(attrs, off)); + EXPECT_STREQ("", last_extack); /* nothing to warn about */ + ASSERT_EQ(1, listener_get(got, MAX_LISTENERS)); + EXPECT_NE(NULL, find_listener(got, 1, "tcp", AF_INET, TEST_PORT)); +} + +TEST_F(nfsd_listener, func_create_udp) +{ + struct listener_ent got[MAX_LISTENERS]; + char attrs[64]; + int off =3D put_listener(attrs, 0, "udp", TEST_PORT); + + ASSERT_EQ(0, listener_set(attrs, off)); + ASSERT_EQ(1, listener_get(got, MAX_LISTENERS)); + EXPECT_NE(NULL, find_listener(got, 1, "udp", AF_INET, TEST_PORT)); +} + +TEST_F(nfsd_listener, func_create_multi) +{ + struct listener_ent got[MAX_LISTENERS]; + char attrs[128]; + int off =3D put_listener(attrs, 0, "tcp", TEST_PORT); + + off =3D put_listener(attrs, off, "udp", TEST_PORT); + ASSERT_EQ(0, listener_set(attrs, off)); + ASSERT_EQ(2, listener_get(got, MAX_LISTENERS)); + EXPECT_NE(NULL, find_listener(got, 2, "tcp", AF_INET, TEST_PORT)); + EXPECT_NE(NULL, find_listener(got, 2, "udp", AF_INET, TEST_PORT)); +} + +TEST_F(nfsd_listener, func_idempotent) +{ + struct listener_ent got[MAX_LISTENERS]; + char attrs[64]; + int off =3D put_listener(attrs, 0, "tcp", TEST_PORT); + + ASSERT_EQ(0, listener_set(attrs, off)); + EXPECT_EQ(0, listener_set(attrs, off)); /* re-set same list */ + ASSERT_EQ(1, listener_get(got, MAX_LISTENERS)); + EXPECT_NE(NULL, find_listener(got, 1, "tcp", AF_INET, TEST_PORT)); +} + +TEST_F(nfsd_listener, func_add) +{ + struct listener_ent got[MAX_LISTENERS]; + char one[64], two[128]; + int o1 =3D put_listener(one, 0, "tcp", TEST_PORT); + int o2 =3D put_listener(two, 0, "tcp", TEST_PORT); + + o2 =3D put_listener(two, o2, "udp", TEST_PORT); + ASSERT_EQ(0, listener_set(one, o1)); + ASSERT_EQ(0, listener_set(two, o2)); /* add udp, keep tcp */ + ASSERT_EQ(2, listener_get(got, MAX_LISTENERS)); + EXPECT_NE(NULL, find_listener(got, 2, "tcp", AF_INET, TEST_PORT)); + EXPECT_NE(NULL, find_listener(got, 2, "udp", AF_INET, TEST_PORT)); +} + +TEST_F(nfsd_listener, func_remove_subset) +{ + struct listener_ent got[MAX_LISTENERS]; + char both[128], one[64]; + int ob =3D put_listener(both, 0, "tcp", TEST_PORT); + int oo =3D put_listener(one, 0, "tcp", TEST_PORT); + + ob =3D put_listener(both, ob, "udp", TEST_PORT); + ASSERT_EQ(0, listener_set(both, ob)); + ASSERT_EQ(0, listener_set(one, oo)); /* drop udp */ + ASSERT_EQ(1, listener_get(got, MAX_LISTENERS)); + EXPECT_NE(NULL, find_listener(got, 1, "tcp", AF_INET, TEST_PORT)); +} + +/* + * LISTENER_GET cannot tell a destroyed serv from a live one with no + * permsocks: nfsd_nl_listener_get_doit() replies empty either way. The + * rpcbind client can. nfsd_destroy_serv() is the only path that reaches + * svc_xprt_destroy_all(..., unregister=3Dtrue) -> svc_rpcb_cleanup() -> + * rpcb_put_local(), which drops the last user and shuts the local client + * down; the next serv then has to connect again. Leaving the serv in place + * would keep the first connection and the stub would see just the one. + */ +TEST_F(nfsd_listener, func_empty_destroys) +{ + struct listener_ent got[MAX_LISTENERS]; + char attrs[64]; + int off =3D put_listener(attrs, 0, "tcp", TEST_PORT); + int conns; + + ASSERT_EQ(0, listener_set(attrs, off)); + conns =3D rpcb_conns(); + ASSERT_GT(conns, 0); + + EXPECT_EQ(0, listener_set(NULL, 0)); /* empty -> destroy serv */ + EXPECT_EQ(0, listener_get(got, MAX_LISTENERS)); + + ASSERT_EQ(0, listener_set(attrs, off)); + EXPECT_GT(rpcb_conns(), conns); +} + +TEST_F(nfsd_listener, func_ipv6) +{ + struct listener_ent got[MAX_LISTENERS]; + char attrs[64]; + int off, s; + + s =3D socket(AF_INET6, SOCK_STREAM, 0); + if (s < 0) + SKIP(return, "IPv6 unavailable: %s", strerror(errno)); + close(s); + + off =3D put_listener_af(attrs, 0, "tcp", AF_INET6, TEST_PORT); + ASSERT_EQ(0, listener_set(attrs, off)); + ASSERT_EQ(1, listener_get(got, MAX_LISTENERS)); + EXPECT_NE(NULL, find_listener(got, 1, "tcp", AF_INET6, TEST_PORT)); +} + +/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D rpcbind= registration =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D */ + +/* + * A rpcbind that refuses the registration takes the listener down with it. + * svc_register() fails, so svc_setup_socket() fails, so no listener is + * created. -EACCES alone does not show that, since a bind can return it + * too, so read the listener set back as well. + */ +TEST_F(nfsd_listener, sem_register_refused) +{ + struct listener_ent got[MAX_LISTENERS]; + char attrs[64]; + int off =3D put_listener(attrs, 0, "tcp", TEST_PORT); + + rpcb_stub_set_mode(RPCB_STUB_REFUSE); + + EXPECT_EQ(-EACCES, listener_set(attrs, off)); + EXPECT_STRNE("", last_extack); + EXPECT_EQ(0, listener_get(got, MAX_LISTENERS)); +} + +/* + * A listener that cannot be created reports which one it was: the errno + * alone does not name the entry in a multi-listener request. + */ +TEST_F(nfsd_listener, sem_create_failure_extack) +{ + struct sockaddr_in s4 =3D { .sin_family =3D AF_INET, + .sin_port =3D htons(TEST_PORT), + .sin_addr.s_addr =3D htonl(INADDR_LOOPBACK) }; + struct listener_ent got[MAX_LISTENERS]; + char attrs[64]; + int off =3D put_listener(attrs, 0, "tcp", TEST_PORT); + int s; + + /* squat on the port so the listener cannot bind */ + s =3D socket(AF_INET, SOCK_STREAM, 0); + ASSERT_GE(s, 0); + ASSERT_EQ(0, bind(s, (struct sockaddr *)&s4, sizeof(s4))); + + EXPECT_EQ(-EADDRINUSE, listener_set(attrs, off)); + EXPECT_STRNE("", last_extack); + EXPECT_EQ(0, listener_get(got, MAX_LISTENERS)); + close(s); +} + +/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D threads= / -EBUSY semantics =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D */ + +TEST_F(nfsd_listener, sem_busy_on_change) +{ + struct listener_ent got[MAX_LISTENERS]; + char one[64], two[128]; + int o1 =3D put_listener(one, 0, "tcp", TEST_PORT); + int o2 =3D put_listener(two, 0, "tcp", TEST_PORT); + + o2 =3D put_listener(two, o2, "udp", TEST_PORT); + ASSERT_EQ(0, listener_set(one, o1)); + ASSERT_EQ(0, threads_set(1)); /* threads now running */ + EXPECT_EQ(-EBUSY, listener_set(two, o2)); /* add refused */ + + /* refused means refused: the udp listener must not have been added */ + EXPECT_EQ(1, listener_get(got, MAX_LISTENERS)); + EXPECT_NE(NULL, find_listener(got, 1, "tcp", AF_INET, TEST_PORT)); + + threads_set(0); /* stop before netns exit */ +} + +TEST_F(nfsd_listener, sem_busy_on_remove) +{ + struct listener_ent got[MAX_LISTENERS]; + char one[64]; + int o1 =3D put_listener(one, 0, "tcp", TEST_PORT); + + ASSERT_EQ(0, listener_set(one, o1)); + ASSERT_EQ(0, threads_set(1)); + EXPECT_EQ(-EBUSY, listener_set(NULL, 0)); /* remove refused */ + + /* the doit moves the permsocks to a temp list before it can fail */ + EXPECT_EQ(1, listener_get(got, MAX_LISTENERS)); + EXPECT_NE(NULL, find_listener(got, 1, "tcp", AF_INET, TEST_PORT)); + + threads_set(0); +} + TEST_HARNESS_MAIN --=20 2.55.0 From nobody Sat Sep 26 23:02:48 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 880B6399036; Fri, 28 Aug 2026 16:38:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787935089; cv=none; b=ivXkj3e2kKwRCt8rErqi/6WH9Zv8rPm1uNgFuqfCRkjs4d2Os5p9INaW49vIqyzPTVe8GAw7LJM/BbzpA59PUZ8dbFWWTktsWhKAPRtnnZc/DQFeh/nx5xrHk/BrVnBDDdmoKg2kbrlrHmdaup9vWXaTKAV6vDK+N79vbsI2N/4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787935089; c=relaxed/simple; bh=MIR3rubKscsZidNahSMzjgOnE9yq2FwNrVqOoqV3JX4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Gq1TAUvmDrmmwAVvBqEBVPuOlcZnqJk+DF6MZ/pr4GOfBA73f4HyP2cWqh+9/DLfFC2AT1+R9eajmpSpsL18JIdxPwim0XnzmiGYv6J5TYNQbcP2+gda7ktHV5qOiYhx5JDSL6/KYBmpeqg9NoyKuKtM9LExHD4XF+/nknHYnUU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jliM5px3; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jliM5px3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F9B21F00A3F; Fri, 28 Aug 2026 16:38:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787935087; bh=wRFZHmFVeVOFufoeeCToiP5M0y58uqHGKptV/fgLHx8=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=jliM5px3NtjYvmkTjzqPuQvEgVWzRB0vfYhDWxkfwuK/Uu2GZw4F6L9upcp4tAbGY w7PzIv8ZQY5+OjW/i17Gv7PBB86SWLEqBFA8wwlx57hCz0qzmmZSRCXJMVSNDN0inX T+HTrJ0wRVHsDQDWiVfrTWG7oKCVJZ52BQrI346rGL9GLFdN9Lfd7jTi5ciMube6xq M3pwQaWHxoznpJiFo11vbKeRd5+sba3JTlpc3dcf+x2uILsi2CZCEwpthFWXlNobEQ TyrL5nqCO3iW4MuPuyflXH/3JH2VxXu02ZfW6autP7PndoOvxbPDY2xdVTpaQANL23 lHhUXUYaJhFVg== From: Jeff Layton Date: Fri, 28 Aug 2026 12:37:43 -0400 Subject: [PATCH v3 13/14] selftests/nfsd: check that listener_set asks rpcbind once Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260828-nfsd-nl-hang-v3-13-55026685c75d@kernel.org> References: <20260828-nfsd-nl-hang-v3-0-55026685c75d@kernel.org> In-Reply-To: <20260828-nfsd-nl-hang-v3-0-55026685c75d@kernel.org> To: Chuck Lever , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: Slawomir Stepien , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Trond Myklebust , linux-kselftest@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=11536; i=jlayton@kernel.org; h=from:subject:message-id; bh=MIR3rubKscsZidNahSMzjgOnE9yq2FwNrVqOoqV3JX4=; b=owEBbQKS/ZANAwAKAQAOaEEZVoIVAcsmYgBqkblXdAsAb+KSFhAmiMnueC+KEKde+sgYFsXO1 RZj+YjW4EeJAjMEAAEKAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCapG5VwAKCRAADmhBGVaC FeoFD/4yOzCIj+LKHcaSxFjS4Fa5fPhonY2BhHBMvv4zK0CLOIrbxgx9+zwJ5kMptzNqHPRUSrs LRVgRoUWdIVsawWSaN/QwcRdcf5++eaNmhF3CdMR25z1kxF2pGPEq7HsiVCwZ1Fg1G1f5ssuZ+7 YXOl/2WOuSVmSGOxvEeQaZFnWvXpFmeJraln5xK97ULuBhwgTRjAYPdsSnUEza07x4l74NHBnnG gaS6Oa2RMOq2NULNphB78YxEuRLs2XTXjVgtCFZnwGIVbXuPpfpoFomEksioHY7Y3EZvjpyn2Ur v7xgYJt0Ipu++6wrVHRpWUsKJy3Ggty6NYks5S9JFytm3pMPKLELpes8k+4j5dQ6ZqLgs3jmLvl C+P/U0w+DBU4zCh81cWoFN0CvzJar1wFJiqaRupJ0ZTsGCP3uh2rSlvQpfh92N6YhWJU3wkbbYb 4I1FbS8d8qM00RJLmniKtU/+UeohhMWZPPGFhaw5eXDbFM9KmLdMf66TKGBNWLWa3tLCErdFDcq 2TQ2PeJWXSWTXHa4U3HbfRm/YpbDAI7AnviMxaHTRiOlXx3cSDGcbX03r1PBmYAof6OLKR7y5d8 QAX+iLZthernQYLhxsrNYicXAZ9uCqlJTWDlCHpIcMA93fd3wpqrgAc+sDrZh58S+HtPE7Uw1Yd laEUBpIo6wxhcdQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Cover the change that stops a listener_set request from registering after rpcbind stops answering. RPCB_STUB_SILENT is new. It reads a call and writes nothing back, so the kernel waits out its own timeout. RPCB_STUB_REFUSE cannot serve here: a refusal is an answer, and the count ignores it on purpose. Every procedure but the NULL one is silenced, so an unregistration goes unanswered as well. The NULL one has to be answered: rpcb_create_af_local() builds its client without RPC_CLNT_CREATE_NOPING, so rpc_create() pings at creation. Silencing that ping too would fail the AF_LOCAL client, send rpcb_create_local() on to the loopback client of rpcb_create_local_net(), and leave the stub seeing one call per request no matter how many listeners it carried. - rpcb_stop_after_failure. Ask for one listener, then for three, and compare what the stub saw. Three entries must not cost three times as much. - rpcb_silent_set_complete. The entry that finds rpcbind silent is the one that pays the timeout, and with v3 enabled it is the only entry whose listener would be lost. Require that a three-entry request brings up all three, succeeds, and warns. - rpcb_v4_only_bounded. The case that needs the count rather than a failed listener. version_set_only() makes the server v4-only, so vs_rpcb_optnl discards every error and every listener comes up. Require that the listeners are present, that the ack warns about them, and that three entries do not cost three round trips. - rpcb_retry_next_request. The stop lasts for one request. After the stub starts to answer, the next request must reach rpcbind again. The counts these tests compare include the unregistrations that the teardown between the two measurements issues. The preceding patches bound that direction too, so the sweeps stay at one timeout rather than one per program and version. version_set_only() is new. NFSD_CMD_VERSION_SET clears every version before it reads the request, so one nest leaves the server v4-only. It returns -EBUSY once a serv exists, so the test calls it first. Assisted-by: LLM Signed-off-by: Jeff Layton --- .../testing/selftests/nfsd/nfsd_netlink_listener.c | 188 +++++++++++++++++= +++- 1 file changed, 186 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/nfsd/nfsd_netlink_listener.c b/tools/t= esting/selftests/nfsd/nfsd_netlink_listener.c index 99c320e2f7c2..511d20566ff3 100644 --- a/tools/testing/selftests/nfsd/nfsd_netlink_listener.c +++ b/tools/testing/selftests/nfsd/nfsd_netlink_listener.c @@ -48,12 +48,17 @@ /* NFSD generic-netlink constants (from linux/nfsd_netlink.h). */ #define NFSD_FAMILY_NAME "nfsd" #define NFSD_CMD_THREADS_SET 2 +#define NFSD_CMD_VERSION_SET 4 #define NFSD_CMD_LISTENER_SET 6 #define NFSD_CMD_LISTENER_GET 7 #define NFSD_A_SERVER_THREADS 1 #define NFSD_A_SERVER_SOCK_ADDR 1 /* per-listener nest */ #define NFSD_A_SOCK_ADDR 1 /* inside the nest */ #define NFSD_A_SOCK_TRANSPORT_NAME 2 /* inside the nest */ +#define NFSD_A_SERVER_PROTO_VERSION 1 /* per-version nest */ +#define NFSD_A_VERSION_MAJOR 1 /* inside the version nest */ +#define NFSD_A_VERSION_MINOR 2 /* inside the version nest */ +#define NFSD_A_VERSION_ENABLED 3 /* inside the version nest */ =20 #define NLA_ALIGN4(len) (((len) + 3) & ~3) #define TEST_PORT 20049 @@ -370,6 +375,28 @@ static int listener_set(const char *attrs, int len) return genl_request(NFSD_CMD_LISTENER_SET, attrs, len); } =20 +/* + * Enable exactly one NFS version in this netns. NFSD_CMD_VERSION_SET clea= rs + * every version first, so one nest is enough to leave the server v4-only. + * It refuses once a serv exists, so call it before any listener. + */ +static int version_set_only(uint32_t major, uint32_t minor) +{ + char attrs[64]; + struct nlattr *nest =3D (void *)attrs; + int inner =3D NLA_HDRLEN; + + inner =3D put_attr(attrs, inner, NFSD_A_VERSION_MAJOR, + &major, sizeof(major)); + inner =3D put_attr(attrs, inner, NFSD_A_VERSION_MINOR, + &minor, sizeof(minor)); + inner =3D put_attr(attrs, inner, NFSD_A_VERSION_ENABLED, NULL, 0); + nest->nla_type =3D NFSD_A_SERVER_PROTO_VERSION | NLA_F_NESTED; + nest->nla_len =3D inner; + + return genl_request(NFSD_CMD_VERSION_SET, attrs, NLA_ALIGN4(inner)); +} + /* Fetch the current listeners; returns count (>=3D0) or -errno. */ static int listener_get(struct listener_ent *out, int max) { @@ -440,6 +467,14 @@ static int threads_set(int n) * rpcb_register_call() reports as -EACCES. UNSET is left alone: only * svc_unregister() issues it, and it discards the result. * + * In RPCB_STUB_SILENT mode a SET or an UNSET is read and nothing is writt= en + * back, so the kernel waits out its own timeout. That is the only mode th= at + * makes rpcb_register_call() report a call that got no answer, which is w= hat + * the per-net failure count records. The NULL procedure is still answered: + * rpcb_create_af_local() builds its client without RPC_CLNT_CREATE_NOPING= , so + * rpc_create() pings, and a ping that goes unanswered drops the kernel on= to + * the loopback rpcb_create_local_net() client, which never reaches this s= tub. + * * The stub also keeps counters and the mode in a page shared with the tes= t, so * a test can assert that the kernel never talked to rpcbind at all, or th= at it * dropped the local rpcbind client and had to reconnect. @@ -457,7 +492,7 @@ static int threads_set(int n) #define RPCB_ABSTRACT_NAME "/run/rpcbind.sock" #define RPCB_STUB_MAXCONN 4 =20 -enum { RPCB_STUB_ACCEPT, RPCB_STUB_REFUSE }; +enum { RPCB_STUB_ACCEPT, RPCB_STUB_REFUSE, RPCB_STUB_SILENT }; =20 struct rpcb_stub_stats { unsigned int conns; /* connections accepted */ @@ -572,7 +607,9 @@ static int rpcb_stub_call(int fd) if (ntohl(call[3]) !=3D RPCB_PROGRAM) { rep[5] =3D htonl(1); /* PROG_UNAVAIL */ } else { - switch (ntohl(call[5])) { + unsigned int proc =3D ntohl(call[5]); + + switch (proc) { case RPCB_PROC_NULL: break; case RPCB_PROC_SET: @@ -586,6 +623,15 @@ static int rpcb_stub_call(int fd) default: rep[5] =3D htonl(3); /* PROC_UNAVAIL */ } + + /* + * Answer nothing, so the caller waits out its timeout. The + * NULL procedure is answered even here: the kernel pings at + * client creation, and a ping with no answer takes it off + * this socket entirely. + */ + if (mode =3D=3D RPCB_STUB_SILENT && proc !=3D RPCB_PROC_NULL) + return 0; } =20 replen =3D nrep * sizeof(rep[0]); @@ -1064,6 +1110,144 @@ TEST_F(nfsd_listener, sem_create_failure_extack) close(s); } =20 +/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D one rpcbind attempt for each reque= st =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */ + +/* + * Every listener used to register on its own, so a rpcbind that never + * answers cost one timeout for each entry. Ask for one listener, then for + * three, and compare what the stub saw. Three entries must not cost three + * times as much. + * + * The stub has to stay silent rather than refuse. A refusal is an answer, + * and rpcbind refuses one entry at a time, so the count ignores it. + */ +TEST_F(nfsd_listener, rpcb_stop_after_failure) +{ + int before, one, three, off; + char attrs[192]; + + rpcb_stub_set_mode(RPCB_STUB_SILENT); + + before =3D rpcb_calls(); + off =3D put_listener(attrs, 0, "tcp", TEST_PORT); + listener_set(attrs, off); + one =3D rpcb_calls() - before; + ASSERT_GT(one, 0); + + ASSERT_EQ(0, listener_set(attrs, 0)); + + before =3D rpcb_calls(); + off =3D put_listener(attrs, 0, "tcp", TEST_PORT); + off =3D put_listener(attrs, off, "tcp", TEST_PORT + 1); + off =3D put_listener(attrs, off, "tcp", TEST_PORT + 2); + listener_set(attrs, off); + three =3D rpcb_calls() - before; + + /* the second and third entries must not reach rpcbind at all */ + EXPECT_LE(three, one); +} + +/* + * The entry that finds rpcbind silent is the one that pays for the + * discovery, and v3 has no vs_rpcb_optnl to discard the error, so it is t= he + * only entry whose listener would be lost. Nothing distinguishes it from = the + * rest of the request, and a retry of the same request would fail the same + * entry again, so the set would stay short for as long as rpcbind was qui= et. + * + * Ask for three listeners against a silent stub and require the whole set, + * a success, and a warning that says why. + */ +TEST_F(nfsd_listener, rpcb_silent_set_complete) +{ + struct listener_ent got[MAX_LISTENERS]; + char attrs[192]; + int off; + + rpcb_stub_set_mode(RPCB_STUB_SILENT); + + off =3D put_listener(attrs, 0, "tcp", TEST_PORT); + off =3D put_listener(attrs, off, "tcp", TEST_PORT + 1); + off =3D put_listener(attrs, off, "tcp", TEST_PORT + 2); + EXPECT_EQ(0, listener_set(attrs, off)); + + /* the first entry is not the odd one out */ + EXPECT_EQ(3, listener_get(got, MAX_LISTENERS)); + /* no errno reports this, so the ack has to */ + EXPECT_STRNE("", last_extack); +} + +/* + * The case that needs the count rather than a failed listener. NFSv4 sets + * vs_rpcb_optnl, so svc_generic_rpcbind_set() discards the error, every + * listener comes up, and nothing reports a failure. Without the fix each + * entry still waits for rpcbind on its own. + * + * Make the server v4-only, answer no SET, and require three things: the + * listeners come up, the ack warns that they are not registered, and the + * stub does not see one round trip for each entry. + */ +TEST_F(nfsd_listener, rpcb_v4_only_bounded) +{ + struct listener_ent got[MAX_LISTENERS]; + int before, one, three, off; + char attrs[192]; + + /* refuses once a serv exists, so this has to come first */ + ASSERT_EQ(0, version_set_only(4, 1)); + rpcb_stub_set_mode(RPCB_STUB_SILENT); + + before =3D rpcb_calls(); + off =3D put_listener(attrs, 0, "tcp", TEST_PORT); + ASSERT_EQ(0, listener_set(attrs, off)); + one =3D rpcb_calls() - before; + ASSERT_GT(one, 0); + + /* start over, so the second measurement also builds a serv */ + ASSERT_EQ(0, listener_set(attrs, 0)); + + before =3D rpcb_calls(); + off =3D put_listener(attrs, 0, "tcp", TEST_PORT); + off =3D put_listener(attrs, off, "tcp", TEST_PORT + 1); + off =3D put_listener(attrs, off, "tcp", TEST_PORT + 2); + ASSERT_EQ(0, listener_set(attrs, off)); + three =3D rpcb_calls() - before; + + /* the listeners are up even though rpcbind never answered */ + EXPECT_EQ(3, listener_get(got, MAX_LISTENERS)); + /* and the ack says they are unregistered, since no errno can */ + EXPECT_STRNE("", last_extack); + EXPECT_LE(three, one); +} + +/* + * The stop applies to one request only. After rpcbind starts answering, + * the next request must register without any other step. + */ +TEST_F(nfsd_listener, rpcb_retry_next_request) +{ + int before, after, off; + char attrs[192]; + + rpcb_stub_set_mode(RPCB_STUB_SILENT); + + off =3D put_listener(attrs, 0, "tcp", TEST_PORT); + off =3D put_listener(attrs, off, "tcp", TEST_PORT + 1); + listener_set(attrs, off); + ASSERT_EQ(0, listener_set(attrs, 0)); + + /* rpcbind recovers */ + rpcb_stub_set_mode(RPCB_STUB_ACCEPT); + + before =3D rpcb_calls(); + off =3D put_listener(attrs, 0, "tcp", TEST_PORT); + EXPECT_EQ(0, listener_set(attrs, off)); + after =3D rpcb_calls(); + + /* a fresh request starts from a fresh reading and tries again */ + EXPECT_GT(after, before); + EXPECT_STREQ("", last_extack); +} + /* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D threads= / -EBUSY semantics =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D */ =20 TEST_F(nfsd_listener, sem_busy_on_change) --=20 2.55.0 From nobody Sat Sep 26 23:02:48 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D887D471D1A; Fri, 28 Aug 2026 16:38:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787935090; cv=none; b=Ob073JGAl/QwEGrgxNZWg3dDpolknbnejiN5mUsgd+HQItzFHAso0Pxe5n9a85YpZJ8gtFO04E/Oq1CaZ64Yzk8DocKw6+aBGt7Qm4z6o8h6yF4M+9E5f+JLCevSlJxNafusT99HCdDuM8mS3xOYPboeRSjWeAxZUyPJ3YEAutM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787935090; c=relaxed/simple; bh=grf6clZnkQGXGoZ9rkU2+lKlywCVByX9ysCCD0mMuIg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iiBR1HMOMl0pQqvikjwxwvs4ejYcO89qjYl2fpjNc5ZM4ALoxZldQVu5WzTRqzMkQ+y2QdjOhFRBN1LD9aMr6DUYh4W02PWVjD1UeGOKxebrqmkb4hYQL0jmyWnnnH1iSaIfagb4PNw+D64HxpC8XEktL7kDkE/3VbJRAf2O9Fo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QXJ70Eww; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QXJ70Eww" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 327DE1F00A3E; Fri, 28 Aug 2026 16:38:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787935088; bh=+xLJWmj9sHbeFwxKybs/pfRQuWXRiA1jYXOW+vEeb5Y=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=QXJ70EwwrIbUEgXB/o3pZWDrildJPBUbdTtferhpVBxs5btkH/7PSMcN/knX6kdfu RP0A5DmRKXkH1G/uu/RyhJtchqK+kKxWbQcK8Kgy6dhIG2JFrfhrPFLGX6zG/6NTtl lq/dMCbVu/3BCax44MHimVryl9ZQqqKuGhSGTAIdUg5Gz34IThclmPQCIpoS0O48Os q+FpWCmwozZpne6y8HJzavL9iV8viZowrjsNtF3m9gOpRgtnlWyAgaJK2ZzPYgGG/T yxVl9EK8TmL/VrOSQ4EFmO6v0R07F48AQ9ruUZMU+qehrea1OUwjOwEt/TCLMtJYFu hN4/ITAcYk9Pg== From: Jeff Layton Date: Fri, 28 Aug 2026 12:37:44 -0400 Subject: [PATCH v3 14/14] selftests/nfsd: check that listener removal asks rpcbind once Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260828-nfsd-nl-hang-v3-14-55026685c75d@kernel.org> References: <20260828-nfsd-nl-hang-v3-0-55026685c75d@kernel.org> In-Reply-To: <20260828-nfsd-nl-hang-v3-0-55026685c75d@kernel.org> To: Chuck Lever , NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: Slawomir Stepien , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Trond Myklebust , linux-kselftest@vger.kernel.org, Jeff Layton X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2494; i=jlayton@kernel.org; h=from:subject:message-id; bh=grf6clZnkQGXGoZ9rkU2+lKlywCVByX9ysCCD0mMuIg=; b=owEBbQKS/ZANAwAKAQAOaEEZVoIVAcsmYgBqkblXQ84/SwzI8TY+nEZKodk71hnK9eZPXcoE2 /7OJjXpLT+JAjMEAAEKAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCapG5VwAKCRAADmhBGVaC FctmD/9P6TyHKgFTtGhoaBecAnRF+LL2b27njB3KxVyN5Dj/4EaLYaHqaEhFvQJHR/6YGpc8vQF I9ZOd7mBPH3JHzbL83z7IN/5hipG7Yg25XlD2LGPzDt6vs9pQNCIk8AahZasSSSoMtSKh/B8sjY otz6FdbiZE3sSEpGZlfynSx5Yzx8grXgMhEOuwxYeov8Cb7d6I1OFd6ADbf4p4EfLX0RvirkZe/ wUv9eFmue9t78nrmEh+X5wD949snKF6NQ0y0P+Qh/Da3HZFB+GvLn36eExZKI6AFs8RriEAIadM HkWf9SINcYVMLPQMGy6lXeb52x93tE5ng3+qWVtR47/XVy9htIuU0CFl/SRRW6XduvcLAIcKaG7 gE6xl6tY1t5rHr+SF1bXIhz+0Ut2VskEW72NXD60/V74fFZ4OSMdN6yyL5YVcAAvMpD/egtqmYP XMN2ynwJ+udaVUgKwr+iXRauCiYOT457O5RkCSbjySfEHck1raRaIsHiKFarWHUrAqLLF45FNDW EVdCBL6so9dU6xgOmP83th0mjvgwYL2X3QfxnUQhK0/YfdPextuh89POHJgb6A7R8+8cyNRNfNL tFYS2/LP7DR3fhZ3rNahotlbSPXODBPqZw6NwNlP7i+C5sRXfYHayoyBrSHxHzWVsgQXLsOmgYN soyNYcP2FbV5++g== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 Cover the teardown side of the same rule. Remove one listener, then three, with the stub silent, and compare what it saw. Three removals must not cost three timeouts. Both measurements also pay the svc_unregister() sweep that nfsd_destroy_serv() runs once the last listener is gone, so that cancels out of the comparison. The listeners are registered with the stub answering, so each one has an entry to remove. Assisted-by: LLM Signed-off-by: Jeff Layton --- .../testing/selftests/nfsd/nfsd_netlink_listener.c | 39 ++++++++++++++++++= ++++ 1 file changed, 39 insertions(+) diff --git a/tools/testing/selftests/nfsd/nfsd_netlink_listener.c b/tools/t= esting/selftests/nfsd/nfsd_netlink_listener.c index 511d20566ff3..89d1da825b95 100644 --- a/tools/testing/selftests/nfsd/nfsd_netlink_listener.c +++ b/tools/testing/selftests/nfsd/nfsd_netlink_listener.c @@ -1248,6 +1248,45 @@ TEST_F(nfsd_listener, rpcb_retry_next_request) EXPECT_STREQ("", last_extack); } =20 +/* + * The same rule on the way out. Removing a listener unregisters it, so a + * rpcbind that stops answering used to cost one timeout for each listener + * removed. Register one listener while the stub answers, silence the stub, + * remove it and count; then do the same with three. + * + * Both measurements also pay the svc_unregister() sweep that + * nfsd_destroy_serv() runs once the last listener is gone, so that cancels + * out of the comparison. + */ +TEST_F(nfsd_listener, rpcb_unreg_stop_after_failure) +{ + int before, one, three, off; + char attrs[192]; + + off =3D put_listener(attrs, 0, "tcp", TEST_PORT); + ASSERT_EQ(0, listener_set(attrs, off)); + + rpcb_stub_set_mode(RPCB_STUB_SILENT); + before =3D rpcb_calls(); + ASSERT_EQ(0, listener_set(NULL, 0)); + one =3D rpcb_calls() - before; + ASSERT_GT(one, 0); + + rpcb_stub_set_mode(RPCB_STUB_ACCEPT); + off =3D put_listener(attrs, 0, "tcp", TEST_PORT); + off =3D put_listener(attrs, off, "tcp", TEST_PORT + 1); + off =3D put_listener(attrs, off, "tcp", TEST_PORT + 2); + ASSERT_EQ(0, listener_set(attrs, off)); + + rpcb_stub_set_mode(RPCB_STUB_SILENT); + before =3D rpcb_calls(); + ASSERT_EQ(0, listener_set(NULL, 0)); + three =3D rpcb_calls() - before; + + /* the second and third removals must not reach rpcbind at all */ + EXPECT_LE(three, one); +} + /* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D threads= / -EBUSY semantics =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D */ =20 TEST_F(nfsd_listener, sem_busy_on_change) --=20 2.55.0