lockd: Don't expose the process pid to the NLM server
Trond Myklebust [Mon, 20 Mar 2006 18:44:06 +0000 (13:44 -0500)]
Instead we use the nlm_lockowner->pid.

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

fs/lockd/clntlock.c
fs/lockd/clntproc.c
fs/lockd/svclock.c
fs/lockd/xdr.c
fs/lockd/xdr4.c
include/linux/lockd/xdr.h

index da6354b..8ae79ae 100644 (file)
@@ -125,7 +125,15 @@ u32 nlmclnt_grant(const struct sockaddr_in *addr, const struct nlm_lock *lock)
        list_for_each_entry(block, &nlm_blocked, b_list) {
                struct file_lock *fl_blocked = block->b_lock;
 
-               if (!nlm_compare_locks(fl_blocked, fl))
+               if (fl_blocked->fl_start != fl->fl_start)
+                       continue;
+               if (fl_blocked->fl_end != fl->fl_end)
+                       continue;
+               /*
+                * Careful! The NLM server will return the 32-bit "pid" that
+                * we put on the wire: in this case the lockowner "pid".
+                */
+               if (fl_blocked->fl_u.nfs_fl.owner->pid != lock->svid)
                        continue;
                if (!nlm_cmp_addr(&block->b_host->h_addr, addr))
                        continue;
index 615a988..acc3eb1 100644 (file)
@@ -132,8 +132,10 @@ static void nlmclnt_setlockargs(struct nlm_rqst *req, struct file_lock *fl)
        memcpy(&lock->fh, NFS_FH(fl->fl_file->f_dentry->d_inode), sizeof(struct nfs_fh));
        lock->caller  = system_utsname.nodename;
        lock->oh.data = req->a_owner;
-       lock->oh.len  = sprintf(req->a_owner, "%d@%s",
-                               current->pid, system_utsname.nodename);
+       lock->oh.len  = snprintf(req->a_owner, sizeof(req->a_owner), "%u@%s",
+                               (unsigned int)fl->fl_u.nfs_fl.owner->pid,
+                               system_utsname.nodename);
+       lock->svid = fl->fl_u.nfs_fl.owner->pid;
        locks_copy_lock(&lock->fl, fl);
 }
 
@@ -159,6 +161,7 @@ nlmclnt_setgrantargs(struct nlm_rqst *call, struct nlm_lock *lock)
 
        /* set default data area */
        call->a_args.lock.oh.data = call->a_owner;
+       call->a_args.lock.svid = lock->fl.fl_pid;
 
        if (lock->oh.len > NLMCLNT_OHSIZE) {
                void *data = kmalloc(lock->oh.len, GFP_KERNEL);
index 9cfced6..a525a14 100644 (file)
@@ -397,6 +397,7 @@ nlmsvc_testlock(struct nlm_file *file, struct nlm_lock *lock,
                                (long long)fl->fl_end);
                conflock->caller = "somehost";  /* FIXME */
                conflock->oh.len = 0;           /* don't return OH info */
+               conflock->svid = fl->fl_pid;
                conflock->fl = *fl;
                return nlm_lck_denied;
        }
index 200fbda..1e984ab 100644 (file)
@@ -131,10 +131,11 @@ nlm_decode_lock(u32 *p, struct nlm_lock *lock)
         || !(p = nlm_decode_fh(p, &lock->fh))
         || !(p = nlm_decode_oh(p, &lock->oh)))
                return NULL;
+       lock->svid  = ntohl(*p++);
 
        locks_init_lock(fl);
        fl->fl_owner = current->files;
-       fl->fl_pid   = ntohl(*p++);
+       fl->fl_pid   = (pid_t)lock->svid;
        fl->fl_flags = FL_POSIX;
        fl->fl_type  = F_RDLCK;         /* as good as anything else */
        start = ntohl(*p++);
@@ -174,7 +175,7 @@ nlm_encode_lock(u32 *p, struct nlm_lock *lock)
        else
                len = loff_t_to_s32(fl->fl_end - fl->fl_start + 1);
 
-       *p++ = htonl(fl->fl_pid);
+       *p++ = htonl(lock->svid);
        *p++ = htonl(start);
        *p++ = htonl(len);
 
@@ -197,7 +198,7 @@ nlm_encode_testres(u32 *p, struct nlm_res *resp)
                struct file_lock        *fl = &resp->lock.fl;
 
                *p++ = (fl->fl_type == F_RDLCK)? xdr_zero : xdr_one;
-               *p++ = htonl(fl->fl_pid);
+               *p++ = htonl(resp->lock.svid);
 
                /* Encode owner handle. */
                if (!(p = xdr_encode_netobj(p, &resp->lock.oh)))
