Skip to content

Commit 0fd08c5

Browse files
committed
Merge branch 'bugfixes' of git://git.linux-nfs.org/projects/trondmy/nfs-2.6
* 'bugfixes' of git://git.linux-nfs.org/projects/trondmy/nfs-2.6: NFS: NFSv4 readdir loses entries NFS: Micro-optimize nfs4_decode_dirent() NFS: Fix an NFS client lockdep issue NFS construct consistent co_ownerid for v4.1 NFS: nfs_wcc_update_inode() should set nfsi->attr_gencount NFS improve pnfs_put_deviceid_cache debug print NFS fix cb_sequence error processing NFS do not find client in NFSv4 pg_authenticate NLM: Fix "kernel BUG at fs/lockd/host.c:417!" or ".../host.c:283!" NFS: Prevent memory allocation failure in nfsacl_encode() NFS: nfsacl_{encode,decode} should return signed integer NFS: Fix "kernel BUG at fs/nfs/nfs3xdr.c:1338!" NFS: Fix "kernel BUG at fs/aio.c:554!" NFS4: Avoid potential NULL pointer dereference in decode_and_add_ds(). NFS: fix handling of malloc failure during nfs_flush_multi()
2 parents 7921127 + d1205f8 commit 0fd08c5

25 files changed

Lines changed: 174 additions & 210 deletions

‎fs/lockd/host.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ static struct nlm_host *next_host_state(struct hlist_head *cache,
520520
struct nsm_handle *nsm,
521521
const struct nlm_reboot *info)
522522
{
523-
struct nlm_host *host = NULL;
523+
struct nlm_host *host;
524524
struct hlist_head *chain;
525525
struct hlist_node *pos;
526526

@@ -532,12 +532,13 @@ static struct nlm_host *next_host_state(struct hlist_head *cache,
532532
host->h_state++;
533533

534534
nlm_get_host(host);
535-
goto out;
535+
mutex_unlock(&nlm_host_mutex);
536+
return host;
536537
}
537538
}
538-
out:
539+
539540
mutex_unlock(&nlm_host_mutex);
540-
return host;
541+
return NULL;
541542
}
542543

543544
/**

‎fs/nfs/callback.c‎

Lines changed: 29 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -134,33 +134,6 @@ nfs4_callback_up(struct svc_serv *serv)
134134
}
135135

136136
#if defined(CONFIG_NFS_V4_1)
137-
/*
138-
* * CB_SEQUENCE operations will fail until the callback sessionid is set.
139-
* */
140-
int nfs4_set_callback_sessionid(struct nfs_client *clp)
141-
{
142-
struct svc_serv *serv = clp->cl_rpcclient->cl_xprt->bc_serv;
143-
struct nfs4_sessionid *bc_sid;
144-
145-
if (!serv->sv_bc_xprt)
146-
return -EINVAL;
147-
148-
/* on success freed in xprt_free */
149-
bc_sid = kmalloc(sizeof(struct nfs4_sessionid), GFP_KERNEL);
150-
if (!bc_sid)
151-
return -ENOMEM;
152-
memcpy(bc_sid->data, &clp->cl_session->sess_id.data,
153-
NFS4_MAX_SESSIONID_LEN);
154-
spin_lock_bh(&serv->sv_cb_lock);
155-
serv->sv_bc_xprt->xpt_bc_sid = bc_sid;
156-
spin_unlock_bh(&serv->sv_cb_lock);
157-
dprintk("%s set xpt_bc_sid=%u:%u:%u:%u for sv_bc_xprt %p\n", __func__,
158-
((u32 *)bc_sid->data)[0], ((u32 *)bc_sid->data)[1],
159-
((u32 *)bc_sid->data)[2], ((u32 *)bc_sid->data)[3],
160-
serv->sv_bc_xprt);
161-
return 0;
162-
}
163-
164137
/*
165138
* The callback service for NFSv4.1 callbacks
166139
*/
@@ -266,10 +239,6 @@ static inline void nfs_callback_bc_serv(u32 minorversion, struct rpc_xprt *xprt,
266239
struct nfs_callback_data *cb_info)
267240
{
268241
}
269-
int nfs4_set_callback_sessionid(struct nfs_client *clp)
270-
{
271-
return 0;
272-
}
273242
#endif /* CONFIG_NFS_V4_1 */
274243

