Skip to content

Commit 890939e

Browse files
chuckleverJ. Bruce Fields
authored andcommitted
lockd: Update the NLMv1 SHARE arguments decoder to use struct xdr_stream
Signed-off-by: Chuck Lever <[email protected]> Signed-off-by: J. Bruce Fields <[email protected]>
1 parent 137e05e commit 890939e

File tree

1 file changed

+26
-70
lines changed

1 file changed

+26
-70
lines changed

fs/lockd/xdr.c

Lines changed: 26 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
#include "svcxdr.h"
2323

24-
#define NLMDBG_FACILITY NLMDBG_XDR
25-
2624

2725
static inline loff_t
2826
s32_to_loff_t(__s32 offset)
@@ -46,33 +44,6 @@ loff_t_to_s32(loff_t offset)
4644
/*
4745
* XDR functions for basic NLM types
4846
*/
49-
static __be32 *nlm_decode_cookie(__be32 *p, struct nlm_cookie *c)
50-
{
51-
unsigned int len;
52-
53-
len = ntohl(*p++);
54-
55-
if(len==0)
56-
{
57-
c->len=4;
58-
memset(c->data, 0, 4); /* hockeypux brain damage */
59-
}
60-
else if(len<=NLM_MAXCOOKIELEN)
61-
{
62-
c->len=len;
63-
memcpy(c->data, p, len);
64-
p+=XDR_QUADLEN(len);
65-
}
66-
else
67-
{
68-
dprintk("lockd: bad cookie size %d (only cookies under "
69-
"%d bytes are supported.)\n",
70-
len, NLM_MAXCOOKIELEN);
71-
return NULL;
72-
}
73-
return p;
74-
}
75-
7647
static inline __be32 *
7748
nlm_encode_cookie(__be32 *p, struct nlm_cookie *c)
7849
{
@@ -82,22 +53,6 @@ nlm_encode_cookie(__be32 *p, struct nlm_cookie *c)
8253
return p;
8354
}
8455

85-
static __be32 *
86-
nlm_decode_fh(__be32 *p, struct nfs_fh *f)
87-
{
88-
unsigned int len;
89-
90-
if ((len = ntohl(*p++)) != NFS2_FHSIZE) {
91-
dprintk("lockd: bad fhandle size %d (should be %d)\n",
92-
len, NFS2_FHSIZE);
93-
return NULL;
94-
}
95-
f->size = NFS2_FHSIZE;
96-
memset(f->data, 0, sizeof(f->data));
97-
memcpy(f->data, p, NFS2_FHSIZE);
98-
return p + XDR_QUADLEN(NFS2_FHSIZE);
99-
}
100-
10156
/*
10257
* NLM file handles are defined by specification to be a variable-length
10358
* XDR opaque no longer than 1024 bytes. However, this implementation
@@ -128,12 +83,6 @@ svcxdr_decode_fhandle(struct xdr_stream *xdr, struct nfs_fh *fh)
12883
/*
12984
* Encode and decode owner handle
13085
*/
131-
static inline __be32 *
132-
nlm_decode_oh(__be32 *p, struct xdr_netobj *oh)
133-
{
134-
return xdr_decode_netobj(p, oh);
135-
}
136-
13786
static inline __be32 *
13887
nlm_encode_oh(__be32 *p, struct xdr_netobj *oh)
13988
{
@@ -339,35 +288,42 @@ nlmsvc_decode_reboot(struct svc_rqst *rqstp, __be32 *p)
339288
return 1;
340289
}
341290

342-
int
343-
nlmsvc_encode_testres(struct svc_rqst *rqstp, __be32 *p)
344-
{
345-
struct nlm_res *resp = rqstp->rq_resp;
346-
347-
if (!(p = nlm_encode_testres(p, resp)))
348-
return 0;
349-
return xdr_ressize_check(rqstp, p);
350-
}
351-
352291
int
353292
nlmsvc_decode_shareargs(struct svc_rqst *rqstp, __be32 *p)
354293
{
294+
struct xdr_stream *xdr = &rqstp->rq_arg_stream;
355295
struct nlm_args *argp = rqstp->rq_argp;
356296
struct nlm_lock *lock = &argp->lock;
357297

358298
memset(lock, 0, sizeof(*lock));
359299
locks_init_lock(&lock->fl);
360-
lock->svid = ~(u32) 0;
300+
lock->svid = ~(u32)0;
361301

362-
if (!(p = nlm_decode_cookie(p, &argp->cookie))
363-
|| !(p = xdr_decode_string_inplace(p, &lock->caller,
364-
&lock->len, NLM_MAXSTRLEN))
365-
|| !(p = nlm_decode_fh(p, &lock->fh))
366-
|| !(p = nlm_decode_oh(p, &lock->oh)))
302+
if (!svcxdr_decode_cookie(xdr, &argp->cookie))
367303
return 0;
368-
argp->fsm_mode = ntohl(*p++);
369-
argp->fsm_access = ntohl(*p++);
370-
return xdr_argsize_check(rqstp, p);
304+
if (!svcxdr_decode_string(xdr, &lock->caller, &lock->len))
305+
return 0;
306+
if (!svcxdr_decode_fhandle(xdr, &lock->fh))
307+
return 0;
308+
if (!svcxdr_decode_owner(xdr, &lock->oh))
309+
return 0;
310+
/* XXX: Range checks are missing in the original code */
311+
if (xdr_stream_decode_u32(xdr, &argp->fsm_mode) < 0)
312+
return 0;
313+
if (xdr_stream_decode_u32(xdr, &argp->fsm_access) < 0)
314+
return 0;
315+
316+
return 1;
317+
}
318+
319+
int
320+
nlmsvc_encode_testres(struct svc_rqst *rqstp, __be32 *p)
321+
{
322+
struct nlm_res *resp = rqstp->rq_resp;
323+
324+
if (!(p = nlm_encode_testres(p, resp)))
325+
return 0;
326+
return xdr_ressize_check(rqstp, p);
371327
}
372328

373329
int

0 commit comments

Comments
 (0)