04 Jan, 2012

1 commit


27 Aug, 2011

2 commits


11 Apr, 2011

1 commit


21 Dec, 2009

1 commit


16 Dec, 2009

2 commits

  • The new .h files have paths at the top that are now out of date. While
    we're here, just remove all of those from fs/nfsd; they never served any
    purpose.

    Signed-off-by: J. Bruce Fields

    J. Bruce Fields
     
  • On V4ROOT exports, only accept filehandles that are the *root* of some
    export. This allows mountd to allow or deny access to individual
    directories and symlinks on the pseudofilesystem.

    Note that the checks in readdir and lookup are not enough, since a
    malicious host with access to the network could guess filehandles that
    they weren't able to obtain through lookup or readdir.

    Signed-off-by: Steve Dickson
    Signed-off-by: J. Bruce Fields

    Steve Dickson
     

15 Dec, 2009

3 commits


26 Nov, 2009

1 commit

  • All nfsd security depends on the security checks in fh_verify, and
    especially on nfsd_setuser().

    It therefore bothers me that the nfsd_setuser call may be made from
    three different places, depending on whether the filehandle has already
    been mapped to a dentry, and on whether subtreechecking is in force.

    Instead, make an unconditional call in fh_verify(), so it's trivial to
    verify that the call always occurs.

    That leaves us with a redundant nfsd_setuser() call in the subtreecheck
    case--it needs the correct user set earlier in order to check execute
    permissions on the path to this filehandle--but I'm willing to accept
    that minor inefficiency in the subtreecheck case in return for more
    straightforward permission checking.

    Signed-off-by: J. Bruce Fields

    J. Bruce Fields
     

14 Nov, 2009

1 commit


04 Sep, 2009

1 commit


03 Sep, 2009

2 commits


28 May, 2009

1 commit

  • The file nfsfh.c contains two static variables nfsd_nr_verified and
    nfsd_nr_put. These are counters which are incremented as a side
    effect of the fh_verify() fh_compose() and fh_put() operations,
    i.e. at least twice per NFS call for any non-trivial workload.
    Needless to say this makes the cacheline that contains them (and any
    other innocent victims) a very hot contention point indeed under high
    call-rate workloads on multiprocessor NFS server. It also turns out
    that these counters are not used anywhere. They're not reported to
    userspace, they're not used in logic, they're not even exported from
    the object file (let alone the module). All they do is waste CPU time.

    So this patch removes them.

    Tests on a 16 CPU Altix A4700 with 2 10gige Myricom cards, configured
    separately (no bonding). Workload is 640 client threads doing directory
    traverals with random small reads, from server RAM.

    Before
    ======

    Kernel profile:

    % cumulative self self total
    time samples samples calls 1/call 1/call name
    6.05 2716.00 2716.00 30406 0.09 1.02 svc_process
    4.44 4706.00 1990.00 1975 1.01 1.01 spin_unlock_irqrestore
    3.72 6376.00 1670.00 1666 1.00 1.00 svc_export_put
    3.41 7907.00 1531.00 1786 0.86 1.02 nfsd_ofcache_lookup
    3.25 9363.00 1456.00 10965 0.13 1.01 nfsd_dispatch
    3.10 10752.00 1389.00 1376 1.01 1.01 nfsd_cache_lookup
    2.57 11907.00 1155.00 4517 0.26 1.03 svc_tcp_recvfrom
    ...
    2.21 15352.00 1003.00 1081 0.93 1.00 nfsd_choose_ofc
    Reviewed-by: David Chinner
    Signed-off-by: J. Bruce Fields

    Greg Banks
     

08 Jan, 2009

1 commit


07 Jan, 2009

1 commit


14 Nov, 2008

