From: Sergey Shtylyov <s.shtylyov@omp.ru>
To: Trond Myklebust <trondmy@kernel.org>,
Anna Schumaker <anna@kernel.org>, <linux-nfs@vger.kernel.org>
Cc: Sergey Shtylyov <s.shtylyov@omp.ru>
Subject: [PATCH 2/2] NFSv4: limit lease period in nfs4_set_lease_period()
Date: Mon, 8 Dec 2025 23:03:37 +0300 [thread overview]
Message-ID: <20251208200345.20414-3-s.shtylyov@omp.ru> (raw)
In-Reply-To: <20251208200345.20414-1-s.shtylyov@omp.ru>
In nfs4_set_lease_period(), the passed 32-bit lease period in seconds is
multiplied by HZ -- that might overflow before being implicitly cast to
*unsigned long* (32/64-bit type), while initializing the lease variable.
Cap the lease period at MAX_LEASE_PERIOD (#define'd to 1 hour for now),
before multipying to avoid such overflow...
Found by Linux Verification Center (linuxtesting.org) with the Svace static
analysis tool.
Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>
Suggested-by: Trond Myklebust <trondmy@kernel.org>
---
fs/nfs/nfs4renewd.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/fs/nfs/nfs4renewd.c b/fs/nfs/nfs4renewd.c
index 043b2de8d416..30065df1482e 100644
--- a/fs/nfs/nfs4renewd.c
+++ b/fs/nfs/nfs4renewd.c
@@ -133,6 +133,8 @@ nfs4_kill_renewd(struct nfs_client *clp)
cancel_delayed_work_sync(&clp->cl_renewd);
}
+#define MAX_LEASE_PERIOD (60 * 60) /* 1 hour */
+
/**
* nfs4_set_lease_period - Sets the lease period on a nfs_client
*
@@ -141,7 +143,13 @@ nfs4_kill_renewd(struct nfs_client *clp)
*/
void nfs4_set_lease_period(struct nfs_client *clp, u32 period)
{
- unsigned long lease = period * HZ;
+ unsigned long lease;
+
+ /* Limit the lease period */
+ if (period < MAX_LEASE_PERIOD)
+ lease = period * HZ;
+ else
+ lease = MAX_LEASE_PERIOD * HZ;
spin_lock(&clp->cl_lock);
clp->cl_lease_time = lease;
--
2.52.0
next prev parent reply other threads:[~2025-12-08 20:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-08 20:03 [PATCH 0/2] Sergey Shtylyov
2025-12-08 20:03 ` [PATCH 1/2] NFSv4: pass lease period in seconds to nfs4_set_lease_period() Sergey Shtylyov
2025-12-08 20:03 ` Sergey Shtylyov [this message]
2025-12-08 20:07 ` [PATCH 0/2] Sergey Shtylyov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251208200345.20414-3-s.shtylyov@omp.ru \
--to=s.shtylyov@omp.ru \
--cc=anna@kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=trondmy@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox