Commit 0ff08ba5 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'for-3.11' of git://linux-nfs.org/~bfields/linux

Pull nfsd changes from Bruce Fields:
 "Changes this time include:

   - 4.1 enabled on the server by default: the last 4.1-specific issues
     I know of are fixed, so we're not going to find the rest of the
     bugs without more exposure.
   - Experimental support for NFSv4.2 MAC Labeling (to allow running
     selinux over NFS), from Dave Quigley.
   - Fixes for some delicate cache/upcall races that could cause rare
     server hangs; thanks to Neil Brown and Bodo Stroesser for extreme
     debugging persistence.
   - Fixes for some bugs found at the recent NFS bakeathon, mostly v4
     and v4.1-specific, but also a generic bug handling fragmented rpc
     calls"

* 'for-3.11' of git://linux-nfs.org/~bfields/linux: (31 commits)
  nfsd4: support minorversion 1 by default
  nfsd4: allow destroy_session over destroyed session
  svcrpc: fix failures to handle -1 uid's
  sunrpc: Don't schedule an upcall on a replaced cache entry.
  net/sunrpc: xpt_auth_cache should be ignored when expired.
  sunrpc/cache: ensure items removed from cache do not have pending upcalls.
  sunrpc/cache: use cache_fresh_unlocked consistently and correctly.
  sunrpc/cache: remove races with queuing an upcall.
  nfsd4: return delegation immediately if lease fails
  nfsd4: do not throw away 4.1 lock state on last unlock
  nfsd4: delegation-based open reclaims should bypass permissions
  svcrpc: don't error out on small tcp fragment
  svcrpc: fix handling of too-short rpc's
  nfsd4: minor read_buf cleanup
  nfsd4: fix decoding of compounds across page boundaries
  nfsd4: clean up nfs4_open_delegation
  NFSD: Don't give out read delegations on creates
  nfsd4: allow client to send no cb_sec flavors
  nfsd4: fail attempts to request gss on the backchannel
  nfsd4: implement minimal SP4_MACH_CRED
  ...
