Skip to content

Commit 31fc92f

Browse files
committed
Merge tag 'nfs-for-6.1-2' of git://git.linux-nfs.org/projects/anna/linux-nfs
Pull NFS client bugfixes from Anna Schumaker: - Fix some coccicheck warnings - Avoid memcpy() run-time warning - Fix up various state reclaim / RECLAIM_COMPLETE errors - Fix a null pointer dereference in sysfs - Fix LOCK races - Fix gss_unwrap_resp_integ() crasher - Fix zero length clones - Fix memleak when allocate slot fails * tag 'nfs-for-6.1-2' of git://git.linux-nfs.org/projects/anna/linux-nfs: nfs4: Fix kmemleak when allocate slot failed NFSv4.2: Fixup CLONE dest file size for zero-length count SUNRPC: Fix crasher in gss_unwrap_resp_integ() NFSv4: Retry LOCK on OLD_STATEID during delegation return SUNRPC: Fix null-ptr-deref when xps sysfs alloc failed NFSv4.1: We must always send RECLAIM_COMPLETE after a reboot NFSv4.1: Handle RECLAIM_COMPLETE trunking errors NFSv4: Fix a potential state reclaim deadlock NFS: Avoid memcpy() run-time warning for struct sockaddr overflows nfs: Remove redundant null checks before kfree
2 parents ae13366 + 7e84367 commit 31fc92f

20 files changed

+91
-78
lines changed