2 commits

  • Inaugurate copy-on-write credentials management. This uses RCU to manage the
    credentials pointer in the task_struct with respect to accesses by other tasks.
    A process may only modify its own credentials, and so does not need locking to
    access or modify its own credentials.

    A mutex (cred_replace_mutex) is added to the task_struct to control the effect
    of PTRACE_ATTACHED on credential calculations, particularly with respect to
    execve().

    With this patch, the contents of an active credentials struct may not be
    changed directly; rather a new set of credentials must be prepared, modified
    and committed using something like the following sequence of events:

    struct cred *new = prepare_creds();
    int ret = blah(new);
    if (ret < 0) {
    abort_creds(new);
    return ret;
    }
    return commit_creds(new);

    There are some exceptions to this rule: the keyrings pointed to by the active
    credentials may be instantiated - keyrings violate the COW rule as managing
    COW keyrings is tricky, given that it is possible for a task to directly alter
    the keys in a keyring in use by another task.

    To help enforce this, various pointers to sets of credentials, such as those in
    the task_struct, are declared const. The purpose of this is compile-time
    discouragement of altering credentials through those pointers. Once a set of
    credentials has been made public through one of these pointers, it may not be
    modified, except under special circumstances:

    (1) Its reference count may incremented and decremented.

    (2) The keyrings to which it points may be modified, but not replaced.

    The only safe way to modify anything else is to create a replacement and commit
    using the functions described in Documentation/credentials.txt (which will be
    added by a later patch).

    This patch and the preceding patches have been tested with the LTP SELinux
    testsuite.

    This patch makes several logical sets of alteration:

    (1) execve().

    This now prepares and commits credentials in various places in the
    security code rather than altering the current creds directly.

    (2) Temporary credential overrides.

    do_coredump() and sys_faccessat() now prepare their own credentials and
    temporarily override the ones currently on the acting thread, whilst
    preventing interference from other threads by holding cred_replace_mutex
    on the thread being dumped.

    This will be replaced in a future patch by something that hands down the
    credentials directly to the functions being called, rather than altering
    the task's objective credentials.

    (3) LSM interface.

    A number of functions have been changed, added or removed:

    (*) security_capset_check(), ->capset_check()
    (*) security_capset_set(), ->capset_set()

    Removed in favour of security_capset().

    (*) security_capset(), ->capset()

    New. This is passed a pointer to the new creds, a pointer to the old
    creds and the proposed capability sets. It should fill in the new
    creds or return an error. All pointers, barring the pointer to the
    new creds, are now const.

    (*) security_bprm_apply_creds(), ->bprm_apply_creds()

    Changed; now returns a value, which will cause the process to be
    killed if it's an error.

    (*) security_task_alloc(), ->task_alloc_security()

    Removed in favour of security_prepare_creds().

    (*) security_cred_free(), ->cred_free()

    New. Free security data attached to cred->security.

    (*) security_prepare_creds(), ->cred_prepare()

    New. Duplicate any security data attached to cred->security.

    (*) security_commit_creds(), ->cred_commit()

    New. Apply any security effects for the upcoming installation of new
    security by commit_creds().

    (*) security_task_post_setuid(), ->task_post_setuid()

    Removed in favour of security_task_fix_setuid().

    (*) security_task_fix_setuid(), ->task_fix_setuid()

    Fix up the proposed new credentials for setuid(). This is used by
    cap_set_fix_setuid() to implicitly adjust capabilities in line with
    setuid() changes. Changes are made to the new credentials, rather
    than the task itself as in security_task_post_setuid().

    (*) security_task_reparent_to_init(), ->task_reparent_to_init()

    Removed. Instead the task being reparented to init is referred
    directly to init's credentials.

    NOTE! This results in the loss of some state: SELinux's osid no
    longer records the sid of the thread that forked it.

    (*) security_key_alloc(), ->key_alloc()
    (*) security_key_permission(), ->key_permission()

    Changed. These now take cred pointers rather than task pointers to
    refer to the security context.

    (4) sys_capset().

    This has been simplified and uses less locking. The LSM functions it
    calls have been merged.

    (5) reparent_to_kthreadd().

    This gives the current thread the same credentials as init by simply using
    commit_thread() to point that way.

    (6) __sigqueue_alloc() and switch_uid()

    __sigqueue_alloc() can't stop the target task from changing its creds
    beneath it, so this function gets a reference to the currently applicable
    user_struct which it then passes into the sigqueue struct it returns if
    successful.

    switch_uid() is now called from commit_creds(), and possibly should be
    folded into that. commit_creds() should take care of protecting
    __sigqueue_alloc().

    (7) [sg]et[ug]id() and co and [sg]et_current_groups.

    The set functions now all use prepare_creds(), commit_creds() and
    abort_creds() to build and check a new set of credentials before applying
    it.

    security_task_set[ug]id() is called inside the prepared section. This
    guarantees that nothing else will affect the creds until we've finished.

    The calling of set_dumpable() has been moved into commit_creds().

    Much of the functionality of set_user() has been moved into
    commit_creds().

    The get functions all simply access the data directly.

    (8) security_task_prctl() and cap_task_prctl().

    security_task_prctl() has been modified to return -ENOSYS if it doesn't
    want to handle a function, or otherwise return the return value directly
    rather than through an argument.

    Additionally, cap_task_prctl() now prepares a new set of credentials, even
    if it doesn't end up using it.

    (9) Keyrings.

    A number of changes have been made to the keyrings code:

    (a) switch_uid_keyring(), copy_keys(), exit_keys() and suid_keys() have
    all been dropped and built in to the credentials functions directly.
    They may want separating out again later.

    (b) key_alloc() and search_process_keyrings() now take a cred pointer
    rather than a task pointer to specify the security context.

    (c) copy_creds() gives a new thread within the same thread group a new
    thread keyring if its parent had one, otherwise it discards the thread
    keyring.

    (d) The authorisation key now points directly to the credentials to extend
    the search into rather pointing to the task that carries them.

    (e) Installing thread, process or session keyrings causes a new set of
    credentials to be created, even though it's not strictly necessary for
    process or session keyrings (they're shared).

    (10) Usermode helper.

    The usermode helper code now carries a cred struct pointer in its
    subprocess_info struct instead of a new session keyring pointer. This set
    of credentials is derived from init_cred and installed on the new process
    after it has been cloned.

    call_usermodehelper_setup() allocates the new credentials and
    call_usermodehelper_freeinfo() discards them if they haven't been used. A
    special cred function (prepare_usermodeinfo_creds()) is provided
    specifically for call_usermodehelper_setup() to call.

    call_usermodehelper_setkeys() adjusts the credentials to sport the
    supplied keyring as the new session keyring.

    (11) SELinux.

    SELinux has a number of changes, in addition to those to support the LSM
    interface changes mentioned above:

    (a) selinux_setprocattr() no longer does its check for whether the
    current ptracer can access processes with the new SID inside the lock
    that covers getting the ptracer's SID. Whilst this lock ensures that
    the check is done with the ptracer pinned, the result is only valid
    until the lock is released, so there's no point doing it inside the
    lock.

    (12) is_single_threaded().

    This function has been extracted from selinux_setprocattr() and put into
    a file of its own in the lib/ directory as join_session_keyring() now
    wants to use it too.

    The code in SELinux just checked to see whether a task shared mm_structs
    with other tasks (CLONE_VM), but that isn't good enough. We really want
    to know if they're part of the same thread group (CLONE_THREAD).

    (13) nfsd.

    The NFS server daemon now has to use the COW credentials to set the
    credentials it is going to use. It really needs to pass the credentials
    down to the functions it calls, but it can't do that until other patches
    in this series have been applied.

    Signed-off-by: David Howells
    Acked-by: James Morris
    Signed-off-by: James Morris

    David Howells
     
  • Separate the task security context from task_struct. At this point, the
    security data is temporarily embedded in the task_struct with two pointers
    pointing to it.

    Note that the Alpha arch is altered as it refers to (E)UID and (E)GID in
    entry.S via asm-offsets.

    With comment fixes Signed-off-by: Marc Dionne

    Signed-off-by: David Howells
    Acked-by: James Morris
    Acked-by: Serge Hallyn
    Signed-off-by: James Morris

    David Howells
     

30 Sep, 2008

1 commit

  • RFC 2623 section 2.3.2 permits the server to bypass gss authentication
    checks for certain operations that a client may perform when mounting.
    In the case of a client that doesn't have some form of credentials
    available to it on boot, this allows it to perform the mount unattended.
    (Presumably real file access won't be needed until a user with
    credentials logs in.)

    Being slightly more lenient allows lots of old clients to access
    krb5-only exports, with the only loss being a small amount of
    information leaked about the root directory of the export.

    This affects only v2 and v3; v4 still requires authentication for all
    access.

    Thanks to Peter Staubach testing against a Solaris client, which
    suggesting addition of v3 getattr, to the list, and to Trond for noting
    that doing so exposes no additional information.

    Signed-off-by: J. Bruce Fields
    Cc: Peter Staubach
    Cc: Trond Myklebust

    J. Bruce Fields
     

27 Jul, 2008

1 commit


01 Jul, 2008

1 commit

  • Thanks to Frank Van Maarseveen for the original problem report: "A
    privileged process on an NFS client which drops privileges after using
    them to change the current working directory, will experience incorrect
    EACCES after an NFS server reboot. This problem can also occur after
    memory pressure on the server, particularly when the client side is
    quiet for some time."

    This occurs because the filehandle points to a directory whose parents
    are no longer in the dentry cache, and we're attempting to reconnect the
    directory to its parents without adequate permissions to perform lookups
    in the parent directories.

    We can therefore fix the problem by acquiring the necessary capabilities
    before attempting the reconnection. We do this only in the
    no_subtree_check case, since the documented behavior of the
    subtree_check export option requires the server to check that the user
    has lookup permissions on all parents.

    The subtree_check case still has a problem, since reconnect_path()
    unnecessarily requires both read and lookup permissions on all parent
    directories. However, a fix in that case would be more delicate, and
    use of subtree_check is already discouraged for other reasons.

    Signed-off-by: Neil Brown
    Cc: Frank van Maarseveen
    Signed-off-by: J. Bruce Fields

    Neil Brown
     

24 Jun, 2008

1 commit

  • Rename nfsd_permission() specific MAY_* flags to NFSD_MAY_* to make it
    clear, that these are not used outside nfsd, and to avoid name and
    number space conflicts with the VFS.

    [comment from hch: rename MAY_READ, MAY_WRITE and MAY_EXEC as well]

    Signed-off-by: Miklos Szeredi
    Signed-off-by: J. Bruce Fields

    Miklos Szeredi
     

24 Apr, 2008

1 commit

  • Move the code that actually parses the filehandle and looks up the
    dentry and export to a separate function. This simplifies the reference
    counting a little and moves fh_verify() a little closer to the kernel
    ideal of small, minimally-indentended functions. Clean up a few other
    minor style sins along the way.

    Signed-off-by: J. Bruce Fields
    Cc: Neil Brown

    J. Bruce Fields
     

15 Mar, 2008

1 commit

  • This bug was always here, but before my commit 6fa02839bf9412e18e77
    ("recheck for secure ports in fh_verify"), it could only be triggered by
    failure of a kmalloc(). After that commit it could be triggered by a
    client making a request from a non-reserved port for access to an export
    marked "secure". (Exports are "secure" by default.)

    The result is a struct svc_export with a reference count one too low,
    resulting in likely oopses next time the export is accessed.

    The reference counting here is not straightforward; a later patch will
    clean up fh_verify().

    Thanks to Lukas Hejtmanek for the bug report and followup.

    Signed-off-by: J. Bruce Fields
    Cc: Lukas Hejtmanek
    Signed-off-by: Linus Torvalds

    J. Bruce Fields
     

22 Feb, 2008

1 commit

  • Sorry for the noise, but here's the v3 of this compilation fix :)

    There are some places, which declare the char buf[...] on the stack
    to push it later into dprintk(). Since the dprintk sometimes (if the
    CONFIG_SYSCTL=n) becomes an empty do { } while (0) stub, these buffers
    cause gcc to produce appropriate warnings.

    Wrap these buffers with RPC_IFDEBUG macro, as Trond proposed, to
    compile them out when not needed.

    Signed-off-by: Pavel Emelyanov
    Acked-by: J. Bruce Fields
    Signed-off-by: Trond Myklebust

    Pavel Emelyanov
     

15 Feb, 2008

1 commit

  • I'm embedding struct path into struct svc_export.

    [akpm@linux-foundation.org: coding-style fixes]
    [ezk@cs.sunysb.edu: NFSD: fix wrong mnt_writer count in rename]
    Signed-off-by: Jan Blunck
    Acked-by: J. Bruce Fields
    Acked-by: Christoph Hellwig
    Cc: Al Viro
    Cc: "J. Bruce Fields"
    Cc: Neil Brown
    Cc: Trond Myklebust
    Signed-off-by: Erez Zadok
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jan Blunck
     

02 Feb, 2008

1 commit


13 Nov, 2007

1 commit

  • As with commit 7fc90ec93a5eb71f4b08403baf5ba7176b3ec6b1 ("knfsd: nfsd:
    call nfsd_setuser() on fh_compose(), fix nfsd4 permissions problem")
    this is a case where we need to redo a security check in fh_verify()
    even though the filehandle already has an associated dentry--if the
    filehandle was created by fh_compose() in an earlier operation of the
    nfsv4 compound, then we may not have done these checks yet.

    Without this fix it is possible, for example, to traverse from an export
    without the secure ports requirement to one with it in a single
    compound, and bypass the secure port check on the new export.

    While we're here, fix up some minor style problems and change a printk()
    to a dprintk(), to make it harder for random unprivileged users to spam
    the logs.

    Signed-off-by: J. Bruce Fields
    Reviewed-By: NeilBrown
    Signed-off-by: Linus Torvalds

    J. Bruce Fields
     

22 Oct, 2007

1 commit

  • This patchset is a medium scale rewrite of the export operations interface.
    The goal is to make the interface less complex, and easier to understand from
    the filesystem side, aswell as preparing generic support for exporting of
    64bit inode numbers.

    This touches all nfs exporting filesystems, and I've done testing on all of
    the filesystems I have here locally (xfs, ext2, ext3, reiserfs, jfs)

    This patch:

    Add a structured fid type so that we don't have to pass an array of u32 values
    around everywhere. It's a union of possible layouts.

    As a start there's only the u32 array and the traditional 32bit inode format,
    but there will be more in one of my next patchset when I start to document the
    various filehandle formats we have in lowlevel filesystems better.

    Also add an enum that gives the various filehandle types human- readable
    names.

    Note: Some people might think the struct containing an anonymous union is
    ugly, but I didn't want to pass around a raw union type.

    Signed-off-by: Christoph Hellwig
    Cc: Neil Brown
    Cc: "J. Bruce Fields"
    Cc:
    Cc: Dave Kleikamp
    Cc: Anton Altaparmakov
    Cc: David Chinner
    Cc: Timothy Shimmin
    Cc: OGAWA Hirofumi
    Cc: Hugh Dickins
    Cc: Chris Mason
    Cc: Jeff Mahoney
    Cc: "Vladimir V. Saveliev"
    Cc: Steven Whitehouse
    Cc: Mark Fasheh
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Christoph Hellwig
     

11 Sep, 2007

1 commit

  • fsid_source decided where to get the 'fsid' number to
    return for a GETATTR based on the type of filehandle.
    It can be from the device, from the fsid, or from the
    UUID.

    It is possible for the filehandle to be inconsistent
    with the export information, so make sure the export information
    actually has the info implied by the value returned by
    fsid_source.

    Signed-off-by: Neil Brown
    Cc: "Luiz Fernando N. Capitulino"
    Signed-off-by: "J. Bruce Fields"
    Signed-off-by: Linus Torvalds

    Neil Brown
     

18 Jul, 2007

8 commits

  • Our clients (like other clients, as far as I know) use only auth_sys for nlm,
    even when using rpcsec_gss for the main nfs operations.

    Administrators that want to deny non-kerberos-authenticated locking requests
    will need to turn off NFS protocol versions less than 4....

    Signed-off-by: "J. Bruce Fields"
    Signed-off-by: Neil Brown
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    J. Bruce Fields
     
  • Allow readonly access to vary depending on the pseudoflavor, using the flag
    passed with each pseudoflavor in the export downcall. The rest of the flags
    are ignored for now, though some day we might also allow id squashing to vary
    based on the flavor.

    Signed-off-by: "J. Bruce Fields"
    Signed-off-by: Neil Brown
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    J. Bruce Fields
     
  • Make the first actual use of the secinfo information by using it to return
    nfserr_wrongsec when an export is found that doesn't allow the flavor used on
    this request.

    Signed-off-by: J. Bruce Fields
    Signed-off-by: Andy Adamson
    Signed-off-by: Neil Brown
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andy Adamson
     
  • We want it to be possible for users to restrict exports both by IP address and
    by pseudoflavor. The pseudoflavor information has previously been passed
    using special auth_domains stored in the rq_client field. After the preceding
    patch that stored the pseudoflavor in rq_pflavor, that's now superfluous; so
    now we use rq_client for the ip information, as auth_null and auth_unix do.

    However, we keep around the special auth_domain in the rq_gssclient field for
    backwards compatibility purposes, so we can still do upcalls using the old
    "gss/pseudoflavor" auth_domain if upcalls using the unix domain to give us an
    appropriate export. This allows us to continue supporting old mountd.

    In fact, for this first patch, we always use the "gss/pseudoflavor"
    auth_domain (and only it) if it is available; thus rq_client is ignored in the
    auth_gss case, and this patch on its own makes no change in behavior; that
    will be left to later patches.

    Note on idmap: I'm almost tempted to just replace the auth_domain in the idmap
    upcall by a dummy value--no version of idmapd has ever used it, and it's
    unlikely anyone really wants to perform idmapping differently depending on the
    where the client is (they may want to perform *credential* mapping
    differently, but that's a different matter--the idmapper just handles id's
    used in getattr and setattr). But I'm updating the idmapd code anyway, just
    out of general backwards-compatibility paranoia.

    Signed-off-by: "J. Bruce Fields"
    Signed-off-by: Neil Brown
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    J. Bruce Fields
     
  • Split the callers of exp_get_by_name(), exp_find(), and exp_parent() into
    those that are processing requests and those that are doing other stuff (like
    looking up filehandles for mountd).

    No change in behavior, just a (fairly pointless, on its own) cleanup.

    (Note this has the effect of making nfsd_cross_mnt() pass rqstp->rq_client
    instead of exp->ex_client into exp_find_by_name(). However, the two should
    have the same value at this point.)

    Signed-off-by: "J. Bruce Fields"
    Signed-off-by: Neil Brown
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    J. Bruce Fields
     
  • Currently exp_find(), exp_get_by_name(), and friends, return an export on
    success, and on failure return:

    errors -EAGAIN (drop this request pending an upcall) or
    -ETIMEDOUT (an upcall has timed out), or
    return NULL, which can mean either that there was a memory allocation
    failure, or that an export was not found, or that a passed-in
    export lacks an auth_domain.

    Many callers seem to assume that NULL means that an export was not found,
    which may lead to bugs in the case of a memory allocation failure.

    Modify these functions to distinguish between the two NULL cases by returning
    either -ENOENT or -ENOMEM. They now never return NULL. We get to simplify
    some code in the process.

    We return -ENOENT in the case of a missing auth_domain. This case should
    probably be removed (or converted to a bug) after confirming that it can never
    happen.

    Signed-off-by: "J. Bruce Fields"
    Signed-off-by: Neil Brown
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    J. Bruce Fields
     
  • Currently NFSD calls directly into filesystems through the export_operations
    structure. I plan to change this interface in various ways in later patches,
    and want to avoid the export of the default operations to NFSD, so this patch
    adds two simple exportfs_encode_fh/exportfs_decode_fh helpers for NFSD to call
    instead of poking into exportfs guts.

    Signed-off-by: Christoph Hellwig
    Signed-off-by: Neil Brown
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Christoph Hellwig
     
  • currently the export_operation structure and helpers related to it are in
    fs.h. fs.h is already far too large and there are very few places needing the
    export bits, so split them off into a separate header.

    [akpm@linux-foundation.org: fix cifs build]
    Signed-off-by: Christoph Hellwig
    Signed-off-by: Neil Brown
    Cc: Steven French
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Christoph Hellwig