275244
/*
@@ -359,78 +328,58 @@ void nfs_callback_down(int minorversion)
359328
mutex_unlock(&nfs_callback_mutex);
360329
}
361330

362-
static int check_gss_callback_principal(struct nfs_client *clp,
363-
struct svc_rqst *rqstp)
331+
/* Boolean check of RPC_AUTH_GSS principal */
332+
int
333+
check_gss_callback_principal(struct nfs_client *clp, struct svc_rqst *rqstp)
364334
{
365335
struct rpc_clnt *r = clp->cl_rpcclient;
366336
char *p = svc_gss_principal(rqstp);
367337

338+
if (rqstp->rq_authop->flavour != RPC_AUTH_GSS)
339+
return 1;
340+
368341
/* No RPC_AUTH_GSS on NFSv4.1 back channel yet */
369342
if (clp->cl_minorversion != 0)
370-
return SVC_DROP;
343+
return 0;
371344
/*
372345
* It might just be a normal user principal, in which case
373346
* userspace won't bother to tell us the name at all.
374347
*/
375348
if (p == NULL)
376-
return SVC_DENIED;
349+
return 0;
377350

378351
/* Expect a GSS_C_NT_HOSTBASED_NAME like "nfs@serverhostname" */
379352

380353
if (memcmp(p, "nfs@", 4) != 0)
381-
return SVC_DENIED;
354+
return 0;
382355
p += 4;
383356
if (strcmp(p, r->cl_server) != 0)
384-
return SVC_DENIED;
385-
return SVC_OK;
357+
return 0;
358+
return 1;
386359
}
387360

388-
/* pg_authenticate method helper */
389-
static struct nfs_client *nfs_cb_find_client(struct svc_rqst *rqstp)
390-
{
391-
struct nfs4_sessionid *sessionid = bc_xprt_sid(rqstp);
392-
int is_cb_compound = rqstp->rq_proc == CB_COMPOUND ? 1 : 0;
393-
394-
dprintk("--> %s rq_proc %d\n", __func__, rqstp->rq_proc);
395-
if (svc_is_backchannel(rqstp))
396-
/* Sessionid (usually) set after CB_NULL ping */
397-
return nfs4_find_client_sessionid(svc_addr(rqstp), sessionid,
398-
is_cb_compound);
399-
else
400-
/* No callback identifier in pg_authenticate */
401-
return nfs4_find_client_no_ident(svc_addr(rqstp));
402-
}
403-
404-
/* pg_authenticate method for nfsv4 callback threads. */
361+
/*
362+
* pg_authenticate method for nfsv4 callback threads.
363+
*
364+
* The authflavor has been negotiated, so an incorrect flavor is a server
365+
* bug. Drop packets with incorrect authflavor.
366+
*
367+
* All other checking done after NFS decoding where the nfs_client can be
368+
* found in nfs4_callback_compound
369+
*/
405370
static int nfs_callback_authenticate(struct svc_rqst *rqstp)
406371
{
407-
struct nfs_client *clp;
408-
RPC_IFDEBUG(char buf[RPC_MAX_ADDRBUFLEN]);
409-
int ret = SVC_OK;
410-
411-
/* Don't talk to strangers */
412-
clp = nfs_cb_find_client(rqstp);
413-
if (clp == NULL)
414-
return SVC_DROP;
415-
416-
dprintk("%s: %s NFSv4 callback!\n", __func__,
417-
svc_print_addr(rqstp, buf, sizeof(buf)));
418-
419372
switch (rqstp->rq_authop->flavour) {
420-
case RPC_AUTH_NULL:
421-
if (rqstp->rq_proc != CB_NULL)
422-
ret = SVC_DENIED;
423-
break;
424-
case RPC_AUTH_UNIX:
425-
break;
426-
case RPC_AUTH_GSS:
427-
ret = check_gss_callback_principal(clp, rqstp);
428-
break;
429-
default:
430-
ret = SVC_DENIED;
373+
case RPC_AUTH_NULL:
374+
if (rqstp->rq_proc != CB_NULL)
375+
return SVC_DROP;
376+
break;
377+
case RPC_AUTH_GSS:
378+
/* No RPC_AUTH_GSS support yet in NFSv4.1 */
379+
if (svc_is_backchannel(rqstp))
380+
return SVC_DROP;
431381
}
432-
nfs_put_client(clp);
433-
return ret;
382+
return SVC_OK;
434383
}
435384

