Re: [patch 08/12] NLM: Fix a circular lock dependency in lockd

Trond Myklebust
2007-10-09T15:27:20Z

[-- Attachment #1: Type: text/plain, Size: 1221 bytes --]

On Tue, 2007-10-09 at 08:13 -0700, Greg KH wrote:
> On Tue, Oct 09, 2007 at 11:00:28AM -0400, Trond Myklebust wrote:
> >
> > On Mon, 2007-10-08 at 22:01 +0200, Roel Kluin wrote:
> > > Greg KH wrote:
> > >
> > > @@ -477,10 +479,15 @@ nlmsvc_testlock(struct svc_rqst *rqstp,
> > >
> > > if (block == NULL) {
> > > struct file_lock *conf = kzalloc(sizeof(*conf), GFP_KERNEL);
> > > + struct nlm_host *host;
> > >
> > > if (conf == NULL)
> > > return nlm_granted;
> > > - block = nlmsvc_create_block(rqstp, file, lock, cookie);
> > > + /* Create host handle for callback */
> > > + host = nlmsvc_lookup_host(rqstp, lock->caller, lock->len);
> > > + if (host == NULL)
> > > + return nlm_lck_denied_nolocks;
> > > + block = nlmsvc_create_block(rqstp, host, file, lock, cookie);
> > > if (block == NULL) {
> > > kfree(conf);
> > > return nlm_granted;
> > >
> > > To be frankly I don't know what this is about, but shouldn't conf be freed if host == NULL?
> >
> > Thanks for spotting this!
> >
> > Greg, should I resend this patch, or would you prefer an incremental
> > fix?
>
> An incremental one would be best.
>
> thanks,
>
> greg k-h

Please see the attachment.

Cheers
Trond

[-- Attachment #2: linux-2.6.23-000-fix_memleak_in_nlmsvc_testlock.dif --]
[-- Type: message/rfc822, Size: 1141 bytes --]

From: Trond Myklebust <Trond.Myklebust@netapp.com>
Subject: No Subject
Date: Tue, 9 Oct 2007 10:55:45 -0400
Message-ID: <1191943677.8739.14.camel@heimdal.trondhjem.org>

The recent fix for a circular lock dependency unfortunately introduced a
potential memory leak in the event where the call to nlmsvc_lookup_host
fails for some reason.

Thanks to Roel Kluin for spotting this.

Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
---

fs/lockd/svclock.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c
index d098c7a..d120ec3 100644
--- a/fs/lockd/svclock.c
+++ b/fs/lockd/svclock.c
@@ -485,8 +485,10 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,
return nlm_granted;
/* Create host handle for callback */
host = nlmsvc_lookup_host(rqstp, lock->caller, lock->len);
- if (host == NULL)
+ if (host == NULL) {
+ kfree(conf);
return nlm_lck_denied_nolocks;
+ }
block = nlmsvc_create_block(rqstp, host, file, lock, cookie);
if (block == NULL) {
kfree(conf);