Skip to content

Commit

Permalink
lockd: nlmclnt_reclaim(): avoid stack overflow
Browse files Browse the repository at this point in the history
Even though nlmclnt_reclaim() is only one call into the stack frame,
928 bytes on the stack seems like a lot. Recode to dynamically
allocate the request structure once from within the reclaimer task,
then pass this pointer into nlmclnt_reclaim() for reuse on
subsequent calls.

smatch analysis:

fs/lockd/clntproc.c:620 nlmclnt_reclaim() warn: 'reqst' puts
 928 bytes on stack

Also remove redundant assignment of 0 after memset.

Cc: Trond Myklebust <[email protected]>
Signed-off-by: Tim Gardner <[email protected]>
Reviewed-by: Jeff Layton <[email protected]>
Signed-off-by: J. Bruce Fields <[email protected]>
  • Loading branch information
rtg-canonical authored and J. Bruce Fields committed Feb 15, 2013
1 parent deb4534 commit f25cc71
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
12 changes: 11 additions & 1 deletion fs/lockd/clntlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,19 @@ reclaimer(void *ptr)
{
struct nlm_host *host = (struct nlm_host *) ptr;
struct nlm_wait *block;
struct nlm_rqst *req;
struct file_lock *fl, *next;
u32 nsmstate;
struct net *net = host->net;

req = kmalloc(sizeof(*req), GFP_KERNEL);
if (!req) {
printk(KERN_ERR "lockd: reclaimer unable to alloc memory."
" Locks for %s won't be reclaimed!\n",
host->h_name);
return 0;
}

allow_signal(SIGKILL);

down_write(&host->h_rwsem);
Expand Down Expand Up @@ -253,7 +262,7 @@ reclaimer(void *ptr)
*/
if (signalled())
continue;
if (nlmclnt_reclaim(host, fl) != 0)
if (nlmclnt_reclaim(host, fl, req) != 0)
continue;
list_add_tail(&fl->fl_u.nfs_fl.list, &host->h_granted);
if (host->h_nsmstate != nsmstate) {
Expand All @@ -279,5 +288,6 @@ reclaimer(void *ptr)
/* Release host handle after use */
nlmclnt_release_host(host);
lockd_down(net);
kfree(req);
return 0;
}
6 changes: 2 additions & 4 deletions fs/lockd/clntproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -615,17 +615,15 @@ nlmclnt_lock(struct nlm_rqst *req, struct file_lock *fl)
* RECLAIM: Try to reclaim a lock
*/
int
nlmclnt_reclaim(struct nlm_host *host, struct file_lock *fl)
nlmclnt_reclaim(struct nlm_host *host, struct file_lock *fl,
struct nlm_rqst *req)
{
struct nlm_rqst reqst, *req;
int status;

req = &reqst;
memset(req, 0, sizeof(*req));
locks_init_lock(&req->a_args.lock.fl);
locks_init_lock(&req->a_res.lock.fl);
req->a_host = host;
req->a_flags = 0;

/* Set up the argument struct */
nlmclnt_setlockargs(req, fl);
Expand Down
3 changes: 2 additions & 1 deletion include/linux/lockd/lockd.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ int nlmclnt_block(struct nlm_wait *block, struct nlm_rqst *req, long timeout)
__be32 nlmclnt_grant(const struct sockaddr *addr,
const struct nlm_lock *lock);
void nlmclnt_recovery(struct nlm_host *);
int nlmclnt_reclaim(struct nlm_host *, struct file_lock *);
int nlmclnt_reclaim(struct nlm_host *, struct file_lock *,
struct nlm_rqst *);
void nlmclnt_next_cookie(struct nlm_cookie *);

/*
Expand Down

0 comments on commit f25cc71

Please sign in to comment.