436385
/*

‎fs/nfs/callback.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
#ifndef __LINUX_FS_NFS_CALLBACK_H
99
#define __LINUX_FS_NFS_CALLBACK_H
10+
#include <linux/sunrpc/svc.h>
1011

1112
#define NFS4_CALLBACK 0x40000000
1213
#define NFS4_CALLBACK_XDRSIZE 2048
@@ -37,7 +38,6 @@ enum nfs4_callback_opnum {
3738
struct cb_process_state {
3839
__be32 drc_status;
3940
struct nfs_client *clp;
40-
struct nfs4_sessionid *svc_sid; /* v4.1 callback service sessionid */
4141
};
4242

4343
struct cb_compound_hdr_arg {
@@ -168,7 +168,7 @@ extern unsigned nfs4_callback_layoutrecall(
168168
extern void nfs4_check_drain_bc_complete(struct nfs4_session *ses);
169169
extern void nfs4_cb_take_slot(struct nfs_client *clp);
170170
#endif /* CONFIG_NFS_V4_1 */
171-
171+
extern int check_gss_callback_principal(struct nfs_client *, struct svc_rqst *);
172172
extern __be32 nfs4_callback_getattr(struct cb_getattrargs *args,
173173
struct cb_getattrres *res,
174174
struct cb_process_state *cps);

‎fs/nfs/callback_proc.c‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -373,17 +373,11 @@ __be32 nfs4_callback_sequence(struct cb_sequenceargs *args,
373373
{
374374
struct nfs_client *clp;
375375
int i;
376-
__be32 status;
376+
__be32 status = htonl(NFS4ERR_BADSESSION);
377377

378378
cps->clp = NULL;
379379

380-
status = htonl(NFS4ERR_BADSESSION);
381-
/* Incoming session must match the callback session */
382-
if (memcmp(&args->csa_sessionid, cps->svc_sid, NFS4_MAX_SESSIONID_LEN))
383-
goto out;
384-
385-
clp = nfs4_find_client_sessionid(args->csa_addr,
386-
&args->csa_sessionid, 1);
380+
clp = nfs4_find_client_sessionid(args->csa_addr, &args->csa_sessionid);
387381
if (clp == NULL)
388382
goto out;
389383

@@ -414,9 +408,9 @@ __be32 nfs4_callback_sequence(struct cb_sequenceargs *args,
414408
res->csr_highestslotid = NFS41_BC_MAX_CALLBACKS - 1;
415409
res->csr_target_highestslotid = NFS41_BC_MAX_CALLBACKS - 1;
416410
nfs4_cb_take_slot(clp);
417-
cps->clp = clp; /* put in nfs4_callback_compound */
418411

419412
out:
413+
cps->clp = clp; /* put in nfs4_callback_compound */
420414
for (i = 0; i < args->csa_nrclists; i++)
421415
kfree(args->csa_rclists[i].rcl_refcalls);
422416
kfree(args->csa_rclists);

‎fs/nfs/callback_xdr.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -794,10 +794,9 @@ static __be32 nfs4_callback_compound(struct svc_rqst *rqstp, void *argp, void *r
794794

795795
if (hdr_arg.minorversion == 0) {
796796
cps.clp = nfs4_find_client_ident(hdr_arg.cb_ident);
797-
if (!cps.clp)
797+
if (!cps.clp || !check_gss_callback_principal(cps.clp, rqstp))
798798
return rpc_drop_reply;
799-
} else
800-
cps.svc_sid = bc_xprt_sid(rqstp);
799+
}
801800

802801
hdr_res.taglen = hdr_arg.taglen;
803802
hdr_res.tag = hdr_arg.tag;

‎fs/nfs/client.c‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,16 +1206,11 @@ nfs4_find_client_ident(int cb_ident)
12061206
* For CB_COMPOUND calls, find a client by IP address, protocol version,
12071207
* minorversion, and sessionID
12081208
*
1209-
* CREATE_SESSION triggers a CB_NULL ping from servers. The callback service
1210-
* sessionid can only be set after the CREATE_SESSION return, so a CB_NULL
1211-
* can arrive before the callback sessionid is set. For CB_NULL calls,
1212-
* find a client by IP address protocol version, and minorversion.
1213-
*
12141209
* Returns NULL if no such client
12151210
*/
12161211
struct nfs_client *
12171212
nfs4_find_client_sessionid(const struct sockaddr *addr,
1218-
struct nfs4_sessionid *sid, int is_cb_compound)
1213+
struct nfs4_sessionid *sid)
12191214
{
12201215
struct nfs_client *clp;
12211216

@@ -1227,9 +1222,9 @@ nfs4_find_client_sessionid(const struct sockaddr *addr,
12271222
if (!nfs4_has_session(clp))
12281223
continue;
12291224

1230-
/* Match sessionid unless cb_null call*/
1231-
if (is_cb_compound && (memcmp(clp->cl_session->sess_id.data,
1232-
sid->data, NFS4_MAX_SESSIONID_LEN) != 0))
1225+
/* Match sessionid*/
1226+
if (memcmp(clp->cl_session->sess_id.data,
1227+
sid->data, NFS4_MAX_SESSIONID_LEN) != 0)
12331228
continue;
12341229

12351230
atomic_inc(&clp->cl_count);
@@ -1244,7 +1239,7 @@ nfs4_find_client_sessionid(const struct sockaddr *addr,
12441239

12451240
struct nfs_client *
12461241
nfs4_find_client_sessionid(const struct sockaddr *addr,
1247-
struct nfs4_sessionid *sid, int is_cb_compound)
1242+
struct nfs4_sessionid *sid)
12481243
{
12491244
return NULL;
12501245
}

‎fs/nfs/delegation.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323

2424
static void nfs_do_free_delegation(struct nfs_delegation *delegation)
2525
{
26-
if (delegation->cred)
27-
put_rpccred(delegation->cred);
2826
kfree(delegation);
2927
}
3028

@@ -37,6 +35,10 @@ static void nfs_free_delegation_callback(struct rcu_head *head)
3735

3836
static void nfs_free_delegation(struct nfs_delegation *delegation)
3937
{
38+
if (delegation->cred) {
39+
put_rpccred(delegation->cred);
40+
delegation->cred = NULL;
41+
}
4042
call_rcu(&delegation->rcu, nfs_free_delegation_callback);
4143
}
4244

‎fs/nfs/direct.c‎

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -407,15 +407,18 @@ static ssize_t nfs_direct_read_schedule_iovec(struct nfs_direct_req *dreq,
407407
pos += vec->iov_len;
408408
}
409409

410+
/*
411+
* If no bytes were started, return the error, and let the
412+
* generic layer handle the completion.
413+
*/
414+
if (requested_bytes == 0) {
415+
nfs_direct_req_release(dreq);
416+
return result < 0 ? result : -EIO;
417+
}
418+
410419
if (put_dreq(dreq))
411420
nfs_direct_complete(dreq);
412-
413-
if (requested_bytes != 0)
414-
return 0;
415-
416-
if (result < 0)
417-
return result;
418-
return -EIO;
421+
return 0;
419422
}
420423

421424
static ssize_t nfs_direct_read(struct kiocb *iocb, const struct iovec *iov,
@@ -841,15 +844,18 @@ static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq,
841844
pos += vec->iov_len;
842845
}
843846

847+
/*
848+
* If no bytes were started, return the error, and let the
849+
* generic layer handle the completion.
850+
*/
851+
if (requested_bytes == 0) {
852+
nfs_direct_req_release(dreq);
853+
return result < 0 ? result : -EIO;
854+
}
855+
844856
if (put_dreq(dreq))
845857
nfs_direct_write_complete(dreq, dreq->inode);
846-
847-
if (requested_bytes != 0)
848-
return 0;
849-
850-
if (result < 0)
851-
return result;
852-
return -EIO;
858+
return 0;
853859
}
854860

855861
static ssize_t nfs_direct_write(struct kiocb *iocb, const struct iovec *iov,

0 commit comments

Comments
 (0)