Skip to content

Commit 7bab377

Browse files
Trond MyklebustTrond Myklebust
authored andcommitted
lockd: Don't expose the process pid to the NLM server
Instead we use the nlm_lockowner->pid. Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
1 parent 36943fa commit 7bab377

6 files changed

Lines changed: 34 additions & 15 deletions

File tree

‎fs/lockd/clntlock.c‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,15 @@ u32 nlmclnt_grant(const struct sockaddr_in *addr, const struct nlm_lock *lock)
125125
list_for_each_entry(block, &nlm_blocked, b_list) {
126126
struct file_lock *fl_blocked = block->b_lock;
127127

128-
if (!nlm_compare_locks(fl_blocked, fl))
128+
if (fl_blocked->fl_start != fl->fl_start)
129+
continue;
130+
if (fl_blocked->fl_end != fl->fl_end)
131+
continue;
132+
/*
133+
* Careful! The NLM server will return the 32-bit "pid" that
134+
* we put on the wire: in this case the lockowner "pid".
135+
*/
136+
if (fl_blocked->fl_u.nfs_fl.owner->pid != lock->svid)
129137
continue;
130138
if (!nlm_cmp_addr(&block->b_host->h_addr, addr))
131139
continue;

‎fs/lockd/clntproc.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,10 @@ static void nlmclnt_setlockargs(struct nlm_rqst *req, struct file_lock *fl)
132132
memcpy(&lock->fh, NFS_FH(fl->fl_file->f_dentry->d_inode), sizeof(struct nfs_fh));
133133
lock->caller = system_utsname.nodename;
134134
lock->oh.data = req->a_owner;
135-
lock->oh.len = sprintf(req->a_owner, "%d@%s",
136-
current->pid, system_utsname.nodename);
135+
lock->oh.len = snprintf(req->a_owner, sizeof(req->a_owner), "%u@%s",
136+
(unsigned int)fl->fl_u.nfs_fl.owner->pid,
137+
system_utsname.nodename);
138+
lock->svid = fl->fl_u.nfs_fl.owner->pid;
137139
locks_copy_lock(&lock->fl, fl);
138140
}
139141

@@ -159,6 +161,7 @@ nlmclnt_setgrantargs(struct nlm_rqst *call, struct nlm_lock *lock)
159161

160162
/* set default data area */
161163
call->a_args.lock.oh.data = call->a_owner;
164+
call->a_args.lock.svid = lock->fl.fl_pid;
162165

163166
if (lock->oh.len > NLMCLNT_OHSIZE) {
164167
void *data = kmalloc(lock->oh.len, GFP_KERNEL);

‎fs/lockd/svclock.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ nlmsvc_testlock(struct nlm_file *file, struct nlm_lock *lock,
397397
(long long)fl->fl_end);
398398
conflock->caller = "somehost"; /* FIXME */
399399
conflock->oh.len = 0; /* don't return OH info */
400+
conflock->svid = fl->fl_pid;
400401
conflock->fl = *fl;
401402
return nlm_lck_denied;
402403
}

‎fs/lockd/xdr.c‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,11 @@ nlm_decode_lock(u32 *p, struct nlm_lock *lock)
131131
|| !(p = nlm_decode_fh(p, &lock->fh))
132132
|| !(p = nlm_decode_oh(p, &lock->oh)))
133133
return NULL;
134+
lock->svid = ntohl(*p++);
134135

135136
locks_init_lock(fl);
136137
fl->fl_owner = current->files;
137-
fl->fl_pid = ntohl(*p++);
138+
fl->fl_pid = (pid_t)lock->svid;
138139
fl->fl_flags = FL_POSIX;
139140
fl->fl_type = F_RDLCK; /* as good as anything else */
140141
start = ntohl(*p++);
@@ -174,7 +175,7 @@ nlm_encode_lock(u32 *p, struct nlm_lock *lock)
174175
else
175176
len = loff_t_to_s32(fl->fl_end - fl->fl_start + 1);
176177

177-
*p++ = htonl(fl->fl_pid);
178+
*p++ = htonl(lock->svid);
178179
*p++ = htonl(start);
179180
*p++ = htonl(len);
180181

@@ -197,7 +198,7 @@ nlm_encode_testres(u32 *p, struct nlm_res *resp)
197198
struct file_lock *fl = &resp->lock.fl;
198199

199200
*p++ = (fl->fl_type == F_RDLCK)? xdr_zero : xdr_one;
200-
*p++ = htonl(fl->fl_pid);
201+
*p++ = htonl(resp->lock.svid);
201202

202203
/* Encode owner handle. */
203204
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)
298299