parents c72bb316 d1091481
...@@ -81,6 +81,22 @@ config NFSD_V4 ...@@ -81,6 +81,22 @@ config NFSD_V4
If unsure, say N. If unsure, say N.
config NFSD_V4_SECURITY_LABEL
bool "Provide Security Label support for NFSv4 server"
depends on NFSD_V4 && SECURITY
help
Say Y here if you want enable fine-grained security label attribute
support for NFS version 4. Security labels allow security modules like
SELinux and Smack to label files to facilitate enforcement of their policies.
Without this an NFSv4 mount will have the same label on each file.
If you do not wish to enable fine-grained security labels SELinux or
Smack policies on NFSv4 files, say N.
WARNING: there is still a chance of backwards-incompatible protocol changes.
For now we recommend "Y" only for developers and testers."
config NFSD_FAULT_INJECTION config NFSD_FAULT_INJECTION
bool "NFS server manual fault injection" bool "NFS server manual fault injection"
depends on NFSD_V4 && DEBUG_KERNEL depends on NFSD_V4 && DEBUG_KERNEL
......
...@@ -42,6 +42,36 @@ ...@@ -42,6 +42,36 @@
#include "current_stateid.h" #include "current_stateid.h"
#include "netns.h" #include "netns.h"
#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
#include <linux/security.h>
static inline void
nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval)
{
struct inode *inode = resfh->fh_dentry->d_inode;
int status;
mutex_lock(&inode->i_mutex);
status = security_inode_setsecctx(resfh->fh_dentry,
label->data, label->len);
mutex_unlock(&inode->i_mutex);
if (status)
/*
* XXX: We should really fail the whole open, but we may
* already have created a new file, so it may be too
* late. For now this seems the least of evils:
*/
bmval[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
return;
}
#else
static inline void
nfsd4_security_inode_setsecctx(struct svc_fh *resfh, struct xdr_netobj *label, u32 *bmval)
{ }
#endif
#define NFSDDBG_FACILITY NFSDDBG_PROC #define NFSDDBG_FACILITY NFSDDBG_PROC
static u32 nfsd_attrmask[] = { static u32 nfsd_attrmask[] = {
...@@ -239,6 +269,9 @@ do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, stru ...@@ -239,6 +269,9 @@ do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, stru
(u32 *)open->op_verf.data, (u32 *)open->op_verf.data,
&open->op_truncate, &open->op_created); &open->op_truncate, &open->op_created);
if (!status && open->op_label.len)
nfsd4_security_inode_setsecctx(resfh, &open->op_label, open->op_bmval);
/* /*
* Following rfc 3530 14.2.16, use the returned bitmask * Following rfc 3530 14.2.16, use the returned bitmask
* to indicate which attributes we used to store the * to indicate which attributes we used to store the
...@@ -263,7 +296,8 @@ do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, stru ...@@ -263,7 +296,8 @@ do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, stru
nfsd4_set_open_owner_reply_cache(cstate, open, resfh); nfsd4_set_open_owner_reply_cache(cstate, open, resfh);
accmode = NFSD_MAY_NOP; accmode = NFSD_MAY_NOP;
if (open->op_created) if (open->op_created ||
open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR)
accmode |= NFSD_MAY_OWNER_OVERRIDE; accmode |= NFSD_MAY_OWNER_OVERRIDE;
status = do_open_permission(rqstp, resfh, open, accmode); status = do_open_permission(rqstp, resfh, open, accmode);
set_change_info(&open->op_cinfo, current_fh); set_change_info(&open->op_cinfo, current_fh);
...@@ -637,6 +671,9 @@ nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, ...@@ -637,6 +671,9 @@ nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
if (status) if (status)
goto out; goto out;
if (create->cr_label.len)
nfsd4_security_inode_setsecctx(&resfh, &create->cr_label, create->cr_bmval);
if (create->cr_acl != NULL) if (create->cr_acl != NULL)
do_set_nfs4_acl(rqstp, &resfh, create->cr_acl, do_set_nfs4_acl(rqstp, &resfh, create->cr_acl,
create->cr_bmval); create->cr_bmval);
...@@ -916,6 +953,11 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, ...@@ -916,6 +953,11 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
setattr->sa_acl); setattr->sa_acl);
if (status) if (status)
goto out; goto out;
if (setattr->sa_label.len)
status = nfsd4_set_nfs4_label(rqstp, &cstate->current_fh,
&setattr->sa_label);
if (status)
goto out;
status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr, status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr,
0, (time_t)0); 0, (time_t)0);
out: out:
......
This diff is collapsed.
...@@ -55,6 +55,11 @@ ...@@ -55,6 +55,11 @@
#include "cache.h" #include "cache.h"
#include "netns.h" #include "netns.h"
#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
#include <linux/security.h>
#endif
#define NFSDDBG_FACILITY NFSDDBG_XDR #define NFSDDBG_FACILITY NFSDDBG_XDR
/* /*
...@@ -134,6 +139,19 @@ xdr_error: \ ...@@ -134,6 +139,19 @@ xdr_error: \
} \ } \
} while (0) } while (0)
static void next_decode_page(struct nfsd4_compoundargs *argp)
{
argp->pagelist++;
argp->p = page_address(argp->pagelist[0]);
if (argp->pagelen < PAGE_SIZE) {
argp->end = argp->p + (argp->pagelen>>2);
argp->pagelen = 0;
} else {
argp->end = argp->p + (PAGE_SIZE>>2);
argp->pagelen -= PAGE_SIZE;
}
}
static __be32 *read_buf(struct nfsd4_compoundargs *argp, u32 nbytes) static __be32 *read_buf(struct nfsd4_compoundargs *argp, u32 nbytes)
{ {
/* We want more bytes than seem to be available. /* We want more bytes than seem to be available.
...@@ -161,16 +179,7 @@ static __be32 *read_buf(struct nfsd4_compoundargs *argp, u32 nbytes) ...@@ -161,16 +179,7 @@ static __be32 *read_buf(struct nfsd4_compoundargs *argp, u32 nbytes)
* guarantee p points to at least nbytes bytes. * guarantee p points to at least nbytes bytes.
*/ */
memcpy(p, argp->p, avail); memcpy(p, argp->p, avail);
/* step to next page */ next_decode_page(argp);
argp->p = page_address(argp->pagelist[0]);
argp->pagelist++;
if (argp->pagelen < PAGE_SIZE) {
argp->end = argp->p + (argp->pagelen>>2);
argp->pagelen = 0;
} else {
argp->end = argp->p + (PAGE_SIZE>>2);
argp->pagelen -= PAGE_SIZE;
}
memcpy(((char*)p)+avail, argp->p, (nbytes - avail)); memcpy(((char*)p)+avail, argp->p, (nbytes - avail));
argp->p += XDR_QUADLEN(nbytes - avail); argp->p += XDR_QUADLEN(nbytes - avail);
return p; return p;
...@@ -242,7 +251,8 @@ nfsd4_decode_bitmap(struct nfsd4_compoundargs *argp, u32 *bmval) ...@@ -242,7 +251,8 @@ nfsd4_decode_bitmap(struct nfsd4_compoundargs *argp, u32 *bmval)
static __be32 static __be32
nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval, nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval,
struct iattr *iattr, struct nfs4_acl **acl) struct iattr *iattr, struct nfs4_acl **acl,
struct xdr_netobj *label)
{ {
int expected_len, len = 0; int expected_len, len = 0;
u32 dummy32; u32 dummy32;
...@@ -380,6 +390,32 @@ nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval, ...@@ -380,6 +390,32 @@ nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval,
goto xdr_error; goto xdr_error;
} }
} }
label->len = 0;
#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
READ_BUF(4);
len += 4;
READ32(dummy32); /* lfs: we don't use it */
READ_BUF(4);
len += 4;
READ32(dummy32); /* pi: we don't use it either */
READ_BUF(4);
len += 4;
READ32(dummy32);
READ_BUF(dummy32);
if (dummy32 > NFSD4_MAX_SEC_LABEL_LEN)
return nfserr_badlabel;
len += (XDR_QUADLEN(dummy32) << 2);
READMEM(buf, dummy32);
label->data = kzalloc(dummy32 + 1, GFP_KERNEL);
if (!label->data)
return nfserr_jukebox;
defer_free(argp, kfree, label->data);
memcpy(label->data, buf, dummy32);
}
#endif
if (bmval[0] & ~NFSD_WRITEABLE_ATTRS_WORD0 if (bmval[0] & ~NFSD_WRITEABLE_ATTRS_WORD0
|| bmval[1] & ~NFSD_WRITEABLE_ATTRS_WORD1 || bmval[1] & ~NFSD_WRITEABLE_ATTRS_WORD1
|| bmval[2] & ~NFSD_WRITEABLE_ATTRS_WORD2) || bmval[2] & ~NFSD_WRITEABLE_ATTRS_WORD2)
...@@ -428,7 +464,11 @@ static __be32 nfsd4_decode_cb_sec(struct nfsd4_compoundargs *argp, struct nfsd4_ ...@@ -428,7 +464,11 @@ static __be32 nfsd4_decode_cb_sec(struct nfsd4_compoundargs *argp, struct nfsd4_
/* callback_sec_params4 */ /* callback_sec_params4 */
READ_BUF(4); READ_BUF(4);
READ32(nr_secflavs); READ32(nr_secflavs);
cbs->flavor = (u32)(-1); if (nr_secflavs)
cbs->flavor = (u32)(-1);
else
/* Is this legal? Be generous, take it to mean AUTH_NONE: */
cbs->flavor = 0;
for (i = 0; i < nr_secflavs; ++i) { for (i = 0; i < nr_secflavs; ++i) {
READ_BUF(4); READ_BUF(4);
READ32(dummy); READ32(dummy);
...@@ -576,7 +616,7 @@ nfsd4_decode_create(struct nfsd4_compoundargs *argp, struct nfsd4_create *create ...@@ -576,7 +616,7 @@ nfsd4_decode_create(struct nfsd4_compoundargs *argp, struct nfsd4_create *create
return status; return status;
status = nfsd4_decode_fattr(argp, create->cr_bmval, &create->cr_iattr, status = nfsd4_decode_fattr(argp, create->cr_bmval, &create->cr_iattr,
&create->cr_acl); &create->cr_acl, &create->cr_label);
if (status) if (status)
goto out; goto out;
...@@ -827,7 +867,7 @@ nfsd4_decode_open(struct nfsd4_compoundargs *argp, struct nfsd4_open *open) ...@@ -827,7 +867,7 @@ nfsd4_decode_open(struct nfsd4_compoundargs *argp, struct nfsd4_open *open)
case NFS4_CREATE_UNCHECKED: case NFS4_CREATE_UNCHECKED:
case NFS4_CREATE_GUARDED: case NFS4_CREATE_GUARDED:
status = nfsd4_decode_fattr(argp, open->op_bmval, status = nfsd4_decode_fattr(argp, open->op_bmval,
&open->op_iattr, &open->op_acl); &open->op_iattr, &open->op_acl, &open->op_label);
if (status) if (status)
goto out; goto out;
break; break;
...@@ -841,7 +881,7 @@ nfsd4_decode_open(struct nfsd4_compoundargs *argp, struct nfsd4_open *open) ...@@ -841,7 +881,7 @@ nfsd4_decode_open(struct nfsd4_compoundargs *argp, struct nfsd4_open *open)
READ_BUF(NFS4_VERIFIER_SIZE); READ_BUF(NFS4_VERIFIER_SIZE);
COPYMEM(open->op_verf.data, NFS4_VERIFIER_SIZE); COPYMEM(open->op_verf.data, NFS4_VERIFIER_SIZE);
status = nfsd4_decode_fattr(argp, open->op_bmval, status = nfsd4_decode_fattr(argp, open->op_bmval,
&open->op_iattr, &open->op_acl); &open->op_iattr, &open->op_acl, &open->op_label);
if (status) if (status)
goto out; goto out;
break; break;
...@@ -1063,7 +1103,7 @@ nfsd4_decode_setattr(struct nfsd4_compoundargs *argp, struct nfsd4_setattr *seta ...@@ -1063,7 +1103,7 @@ nfsd4_decode_setattr(struct nfsd4_compoundargs *argp, struct nfsd4_setattr *seta
if (status) if (status)
return status; return status;
return nfsd4_decode_fattr(argp, setattr->sa_bmval, &setattr->sa_iattr, return nfsd4_decode_fattr(argp, setattr->sa_bmval, &setattr->sa_iattr,
&setattr->sa_acl); &setattr->sa_acl, &setattr->sa_label);
} }
static __be32 static __be32
...@@ -1567,6 +1607,7 @@ struct nfsd4_minorversion_ops { ...@@ -1567,6 +1607,7 @@ struct nfsd4_minorversion_ops {
static struct nfsd4_minorversion_ops nfsd4_minorversion[] = { static struct nfsd4_minorversion_ops nfsd4_minorversion[] = {
[0] = { nfsd4_dec_ops, ARRAY_SIZE(nfsd4_dec_ops) }, [0] = { nfsd4_dec_ops, ARRAY_SIZE(nfsd4_dec_ops) },
[1] = { nfsd41_dec_ops, ARRAY_SIZE(nfsd41_dec_ops) }, [1] = { nfsd41_dec_ops, ARRAY_SIZE(nfsd41_dec_ops) },
[2] = { nfsd41_dec_ops, ARRAY_SIZE(nfsd41_dec_ops) },
}; };
static __be32 static __be32
...@@ -1953,6 +1994,36 @@ nfsd4_encode_aclname(struct svc_rqst *rqstp, struct nfs4_ace *ace, ...@@ -1953,6 +1994,36 @@ nfsd4_encode_aclname(struct svc_rqst *rqstp, struct nfs4_ace *ace,
FATTR4_WORD0_RDATTR_ERROR) FATTR4_WORD0_RDATTR_ERROR)
#define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID #define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID
#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
static inline __be32
nfsd4_encode_security_label(struct svc_rqst *rqstp, void *context, int len, __be32 **pp, int *buflen)
{
__be32 *p = *pp;
if (*buflen < ((XDR_QUADLEN(len) << 2) + 4 + 4 + 4))
return nfserr_resource;
/*
* For now we use a 0 here to indicate the null translation; in
* the future we may place a call to translation code here.
*/
if ((*buflen -= 8) < 0)
return nfserr_resource;
WRITE32(0); /* lfs */
WRITE32(0); /* pi */
p = xdr_encode_opaque(p, context, len);
*buflen -= (XDR_QUADLEN(len) << 2) + 4;
*pp = p;
return 0;
}
#else
static inline __be32
nfsd4_encode_security_label(struct svc_rqst *rqstp, void *context, int len, __be32 **pp, int *buflen)
{ return 0; }
#endif
static __be32 fattr_handle_absent_fs(u32 *bmval0, u32 *bmval1, u32 *rdattr_err) static __be32 fattr_handle_absent_fs(u32 *bmval0, u32 *bmval1, u32 *rdattr_err)
{ {
/* As per referral draft: */ /* As per referral draft: */
...@@ -2012,6 +2083,9 @@ nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp, ...@@ -2012,6 +2083,9 @@ nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp,
int err; int err;
int aclsupport = 0; int aclsupport = 0;
struct nfs4_acl *acl = NULL; struct nfs4_acl *acl = NULL;
void *context = NULL;
int contextlen;
bool contextsupport = false;
struct nfsd4_compoundres *resp = rqstp->rq_resp; struct nfsd4_compoundres *resp = rqstp->rq_resp;
u32 minorversion = resp->cstate.minorversion; u32 minorversion = resp->cstate.minorversion;
struct path path = { struct path path = {
...@@ -2065,6 +2139,21 @@ nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp, ...@@ -2065,6 +2139,21 @@ nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp,
} }
} }
#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
if ((bmval[2] & FATTR4_WORD2_SECURITY_LABEL) ||
bmval[0] & FATTR4_WORD0_SUPPORTED_ATTRS) {
err = security_inode_getsecctx(dentry->d_inode,
&context, &contextlen);
contextsupport = (err == 0);
if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) {
if (err == -EOPNOTSUPP)
bmval2 &= ~FATTR4_WORD2_SECURITY_LABEL;
else if (err)
goto out_nfserr;
}
}
#endif /* CONFIG_NFSD_V4_SECURITY_LABEL */
if (bmval2) { if (bmval2) {
if ((buflen -= 16) < 0) if ((buflen -= 16) < 0)
goto out_resource; goto out_resource;
...@@ -2093,6 +2182,8 @@ nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp, ...@@ -2093,6 +2182,8 @@ nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp,
if (!aclsupport) if (!aclsupport)
word0 &= ~FATTR4_WORD0_ACL; word0 &= ~FATTR4_WORD0_ACL;
if (!contextsupport)
word2 &= ~FATTR4_WORD2_SECURITY_LABEL;
if (!word2) { if (!word2) {
if ((buflen -= 12) < 0) if ((buflen -= 12) < 0)
goto out_resource; goto out_resource;
...@@ -2400,6 +2491,12 @@ nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp, ...@@ -2400,6 +2491,12 @@ nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp,
get_parent_attributes(exp, &stat); get_parent_attributes(exp, &stat);
WRITE64(stat.ino); WRITE64(stat.ino);
} }
if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) {
status = nfsd4_encode_security_label(rqstp, context,
contextlen, &p, &buflen);
if (status)
goto out;
}
if (bmval2 & FATTR4_WORD2_SUPPATTR_EXCLCREAT) { if (bmval2 & FATTR4_WORD2_SUPPATTR_EXCLCREAT) {
WRITE32(3); WRITE32(3);
WRITE32(NFSD_SUPPATTR_EXCLCREAT_WORD0); WRITE32(NFSD_SUPPATTR_EXCLCREAT_WORD0);
...@@ -2412,6 +2509,10 @@ nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp, ...@@ -2412,6 +2509,10 @@ nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp,
status = nfs_ok; status = nfs_ok;
out: out:
#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
if (context)
security_release_secctx(context, contextlen);
#endif /* CONFIG_NFSD_V4_SECURITY_LABEL */
kfree(acl); kfree(acl);
if (fhp == &tempfh) if (fhp == &tempfh)
fh_put(&tempfh); fh_put(&tempfh);
...@@ -3176,16 +3277,18 @@ nfsd4_encode_setattr(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4 ...@@ -3176,16 +3277,18 @@ nfsd4_encode_setattr(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4
{ {
__be32 *p; __be32 *p;
RESERVE_SPACE(12); RESERVE_SPACE(16);
if (nfserr) { if (nfserr) {
WRITE32(2); WRITE32(3);
WRITE32(0);
WRITE32(0); WRITE32(0);
WRITE32(0); WRITE32(0);
} }
else { else {
WRITE32(2); WRITE32(3);
WRITE32(setattr->sa_bmval[0]); WRITE32(setattr->sa_bmval[0]);
WRITE32(setattr->sa_bmval[1]); WRITE32(setattr->sa_bmval[1]);
WRITE32(setattr->sa_bmval[2]);
} }
ADJUST_ARGS(); ADJUST_ARGS();
return nfserr; return nfserr;
...@@ -3226,6 +3329,14 @@ nfsd4_encode_write(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_w ...@@ -3226,6 +3329,14 @@ nfsd4_encode_write(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_w
return nfserr; return nfserr;
} }
static const u32 nfs4_minimal_spo_must_enforce[2] = {
[1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) |
1 << (OP_EXCHANGE_ID - 32) |
1 << (OP_CREATE_SESSION - 32) |
1 << (OP_DESTROY_SESSION - 32) |
1 << (OP_DESTROY_CLIENTID - 32)
};
static __be32 static __be32
nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr, nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr,
struct nfsd4_exchange_id *exid) struct nfsd4_exchange_id *exid)
...@@ -3264,6 +3375,20 @@ nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr, ...@@ -3264,6 +3375,20 @@ nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr,
/* state_protect4_r. Currently only support SP4_NONE */ /* state_protect4_r. Currently only support SP4_NONE */
BUG_ON(exid->spa_how != SP4_NONE); BUG_ON(exid->spa_how != SP4_NONE);
WRITE32(exid->spa_how); WRITE32(exid->spa_how);
switch (exid->spa_how) {
case SP4_NONE:
break;
case SP4_MACH_CRED:
/* spo_must_enforce bitmap: */
WRITE32(2);
WRITE32(nfs4_minimal_spo_must_enforce[0]);
WRITE32(nfs4_minimal_spo_must_enforce[1]);
/* empty spo_must_allow bitmap: */
WRITE32(0);
break;
default:
WARN_ON_ONCE(1);
}
/* The server_owner struct */ /* The server_owner struct */
WRITE64(minor_id); /* Minor id */ WRITE64(minor_id); /* Minor id */
...@@ -3635,13 +3760,17 @@ nfs4svc_encode_compoundres(struct svc_rqst *rqstp, __be32 *p, struct nfsd4_compo ...@@ -3635,13 +3760,17 @@ nfs4svc_encode_compoundres(struct svc_rqst *rqstp, __be32 *p, struct nfsd4_compo
iov->iov_len = ((char*)resp->p) - (char*)iov->iov_base; iov->iov_len = ((char*)resp->p) - (char*)iov->iov_base;
BUG_ON(iov->iov_len > PAGE_SIZE); BUG_ON(iov->iov_len > PAGE_SIZE);
if (nfsd4_has_session(cs)) { if (nfsd4_has_session(cs)) {
struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
struct nfs4_client *clp = cs->session->se_client;
if (cs->status != nfserr_replay_cache) { if (cs->status != nfserr_replay_cache) {
nfsd4_store_cache_entry(resp); nfsd4_store_cache_entry(resp);
cs->slot->sl_flags &= ~NFSD4_SLOT_INUSE; cs->slot->sl_flags &= ~NFSD4_SLOT_INUSE;
} }
/* Renew the clientid on success and on replay */ /* Renew the clientid on success and on replay */
put_client_renew(cs->session->se_client); spin_lock(&nn->client_lock);
nfsd4_put_session(cs->session); nfsd4_put_session(cs->session);
spin_unlock(&nn->client_lock);
put_client_renew(clp);
} }
return 1; return 1;
} }
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
/* /*
* nfsd version * nfsd version
*/ */
#define NFSD_SUPPORTED_MINOR_VERSION 1 #define NFSD_SUPPORTED_MINOR_VERSION 2
/* /*
* Maximum blocksizes supported by daemon under various circumstances. * Maximum blocksizes supported by daemon under various circumstances.
*/ */
...@@ -328,6 +328,13 @@ void nfsd_lockd_shutdown(void); ...@@ -328,6 +328,13 @@ void nfsd_lockd_shutdown(void);
#define NFSD4_1_SUPPORTED_ATTRS_WORD2 \ #define NFSD4_1_SUPPORTED_ATTRS_WORD2 \
(NFSD4_SUPPORTED_ATTRS_WORD2 | FATTR4_WORD2_SUPPATTR_EXCLCREAT) (NFSD4_SUPPORTED_ATTRS_WORD2 | FATTR4_WORD2_SUPPATTR_EXCLCREAT)
#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
#define NFSD4_2_SUPPORTED_ATTRS_WORD2 \
(NFSD4_1_SUPPORTED_ATTRS_WORD2 | FATTR4_WORD2_SECURITY_LABEL)
#else
#define NFSD4_2_SUPPORTED_ATTRS_WORD2 0
#endif
static inline u32 nfsd_suppattrs0(u32 minorversion) static inline u32 nfsd_suppattrs0(u32 minorversion)
{ {
return minorversion ? NFSD4_1_SUPPORTED_ATTRS_WORD0 return minorversion ? NFSD4_1_SUPPORTED_ATTRS_WORD0
...@@ -342,8 +349,11 @@ static inline u32 nfsd_suppattrs1(u32 minorversion) ...@@ -342,8 +349,11 @@ static inline u32 nfsd_suppattrs1(u32 minorversion)
static inline u32 nfsd_suppattrs2(u32 minorversion) static inline u32 nfsd_suppattrs2(u32 minorversion)
{ {
return minorversion ? NFSD4_1_SUPPORTED_ATTRS_WORD2 switch (minorversion) {
: NFSD4_SUPPORTED_ATTRS_WORD2; default: return NFSD4_2_SUPPORTED_ATTRS_WORD2;
case 1: return NFSD4_1_SUPPORTED_ATTRS_WORD2;
case 0: return NFSD4_SUPPORTED_ATTRS_WORD2;
}
} }
/* These will return ERR_INVAL if specified in GETATTR or READDIR. */ /* These will return ERR_INVAL if specified in GETATTR or READDIR. */
...@@ -356,7 +366,11 @@ static inline u32 nfsd_suppattrs2(u32 minorversion) ...@@ -356,7 +366,11 @@ static inline u32 nfsd_suppattrs2(u32 minorversion)
#define NFSD_WRITEABLE_ATTRS_WORD1 \ #define NFSD_WRITEABLE_ATTRS_WORD1 \
(FATTR4_WORD1_MODE | FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP \ (FATTR4_WORD1_MODE | FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP \
| FATTR4_WORD1_TIME_ACCESS_SET | FATTR4_WORD1_TIME_MODIFY_SET) | FATTR4_WORD1_TIME_ACCESS_SET | FATTR4_WORD1_TIME_MODIFY_SET)
#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
#define NFSD_WRITEABLE_ATTRS_WORD2 FATTR4_WORD2_SECURITY_LABEL
#else
#define NFSD_WRITEABLE_ATTRS_WORD2 0 #define NFSD_WRITEABLE_ATTRS_WORD2 0
#endif
#define NFSD_SUPPATTR_EXCLCREAT_WORD0 \ #define NFSD_SUPPATTR_EXCLCREAT_WORD0 \
NFSD_WRITEABLE_ATTRS_WORD0 NFSD_WRITEABLE_ATTRS_WORD0
......
...@@ -116,7 +116,7 @@ struct svc_program nfsd_program = { ...@@ -116,7 +116,7 @@ struct svc_program nfsd_program = {
}; };
u32 nfsd_supported_minorversion; u32 nfsd_supported_minorversion = 1;
int nfsd_vers(int vers, enum vers_op change) int nfsd_vers(int vers, enum vers_op change)
{ {
......
...@@ -246,6 +246,7 @@ struct nfs4_client { ...@@ -246,6 +246,7 @@ struct nfs4_client {
nfs4_verifier cl_verifier; /* generated by client */ nfs4_verifier cl_verifier; /* generated by client */
time_t cl_time; /* time of last lease renewal */ time_t cl_time; /* time of last lease renewal */
struct sockaddr_storage cl_addr; /* client ipaddress */ struct sockaddr_storage cl_addr; /* client ipaddress */
bool cl_mach_cred; /* SP4_MACH_CRED in force */
struct svc_cred cl_cred; /* setclientid principal */ struct svc_cred cl_cred; /* setclientid principal */
clientid_t cl_clientid; /* generated by server */ clientid_t cl_clientid; /* generated by server */
nfs4_verifier cl_confirm; /* generated by server */ nfs4_verifier cl_confirm; /* generated by server */
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <linux/exportfs.h> #include <linux/exportfs.h>
#include <linux/writeback.h> #include <linux/writeback.h>
#include <linux/security.h>
#ifdef CONFIG_NFSD_V3 #ifdef CONFIG_NFSD_V3
#include "xdr3.h" #include "xdr3.h"
...@@ -621,6 +622,33 @@ int nfsd4_is_junction(struct dentry *dentry) ...@@ -621,6 +622,33 @@ int nfsd4_is_junction(struct dentry *dentry)
return 0; return 0;
return 1; return 1;
} }
#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
__be32 nfsd4_set_nfs4_label(struct svc_rqst *rqstp, struct svc_fh *fhp,
struct xdr_netobj *label)
{
__be32 error;
int host_error;
struct dentry *dentry;
error = fh_verify(rqstp, fhp, 0 /* S_IFREG */, NFSD_MAY_SATTR);
if (error)
return error;
dentry = fhp->fh_dentry;
mutex_lock(&dentry->d_inode->i_mutex);
host_error = security_inode_setsecctx(dentry, label->data, label->len);
mutex_unlock(&dentry->d_inode->i_mutex);
return nfserrno(host_error);
}
#else
__be32 nfsd4_set_nfs4_label(struct svc_rqst *rqstp, struct svc_fh *fhp,
struct xdr_netobj *label)
{
return nfserr_notsupp;
}
#endif
#endif /* defined(CONFIG_NFSD_V4) */ #endif /* defined(CONFIG_NFSD_V4) */
#ifdef CONFIG_NFSD_V3 #ifdef CONFIG_NFSD_V3
......
...@@ -39,7 +39,6 @@ ...@@ -39,7 +39,6 @@
typedef int (*nfsd_dirop_t)(struct inode *, struct dentry *, int, int); typedef int (*nfsd_dirop_t)(struct inode *, struct dentry *, int, int);
/* nfsd/vfs.c */ /* nfsd/vfs.c */
int fh_lock_parent(struct svc_fh *, struct dentry *);
int nfsd_racache_init(int); int nfsd_racache_init(int);
void nfsd_racache_shutdown(void); void nfsd_racache_shutdown(void);
int nfsd_cross_mnt(struct svc_rqst *rqstp, struct dentry **dpp, int nfsd_cross_mnt(struct svc_rqst *rqstp, struct dentry **dpp,
...@@ -56,6 +55,8 @@ int nfsd_mountpoint(struct dentry *, struct svc_export *); ...@@ -56,6 +55,8 @@ int nfsd_mountpoint(struct dentry *, struct svc_export *);
__be32 nfsd4_set_nfs4_acl(struct svc_rqst *, struct svc_fh *, __be32 nfsd4_set_nfs4_acl(struct svc_rqst *, struct svc_fh *,
struct nfs4_acl *); struct nfs4_acl *);
int nfsd4_get_nfs4_acl(struct svc_rqst *, struct dentry *, struct nfs4_acl **); int nfsd4_get_nfs4_acl(struct svc_rqst *, struct dentry *, struct nfs4_acl **);
__be32 nfsd4_set_nfs4_label(struct svc_rqst *, struct svc_fh *,
struct xdr_netobj *);
#endif /* CONFIG_NFSD_V4 */ #endif /* CONFIG_NFSD_V4 */
__be32 nfsd_create(struct svc_rqst *, struct svc_fh *, __be32 nfsd_create(struct svc_rqst *, struct svc_fh *,
char *name, int len, struct iattr *attrs, char *name, int len, struct iattr *attrs,
...@@ -92,17 +93,13 @@ __be32 nfsd_remove(struct svc_rqst *, ...@@ -92,17 +93,13 @@ __be32 nfsd_remove(struct svc_rqst *,
struct svc_fh *, char *, int); struct svc_fh *, char *, int);
__be32 nfsd_unlink(struct svc_rqst *, struct svc_fh *, int type, __be32 nfsd_unlink(struct svc_rqst *, struct svc_fh *, int type,
char *name, int len); char *name, int len);
int nfsd_truncate(struct svc_rqst *, struct svc_fh *,
unsigned long size);
__be32 nfsd_readdir(struct svc_rqst *, struct svc_fh *, __be32 nfsd_readdir(struct svc_rqst *, struct svc_fh *,
loff_t *, struct readdir_cd *, filldir_t); loff_t *, struct readdir_cd *, filldir_t);
__be32 nfsd_statfs(struct svc_rqst *, struct svc_fh *, __be32 nfsd_statfs(struct svc_rqst *, struct svc_fh *,
struct kstatfs *, int access); struct kstatfs *, int access);
int nfsd_notify_change(struct inode *, struct iattr *);
__be32 nfsd_permission(struct svc_rqst *, struct svc_export *, __be32 nfsd_permission(struct svc_rqst *, struct svc_export *,
struct dentry *, int); struct dentry *, int);
int nfsd_sync_dir(struct dentry *dp);
#if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL) #if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL)
struct posix_acl *nfsd_get_posix_acl(struct svc_fh *, int); struct posix_acl *nfsd_get_posix_acl(struct svc_fh *, int);
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include "state.h" #include "state.h"
#include "nfsd.h" #include "nfsd.h"
#define NFSD4_MAX_SEC_LABEL_LEN 2048
#define NFSD4_MAX_TAGLEN 128 #define NFSD4_MAX_TAGLEN 128
#define XDR_LEN(n) (((n) + 3) & ~3) #define XDR_LEN(n) (((n) + 3) & ~3)
...@@ -118,6 +119,7 @@ struct nfsd4_create { ...@@ -118,6 +119,7 @@ struct nfsd4_create {
struct iattr cr_iattr; /* request */ struct iattr cr_iattr; /* request */
struct nfsd4_change_info cr_cinfo; /* response */ struct nfsd4_change_info cr_cinfo; /* response */
struct nfs4_acl *cr_acl; struct nfs4_acl *cr_acl;
struct xdr_netobj cr_label;
}; };
#define cr_linklen u.link.namelen #define cr_linklen u.link.namelen
#define cr_linkname u.link.name #define cr_linkname u.link.name
...@@ -246,6 +248,7 @@ struct nfsd4_open { ...@@ -246,6 +248,7 @@ struct nfsd4_open {
struct nfs4_file *op_file; /* used during processing */ struct nfs4_file *op_file; /* used during processing */
struct nfs4_ol_stateid *op_stp; /* used during processing */ struct nfs4_ol_stateid *op_stp; /* used during processing */
struct nfs4_acl *op_acl; struct nfs4_acl *op_acl;
struct xdr_netobj op_label;
}; };
#define op_iattr iattr #define op_iattr iattr
...@@ -330,6 +333,7 @@ struct nfsd4_setattr { ...@@ -330,6 +333,7 @@ struct nfsd4_setattr {
u32 sa_bmval[3]; /* request */ u32 sa_bmval[3]; /* request */
struct iattr sa_iattr; /* request */ struct iattr sa_iattr; /* request */
struct nfs4_acl *sa_acl; struct nfs4_acl *sa_acl;
struct xdr_netobj sa_label;
}; };
struct nfsd4_setclientid { struct nfsd4_setclientid {
......
...@@ -57,6 +57,7 @@ struct cache_head { ...@@ -57,6 +57,7 @@ struct cache_head {
#define CACHE_VALID 0 /* Entry contains valid data */ #define CACHE_VALID 0 /* Entry contains valid data */
#define CACHE_NEGATIVE 1 /* Negative entry - there is no match for the key */ #define CACHE_NEGATIVE 1 /* Negative entry - there is no match for the key */
#define CACHE_PENDING 2 /* An upcall has been sent but no reply received yet*/ #define CACHE_PENDING 2 /* An upcall has been sent but no reply received yet*/
#define CACHE_CLEANED 3 /* Entry has been cleaned from cache */
#define CACHE_NEW_EXPIRY 120 /* keep new things pending confirmation for 120 seconds */ #define CACHE_NEW_EXPIRY 120 /* keep new things pending confirmation for 120 seconds */
...@@ -148,6 +149,24 @@ struct cache_deferred_req { ...@@ -148,6 +149,24 @@ struct cache_deferred_req {
int too_many); int too_many);
}; };
/*
* timestamps kept in the cache are expressed in seconds
* since boot. This is the best for measuring differences in
* real time.
*/
static inline time_t seconds_since_boot(void)
{
struct timespec boot;
getboottime(&boot);
return get_seconds() - boot.tv_sec;
}
static inline time_t convert_to_wallclock(time_t sinceboot)
{
struct timespec boot;
getboottime(&boot);
return boot.tv_sec + sinceboot;
}
extern const struct file_operations cache_file_operations_pipefs; extern const struct file_operations cache_file_operations_pipefs;
extern const struct file_operations content_file_operations_pipefs; extern const struct file_operations content_file_operations_pipefs;
...@@ -181,15 +200,10 @@ static inline void cache_put(struct cache_head *h, struct cache_detail *cd) ...@@ -181,15 +200,10 @@ static inline void cache_put(struct cache_head *h, struct cache_detail *cd)
kref_put(&h->ref, cd->cache_put); kref_put(&h->ref, cd->cache_put);
} }
static inline int cache_valid(struct cache_head *h) static inline int cache_is_expired(struct cache_detail *detail, struct cache_head *h)
{ {
/* If an item has been unhashed pending removal when return (h->expiry_time < seconds_since_boot()) ||
* the refcount drops to 0, the expiry_time will be (detail->flush_time > h->last_refresh);
* set to 0. We don't want to consider such items
* valid in this context even though CACHE_VALID is
* set.
*/
return (h->expiry_time != 0 && test_bit(CACHE_VALID, &h->flags));
} }
extern int cache_check(struct cache_detail *detail, extern int cache_check(struct cache_detail *detail,
...@@ -250,25 +264,6 @@ static inline int get_uint(char **bpp, unsigned int *anint) ...@@ -250,25 +264,6 @@ static inline int get_uint(char **bpp, unsigned int *anint)
return 0; return 0;
} }
/*
* timestamps kept in the cache are expressed in seconds
* since boot. This is the best for measuring differences in
* real time.
*/
static inline time_t seconds_since_boot(void)
{
struct timespec boot;
getboottime(&boot);
return get_seconds() - boot.tv_sec;
}
static inline time_t convert_to_wallclock(time_t sinceboot)
{
struct timespec boot;
getboottime(&boot);
return boot.tv_sec + sinceboot;
}
static inline time_t get_expiry(char **bpp) static inline time_t get_expiry(char **bpp)
{ {
int rv; int rv;
......
...@@ -151,6 +151,8 @@ struct gss_api_mech *gss_mech_get_by_pseudoflavor(u32); ...@@ -151,6 +151,8 @@ struct gss_api_mech *gss_mech_get_by_pseudoflavor(u32);
/* Fill in an array with a list of supported pseudoflavors */ /* Fill in an array with a list of supported pseudoflavors */
int gss_mech_list_pseudoflavors(rpc_authflavor_t *, int); int gss_mech_list_pseudoflavors(rpc_authflavor_t *, int);
struct gss_api_mech * gss_mech_get(struct gss_api_mech *);
/* For every successful gss_mech_get or gss_mech_get_by_* call there must be a /* For every successful gss_mech_get or gss_mech_get_by_* call there must be a
* corresponding call to gss_mech_put. */ * corresponding call to gss_mech_put. */
void gss_mech_put(struct gss_api_mech *); void gss_mech_put(struct gss_api_mech *);
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <linux/string.h> #include <linux/string.h>
#include <linux/sunrpc/msg_prot.h> #include <linux/sunrpc/msg_prot.h>
#include <linux/sunrpc/cache.h> #include <linux/sunrpc/cache.h>
#include <linux/sunrpc/gss_api.h>
#include <linux/hash.h> #include <linux/hash.h>
#include <linux/cred.h> #include <linux/cred.h>
...@@ -23,13 +24,23 @@ struct svc_cred { ...@@ -23,13 +24,23 @@ struct svc_cred {
struct group_info *cr_group_info; struct group_info *cr_group_info;
u32 cr_flavor; /* pseudoflavor */ u32 cr_flavor; /* pseudoflavor */
char *cr_principal; /* for gss */ char *cr_principal; /* for gss */
struct gss_api_mech *cr_gss_mech;
}; };
static inline void init_svc_cred(struct svc_cred *cred)
{
cred->cr_group_info = NULL;
cred->cr_principal = NULL;
cred->cr_gss_mech = NULL;
}
static inline void free_svc_cred(struct svc_cred *cred) static inline void free_svc_cred(struct svc_cred *cred)
{ {
if (cred->cr_group_info) if (cred->cr_group_info)
put_group_info(cred->cr_group_info); put_group_info(cred->cr_group_info);
kfree(cred->cr_principal); kfree(cred->cr_principal);
gss_mech_put(cred->cr_gss_mech);
init_svc_cred(cred);
} }
struct svc_rqst; /* forward decl */ struct svc_rqst; /* forward decl */
......
...@@ -139,11 +139,12 @@ void gss_mech_unregister(struct gss_api_mech *gm) ...@@ -139,11 +139,12 @@ void gss_mech_unregister(struct gss_api_mech *gm)
} }
EXPORT_SYMBOL_GPL(gss_mech_unregister); EXPORT_SYMBOL_GPL(gss_mech_unregister);
static struct gss_api_mech *gss_mech_get(struct gss_api_mech *gm) struct gss_api_mech *gss_mech_get(struct gss_api_mech *gm)
{ {
__module_get(gm->gm_owner); __module_get(gm->gm_owner);
return gm; return gm;
} }
EXPORT_SYMBOL(gss_mech_get);
static struct gss_api_mech * static struct gss_api_mech *
_gss_mech_get_by_name(const char *name) _gss_mech_get_by_name(const char *name)
...@@ -360,6 +361,7 @@ gss_pseudoflavor_to_service(struct gss_api_mech *gm, u32 pseudoflavor) ...@@ -360,6 +361,7 @@ gss_pseudoflavor_to_service(struct gss_api_mech *gm, u32 pseudoflavor)
} }
return 0; return 0;
} }
EXPORT_SYMBOL(gss_pseudoflavor_to_service);
char * char *
gss_service_to_auth_domain_name(struct gss_api_mech *gm, u32 service) gss_service_to_auth_domain_name(struct gss_api_mech *gm, u32 service)
...@@ -379,6 +381,7 @@ gss_mech_put(struct gss_api_mech * gm) ...@@ -379,6 +381,7 @@ gss_mech_put(struct gss_api_mech * gm)
if (gm) if (gm)
module_put(gm->gm_owner); module_put(gm->gm_owner);
} }
EXPORT_SYMBOL(gss_mech_put);
/* The mech could probably be determined from the token instead, but it's just /* The mech could probably be determined from the token instead, but it's just
* as easy for now to pass it in. */ * as easy for now to pass it in. */
......
...@@ -377,8 +377,7 @@ rsc_init(struct cache_head *cnew, struct cache_head *ctmp) ...@@ -377,8 +377,7 @@ rsc_init(struct cache_head *cnew, struct cache_head *ctmp)
new->handle.data = tmp->handle.data; new->handle.data = tmp->handle.data;
tmp->handle.data = NULL; tmp->handle.data = NULL;
new->mechctx = NULL; new->mechctx = NULL;
new->cred.cr_group_info = NULL; init_svc_cred(&new->cred);
new->cred.cr_principal = NULL;
} }
static void static void
...@@ -392,9 +391,7 @@ update_rsc(struct cache_head *cnew, struct cache_head *ctmp) ...@@ -392,9 +391,7 @@ update_rsc(struct cache_head *cnew, struct cache_head *ctmp)
memset(&new->seqdata, 0, sizeof(new->seqdata)); memset(&new->seqdata, 0, sizeof(new->seqdata));
spin_lock_init(&new->seqdata.sd_lock); spin_lock_init(&new->seqdata.sd_lock);
new->cred = tmp->cred; new->cred = tmp->cred;
tmp->cred.cr_group_info = NULL; init_svc_cred(&tmp->cred);
new->cred.cr_principal = tmp->cred.cr_principal;
tmp->cred.cr_principal = NULL;
} }
static struct cache_head * static struct cache_head *
...@@ -487,7 +484,7 @@ static int rsc_parse(struct cache_detail *cd, ...@@ -487,7 +484,7 @@ static int rsc_parse(struct cache_detail *cd,
len = qword_get(&mesg, buf, mlen); len = qword_get(&mesg, buf, mlen);
if (len < 0) if (len < 0)
goto out; goto out;
gm = gss_mech_get_by_name(buf); gm = rsci.cred.cr_gss_mech = gss_mech_get_by_name(buf);
status = -EOPNOTSUPP; status = -EOPNOTSUPP;
if (!gm) if (!gm)
goto out; goto out;
...@@ -517,7 +514,6 @@ static int rsc_parse(struct cache_detail *cd, ...@@ -517,7 +514,6 @@ static int rsc_parse(struct cache_detail *cd,
rscp = rsc_update(cd, &rsci, rscp); rscp = rsc_update(cd, &rsci, rscp);
status = 0; status = 0;
out: out:
gss_mech_put(gm);
rsc_free(&rsci); rsc_free(&rsci);
if (rscp) if (rscp)
cache_put(&rscp->h, cd); cache_put(&rscp->h, cd);
......
...@@ -50,12 +50,6 @@ static void cache_init(struct cache_head *h) ...@@ -50,12 +50,6 @@ static void cache_init(struct cache_head *h)
h->last_refresh = now; h->last_refresh = now;
} }
static inline int cache_is_expired(struct cache_detail *detail, struct cache_head *h)
{
return (h->expiry_time < seconds_since_boot()) ||
(detail->flush_time > h->last_refresh);
}
struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail, struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail,
struct cache_head *key, int hash) struct cache_head *key, int hash)
{ {
...@@ -201,7 +195,7 @@ static int cache_make_upcall(struct cache_detail *cd, struct cache_head *h) ...@@ -201,7 +195,7 @@ static int cache_make_upcall(struct cache_detail *cd, struct cache_head *h)
return sunrpc_cache_pipe_upcall(cd, h); return sunrpc_cache_pipe_upcall(cd, h);
} }
static inline int cache_is_valid(struct cache_detail *detail, struct cache_head *h) static inline int cache_is_valid(struct cache_head *h)
{ {
if (!test_bit(CACHE_VALID, &h->flags)) if (!test_bit(CACHE_VALID, &h->flags))
return -EAGAIN; return -EAGAIN;
...@@ -227,16 +221,15 @@ static int try_to_negate_entry(struct cache_detail *detail, struct cache_head *h ...@@ -227,16 +221,15 @@ static int try_to_negate_entry(struct cache_detail *detail, struct cache_head *h
int rv; int rv;
write_lock(&detail->hash_lock); write_lock(&detail->hash_lock);
rv = cache_is_valid(detail, h); rv = cache_is_valid(h);
if (rv != -EAGAIN) { if (rv == -EAGAIN) {
write_unlock(&detail->hash_lock); set_bit(CACHE_NEGATIVE, &h->flags);
return rv; cache_fresh_locked(h, seconds_since_boot()+CACHE_NEW_EXPIRY);
rv = -ENOENT;
} }
set_bit(CACHE_NEGATIVE, &h->flags);
cache_fresh_locked(h, seconds_since_boot()+CACHE_NEW_EXPIRY);
write_unlock(&detail->hash_lock); write_unlock(&detail->hash_lock);
cache_fresh_unlocked(h, detail); cache_fresh_unlocked(h, detail);
return -ENOENT; return rv;
} }
/* /*
...@@ -260,7 +253,7 @@ int cache_check(struct cache_detail *detail, ...@@ -260,7 +253,7 @@ int cache_check(struct cache_detail *detail,
long refresh_age, age; long refresh_age, age;
/* First decide return status as best we can */ /* First decide return status as best we can */
rv = cache_is_valid(detail, h); rv = cache_is_valid(h);
/* now see if we want to start an upcall */ /* now see if we want to start an upcall */
refresh_age = (h->expiry_time - h->last_refresh); refresh_age = (h->expiry_time - h->last_refresh);
...@@ -269,19 +262,17 @@ int cache_check(struct cache_detail *detail, ...@@ -269,19 +262,17 @@ int cache_check(struct cache_detail *detail,
if (rqstp == NULL) { if (rqstp == NULL) {
if (rv == -EAGAIN) if (rv == -EAGAIN)
rv = -ENOENT; rv = -ENOENT;
} else if (rv == -EAGAIN || age > refresh_age/2) { } else if (rv == -EAGAIN ||
(h->expiry_time != 0 && age > refresh_age/2)) {
dprintk("RPC: Want update, refage=%ld, age=%ld\n", dprintk("RPC: Want update, refage=%ld, age=%ld\n",
refresh_age, age); refresh_age, age);
if (!test_and_set_bit(CACHE_PENDING, &h->flags)) { if (!test_and_set_bit(CACHE_PENDING, &h->flags)) {
switch (cache_make_upcall(detail, h)) { switch (cache_make_upcall(detail, h)) {
case -EINVAL: case -EINVAL:
clear_bit(CACHE_PENDING, &h->flags);
cache_revisit_request(h);
rv = try_to_negate_entry(detail, h); rv = try_to_negate_entry(detail, h);
break; break;
case -EAGAIN: case -EAGAIN:
clear_bit(CACHE_PENDING, &h->flags); cache_fresh_unlocked(h, detail);
cache_revisit_request(h);
break; break;
} }
} }
...@@ -293,7 +284,7 @@ int cache_check(struct cache_detail *detail, ...@@ -293,7 +284,7 @@ int cache_check(struct cache_detail *detail,
* Request was not deferred; handle it as best * Request was not deferred; handle it as best
* we can ourselves: * we can ourselves:
*/ */
rv = cache_is_valid(detail, h); rv = cache_is_valid(h);
if (rv == -EAGAIN) if (rv == -EAGAIN)
rv = -ETIMEDOUT; rv = -ETIMEDOUT;
} }
...@@ -310,7 +301,7 @@ EXPORT_SYMBOL_GPL(cache_check); ...@@ -310,7 +301,7 @@ EXPORT_SYMBOL_GPL(cache_check);
* a current pointer into that list and into the table * a current pointer into that list and into the table
* for that entry. * for that entry.
* *
* Each time clean_cache is called it finds the next non-empty entry * Each time cache_clean is called it finds the next non-empty entry
* in the current table and walks the list in that entry * in the current table and walks the list in that entry
* looking for entries that can be removed. * looking for entries that can be removed.
* *
...@@ -457,9 +448,8 @@ static int cache_clean(void) ...@@ -457,9 +448,8 @@ static int cache_clean(void)
current_index ++; current_index ++;
spin_unlock(&cache_list_lock); spin_unlock(&cache_list_lock);
if (ch) { if (ch) {
if (test_and_clear_bit(CACHE_PENDING, &ch->flags)) set_bit(CACHE_CLEANED, &ch->flags);
cache_dequeue(current_detail, ch); cache_fresh_unlocked(ch, d);
cache_revisit_request(ch);
cache_put(ch, d); cache_put(ch, d);
} }
} else } else
...@@ -1036,23 +1026,32 @@ static int cache_release(struct inode *inode, struct file *filp, ...@@ -1036,23 +1026,32 @@ static int cache_release(struct inode *inode, struct file *filp,
static void cache_dequeue(struct cache_detail *detail, struct cache_head *ch) static void cache_dequeue(struct cache_detail *detail, struct cache_head *ch)
{ {
struct cache_queue *cq; struct cache_queue *cq, *tmp;
struct cache_request *cr;
struct list_head dequeued;
INIT_LIST_HEAD(&dequeued);
spin_lock(&queue_lock); spin_lock(&queue_lock);
list_for_each_entry(cq, &detail->queue, list) list_for_each_entry_safe(cq, tmp, &detail->queue, list)
if (!cq->reader) { if (!cq->reader) {
struct cache_request *cr = container_of(cq, struct cache_request, q); cr = container_of(cq, struct cache_request, q);
if (cr->item != ch) if (cr->item != ch)
continue; continue;
if (test_bit(CACHE_PENDING, &ch->flags))
/* Lost a race and it is pending again */
break;
if (cr->readers != 0) if (cr->readers != 0)
continue; continue;
list_del(&cr->q.list); list_move(&cr->q.list, &dequeued);
spin_unlock(&queue_lock);
cache_put(cr->item, detail);
kfree(cr->buf);
kfree(cr);
return;
} }
spin_unlock(&queue_lock); spin_unlock(&queue_lock);
while (!list_empty(&dequeued)) {
cr = list_entry(dequeued.next, struct cache_request, q.list);
list_del(&cr->q.list);
cache_put(cr->item, detail);
kfree(cr->buf);
kfree(cr);
}
} }
/* /*
...@@ -1166,6 +1165,7 @@ int sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h) ...@@ -1166,6 +1165,7 @@ int sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h)
char *buf; char *buf;
struct cache_request *crq; struct cache_request *crq;
int ret = 0;
if (!detail->cache_request) if (!detail->cache_request)
return -EINVAL; return -EINVAL;
...@@ -1174,6 +1174,9 @@ int sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h) ...@@ -1174,6 +1174,9 @@ int sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h)
warn_no_listener(detail); warn_no_listener(detail);
return -EINVAL; return -EINVAL;
} }
if (test_bit(CACHE_CLEANED, &h->flags))
/* Too late to make an upcall */
return -EAGAIN;
buf = kmalloc(PAGE_SIZE, GFP_KERNEL); buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (!buf) if (!buf)
...@@ -1191,10 +1194,18 @@ int sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h) ...@@ -1191,10 +1194,18 @@ int sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h)
crq->len = 0; crq->len = 0;
crq->readers = 0; crq->readers = 0;
spin_lock(&queue_lock); spin_lock(&queue_lock);
list_add_tail(&crq->q.list, &detail->queue); if (test_bit(CACHE_PENDING, &h->flags))
list_add_tail(&crq->q.list, &detail->queue);
else
/* Lost a race, no longer PENDING, so don't enqueue */
ret = -EAGAIN;
spin_unlock(&queue_lock); spin_unlock(&queue_lock);
wake_up(&queue_wait); wake_up(&queue_wait);
return 0; if (ret == -EAGAIN) {
kfree(buf);
kfree(crq);
}
return ret;
} }
EXPORT_SYMBOL_GPL(sunrpc_cache_pipe_upcall); EXPORT_SYMBOL_GPL(sunrpc_cache_pipe_upcall);
......
...@@ -347,13 +347,13 @@ ip_map_cached_get(struct svc_xprt *xprt) ...@@ -347,13 +347,13 @@ ip_map_cached_get(struct svc_xprt *xprt)
spin_lock(&xprt->xpt_lock); spin_lock(&xprt->xpt_lock);
ipm = xprt->xpt_auth_cache; ipm = xprt->xpt_auth_cache;
if (ipm != NULL) { if (ipm != NULL) {
if (!cache_valid(&ipm->h)) { sn = net_generic(xprt->xpt_net, sunrpc_net_id);
if (cache_is_expired(sn->ip_map_cache, &ipm->h)) {
/* /*
* The entry has been invalidated since it was * The entry has been invalidated since it was
* remembered, e.g. by a second mount from the * remembered, e.g. by a second mount from the
* same IP address. * same IP address.
*/ */
sn = net_generic(xprt->xpt_net, sunrpc_net_id);
xprt->xpt_auth_cache = NULL; xprt->xpt_auth_cache = NULL;
spin_unlock(&xprt->xpt_lock); spin_unlock(&xprt->xpt_lock);
cache_put(&ipm->h, sn->ip_map_cache); cache_put(&ipm->h, sn->ip_map_cache);
...@@ -493,8 +493,6 @@ static int unix_gid_parse(struct cache_detail *cd, ...@@ -493,8 +493,6 @@ static int unix_gid_parse(struct cache_detail *cd,
if (rv) if (rv)
return -EINVAL; return -EINVAL;
uid = make_kuid(&init_user_ns, id); uid = make_kuid(&init_user_ns, id);
if (!uid_valid(uid))
return -EINVAL;
ug.uid = uid; ug.uid = uid;
expiry = get_expiry(&mesg); expiry = get_expiry(&mesg);
......
...@@ -917,7 +917,10 @@ static void svc_tcp_clear_pages(struct svc_sock *svsk) ...@@ -917,7 +917,10 @@ static void svc_tcp_clear_pages(struct svc_sock *svsk)
len = svsk->sk_datalen; len = svsk->sk_datalen;
npages = (len + PAGE_SIZE - 1) >> PAGE_SHIFT; npages = (len + PAGE_SIZE - 1) >> PAGE_SHIFT;
for (i = 0; i < npages; i++) { for (i = 0; i < npages; i++) {
BUG_ON(svsk->sk_pages[i] == NULL); if (svsk->sk_pages[i] == NULL) {
WARN_ON_ONCE(1);
continue;
}
put_page(svsk->sk_pages[i]); put_page(svsk->sk_pages[i]);
svsk->sk_pages[i] = NULL; svsk->sk_pages[i] = NULL;
} }
...@@ -1092,8 +1095,10 @@ static int svc_tcp_recvfrom(struct svc_rqst *rqstp) ...@@ -1092,8 +1095,10 @@ static int svc_tcp_recvfrom(struct svc_rqst *rqstp)
goto err_noclose; goto err_noclose;
} }
if (svc_sock_reclen(svsk) < 8) if (svsk->sk_datalen < 8) {
svsk->sk_datalen = 0;
goto err_delete; /* client is nuts. */ goto err_delete; /* client is nuts. */
}
rqstp->rq_arg.len = svsk->sk_datalen; rqstp->rq_arg.len = svsk->sk_datalen;
rqstp->rq_arg.page_base = 0; rqstp->rq_arg.page_base = 0;
......
...@@ -2534,7 +2534,6 @@ static struct rpc_xprt_ops bc_tcp_ops = { ...@@ -2534,7 +2534,6 @@ static struct rpc_xprt_ops bc_tcp_ops = {
.reserve_xprt = xprt_reserve_xprt, .reserve_xprt = xprt_reserve_xprt,
.release_xprt = xprt_release_xprt, .release_xprt = xprt_release_xprt,
.alloc_slot = xprt_alloc_slot, .alloc_slot = xprt_alloc_slot,
.rpcbind = xs_local_rpcbind,
.buf_alloc = bc_malloc, .buf_alloc = bc_malloc,
.buf_free = bc_free, .buf_free = bc_free,
.send_request = bc_send_request, .send_request = bc_send_request,
......
...@@ -858,7 +858,7 @@ static int cap_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen) ...@@ -858,7 +858,7 @@ static int cap_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
static int cap_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen) static int cap_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
{ {
return 0; return -EOPNOTSUPP;
} }
#ifdef CONFIG_KEYS #ifdef CONFIG_KEYS
static int cap_key_alloc(struct key *key, const struct cred *cred, static int cap_key_alloc(struct key *key, const struct cred *cred,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment