Skip to content

Commit 48df020

Browse files
chuckleverJ. Bruce Fields
authored andcommitted
NLM: Fix sign of length of NLM variable length strings
According to The Open Group's NLM specification, NLM callers are variable length strings. XDR variable length strings use an unsigned 32 bit length. And internally, negative string lengths are not meaningful for the Linux NLM implementation. Clean up: Make nlm_lock.len and nlm_reboot.len unsigned integers. This makes the sign of NLM string lengths consistent with the sign of xdr_netobj lengths. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Acked-By: NeilBrown <neilb@suse.de> Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
1 parent e5cff48 commit 48df020

3 files changed

Lines changed: 19 additions & 13 deletions

File tree

‎fs/lockd/host.c‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,19 @@ static DEFINE_MUTEX(nlm_host_mutex);
3434

3535
static void nlm_gc_hosts(void);
3636
static struct nsm_handle * __nsm_find(const struct sockaddr_in *,
37-
const char *, int, int);
37+
const char *, unsigned int, int);
3838
static struct nsm_handle * nsm_find(const struct sockaddr_in *sin,
3939
const char *hostname,
40-
int hostname_len);
40+
unsigned int hostname_len);
4141

4242
/*
4343
* Common host lookup routine for server & client
4444
*/
4545
static struct nlm_host *
4646
nlm_lookup_host(int server, const struct sockaddr_in *sin,
4747
int proto, int version, const char *hostname,
48-
int hostname_len, const struct sockaddr_in *ssin)
48+
unsigned int hostname_len,
49+
const struct sockaddr_in *ssin)
4950
{
5051
struct hlist_head *chain;
5152
struct hlist_node *pos;
@@ -176,7 +177,7 @@ nlm_destroy_host(struct nlm_host *host)
176177
*/
177178
struct nlm_host *
178179
nlmclnt_lookup_host(const struct sockaddr_in *sin, int proto, int version,
179-
const char *hostname, int hostname_len)
180+
const char *hostname, unsigned int hostname_len)
180181
{
181182
struct sockaddr_in ssin = {0};
182183

@@ -189,7 +190,7 @@ nlmclnt_lookup_host(const struct sockaddr_in *sin, int proto, int version,
189190
*/
190191
struct nlm_host *
191192
nlmsvc_lookup_host(struct svc_rqst *rqstp,
192-
const char *hostname, int hostname_len)
193+
const char *hostname, unsigned int hostname_len)
193194
{
194195
struct sockaddr_in ssin = {0};
195196

@@ -307,7 +308,8 @@ void nlm_release_host(struct nlm_host *host)
307308
* Release all resources held by that peer.
308309
*/
309310
void nlm_host_rebooted(const struct sockaddr_in *sin,
310-
const char *hostname, int hostname_len,
311+
const char *hostname,
312+
unsigned int hostname_len,
311313
u32 new_state)
312314
{
313315
struct hlist_head *chain;
@@ -449,7 +451,7 @@ static DEFINE_MUTEX(nsm_mutex);
449451

450452
static struct nsm_handle *
451453
__nsm_find(const struct sockaddr_in *sin,
452-
const char *hostname, int hostname_len,
454+
const char *hostname, unsigned int hostname_len,
453455
int create)
454456
{
455457
struct nsm_handle *nsm = NULL;
@@ -503,7 +505,8 @@ __nsm_find(const struct sockaddr_in *sin,
503505
}
504506

505507
static struct nsm_handle *
506-
nsm_find(const struct sockaddr_in *sin, const char *hostname, int hostname_len)
508+
nsm_find(const struct sockaddr_in *sin, const char *hostname,
509+
unsigned int hostname_len)
507510
{
508511
return __nsm_find(sin, hostname, hostname_len, 1);
509512
}

‎include/linux/lockd/lockd.h‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,17 @@ void nlmclnt_next_cookie(struct nlm_cookie *);
173173
/*
174174
* Host cache
175175
*/
176-
struct nlm_host * nlmclnt_lookup_host(const struct sockaddr_in *, int, int, const char *, int);
177-
struct nlm_host * nlmsvc_lookup_host(struct svc_rqst *, const char *, int);
176+
struct nlm_host *nlmclnt_lookup_host(const struct sockaddr_in *, int, int,
177+
const char *, unsigned int);
178+
struct nlm_host *nlmsvc_lookup_host(struct svc_rqst *, const char *,
179+
unsigned int);
178180
struct rpc_clnt * nlm_bind_host(struct nlm_host *);
179181
void nlm_rebind_host(struct nlm_host *);
180182
struct nlm_host * nlm_get_host(struct nlm_host *);
181183
void nlm_release_host(struct nlm_host *);
182184
void nlm_shutdown_hosts(void);
183-
extern void nlm_host_rebooted(const struct sockaddr_in *, const char *, int, u32);
185+
extern void nlm_host_rebooted(const struct sockaddr_in *, const char *,
186+
unsigned int, u32);
184187
void nsm_release(struct nsm_handle *);
185188

186189

‎include/linux/lockd/xdr.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct svc_rqst;
2929
/* Lock info passed via NLM */
3030
struct nlm_lock {
3131
char * caller;
32-
int len; /* length of "caller" */
32+
unsigned int len; /* length of "caller" */
3333
struct nfs_fh fh;
3434
struct xdr_netobj oh;
3535
u32 svid;
@@ -78,7 +78,7 @@ struct nlm_res {
7878
*/
7979
struct nlm_reboot {
8080
char * mon;
81-
int len;
81+
unsigned int len;
8282
u32 state;
8383
__be32 addr;
8484
__be32 vers;

0 commit comments

Comments
 (0)