299300
memset(lock, 0, sizeof(*lock));
300301
locks_init_lock(&lock->fl);
301-
lock->fl.fl_pid = ~(u32) 0;
302+
lock->svid = ~(u32) 0;
303+
lock->fl.fl_pid = (pid_t)lock->svid;
302304

303305
if (!(p = nlm_decode_cookie(p, &argp->cookie))
304306
|| !(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)
415417
memset(&resp->lock, 0, sizeof(resp->lock));
416418
locks_init_lock(fl);
417419
excl = ntohl(*p++);
418-
fl->fl_pid = ntohl(*p++);
420+
resp->lock.svid = ntohl(*p++);
421+
fl->fl_pid = (pid_t)resp->lock.svid;
419422
if (!(p = nlm_decode_oh(p, &resp->lock.oh)))
420423
return -EIO;
421424

‎fs/lockd/xdr4.c‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,11 @@ nlm4_decode_lock(u32 *p, struct nlm_lock *lock)
130130
|| !(p = nlm4_decode_fh(p, &lock->fh))
131131
|| !(p = nlm4_decode_oh(p, &lock->oh)))
132132
return NULL;
133+
lock->svid = ntohl(*p++);
133134

134135
locks_init_lock(fl);
135136
fl->fl_owner = current->files;
136-
fl->fl_pid = ntohl(*p++);
137+
fl->fl_pid = (pid_t)lock->svid;
137138
fl->fl_flags = FL_POSIX;
138139
fl->fl_type = F_RDLCK; /* as good as anything else */
139140
p = xdr_decode_hyper(p, &start);
@@ -167,7 +168,7 @@ nlm4_encode_lock(u32 *p, struct nlm_lock *lock)
167168
|| (fl->fl_end > NLM4_OFFSET_MAX && fl->fl_end != OFFSET_MAX))
168169
return NULL;
169170

170-
*p++ = htonl(fl->fl_pid);
171+
*p++ = htonl(lock->svid);
171172

172173
start = loff_t_to_s64(fl->fl_start);
173174
if (fl->fl_end == OFFSET_MAX)
@@ -198,7 +199,7 @@ nlm4_encode_testres(u32 *p, struct nlm_res *resp)
198199
struct file_lock *fl = &resp->lock.fl;
199200

200201
*p++ = (fl->fl_type == F_RDLCK)? xdr_zero : xdr_one;
201-
*p++ = htonl(fl->fl_pid);
202+
*p++ = htonl(resp->lock.svid);
202203

203204
/* Encode owner handle. */
204205
if (!(p = xdr_encode_netobj(p, &resp->lock.oh)))
@@ -212,8 +213,8 @@ nlm4_encode_testres(u32 *p, struct nlm_res *resp)
212213

213214
p = xdr_encode_hyper(p, start);
214215
p = xdr_encode_hyper(p, len);
215-
dprintk("xdr: encode_testres (status %d pid %d type %d start %Ld end %Ld)\n",
216-
resp->status, fl->fl_pid, fl->fl_type,
216+
dprintk("xdr: encode_testres (status %u pid %d type %d start %Ld end %Ld)\n",
217+
resp->status, (int)resp->lock.svid, fl->fl_type,
217218
(long long)fl->fl_start, (long long)fl->fl_end);
218219
}
219220

@@ -303,7 +304,8 @@ nlm4svc_decode_shareargs(struct svc_rqst *rqstp, u32 *p, nlm_args *argp)
303304

304305
memset(lock, 0, sizeof(*lock));
305306
locks_init_lock(&lock->fl);
306-
lock->fl.fl_pid = ~(u32) 0;
307+
lock->svid = ~(u32) 0;
308+
lock->fl.fl_pid = (pid_t)lock->svid;
307309

308310
if (!(p = nlm4_decode_cookie(p, &argp->cookie))
309311
|| !(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)
420422
memset(&resp->lock, 0, sizeof(resp->lock));
421423
locks_init_lock(fl);
422424
excl = ntohl(*p++);
423-
fl->fl_pid = ntohl(*p++);
425+
resp->lock.svid = ntohl(*p++);
426+
fl->fl_pid = (pid_t)resp->lock.svid;
424427
if (!(p = nlm4_decode_oh(p, &resp->lock.oh)))
425428
return -EIO;
426429

‎include/linux/lockd/xdr.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct nlm_lock {
2828
int len; /* length of "caller" */
2929
struct nfs_fh fh;
3030
struct xdr_netobj oh;
31+
u32 svid;
3132
struct file_lock fl;
3233
};
3334

0 commit comments

Comments
 (0)