Skip to content

Commit e29a3e6

Browse files
Sergey ShtylyovAnna Schumaker
authored andcommitted
NFSv4: limit lease period in nfs4_set_lease_period()
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> Signed-off-by: Anna Schumaker <anna.schumaker@oracle.com>
1 parent 3d57c44 commit e29a3e6

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

fs/nfs/nfs4renewd.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ nfs4_kill_renewd(struct nfs_client *clp)
133133
cancel_delayed_work_sync(&clp->cl_renewd);
134134
}
135135

136+
#define MAX_LEASE_PERIOD (60 * 60) /* 1 hour */
137+
136138
/**
137139
* nfs4_set_lease_period - Sets the lease period on a nfs_client
138140
*
@@ -141,7 +143,13 @@ nfs4_kill_renewd(struct nfs_client *clp)
141143
*/
142144
void nfs4_set_lease_period(struct nfs_client *clp, u32 period)
143145
{
144-
unsigned long lease = period * HZ;
146+
unsigned long lease;
147+
148+
/* Limit the lease period */
149+
if (period < MAX_LEASE_PERIOD)
150+
lease = period * HZ;
151+
else
152+
lease = MAX_LEASE_PERIOD * HZ;
145153

146154
spin_lock(&clp->cl_lock);
147155
clp->cl_lease_time = lease;

0 commit comments

Comments
 (0)