@@ -298,7 +299,8 @@ nlmsvc_decode_shareargs(struct svc_rqst *rqstp, u32 *p, nlm_args *argp)
 
        memset(lock, 0, sizeof(*lock));
        locks_init_lock(&lock->fl);
-       lock->fl.fl_pid = ~(u32) 0;
+       lock->svid = ~(u32) 0;
+       lock->fl.fl_pid = (pid_t)lock->svid;
 
        if (!(p = nlm_decode_cookie(p, &argp->cookie))
         || !(p = xdr_decode_string_inplace(p, &lock->caller,
@@ -415,7 +417,8 @@ nlmclt_decode_testres(struct rpc_rqst *req, u32 *p, struct nlm_res *resp)
                memset(&resp->lock, 0, sizeof(resp->lock));
                locks_init_lock(fl);
                excl = ntohl(*p++);
-               fl->fl_pid = ntohl(*p++);
+               resp->lock.svid = ntohl(*p++);
+               fl->fl_pid = (pid_t)resp->lock.svid;
                if (!(p = nlm_decode_oh(p, &resp->lock.oh)))
                        return -EIO;
 
index fdcf105..906ddc2 100644 (file)
@@ -130,10 +130,11 @@ nlm4_decode_lock(u32 *p, struct nlm_lock *lock)
         || !(p = nlm4_decode_fh(p, &lock->fh))
         || !(p = nlm4_decode_oh(p, &lock->oh)))
                return NULL;
+       lock->svid  = ntohl(*p++);
 
        locks_init_lock(fl);
        fl->fl_owner = current->files;
-       fl->fl_pid   = ntohl(*p++);
+       fl->fl_pid   = (pid_t)lock->svid;
        fl->fl_flags = FL_POSIX;
        fl->fl_type  = F_RDLCK;         /* as good as anything else */
        p = xdr_decode_hyper(p, &start);
@@ -167,7 +168,7 @@ nlm4_encode_lock(u32 *p, struct nlm_lock *lock)
         || (fl->fl_end > NLM4_OFFSET_MAX && fl->fl_end != OFFSET_MAX))
                return NULL;
 
-       *p++ = htonl(fl->fl_pid);
+       *p++ = htonl(lock->svid);
 
        start = loff_t_to_s64(fl->fl_start);
        if (fl->fl_end == OFFSET_MAX)
@@ -198,7 +199,7 @@ nlm4_encode_testres(u32 *p, struct nlm_res *resp)
                struct file_lock        *fl = &resp->lock.fl;
 
                *p++ = (fl->fl_type == F_RDLCK)? xdr_zero : xdr_one;
-               *p++ = htonl(fl->fl_pid);
+               *p++ = htonl(resp->lock.svid);
 
                /* Encode owner handle. */
                if (!(p = xdr_encode_netobj(p, &resp->lock.oh)))
@@ -212,8 +213,8 @@ nlm4_encode_testres(u32 *p, struct nlm_res *resp)
                
                p = xdr_encode_hyper(p, start);
                p = xdr_encode_hyper(p, len);
-               dprintk("xdr: encode_testres (status %d pid %d type %d start %Ld end %Ld)\n",
-                       resp->status, fl->fl_pid, fl->fl_type,
+               dprintk("xdr: encode_testres (status %u pid %d type %d start %Ld end %Ld)\n",
+                       resp->status, (int)resp->lock.svid, fl->fl_type,
                        (long long)fl->fl_start,  (long long)fl->fl_end);
        }
 
@@ -303,7 +304,8 @@ nlm4svc_decode_shareargs(struct svc_rqst *rqstp, u32 *p, nlm_args *argp)
 
        memset(lock, 0, sizeof(*lock));
        locks_init_lock(&lock->fl);
-       lock->fl.fl_pid = ~(u32) 0;
+       lock->svid = ~(u32) 0;
+       lock->fl.fl_pid = (pid_t)lock->svid;
 
        if (!(p = nlm4_decode_cookie(p, &argp->cookie))
         || !(p = xdr_decode_string_inplace(p, &lock->caller,
@@ -420,7 +422,8 @@ nlm4clt_decode_testres(struct rpc_rqst *req, u32 *p, struct nlm_res *resp)
                memset(&resp->lock, 0, sizeof(resp->lock));
                locks_init_lock(fl);
                excl = ntohl(*p++);
-               fl->fl_pid = ntohl(*p++);
+               resp->lock.svid = ntohl(*p++);
+               fl->fl_pid = (pid_t)resp->lock.svid;
                if (!(p = nlm4_decode_oh(p, &resp->lock.oh)))
                        return -EIO;
 
index d7a5cc4..bb0a0f1 100644 (file)
@@ -28,6 +28,7 @@ struct nlm_lock {
        int                     len;    /* length of "caller" */
        struct nfs_fh           fh;
        struct xdr_netobj       oh;
+       u32                     svid;
        struct file_lock        fl;
 };