fs/nfs/client.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ EXPORT_SYMBOL_GPL(nfs_put_client);
280280
static struct nfs_client *nfs_match_client(const struct nfs_client_initdata *data)
281281
{
282282
struct nfs_client *clp;
283-
const struct sockaddr *sap = data->addr;
283+
const struct sockaddr *sap = (struct sockaddr *)data->addr;
284284
struct nfs_net *nn = net_generic(data->net, nfs_net_id);
285285
int error;
286286

@@ -666,7 +666,7 @@ static int nfs_init_server(struct nfs_server *server,
666666
struct rpc_timeout timeparms;
667667
struct nfs_client_initdata cl_init = {
668668
.hostname = ctx->nfs_server.hostname,
669-
.addr = (const struct sockaddr *)&ctx->nfs_server.address,
669+
.addr = &ctx->nfs_server._address,
670670
.addrlen = ctx->nfs_server.addrlen,
671671
.nfs_mod = ctx->nfs_mod,
672672
.proto = ctx->nfs_server.protocol,

fs/nfs/delegation.c

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,7 @@ static int nfs_delegation_claim_opens(struct inode *inode,
228228
*
229229
*/
230230
void nfs_inode_reclaim_delegation(struct inode *inode, const struct cred *cred,
231-
fmode_t type,
232-
const nfs4_stateid *stateid,
231+
fmode_t type, const nfs4_stateid *stateid,
233232
unsigned long pagemod_limit)
234233
{
235234
struct nfs_delegation *delegation;
@@ -239,25 +238,24 @@ void nfs_inode_reclaim_delegation(struct inode *inode, const struct cred *cred,
239238
delegation = rcu_dereference(NFS_I(inode)->delegation);
240239
if (delegation != NULL) {
241240
spin_lock(&delegation->lock);
242-
if (nfs4_is_valid_delegation(delegation, 0)) {
243-
nfs4_stateid_copy(&delegation->stateid, stateid);
244-
delegation->type = type;
245-
delegation->pagemod_limit = pagemod_limit;
246-
oldcred = delegation->cred;
247-
delegation->cred = get_cred(cred);
248-
clear_bit(NFS_DELEGATION_NEED_RECLAIM,
249-
&delegation->flags);
250-
spin_unlock(&delegation->lock);
251-
rcu_read_unlock();
252-
put_cred(oldcred);
253-
trace_nfs4_reclaim_delegation(inode, type);
254-
return;
255-
}
256-
/* We appear to have raced with a delegation return. */
241+
nfs4_stateid_copy(&delegation->stateid, stateid);
242+
delegation->type = type;
243+
delegation->pagemod_limit = pagemod_limit;
244+
oldcred = delegation->cred;
245+
delegation->cred = get_cred(cred);
246+
clear_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags);
247+
if (test_and_clear_bit(NFS_DELEGATION_REVOKED,
248+
&delegation->flags))
249+
atomic_long_inc(&nfs_active_delegations);
257250
spin_unlock(&delegation->lock);
251+
rcu_read_unlock();
252+
put_cred(oldcred);
253+
trace_nfs4_reclaim_delegation(inode, type);
254+
} else {
255+
rcu_read_unlock();
256+
nfs_inode_set_delegation(inode, cred, type, stateid,
257+
pagemod_limit);
258258
}
259-
rcu_read_unlock();
260-
nfs_inode_set_delegation(inode, cred, type, stateid, pagemod_limit);
261259
}
262260

263261
static int nfs_do_return_delegation(struct inode *inode, struct nfs_delegation *delegation, int issync)

fs/nfs/dir.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,9 +2489,8 @@ int nfs_unlink(struct inode *dir, struct dentry *dentry)
24892489
spin_unlock(&dentry->d_lock);
24902490
goto out;
24912491
}
2492-
if (dentry->d_fsdata)
2493-
/* old devname */
2494-
kfree(dentry->d_fsdata);
2492+
/* old devname */
2493+
kfree(dentry->d_fsdata);
24952494
dentry->d_fsdata = NFS_FSDATA_BLOCKED;
24962495

24972496
spin_unlock(&dentry->d_lock);

fs/nfs/dns_resolve.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
#include "dns_resolve.h"
1717

1818
ssize_t nfs_dns_resolve_name(struct net *net, char *name, size_t namelen,
19-
struct sockaddr *sa, size_t salen)
19+
struct sockaddr_storage *ss, size_t salen)
2020
{
21+
struct sockaddr *sa = (struct sockaddr *)ss;
2122
ssize_t ret;
2223
char *ip_addr = NULL;
2324
int ip_len;
@@ -341,7 +342,7 @@ static int do_cache_lookup_wait(struct cache_detail *cd,
341342
}
342343

343344
ssize_t nfs_dns_resolve_name(struct net *net, char *name,
344-
size_t namelen, struct sockaddr *sa, size_t salen)
345+
size_t namelen, struct sockaddr_storage *ss, size_t salen)
345346
{
346347
struct nfs_dns_ent key = {
347348
.hostname = name,
@@ -354,7 +355,7 @@ ssize_t nfs_dns_resolve_name(struct net *net, char *name,
354355
ret = do_cache_lookup_wait(nn->nfs_dns_resolve, &key, &item);
355356
if (ret == 0) {
356357
if (salen >= item->addrlen) {
357-
memcpy(sa, &item->addr, item->addrlen);
358+
memcpy(ss, &item->addr, item->addrlen);
358359
ret = item->addrlen;
359360
} else
360361
ret = -EOVERFLOW;

fs/nfs/dns_resolve.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ extern void nfs_dns_resolver_cache_destroy(struct net *net);
3232
#endif
3333

3434
extern ssize_t nfs_dns_resolve_name(struct net *net, char *name,
35-
size_t namelen, struct sockaddr *sa, size_t salen);
35+
size_t namelen, struct sockaddr_storage *sa, size_t salen);
3636

3737
#endif

fs/nfs/fs_context.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,9 @@ static const struct constant_table nfs_secflavor_tokens[] = {
273273
* Address family must be initialized, and address must not be
274274
* the ANY address for that family.
275275
*/
276-
static int nfs_verify_server_address(struct sockaddr *addr)
276+
static int nfs_verify_server_address(struct sockaddr_storage *addr)
277277
{
278-
switch (addr->sa_family) {
278+
switch (addr->ss_family) {
279279
case AF_INET: {
280280
struct sockaddr_in *sa = (struct sockaddr_in *)addr;
281281
return sa->sin_addr.s_addr != htonl(INADDR_ANY);
@@ -969,7 +969,7 @@ static int nfs23_parse_monolithic(struct fs_context *fc,
969969
{
970970
struct nfs_fs_context *ctx = nfs_fc2context(fc);
971971
struct nfs_fh *mntfh = ctx->mntfh;
972-
struct sockaddr *sap = (struct sockaddr *)&ctx->nfs_server.address;
972+
struct sockaddr_storage *sap = &ctx->nfs_server._address;
973973
int extra_flags = NFS_MOUNT_LEGACY_INTERFACE;
974974
int ret;
975975

@@ -1044,7 +1044,7 @@ static int nfs23_parse_monolithic(struct fs_context *fc,
10441044
memcpy(sap, &data->addr, sizeof(data->addr));
10451045
ctx->nfs_server.addrlen = sizeof(data->addr);
10461046
ctx->nfs_server.port = ntohs(data->addr.sin_port);
1047-
if (sap->sa_family != AF_INET ||
1047+
if (sap->ss_family != AF_INET ||
10481048
!nfs_verify_server_address(sap))
10491049
goto out_no_address;
10501050

@@ -1200,7 +1200,7 @@ static int nfs4_parse_monolithic(struct fs_context *fc,
12001200
struct nfs4_mount_data *data)
12011201
{
12021202
struct nfs_fs_context *ctx = nfs_fc2context(fc);
1203-
struct sockaddr *sap = (struct sockaddr *)&ctx->nfs_server.address;
1203+
struct sockaddr_storage *sap = &ctx->nfs_server._address;
12041204
int ret;
12051205
char *c;
12061206

@@ -1314,7 +1314,7 @@ static int nfs_fs_context_validate(struct fs_context *fc)
13141314
{
13151315
struct nfs_fs_context *ctx = nfs_fc2context(fc);
13161316
struct nfs_subversion *nfs_mod;
1317-
struct sockaddr *sap = (struct sockaddr *)&ctx->nfs_server.address;
1317+
struct sockaddr_storage *sap = &ctx->nfs_server._address;
13181318
int max_namelen = PAGE_SIZE;
13191319
int max_pathlen = NFS_MAXPATHLEN;
13201320
int port = 0;
@@ -1540,7 +1540,7 @@ static int nfs_init_fs_context(struct fs_context *fc)
15401540
ctx->version = nfss->nfs_client->rpc_ops->version;
15411541
ctx->minorversion = nfss->nfs_client->cl_minorversion;
15421542

1543-
memcpy(&ctx->nfs_server.address, &nfss->nfs_client->cl_addr,
1543+
memcpy(&ctx->nfs_server._address, &nfss->nfs_client->cl_addr,
15441544
ctx->nfs_server.addrlen);
15451545

15461546
if (fc->net_ns != net) {

fs/nfs/internal.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static inline fmode_t flags_to_mode(int flags)
6969
struct nfs_client_initdata {
7070
unsigned long init_flags;
7171
const char *hostname; /* Hostname of the server */
72-
const struct sockaddr *addr; /* Address of the server */
72+
const struct sockaddr_storage *addr; /* Address of the server */
7373
const char *nodename; /* Hostname of the client */
7474
const char *ip_addr; /* IP address of the client */
7575
size_t addrlen;
@@ -180,7 +180,7 @@ static inline struct nfs_fs_context *nfs_fc2context(const struct fs_context *fc)
180180

181181
/* mount_clnt.c */
182182
struct nfs_mount_request {
183-
struct sockaddr *sap;
183+
struct sockaddr_storage *sap;
184184
size_t salen;
185185
char *hostname;
186186
char *dirpath;
@@ -223,7 +223,7 @@ extern void nfs4_server_set_init_caps(struct nfs_server *);
223223
extern struct nfs_server *nfs4_create_server(struct fs_context *);
224224
extern struct nfs_server *nfs4_create_referral_server(struct fs_context *);
225225
extern int nfs4_update_server(struct nfs_server *server, const char *hostname,
226-
struct sockaddr *sap, size_t salen,
226+
struct sockaddr_storage *sap, size_t salen,
227227
struct net *net);
228228
extern void nfs_free_server(struct nfs_server *server);
229229
extern struct nfs_server *nfs_clone_server(struct nfs_server *,
@@ -235,15 +235,15 @@ extern int nfs_client_init_status(const struct nfs_client *clp);
235235
extern int nfs_wait_client_init_complete(const struct nfs_client *clp);
236236
extern void nfs_mark_client_ready(struct nfs_client *clp, int state);
237237
extern struct nfs_client *nfs4_set_ds_client(struct nfs_server *mds_srv,
238-
const struct sockaddr *ds_addr,
238+
const struct sockaddr_storage *ds_addr,
239239
int ds_addrlen, int ds_proto,
240240
unsigned int ds_timeo,
241241
unsigned int ds_retrans,
242242
u32 minor_version);
243243
extern struct rpc_clnt *nfs4_find_or_create_ds_client(struct nfs_client *,
244244
struct inode *);
245245
extern struct nfs_client *nfs3_set_ds_client(struct nfs_server *mds_srv,
246-
const struct sockaddr *ds_addr, int ds_addrlen,
246+
const struct sockaddr_storage *ds_addr, int ds_addrlen,
247247
int ds_proto, unsigned int ds_timeo,
248248
unsigned int ds_retrans);
249249
#ifdef CONFIG_PROC_FS
@@ -894,13 +894,13 @@ static inline bool nfs_error_is_fatal_on_server(int err)
894894
* Select between a default port value and a user-specified port value.
895895
* If a zero value is set, then autobind will be used.
896896
*/
897-
static inline void nfs_set_port(struct sockaddr *sap, int *port,
897+
static inline void nfs_set_port(struct sockaddr_storage *sap, int *port,
898898
const unsigned short default_port)
899899
{
900900
if (*port == NFS_UNSPEC_PORT)
901901
*port = default_port;
902902

903-
rpc_set_port(sap, *port);
903+
rpc_set_port((struct sockaddr *)sap, *port);
904904
}
905905

906906
struct nfs_direct_req {

fs/nfs/mount_clnt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ int nfs_mount(struct nfs_mount_request *info, int timeo, int retrans)
158158
struct rpc_create_args args = {
159159
.net = info->net,
160160
.protocol = info->protocol,
161-
.address = info->sap,
161+
.address = (struct sockaddr *)info->sap,
162162
.addrsize = info->salen,
163163
.timeout = &mnt_timeout,
164164
.servername = info->hostname,
@@ -245,7 +245,7 @@ void nfs_umount(const struct nfs_mount_request *info)
245245
struct rpc_create_args args = {
246246
.net = info->net,
247247
.protocol = IPPROTO_UDP,
248-
.address = info->sap,
248+
.address = (struct sockaddr *)info->sap,
249249
.addrsize = info->salen,
250250
.timeout = &nfs_umnt_timeout,
251251
.servername = info->hostname,

fs/nfs/namespace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ struct vfsmount *nfs_d_automount(struct path *path)
175175
}
176176

177177
/* for submounts we want the same server; referrals will reassign */
178-
memcpy(&ctx->nfs_server.address, &client->cl_addr, client->cl_addrlen);
178+
memcpy(&ctx->nfs_server._address, &client->cl_addr, client->cl_addrlen);
179179
ctx->nfs_server.addrlen = client->cl_addrlen;
180180
ctx->nfs_server.port = server->port;
181181

fs/nfs/nfs3client.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ struct nfs_server *nfs3_clone_server(struct nfs_server *source,
7878
* the MDS.
7979
*/
8080
struct nfs_client *nfs3_set_ds_client(struct nfs_server *mds_srv,
81-
const struct sockaddr *ds_addr, int ds_addrlen,
81+
const struct sockaddr_storage *ds_addr, int ds_addrlen,
8282
int ds_proto, unsigned int ds_timeo, unsigned int ds_retrans)
8383
{
8484
struct rpc_timeout ds_timeout;
@@ -98,7 +98,7 @@ struct nfs_client *nfs3_set_ds_client(struct nfs_server *mds_srv,
9898
char buf[INET6_ADDRSTRLEN + 1];
9999

100100
/* fake a hostname because lockd wants it */
101-
if (rpc_ntop(ds_addr, buf, sizeof(buf)) <= 0)
101+
if (rpc_ntop((struct sockaddr *)ds_addr, buf, sizeof(buf)) <= 0)
102102
return ERR_PTR(-EINVAL);
103103
cl_init.hostname = buf;
104104

0 commit comments

Comments
 (0)