2005-06-24 13:03:52 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2004 The Regents of the University of Michigan.
|
2012-03-21 21:52:07 +08:00
|
|
|
* Copyright (c) 2012 Jeff Layton <jlayton@redhat.com>
|
2005-06-24 13:03:52 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Andy Adamson <andros@citi.umich.edu>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the University nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
|
|
|
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-01-24 21:20:02 +08:00
|
|
|
#include <crypto/hash.h>
|
2005-06-24 13:04:25 +08:00
|
|
|
#include <linux/file.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2005-06-24 13:04:25 +08:00
|
|
|
#include <linux/namei.h>
|
Detach sched.h from mm.h
First thing mm.h does is including sched.h solely for can_do_mlock() inline
function which has "current" dereference inside. By dealing with can_do_mlock()
mm.h can be detached from sched.h which is good. See below, why.
This patch
a) removes unconditional inclusion of sched.h from mm.h
b) makes can_do_mlock() normal function in mm/mlock.c
c) exports can_do_mlock() to not break compilation
d) adds sched.h inclusions back to files that were getting it indirectly.
e) adds less bloated headers to some files (asm/signal.h, jiffies.h) that were
getting them indirectly
Net result is:
a) mm.h users would get less code to open, read, preprocess, parse, ... if
they don't need sched.h
b) sched.h stops being dependency for significant number of files:
on x86_64 allmodconfig touching sched.h results in recompile of 4083 files,
after patch it's only 3744 (-8.3%).
Cross-compile tested on
all arm defconfigs, all mips defconfigs, all powerpc defconfigs,
alpha alpha-up
arm
i386 i386-up i386-defconfig i386-allnoconfig
ia64 ia64-up
m68k
mips
parisc parisc-up
powerpc powerpc-up
s390 s390-up
sparc sparc-up
sparc64 sparc64-up
um-x86_64
x86_64 x86_64-up x86_64-defconfig x86_64-allnoconfig
as well as my two usual configs.
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-21 05:22:52 +08:00
|
|
|
#include <linux/sched.h>
|
2012-03-21 21:52:07 +08:00
|
|
|
#include <linux/fs.h>
|
2012-03-21 21:52:08 +08:00
|
|
|
#include <linux/module.h>
|
2012-03-21 21:52:07 +08:00
|
|
|
#include <net/net_namespace.h>
|
|
|
|
#include <linux/sunrpc/rpc_pipe_fs.h>
|
|
|
|
#include <linux/sunrpc/clnt.h>
|
|
|
|
#include <linux/nfsd/cld.h>
|
2009-12-04 02:30:56 +08:00
|
|
|
|
|
|
|
#include "nfsd.h"
|
|
|
|
#include "state.h"
|
2009-11-05 07:12:35 +08:00
|
|
|
#include "vfs.h"
|
2012-03-21 21:52:07 +08:00
|
|
|
#include "netns.h"
|
2005-06-24 13:03:52 +08:00
|
|
|
|
|
|
|
#define NFSDDBG_FACILITY NFSDDBG_PROC
|
|
|
|
|
2012-03-22 04:42:43 +08:00
|
|
|
/* Declarations */
|
|
|
|
struct nfsd4_client_tracking_ops {
|
|
|
|
int (*init)(struct net *);
|
|
|
|
void (*exit)(struct net *);
|
|
|
|
void (*create)(struct nfs4_client *);
|
|
|
|
void (*remove)(struct nfs4_client *);
|
|
|
|
int (*check)(struct nfs4_client *);
|
2014-09-13 04:40:20 +08:00
|
|
|
void (*grace_done)(struct nfsd_net *);
|
2019-09-10 04:10:30 +08:00
|
|
|
uint8_t version;
|
|
|
|
size_t msglen;
|
2012-03-22 04:42:43 +08:00
|
|
|
};
|
|
|
|
|
2019-09-10 04:10:30 +08:00
|
|
|
static const struct nfsd4_client_tracking_ops nfsd4_cld_tracking_ops;
|
2019-09-10 04:10:31 +08:00
|
|
|
static const struct nfsd4_client_tracking_ops nfsd4_cld_tracking_ops_v2;
|
2019-09-10 04:10:30 +08:00
|
|
|
|
2005-06-24 13:04:25 +08:00
|
|
|
/* Globals */
|
2011-08-27 08:40:28 +08:00
|
|
|
static char user_recovery_dirname[PATH_MAX] = "/var/lib/nfs/v4recovery";
|
2005-06-24 13:04:25 +08:00
|
|
|
|
CRED: Inaugurate COW credentials
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 <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:23 +08:00
|
|
|
static int
|
|
|
|
nfs4_save_creds(const struct cred **original_creds)
|
2005-06-24 13:04:25 +08:00
|
|
|
{
|
CRED: Inaugurate COW credentials
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 <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:23 +08:00
|
|
|
struct cred *new;
|
|
|
|
|
|
|
|
new = prepare_creds();
|
|
|
|
if (!new)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2013-02-02 22:53:11 +08:00
|
|
|
new->fsuid = GLOBAL_ROOT_UID;
|
|
|
|
new->fsgid = GLOBAL_ROOT_GID;
|
CRED: Inaugurate COW credentials
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 <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:23 +08:00
|
|
|
*original_creds = override_creds(new);
|
|
|
|
put_cred(new);
|
|
|
|
return 0;
|
2005-06-24 13:04:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
CRED: Inaugurate COW credentials
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 <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:23 +08:00
|
|
|
nfs4_reset_creds(const struct cred *original)
|
2005-06-24 13:04:25 +08:00
|
|
|
{
|
CRED: Inaugurate COW credentials
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 <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:23 +08:00
|
|
|
revert_creds(original);
|
2005-06-24 13:04:25 +08:00
|
|
|
}
|
|
|
|
|
2005-06-24 13:03:52 +08:00
|
|
|
static void
|
|
|
|
md5_to_hex(char *out, char *md5)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<16; i++) {
|
|
|
|
unsigned char c = md5[i];
|
|
|
|
|
|
|
|
*out++ = '0' + ((c&0xf0)>>4) + (c>=0xa0)*('a'-'9'-1);
|
|
|
|
*out++ = '0' + (c&0x0f) + ((c&0x0f)>=0x0a)*('a'-'9'-1);
|
|
|
|
}
|
|
|
|
*out = '\0';
|
|
|
|
}
|
|
|
|
|
2012-11-13 04:00:57 +08:00
|
|
|
static int
|
|
|
|
nfs4_make_rec_clidname(char *dname, const struct xdr_netobj *clname)
|
2005-06-24 13:03:52 +08:00
|
|
|
{
|
|
|
|
struct xdr_netobj cksum;
|
2016-01-24 21:20:02 +08:00
|
|
|
struct crypto_shash *tfm;
|
2012-11-13 04:00:57 +08:00
|
|
|
int status;
|
2005-06-24 13:03:52 +08:00
|
|
|
|
|
|
|
dprintk("NFSD: nfs4_make_rec_clidname for %.*s\n",
|
|
|
|
clname->len, clname->data);
|
2016-01-24 21:20:02 +08:00
|
|
|
tfm = crypto_alloc_shash("md5", 0, 0);
|
|
|
|
if (IS_ERR(tfm)) {
|
|
|
|
status = PTR_ERR(tfm);
|
2006-08-24 17:10:20 +08:00
|
|
|
goto out_no_tfm;
|
2012-11-13 04:00:57 +08:00
|
|
|
}
|
|
|
|
|
2016-01-24 21:20:02 +08:00
|
|
|
cksum.len = crypto_shash_digestsize(tfm);
|
2005-06-24 13:03:52 +08:00
|
|
|
cksum.data = kmalloc(cksum.len, GFP_KERNEL);
|
2012-11-13 04:00:57 +08:00
|
|
|
if (cksum.data == NULL) {
|
|
|
|
status = -ENOMEM;
|
2005-06-24 13:03:52 +08:00
|
|
|
goto out;
|
2012-11-13 04:00:57 +08:00
|
|
|
}
|
2005-06-24 13:03:52 +08:00
|
|
|
|
2020-05-02 13:31:17 +08:00
|
|
|
status = crypto_shash_tfm_digest(tfm, clname->data, clname->len,
|
|
|
|
cksum.data);
|
2012-11-13 04:00:57 +08:00
|
|
|
if (status)
|
2006-08-24 17:10:20 +08:00
|
|
|
goto out;
|
2005-06-24 13:03:52 +08:00
|
|
|
|
|
|
|
md5_to_hex(dname, cksum.data);
|
|
|
|
|
2012-11-13 04:00:57 +08:00
|
|
|
status = 0;
|
2005-06-24 13:03:52 +08:00
|
|
|
out:
|
2008-10-20 14:17:09 +08:00
|
|
|
kfree(cksum.data);
|
2016-01-24 21:20:02 +08:00
|
|
|
crypto_free_shash(tfm);
|
2006-08-24 17:10:20 +08:00
|
|
|
out_no_tfm:
|
2005-06-24 13:03:52 +08:00
|
|
|
return status;
|
|
|
|
}
|
2005-06-24 13:04:25 +08:00
|
|
|
|
2012-11-13 04:00:57 +08:00
|
|
|
/*
|
|
|
|
* If we had an error generating the recdir name for the legacy tracker
|
|
|
|
* then warn the admin. If the error doesn't appear to be transient,
|
|
|
|
* then disable recovery tracking.
|
|
|
|
*/
|
|
|
|
static void
|
2013-05-09 20:36:23 +08:00
|
|
|
legacy_recdir_name_error(struct nfs4_client *clp, int error)
|
2012-11-13 04:00:57 +08:00
|
|
|
{
|
|
|
|
printk(KERN_ERR "NFSD: unable to generate recoverydir "
|
|
|
|
"name (%d).\n", error);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if the algorithm just doesn't exist, then disable the recovery
|
|
|
|
* tracker altogether. The crypto libs will generally return this if
|
|
|
|
* FIPS is enabled as well.
|
|
|
|
*/
|
|
|
|
if (error == -ENOENT) {
|
|
|
|
printk(KERN_ERR "NFSD: disabling legacy clientid tracking. "
|
|
|
|
"Reboot recovery will not function correctly!\n");
|
2013-05-09 20:36:23 +08:00
|
|
|
nfsd4_client_tracking_exit(clp->net);
|
2012-11-13 04:00:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-27 06:06:26 +08:00
|
|
|
static void
|
|
|
|
__nfsd4_create_reclaim_record_grace(struct nfs4_client *clp,
|
|
|
|
const char *dname, int len, struct nfsd_net *nn)
|
|
|
|
{
|
|
|
|
struct xdr_netobj name;
|
2019-09-10 04:10:31 +08:00
|
|
|
struct xdr_netobj princhash = { .len = 0, .data = NULL };
|
2019-03-27 06:06:26 +08:00
|
|
|
struct nfs4_client_reclaim *crp;
|
|
|
|
|
|
|
|
name.data = kmemdup(dname, len, GFP_KERNEL);
|
|
|
|
if (!name.data) {
|
|
|
|
dprintk("%s: failed to allocate memory for name.data!\n",
|
|
|
|
__func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
name.len = len;
|
2019-09-10 04:10:31 +08:00
|
|
|
crp = nfs4_client_to_reclaim(name, princhash, nn);
|
2019-03-27 06:06:26 +08:00
|
|
|
if (!crp) {
|
|
|
|
kfree(name.data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
crp->cr_clp = clp;
|
|
|
|
}
|
|
|
|
|
2012-03-22 04:42:43 +08:00
|
|
|
static void
|
|
|
|
nfsd4_create_clid_dir(struct nfs4_client *clp)
|
2005-06-24 13:04:30 +08:00
|
|
|
{
|
CRED: Inaugurate COW credentials
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 <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:23 +08:00
|
|
|
const struct cred *original_cred;
|
2012-11-13 04:00:57 +08:00
|
|
|
char dname[HEXDIR_LEN];
|
2010-03-23 00:32:14 +08:00
|
|
|
struct dentry *dir, *dentry;
|
2005-06-24 13:04:30 +08:00
|
|
|
int status;
|
2012-11-14 23:21:16 +08:00
|
|
|
struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
|
2005-06-24 13:04:30 +08:00
|
|
|
|
2012-03-21 21:52:02 +08:00
|
|
|
if (test_and_set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
|
2012-01-06 04:38:41 +08:00
|
|
|
return;
|
2012-11-26 21:16:25 +08:00
|
|
|
if (!nn->rec_file)
|
2012-01-06 04:38:41 +08:00
|
|
|
return;
|
2012-11-13 04:00:57 +08:00
|
|
|
|
|
|
|
status = nfs4_make_rec_clidname(dname, &clp->cl_name);
|
|
|
|
if (status)
|
2013-05-09 20:36:23 +08:00
|
|
|
return legacy_recdir_name_error(clp, status);
|
2012-11-13 04:00:57 +08:00
|
|
|
|
CRED: Inaugurate COW credentials
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 <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:23 +08:00
|
|
|
status = nfs4_save_creds(&original_cred);
|
|
|
|
if (status < 0)
|
2012-01-06 04:38:41 +08:00
|
|
|
return;
|
2005-06-24 13:04:30 +08:00
|
|
|
|
2012-11-26 21:16:25 +08:00
|
|
|
status = mnt_want_write_file(nn->rec_file);
|
2012-06-12 22:20:33 +08:00
|
|
|
if (status)
|
2014-09-02 22:11:27 +08:00
|
|
|
goto out_creds;
|
2012-06-12 22:20:33 +08:00
|
|
|
|
2012-11-26 21:16:25 +08:00
|
|
|
dir = nn->rec_file->f_path.dentry;
|
2005-06-24 13:04:30 +08:00
|
|
|
/* lock the parent */
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_lock(d_inode(dir));
|
2005-06-24 13:04:30 +08:00
|
|
|
|
2010-03-23 00:32:14 +08:00
|
|
|
dentry = lookup_one_len(dname, dir, HEXDIR_LEN-1);
|
2005-06-24 13:04:30 +08:00
|
|
|
if (IS_ERR(dentry)) {
|
|
|
|
status = PTR_ERR(dentry);
|
|
|
|
goto out_unlock;
|
|
|
|
}
|
2015-03-18 06:25:59 +08:00
|
|
|
if (d_really_is_positive(dentry))
|
2012-01-03 06:30:05 +08:00
|
|
|
/*
|
|
|
|
* In the 4.1 case, where we're called from
|
|
|
|
* reclaim_complete(), records from the previous reboot
|
|
|
|
* may still be left, so this is OK.
|
|
|
|
*
|
|
|
|
* In the 4.0 case, we should never get here; but we may
|
|
|
|
* as well be forgiving and just succeed silently.
|
|
|
|
*/
|
2005-06-24 13:04:30 +08:00
|
|
|
goto out_put;
|
2015-03-18 06:25:59 +08:00
|
|
|
status = vfs_mkdir(d_inode(dir), dentry, S_IRWXU);
|
2005-06-24 13:04:30 +08:00
|
|
|
out_put:
|
|
|
|
dput(dentry);
|
|
|
|
out_unlock:
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_unlock(d_inode(dir));
|
2012-11-13 04:00:55 +08:00
|
|
|
if (status == 0) {
|
2019-03-27 06:06:26 +08:00
|
|
|
if (nn->in_grace)
|
|
|
|
__nfsd4_create_reclaim_record_grace(clp, dname,
|
|
|
|
HEXDIR_LEN, nn);
|
2012-11-26 21:16:25 +08:00
|
|
|
vfs_fsync(nn->rec_file, 0);
|
2012-11-13 04:00:55 +08:00
|
|
|
} else {
|
2011-08-13 08:30:12 +08:00
|
|
|
printk(KERN_ERR "NFSD: failed to write recovery record"
|
|
|
|
" (err %d); please check that %s exists"
|
|
|
|
" and is writeable", status,
|
|
|
|
user_recovery_dirname);
|
2012-11-13 04:00:55 +08:00
|
|
|
}
|
2012-11-26 21:16:25 +08:00
|
|
|
mnt_drop_write_file(nn->rec_file);
|
2014-09-02 22:11:27 +08:00
|
|
|
out_creds:
|
CRED: Inaugurate COW credentials
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 <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:23 +08:00
|
|
|
nfs4_reset_creds(original_cred);
|
2005-06-24 13:04:30 +08:00
|
|
|
}
|
|
|
|
|
2012-11-14 23:21:16 +08:00
|
|
|
typedef int (recdir_func)(struct dentry *, struct dentry *, struct nfsd_net *);
|
2005-06-24 13:04:25 +08:00
|
|
|
|
2009-03-14 04:02:59 +08:00
|
|
|
struct name_list {
|
|
|
|
char name[HEXDIR_LEN];
|
2005-06-24 13:04:25 +08:00
|
|
|
struct list_head list;
|
|
|
|
};
|
|
|
|
|
2013-05-16 06:49:12 +08:00
|
|
|
struct nfs4_dir_ctx {
|
|
|
|
struct dir_context ctx;
|
|
|
|
struct list_head names;
|
|
|
|
};
|
|
|
|
|
2005-06-24 13:04:25 +08:00
|
|
|
static int
|
2014-10-31 00:37:34 +08:00
|
|
|
nfsd4_build_namelist(struct dir_context *__ctx, const char *name, int namlen,
|
2006-10-03 16:13:46 +08:00
|
|
|
loff_t offset, u64 ino, unsigned int d_type)
|
2005-06-24 13:04:25 +08:00
|
|
|
{
|
2014-10-31 00:37:34 +08:00
|
|
|
struct nfs4_dir_ctx *ctx =
|
|
|
|
container_of(__ctx, struct nfs4_dir_ctx, ctx);
|
2009-03-14 04:02:59 +08:00
|
|
|
struct name_list *entry;
|
2005-06-24 13:04:25 +08:00
|
|
|
|
2009-03-14 04:02:59 +08:00
|
|
|
if (namlen != HEXDIR_LEN - 1)
|
2006-10-20 14:28:59 +08:00
|
|
|
return 0;
|
2009-03-14 04:02:59 +08:00
|
|
|
entry = kmalloc(sizeof(struct name_list), GFP_KERNEL);
|
|
|
|
if (entry == NULL)
|
2005-06-24 13:04:25 +08:00
|
|
|
return -ENOMEM;
|
2009-03-14 04:02:59 +08:00
|
|
|
memcpy(entry->name, name, HEXDIR_LEN - 1);
|
|
|
|
entry->name[HEXDIR_LEN - 1] = '\0';
|
2013-05-16 06:49:12 +08:00
|
|
|
list_add(&entry->list, &ctx->names);
|
2005-06-24 13:04:25 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-11-14 23:21:16 +08:00
|
|
|
nfsd4_list_rec_dir(recdir_func *f, struct nfsd_net *nn)
|
2005-06-24 13:04:25 +08:00
|
|
|
{
|
CRED: Inaugurate COW credentials
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 <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:23 +08:00
|
|
|
const struct cred *original_cred;
|
2012-11-26 21:16:25 +08:00
|
|
|
struct dentry *dir = nn->rec_file->f_path.dentry;
|
2013-05-23 10:22:04 +08:00
|
|
|
struct nfs4_dir_ctx ctx = {
|
|
|
|
.ctx.actor = nfsd4_build_namelist,
|
|
|
|
.names = LIST_HEAD_INIT(ctx.names)
|
|
|
|
};
|
2015-07-07 10:13:02 +08:00
|
|
|
struct name_list *entry, *tmp;
|
2005-06-24 13:04:25 +08:00
|
|
|
int status;
|
|
|
|
|
CRED: Inaugurate COW credentials
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 <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:23 +08:00
|
|
|
status = nfs4_save_creds(&original_cred);
|
|
|
|
if (status < 0)
|
|
|
|
return status;
|
2005-06-24 13:04:25 +08:00
|
|
|
|
2012-11-26 21:16:25 +08:00
|
|
|
status = vfs_llseek(nn->rec_file, 0, SEEK_SET);
|
2011-07-08 06:43:21 +08:00
|
|
|
if (status < 0) {
|
|
|
|
nfs4_reset_creds(original_cred);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2013-05-16 01:52:59 +08:00
|
|
|
status = iterate_dir(nn->rec_file, &ctx.ctx);
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_lock_nested(d_inode(dir), I_MUTEX_PARENT);
|
2015-07-07 10:13:02 +08:00
|
|
|
|
|
|
|
list_for_each_entry_safe(entry, tmp, &ctx.names, list) {
|
2011-07-08 06:43:21 +08:00
|
|
|
if (!status) {
|
|
|
|
struct dentry *dentry;
|
|
|
|
dentry = lookup_one_len(entry->name, dir, HEXDIR_LEN-1);
|
|
|
|
if (IS_ERR(dentry)) {
|
|
|
|
status = PTR_ERR(dentry);
|
|
|
|
break;
|
|
|
|
}
|
2012-11-14 23:21:16 +08:00
|
|
|
status = f(dir, dentry, nn);
|
2011-07-08 06:43:21 +08:00
|
|
|
dput(dentry);
|
2009-03-14 04:02:59 +08:00
|
|
|
}
|
|
|
|
list_del(&entry->list);
|
|
|
|
kfree(entry);
|
2005-06-24 13:04:25 +08:00
|
|
|
}
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_unlock(d_inode(dir));
|
CRED: Inaugurate COW credentials
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 <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:23 +08:00
|
|
|
nfs4_reset_creds(original_cred);
|
2015-07-07 10:13:02 +08:00
|
|
|
|
|
|
|
list_for_each_entry_safe(entry, tmp, &ctx.names, list) {
|
|
|
|
dprintk("NFSD: %s. Left entry %s\n", __func__, entry->name);
|
|
|
|
list_del(&entry->list);
|
|
|
|
kfree(entry);
|
|
|
|
}
|
2005-06-24 13:04:25 +08:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2005-06-24 13:04:30 +08:00
|
|
|
static int
|
2012-11-26 21:16:25 +08:00
|
|
|
nfsd4_unlink_clid_dir(char *name, int namlen, struct nfsd_net *nn)
|
2005-06-24 13:04:30 +08:00
|
|
|
{
|
2010-03-23 00:32:14 +08:00
|
|
|
struct dentry *dir, *dentry;
|
2005-06-24 13:04:30 +08:00
|
|
|
int status;
|
|
|
|
|
|
|
|
dprintk("NFSD: nfsd4_unlink_clid_dir. name %.*s\n", namlen, name);
|
|
|
|
|
2012-11-26 21:16:25 +08:00
|
|
|
dir = nn->rec_file->f_path.dentry;
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_lock_nested(d_inode(dir), I_MUTEX_PARENT);
|
2010-03-23 00:32:14 +08:00
|
|
|
dentry = lookup_one_len(name, dir, namlen);
|
2005-06-24 13:04:30 +08:00
|
|
|
if (IS_ERR(dentry)) {
|
|
|
|
status = PTR_ERR(dentry);
|
2009-04-21 06:18:37 +08:00
|
|
|
goto out_unlock;
|
2005-06-24 13:04:30 +08:00
|
|
|
}
|
|
|
|
status = -ENOENT;
|
2015-03-18 06:25:59 +08:00
|
|
|
if (d_really_is_negative(dentry))
|
2005-06-24 13:04:30 +08:00
|
|
|
goto out;
|
2015-03-18 06:25:59 +08:00
|
|
|
status = vfs_rmdir(d_inode(dir), dentry);
|
2005-06-24 13:04:30 +08:00
|
|
|
out:
|
|
|
|
dput(dentry);
|
2009-04-21 06:18:37 +08:00
|
|
|
out_unlock:
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_unlock(d_inode(dir));
|
2005-06-24 13:04:30 +08:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2019-03-27 06:06:26 +08:00
|
|
|
static void
|
|
|
|
__nfsd4_remove_reclaim_record_grace(const char *dname, int len,
|
|
|
|
struct nfsd_net *nn)
|
|
|
|
{
|
|
|
|
struct xdr_netobj name;
|
|
|
|
struct nfs4_client_reclaim *crp;
|
|
|
|
|
|
|
|
name.data = kmemdup(dname, len, GFP_KERNEL);
|
|
|
|
if (!name.data) {
|
|
|
|
dprintk("%s: failed to allocate memory for name.data!\n",
|
|
|
|
__func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
name.len = len;
|
|
|
|
crp = nfsd4_find_reclaim_client(name, nn);
|
|
|
|
kfree(name.data);
|
|
|
|
if (crp)
|
|
|
|
nfs4_remove_reclaim_record(crp, nn);
|
|
|
|
}
|
|
|
|
|
2012-03-22 04:42:43 +08:00
|
|
|
static void
|
2005-06-24 13:04:30 +08:00
|
|
|
nfsd4_remove_clid_dir(struct nfs4_client *clp)
|
|
|
|
{
|
CRED: Inaugurate COW credentials
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 <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:23 +08:00
|
|
|
const struct cred *original_cred;
|
2012-11-13 04:00:57 +08:00
|
|
|
char dname[HEXDIR_LEN];
|
2005-06-24 13:04:30 +08:00
|
|
|
int status;
|
2012-11-14 23:21:16 +08:00
|
|
|
struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
|
2005-06-24 13:04:30 +08:00
|
|
|
|
2012-11-26 21:16:25 +08:00
|
|
|
if (!nn->rec_file || !test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
|
2005-06-24 13:04:30 +08:00
|
|
|
return;
|
|
|
|
|
2012-11-13 04:00:57 +08:00
|
|
|
status = nfs4_make_rec_clidname(dname, &clp->cl_name);
|
|
|
|
if (status)
|
2013-05-09 20:36:23 +08:00
|
|
|
return legacy_recdir_name_error(clp, status);
|
2012-11-13 04:00:57 +08:00
|
|
|
|
2012-11-26 21:16:25 +08:00
|
|
|
status = mnt_want_write_file(nn->rec_file);
|
2008-02-16 06:37:34 +08:00
|
|
|
if (status)
|
|
|
|
goto out;
|
2012-03-21 21:52:02 +08:00
|
|
|
clear_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
|
CRED: Inaugurate COW credentials
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 <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:23 +08:00
|
|
|
|
|
|
|
status = nfs4_save_creds(&original_cred);
|
|
|
|
if (status < 0)
|
2012-11-10 04:31:53 +08:00
|
|
|
goto out_drop_write;
|
CRED: Inaugurate COW credentials
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 <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:23 +08:00
|
|
|
|
2012-11-26 21:16:25 +08:00
|
|
|
status = nfsd4_unlink_clid_dir(dname, HEXDIR_LEN-1, nn);
|
CRED: Inaugurate COW credentials
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 <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:23 +08:00
|
|
|
nfs4_reset_creds(original_cred);
|
2012-11-13 04:00:55 +08:00
|
|
|
if (status == 0) {
|
2012-11-26 21:16:25 +08:00
|
|
|
vfs_fsync(nn->rec_file, 0);
|
2019-03-27 06:06:26 +08:00
|
|
|
if (nn->in_grace)
|
|
|
|
__nfsd4_remove_reclaim_record_grace(dname,
|
|
|
|
HEXDIR_LEN, nn);
|
2012-11-13 04:00:55 +08:00
|
|
|
}
|
2012-11-10 04:31:53 +08:00
|
|
|
out_drop_write:
|
2012-11-26 21:16:25 +08:00
|
|
|
mnt_drop_write_file(nn->rec_file);
|
2008-02-16 06:37:34 +08:00
|
|
|
out:
|
2005-06-24 13:04:30 +08:00
|
|
|
if (status)
|
|
|
|
printk("NFSD: Failed to remove expired client state directory"
|
2012-11-13 04:00:57 +08:00
|
|
|
" %.*s\n", HEXDIR_LEN, dname);
|
2005-06-24 13:04:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-11-14 23:21:16 +08:00
|
|
|
purge_old(struct dentry *parent, struct dentry *child, struct nfsd_net *nn)
|
2005-06-24 13:04:30 +08:00
|
|
|
{
|
|
|
|
int status;
|
2019-03-27 06:06:26 +08:00
|
|
|
struct xdr_netobj name;
|
2005-06-24 13:04:30 +08:00
|
|
|
|
2019-03-27 06:06:26 +08:00
|
|
|
if (child->d_name.len != HEXDIR_LEN - 1) {
|
|
|
|
printk("%s: illegal name %pd in recovery directory\n",
|
|
|
|
__func__, child);
|
|
|
|
/* Keep trying; maybe the others are OK: */
|
2006-10-20 14:28:59 +08:00
|
|
|
return 0;
|
2019-03-27 06:06:26 +08:00
|
|
|
}
|
|
|
|
name.data = kmemdup_nul(child->d_name.name, child->d_name.len, GFP_KERNEL);
|
|
|
|
if (!name.data) {
|
|
|
|
dprintk("%s: failed to allocate memory for name.data!\n",
|
|
|
|
__func__);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
name.len = HEXDIR_LEN;
|
|
|
|
if (nfs4_has_reclaimed_state(name, nn))
|
|
|
|
goto out_free;
|
2005-06-24 13:04:30 +08:00
|
|
|
|
2015-03-18 06:25:59 +08:00
|
|
|
status = vfs_rmdir(d_inode(parent), child);
|
2005-06-24 13:04:30 +08:00
|
|
|
if (status)
|
2013-09-16 22:57:01 +08:00
|
|
|
printk("failed to remove client recovery directory %pd\n",
|
|
|
|
child);
|
2019-03-27 06:06:26 +08:00
|
|
|
out_free:
|
|
|
|
kfree(name.data);
|
|
|
|
out:
|
2005-06-24 13:04:30 +08:00
|
|
|
/* Keep trying, success or failure: */
|
2006-10-20 14:28:59 +08:00
|
|
|
return 0;
|
2005-06-24 13:04:30 +08:00
|
|
|
}
|
|
|
|
|
2012-03-22 04:42:43 +08:00
|
|
|
static void
|
2014-09-13 04:40:20 +08:00
|
|
|
nfsd4_recdir_purge_old(struct nfsd_net *nn)
|
2012-03-22 04:42:43 +08:00
|
|
|
{
|
2005-06-24 13:04:30 +08:00
|
|
|
int status;
|
|
|
|
|
2012-11-26 21:16:30 +08:00
|
|
|
nn->in_grace = false;
|
2012-11-26 21:16:25 +08:00
|
|
|
if (!nn->rec_file)
|
2005-06-24 13:04:30 +08:00
|
|
|
return;
|
2012-11-26 21:16:25 +08:00
|
|
|
status = mnt_want_write_file(nn->rec_file);
|
2008-02-16 06:37:34 +08:00
|
|
|
if (status)
|
|
|
|
goto out;
|
2012-11-14 23:21:16 +08:00
|
|
|
status = nfsd4_list_rec_dir(purge_old, nn);
|
2005-06-24 13:04:30 +08:00
|
|
|
if (status == 0)
|
2012-11-26 21:16:25 +08:00
|
|
|
vfs_fsync(nn->rec_file, 0);
|
|
|
|
mnt_drop_write_file(nn->rec_file);
|
2008-02-16 06:37:34 +08:00
|
|
|
out:
|
2012-11-14 23:21:16 +08:00
|
|
|
nfs4_release_reclaim(nn);
|
2005-06-24 13:04:30 +08:00
|
|
|
if (status)
|
|
|
|
printk("nfsd4: failed to purge old clients from recovery"
|
2013-09-16 22:57:01 +08:00
|
|
|
" directory %pD\n", nn->rec_file);
|
2005-06-24 13:04:30 +08:00
|
|
|
}
|
|
|
|
|
2005-06-24 13:04:25 +08:00
|
|
|
static int
|
2012-11-14 23:21:16 +08:00
|
|
|
load_recdir(struct dentry *parent, struct dentry *child, struct nfsd_net *nn)
|
2005-06-24 13:04:25 +08:00
|
|
|
{
|
2019-03-27 06:06:26 +08:00
|
|
|
struct xdr_netobj name;
|
2019-09-10 04:10:31 +08:00
|
|
|
struct xdr_netobj princhash = { .len = 0, .data = NULL };
|
2019-03-27 06:06:26 +08:00
|
|
|
|
2005-06-24 13:04:25 +08:00
|
|
|
if (child->d_name.len != HEXDIR_LEN - 1) {
|
2019-03-27 06:06:26 +08:00
|
|
|
printk("%s: illegal name %pd in recovery directory\n",
|
|
|
|
__func__, child);
|
2005-06-24 13:04:25 +08:00
|
|
|
/* Keep trying; maybe the others are OK: */
|
2006-10-20 14:28:59 +08:00
|
|
|
return 0;
|
2005-06-24 13:04:25 +08:00
|
|
|
}
|
2019-03-27 06:06:26 +08:00
|
|
|
name.data = kmemdup_nul(child->d_name.name, child->d_name.len, GFP_KERNEL);
|
|
|
|
if (!name.data) {
|
|
|
|
dprintk("%s: failed to allocate memory for name.data!\n",
|
|
|
|
__func__);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
name.len = HEXDIR_LEN;
|
2019-09-10 04:10:31 +08:00
|
|
|
if (!nfs4_client_to_reclaim(name, princhash, nn))
|
2019-03-27 06:06:26 +08:00
|
|
|
kfree(name.data);
|
|
|
|
out:
|
2006-10-20 14:28:59 +08:00
|
|
|
return 0;
|
2005-06-24 13:04:25 +08:00
|
|
|
}
|
|
|
|
|
2012-03-22 04:42:43 +08:00
|
|
|
static int
|
2012-11-14 23:21:16 +08:00
|
|
|
nfsd4_recdir_load(struct net *net) {
|
2005-06-24 13:04:25 +08:00
|
|
|
int status;
|
2012-11-14 23:21:16 +08:00
|
|
|
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
|
2005-06-24 13:04:25 +08:00
|
|
|
|
2012-11-26 21:16:25 +08:00
|
|
|
if (!nn->rec_file)
|
2010-03-23 00:32:14 +08:00
|
|
|
return 0;
|
|
|
|
|
2012-11-14 23:21:16 +08:00
|
|
|
status = nfsd4_list_rec_dir(load_recdir, nn);
|
2005-06-24 13:04:25 +08:00
|
|
|
if (status)
|
|
|
|
printk("nfsd4: failed loading clients from recovery"
|
2013-09-16 22:57:01 +08:00
|
|
|
" directory %pD\n", nn->rec_file);
|
2005-06-24 13:04:25 +08:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Hold reference to the recovery directory.
|
|
|
|
*/
|
|
|
|
|
2012-03-22 04:42:43 +08:00
|
|
|
static int
|
2012-11-26 21:16:25 +08:00
|
|
|
nfsd4_init_recdir(struct net *net)
|
2005-06-24 13:04:25 +08:00
|
|
|
{
|
2012-11-26 21:16:25 +08:00
|
|
|
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
|
CRED: Inaugurate COW credentials
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 <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:23 +08:00
|
|
|
const struct cred *original_cred;
|
|
|
|
int status;
|
2005-06-24 13:04:25 +08:00
|
|
|
|
|
|
|
printk("NFSD: Using %s as the NFSv4 state recovery directory\n",
|
2011-08-27 08:40:28 +08:00
|
|
|
user_recovery_dirname);
|
2005-06-24 13:04:25 +08:00
|
|
|
|
2012-11-26 21:16:25 +08:00
|
|
|
BUG_ON(nn->rec_file);
|
2005-06-24 13:04:25 +08:00
|
|
|
|
CRED: Inaugurate COW credentials
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 <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:23 +08:00
|
|
|
status = nfs4_save_creds(&original_cred);
|
|
|
|
if (status < 0) {
|
|
|
|
printk("NFSD: Unable to change credentials to find recovery"
|
|
|
|
" directory: error %d\n",
|
|
|
|
status);
|
2012-03-22 04:42:43 +08:00
|
|
|
return status;
|
CRED: Inaugurate COW credentials
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 <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:23 +08:00
|
|
|
}
|
2005-06-24 13:04:25 +08:00
|
|
|
|
2012-11-26 21:16:25 +08:00
|
|
|
nn->rec_file = filp_open(user_recovery_dirname, O_RDONLY | O_DIRECTORY, 0);
|
|
|
|
if (IS_ERR(nn->rec_file)) {
|
2006-01-19 09:43:29 +08:00
|
|
|
printk("NFSD: unable to find recovery directory %s\n",
|
2011-08-27 08:40:28 +08:00
|
|
|
user_recovery_dirname);
|
2012-11-26 21:16:25 +08:00
|
|
|
status = PTR_ERR(nn->rec_file);
|
|
|
|
nn->rec_file = NULL;
|
2010-03-23 00:32:14 +08:00
|
|
|
}
|
2005-06-24 13:04:25 +08:00
|
|
|
|
CRED: Inaugurate COW credentials
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 <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: James Morris <jmorris@namei.org>
2008-11-14 07:39:23 +08:00
|
|
|
nfs4_reset_creds(original_cred);
|
2012-11-13 04:00:55 +08:00
|
|
|
if (!status)
|
2012-11-26 21:16:30 +08:00
|
|
|
nn->in_grace = true;
|
2012-03-22 04:42:43 +08:00
|
|
|
return status;
|
2005-06-24 13:04:25 +08:00
|
|
|
}
|
|
|
|
|
2014-09-02 22:12:17 +08:00
|
|
|
static void
|
|
|
|
nfsd4_shutdown_recdir(struct net *net)
|
|
|
|
{
|
|
|
|
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
|
|
|
|
|
|
|
|
if (!nn->rec_file)
|
|
|
|
return;
|
|
|
|
fput(nn->rec_file);
|
|
|
|
nn->rec_file = NULL;
|
|
|
|
}
|
2012-11-14 23:21:16 +08:00
|
|
|
|
|
|
|
static int
|
|
|
|
nfs4_legacy_state_init(struct net *net)
|
|
|
|
{
|
|
|
|
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
|
|
|
|
int i;
|
|
|
|
|
treewide: kmalloc() -> kmalloc_array()
The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
patch replaces cases of:
kmalloc(a * b, gfp)
with:
kmalloc_array(a * b, gfp)
as well as handling cases of:
kmalloc(a * b * c, gfp)
with:
kmalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kmalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kmalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The tools/ directory was manually excluded, since it has its own
implementation of kmalloc().
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kmalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kmalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kmalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kmalloc
+ kmalloc_array
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kmalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kmalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kmalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kmalloc(sizeof(THING) * C2, ...)
|
kmalloc(sizeof(TYPE) * C2, ...)
|
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(C1 * C2, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * E2
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 04:55:00 +08:00
|
|
|
nn->reclaim_str_hashtbl = kmalloc_array(CLIENT_HASH_SIZE,
|
|
|
|
sizeof(struct list_head),
|
|
|
|
GFP_KERNEL);
|
2012-11-14 23:21:16 +08:00
|
|
|
if (!nn->reclaim_str_hashtbl)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
for (i = 0; i < CLIENT_HASH_SIZE; i++)
|
|
|
|
INIT_LIST_HEAD(&nn->reclaim_str_hashtbl[i]);
|
|
|
|
nn->reclaim_str_hashtbl_size = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nfs4_legacy_state_shutdown(struct net *net)
|
|
|
|
{
|
|
|
|
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
|
|
|
|
|
|
|
|
kfree(nn->reclaim_str_hashtbl);
|
|
|
|
}
|
|
|
|
|
2012-03-22 04:42:43 +08:00
|
|
|
static int
|
|
|
|
nfsd4_load_reboot_recovery_data(struct net *net)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
2012-11-26 21:16:25 +08:00
|
|
|
status = nfsd4_init_recdir(net);
|
2012-11-14 23:21:16 +08:00
|
|
|
if (status)
|
2014-09-02 22:12:17 +08:00
|
|
|
return status;
|
|
|
|
|
|
|
|
status = nfsd4_recdir_load(net);
|
|
|
|
if (status)
|
|
|
|
nfsd4_shutdown_recdir(net);
|
|
|
|
|
2012-11-14 23:21:16 +08:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nfsd4_legacy_tracking_init(struct net *net)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
2012-03-21 21:52:09 +08:00
|
|
|
/* XXX: The legacy code won't work in a container */
|
|
|
|
if (net != &init_net) {
|
nfsd: don't WARN/backtrace for invalid container deployment.
These messages, combined with the backtrace they trigger, makes it seem
like a serious problem, though a quick search shows distros marking
it as a "won't fix" non-issue when the problem is reported by users.
The backtrace is overkill, and only really manages to show that if
you follow the code path, you can't really avoid it with bootargs
or configuration settings in the container.
Given that, lets tone it down a bit and get rid of the WARN severity,
and the associated backtrace, so people aren't needlessly alarmed.
Also, lets drop the split printk line, since they are grep unfriendly.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
2015-08-26 04:59:16 +08:00
|
|
|
pr_warn("NFSD: attempt to initialize legacy client tracking in a container ignored.\n");
|
2012-03-21 21:52:09 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2012-11-14 23:21:16 +08:00
|
|
|
status = nfs4_legacy_state_init(net);
|
2012-03-22 04:42:43 +08:00
|
|
|
if (status)
|
2012-11-14 23:21:16 +08:00
|
|
|
return status;
|
|
|
|
|
|
|
|
status = nfsd4_load_reboot_recovery_data(net);
|
|
|
|
if (status)
|
|
|
|
goto err;
|
2019-03-27 06:06:29 +08:00
|
|
|
printk("NFSD: Using legacy client tracking operations.\n");
|
2012-11-14 23:21:16 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
nfs4_legacy_state_shutdown(net);
|
2012-03-22 04:42:43 +08:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nfsd4_legacy_tracking_exit(struct net *net)
|
|
|
|
{
|
2012-11-14 23:21:16 +08:00
|
|
|
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
|
|
|
|
|
|
|
|
nfs4_release_reclaim(nn);
|
2014-09-02 22:12:17 +08:00
|
|
|
nfsd4_shutdown_recdir(net);
|
2012-11-14 23:21:16 +08:00
|
|
|
nfs4_legacy_state_shutdown(net);
|
2012-03-22 04:42:43 +08:00
|
|
|
}
|
|
|
|
|
2011-08-27 08:40:28 +08:00
|
|
|
/*
|
|
|
|
* Change the NFSv4 recovery directory to recdir.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
nfs4_reset_recoverydir(char *recdir)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
struct path path;
|
|
|
|
|
|
|
|
status = kern_path(recdir, LOOKUP_FOLLOW, &path);
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
status = -ENOTDIR;
|
VFS: (Scripted) Convert S_ISLNK/DIR/REG(dentry->d_inode) to d_is_*(dentry)
Convert the following where appropriate:
(1) S_ISLNK(dentry->d_inode) to d_is_symlink(dentry).
(2) S_ISREG(dentry->d_inode) to d_is_reg(dentry).
(3) S_ISDIR(dentry->d_inode) to d_is_dir(dentry). This is actually more
complicated than it appears as some calls should be converted to
d_can_lookup() instead. The difference is whether the directory in
question is a real dir with a ->lookup op or whether it's a fake dir with
a ->d_automount op.
In some circumstances, we can subsume checks for dentry->d_inode not being
NULL into this, provided we the code isn't in a filesystem that expects
d_inode to be NULL if the dirent really *is* negative (ie. if we're going to
use d_inode() rather than d_backing_inode() to get the inode pointer).
Note that the dentry type field may be set to something other than
DCACHE_MISS_TYPE when d_inode is NULL in the case of unionmount, where the VFS
manages the fall-through from a negative dentry to a lower layer. In such a
case, the dentry type of the negative union dentry is set to the same as the
type of the lower dentry.
However, if you know d_inode is not NULL at the call site, then you can use
the d_is_xxx() functions even in a filesystem.
There is one further complication: a 0,0 chardev dentry may be labelled
DCACHE_WHITEOUT_TYPE rather than DCACHE_SPECIAL_TYPE. Strictly, this was
intended for special directory entry types that don't have attached inodes.
The following perl+coccinelle script was used:
use strict;
my @callers;
open($fd, 'git grep -l \'S_IS[A-Z].*->d_inode\' |') ||
die "Can't grep for S_ISDIR and co. callers";
@callers = <$fd>;
close($fd);
unless (@callers) {
print "No matches\n";
exit(0);
}
my @cocci = (
'@@',
'expression E;',
'@@',
'',
'- S_ISLNK(E->d_inode->i_mode)',
'+ d_is_symlink(E)',
'',
'@@',
'expression E;',
'@@',
'',
'- S_ISDIR(E->d_inode->i_mode)',
'+ d_is_dir(E)',
'',
'@@',
'expression E;',
'@@',
'',
'- S_ISREG(E->d_inode->i_mode)',
'+ d_is_reg(E)' );
my $coccifile = "tmp.sp.cocci";
open($fd, ">$coccifile") || die $coccifile;
print($fd "$_\n") || die $coccifile foreach (@cocci);
close($fd);
foreach my $file (@callers) {
chomp $file;
print "Processing ", $file, "\n";
system("spatch", "--sp-file", $coccifile, $file, "--in-place", "--no-show-diff") == 0 ||
die "spatch failed";
}
[AV: overlayfs parts skipped]
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2015-01-29 20:02:35 +08:00
|
|
|
if (d_is_dir(path.dentry)) {
|
2011-08-27 08:40:28 +08:00
|
|
|
strcpy(user_recovery_dirname, recdir);
|
|
|
|
status = 0;
|
|
|
|
}
|
|
|
|
path_put(&path);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
nfs4_recoverydir(void)
|
|
|
|
{
|
|
|
|
return user_recovery_dirname;
|
|
|
|
}
|
2012-03-22 04:42:43 +08:00
|
|
|
|
|
|
|
static int
|
|
|
|
nfsd4_check_legacy_client(struct nfs4_client *clp)
|
|
|
|
{
|
2012-11-13 04:00:57 +08:00
|
|
|
int status;
|
|
|
|
char dname[HEXDIR_LEN];
|
2012-11-13 04:00:55 +08:00
|
|
|
struct nfs4_client_reclaim *crp;
|
2012-11-14 23:21:16 +08:00
|
|
|
struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
|
2019-03-27 06:06:26 +08:00
|
|
|
struct xdr_netobj name;
|
2012-11-13 04:00:55 +08:00
|
|
|
|
2012-03-22 04:42:43 +08:00
|
|
|
/* did we already find that this client is stable? */
|
|
|
|
if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
|
|
|
|
return 0;
|
|
|
|
|
2012-11-13 04:00:57 +08:00
|
|
|
status = nfs4_make_rec_clidname(dname, &clp->cl_name);
|
|
|
|
if (status) {
|
2013-05-09 20:36:23 +08:00
|
|
|
legacy_recdir_name_error(clp, status);
|
2012-11-13 04:00:57 +08:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2012-03-22 04:42:43 +08:00
|
|
|
/* look for it in the reclaim hashtable otherwise */
|
2019-03-27 06:06:26 +08:00
|
|
|
name.data = kmemdup(dname, HEXDIR_LEN, GFP_KERNEL);
|
|
|
|
if (!name.data) {
|
|
|
|
dprintk("%s: failed to allocate memory for name.data!\n",
|
|
|
|
__func__);
|
|
|
|
goto out_enoent;
|
|
|
|
}
|
|
|
|
name.len = HEXDIR_LEN;
|
|
|
|
crp = nfsd4_find_reclaim_client(name, nn);
|
|
|
|
kfree(name.data);
|
2012-11-13 04:00:55 +08:00
|
|
|
if (crp) {
|
2012-03-22 04:42:43 +08:00
|
|
|
set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
|
2012-11-13 04:00:55 +08:00
|
|
|
crp->cr_clp = clp;
|
2012-03-22 04:42:43 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-27 06:06:26 +08:00
|
|
|
out_enoent:
|
2012-03-22 04:42:43 +08:00
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2015-11-22 15:22:10 +08:00
|
|
|
static const struct nfsd4_client_tracking_ops nfsd4_legacy_tracking_ops = {
|
2012-11-14 23:21:16 +08:00
|
|
|
.init = nfsd4_legacy_tracking_init,
|
2012-03-22 04:42:43 +08:00
|
|
|
.exit = nfsd4_legacy_tracking_exit,
|
|
|
|
.create = nfsd4_create_clid_dir,
|
|
|
|
.remove = nfsd4_remove_clid_dir,
|
|
|
|
.check = nfsd4_check_legacy_client,
|
|
|
|
.grace_done = nfsd4_recdir_purge_old,
|
2019-09-10 04:10:30 +08:00
|
|
|
.version = 1,
|
|
|
|
.msglen = 0,
|
2012-03-22 04:42:43 +08:00
|
|
|
};
|
|
|
|
|
2012-03-21 21:52:07 +08:00
|
|
|
/* Globals */
|
|
|
|
#define NFSD_PIPE_DIR "nfsd"
|
|
|
|
#define NFSD_CLD_PIPE "cld"
|
|
|
|
|
|
|
|
/* per-net-ns structure for holding cld upcall info */
|
|
|
|
struct cld_net {
|
|
|
|
struct rpc_pipe *cn_pipe;
|
|
|
|
spinlock_t cn_lock;
|
|
|
|
struct list_head cn_list;
|
|
|
|
unsigned int cn_xid;
|
2019-03-27 06:06:30 +08:00
|
|
|
bool cn_has_legacy;
|
2019-09-10 04:10:31 +08:00
|
|
|
struct crypto_shash *cn_tfm;
|
2012-03-21 21:52:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct cld_upcall {
|
|
|
|
struct list_head cu_list;
|
|
|
|
struct cld_net *cu_net;
|
2018-11-07 02:35:08 +08:00
|
|
|
struct completion cu_done;
|
2019-09-10 04:10:30 +08:00
|
|
|
union {
|
|
|
|
struct cld_msg_hdr cu_hdr;
|
|
|
|
struct cld_msg cu_msg;
|
2019-09-10 04:10:31 +08:00
|
|
|
struct cld_msg_v2 cu_msg_v2;
|
2019-09-10 04:10:30 +08:00
|
|
|
} cu_u;
|
2012-03-21 21:52:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2020-07-11 04:33:07 +08:00
|
|
|
__cld_pipe_upcall(struct rpc_pipe *pipe, void *cmsg, struct nfsd_net *nn)
|
2012-03-21 21:52:07 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct rpc_pipe_msg msg;
|
2019-09-10 04:10:30 +08:00
|
|
|
struct cld_upcall *cup = container_of(cmsg, struct cld_upcall, cu_u);
|
2012-03-21 21:52:07 +08:00
|
|
|
|
|
|
|
memset(&msg, 0, sizeof(msg));
|
|
|
|
msg.data = cmsg;
|
2019-09-10 04:10:30 +08:00
|
|
|
msg.len = nn->client_tracking_ops->msglen;
|
2012-03-21 21:52:07 +08:00
|
|
|
|
|
|
|
ret = rpc_queue_upcall(pipe, &msg);
|
|
|
|
if (ret < 0) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2018-11-07 02:35:08 +08:00
|
|
|
wait_for_completion(&cup->cu_done);
|
2012-03-21 21:52:07 +08:00
|
|
|
|
|
|
|
if (msg.errno < 0)
|
|
|
|
ret = msg.errno;
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2020-07-11 04:33:07 +08:00
|
|
|
cld_pipe_upcall(struct rpc_pipe *pipe, void *cmsg, struct nfsd_net *nn)
|
2012-03-21 21:52:07 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* -EAGAIN occurs when pipe is closed and reopened while there are
|
|
|
|
* upcalls queued.
|
|
|
|
*/
|
|
|
|
do {
|
2020-07-11 04:33:07 +08:00
|
|
|
ret = __cld_pipe_upcall(pipe, cmsg, nn);
|
2012-03-21 21:52:07 +08:00
|
|
|
} while (ret == -EAGAIN);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-03-27 06:06:27 +08:00
|
|
|
static ssize_t
|
2019-09-10 04:10:31 +08:00
|
|
|
__cld_pipe_inprogress_downcall(const struct cld_msg_v2 __user *cmsg,
|
2019-03-27 06:06:27 +08:00
|
|
|
struct nfsd_net *nn)
|
|
|
|
{
|
2019-09-10 04:10:31 +08:00
|
|
|
uint8_t cmd, princhashlen;
|
|
|
|
struct xdr_netobj name, princhash = { .len = 0, .data = NULL };
|
2019-03-27 06:06:27 +08:00
|
|
|
uint16_t namelen;
|
2019-03-27 06:06:30 +08:00
|
|
|
struct cld_net *cn = nn->cld_net;
|
2019-03-27 06:06:27 +08:00
|
|
|
|
|
|
|
if (get_user(cmd, &cmsg->cm_cmd)) {
|
|
|
|
dprintk("%s: error when copying cmd from userspace", __func__);
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
if (cmd == Cld_GraceStart) {
|
2019-09-10 04:10:31 +08:00
|
|
|
if (nn->client_tracking_ops->version >= 2) {
|
|
|
|
const struct cld_clntinfo __user *ci;
|
|
|
|
|
|
|
|
ci = &cmsg->cm_u.cm_clntinfo;
|
|
|
|
if (get_user(namelen, &ci->cc_name.cn_len))
|
|
|
|
return -EFAULT;
|
|
|
|
name.data = memdup_user(&ci->cc_name.cn_id, namelen);
|
|
|
|
if (IS_ERR_OR_NULL(name.data))
|
|
|
|
return -EFAULT;
|
|
|
|
name.len = namelen;
|
|
|
|
get_user(princhashlen, &ci->cc_princhash.cp_len);
|
|
|
|
if (princhashlen > 0) {
|
|
|
|
princhash.data = memdup_user(
|
|
|
|
&ci->cc_princhash.cp_data,
|
|
|
|
princhashlen);
|
|
|
|
if (IS_ERR_OR_NULL(princhash.data))
|
|
|
|
return -EFAULT;
|
|
|
|
princhash.len = princhashlen;
|
|
|
|
} else
|
|
|
|
princhash.len = 0;
|
|
|
|
} else {
|
|
|
|
const struct cld_name __user *cnm;
|
|
|
|
|
|
|
|
cnm = &cmsg->cm_u.cm_name;
|
|
|
|
if (get_user(namelen, &cnm->cn_len))
|
|
|
|
return -EFAULT;
|
|
|
|
name.data = memdup_user(&cnm->cn_id, namelen);
|
|
|
|
if (IS_ERR_OR_NULL(name.data))
|
|
|
|
return -EFAULT;
|
|
|
|
name.len = namelen;
|
|
|
|
}
|
2019-03-27 06:06:30 +08:00
|
|
|
if (name.len > 5 && memcmp(name.data, "hash:", 5) == 0) {
|
|
|
|
name.len = name.len - 5;
|
|
|
|
memmove(name.data, name.data + 5, name.len);
|
|
|
|
cn->cn_has_legacy = true;
|
|
|
|
}
|
2019-09-10 04:10:31 +08:00
|
|
|
if (!nfs4_client_to_reclaim(name, princhash, nn)) {
|
2019-03-27 06:06:27 +08:00
|
|
|
kfree(name.data);
|
2019-09-10 04:10:31 +08:00
|
|
|
kfree(princhash.data);
|
2019-03-27 06:06:27 +08:00
|
|
|
return -EFAULT;
|
|
|
|
}
|
2019-09-10 04:10:30 +08:00
|
|
|
return nn->client_tracking_ops->msglen;
|
2019-03-27 06:06:27 +08:00
|
|
|
}
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
2012-03-21 21:52:07 +08:00
|
|
|
static ssize_t
|
|
|
|
cld_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)
|
|
|
|
{
|
|
|
|
struct cld_upcall *tmp, *cup;
|
2019-09-10 04:10:30 +08:00
|
|
|
struct cld_msg_hdr __user *hdr = (struct cld_msg_hdr __user *)src;
|
2019-09-10 04:10:31 +08:00
|
|
|
struct cld_msg_v2 __user *cmsg = (struct cld_msg_v2 __user *)src;
|
2012-03-21 21:52:07 +08:00
|
|
|
uint32_t xid;
|
2014-10-31 12:41:12 +08:00
|
|
|
struct nfsd_net *nn = net_generic(file_inode(filp)->i_sb->s_fs_info,
|
2012-03-21 21:52:07 +08:00
|
|
|
nfsd_net_id);
|
|
|
|
struct cld_net *cn = nn->cld_net;
|
2019-03-27 06:06:27 +08:00
|
|
|
int16_t status;
|
2012-03-21 21:52:07 +08:00
|
|
|
|
2019-09-10 04:10:30 +08:00
|
|
|
if (mlen != nn->client_tracking_ops->msglen) {
|
2012-05-01 03:25:31 +08:00
|
|
|
dprintk("%s: got %zu bytes, expected %zu\n", __func__, mlen,
|
2019-09-10 04:10:30 +08:00
|
|
|
nn->client_tracking_ops->msglen);
|
2012-03-21 21:52:07 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy just the xid so we can try to find that */
|
2019-09-10 04:10:30 +08:00
|
|
|
if (copy_from_user(&xid, &hdr->cm_xid, sizeof(xid)) != 0) {
|
2012-03-21 21:52:07 +08:00
|
|
|
dprintk("%s: error when copying xid from userspace", __func__);
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
2019-03-27 06:06:27 +08:00
|
|
|
/*
|
|
|
|
* copy the status so we know whether to remove the upcall from the
|
|
|
|
* list (for -EINPROGRESS, we just want to make sure the xid is
|
|
|
|
* valid, not remove the upcall from the list)
|
|
|
|
*/
|
2019-09-10 04:10:30 +08:00
|
|
|
if (get_user(status, &hdr->cm_status)) {
|
2019-03-27 06:06:27 +08:00
|
|
|
dprintk("%s: error when copying status from userspace", __func__);
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
2012-03-21 21:52:07 +08:00
|
|
|
/* walk the list and find corresponding xid */
|
|
|
|
cup = NULL;
|
|
|
|
spin_lock(&cn->cn_lock);
|
|
|
|
list_for_each_entry(tmp, &cn->cn_list, cu_list) {
|
2019-09-10 04:10:30 +08:00
|
|
|
if (get_unaligned(&tmp->cu_u.cu_hdr.cm_xid) == xid) {
|
2012-03-21 21:52:07 +08:00
|
|
|
cup = tmp;
|
2019-03-27 06:06:27 +08:00
|
|
|
if (status != -EINPROGRESS)
|
|
|
|
list_del_init(&cup->cu_list);
|
2012-03-21 21:52:07 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spin_unlock(&cn->cn_lock);
|
|
|
|
|
|
|
|
/* couldn't find upcall? */
|
|
|
|
if (!cup) {
|
2012-03-28 19:36:01 +08:00
|
|
|
dprintk("%s: couldn't find upcall -- xid=%u\n", __func__, xid);
|
2012-03-21 21:52:07 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2019-03-27 06:06:27 +08:00
|
|
|
if (status == -EINPROGRESS)
|
|
|
|
return __cld_pipe_inprogress_downcall(cmsg, nn);
|
|
|
|
|
2019-09-10 04:10:31 +08:00
|
|
|
if (copy_from_user(&cup->cu_u.cu_msg_v2, src, mlen) != 0)
|
2012-03-21 21:52:07 +08:00
|
|
|
return -EFAULT;
|
|
|
|
|
2018-11-07 02:35:08 +08:00
|
|
|
complete(&cup->cu_done);
|
2012-03-21 21:52:07 +08:00
|
|
|
return mlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cld_pipe_destroy_msg(struct rpc_pipe_msg *msg)
|
|
|
|
{
|
|
|
|
struct cld_msg *cmsg = msg->data;
|
|
|
|
struct cld_upcall *cup = container_of(cmsg, struct cld_upcall,
|
2019-09-10 04:10:30 +08:00
|
|
|
cu_u.cu_msg);
|
2012-03-21 21:52:07 +08:00
|
|
|
|
|
|
|
/* errno >= 0 means we got a downcall */
|
|
|
|
if (msg->errno >= 0)
|
|
|
|
return;
|
|
|
|
|
2018-11-07 02:35:08 +08:00
|
|
|
complete(&cup->cu_done);
|
2012-03-21 21:52:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct rpc_pipe_ops cld_upcall_ops = {
|
|
|
|
.upcall = rpc_pipe_generic_upcall,
|
|
|
|
.downcall = cld_pipe_downcall,
|
|
|
|
.destroy_msg = cld_pipe_destroy_msg,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct dentry *
|
|
|
|
nfsd4_cld_register_sb(struct super_block *sb, struct rpc_pipe *pipe)
|
|
|
|
{
|
|
|
|
struct dentry *dir, *dentry;
|
|
|
|
|
|
|
|
dir = rpc_d_lookup_sb(sb, NFSD_PIPE_DIR);
|
|
|
|
if (dir == NULL)
|
|
|
|
return ERR_PTR(-ENOENT);
|
|
|
|
dentry = rpc_mkpipe_dentry(dir, NFSD_CLD_PIPE, NULL, pipe);
|
|
|
|
dput(dir);
|
|
|
|
return dentry;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nfsd4_cld_unregister_sb(struct rpc_pipe *pipe)
|
|
|
|
{
|
|
|
|
if (pipe->dentry)
|
|
|
|
rpc_unlink(pipe->dentry);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct dentry *
|
|
|
|
nfsd4_cld_register_net(struct net *net, struct rpc_pipe *pipe)
|
|
|
|
{
|
|
|
|
struct super_block *sb;
|
|
|
|
struct dentry *dentry;
|
|
|
|
|
|
|
|
sb = rpc_get_sb_net(net);
|
|
|
|
if (!sb)
|
|
|
|
return NULL;
|
|
|
|
dentry = nfsd4_cld_register_sb(sb, pipe);
|
|
|
|
rpc_put_sb_net(net);
|
|
|
|
return dentry;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nfsd4_cld_unregister_net(struct net *net, struct rpc_pipe *pipe)
|
|
|
|
{
|
|
|
|
struct super_block *sb;
|
|
|
|
|
|
|
|
sb = rpc_get_sb_net(net);
|
|
|
|
if (sb) {
|
|
|
|
nfsd4_cld_unregister_sb(pipe);
|
|
|
|
rpc_put_sb_net(net);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize rpc_pipefs pipe for communication with client tracking daemon */
|
|
|
|
static int
|
2019-03-27 06:06:29 +08:00
|
|
|
__nfsd4_init_cld_pipe(struct net *net)
|
2012-03-21 21:52:07 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct dentry *dentry;
|
|
|
|
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
|
|
|
|
struct cld_net *cn;
|
|
|
|
|
|
|
|
if (nn->cld_net)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cn = kzalloc(sizeof(*cn), GFP_KERNEL);
|
|
|
|
if (!cn) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
cn->cn_pipe = rpc_mkpipe_data(&cld_upcall_ops, RPC_PIPE_WAIT_FOR_OPEN);
|
|
|
|
if (IS_ERR(cn->cn_pipe)) {
|
|
|
|
ret = PTR_ERR(cn->cn_pipe);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
spin_lock_init(&cn->cn_lock);
|
|
|
|
INIT_LIST_HEAD(&cn->cn_list);
|
|
|
|
|
|
|
|
dentry = nfsd4_cld_register_net(net, cn->cn_pipe);
|
|
|
|
if (IS_ERR(dentry)) {
|
|
|
|
ret = PTR_ERR(dentry);
|
|
|
|
goto err_destroy_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
cn->cn_pipe->dentry = dentry;
|
2019-03-27 06:06:30 +08:00
|
|
|
cn->cn_has_legacy = false;
|
2012-03-21 21:52:07 +08:00
|
|
|
nn->cld_net = cn;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_destroy_data:
|
|
|
|
rpc_destroy_pipe_data(cn->cn_pipe);
|
|
|
|
err:
|
|
|
|
kfree(cn);
|
|
|
|
printk(KERN_ERR "NFSD: unable to create nfsdcld upcall pipe (%d)\n",
|
|
|
|
ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-03-27 06:06:29 +08:00
|
|
|
static int
|
|
|
|
nfsd4_init_cld_pipe(struct net *net)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
|
|
|
status = __nfsd4_init_cld_pipe(net);
|
|
|
|
if (!status)
|
|
|
|
printk("NFSD: Using old nfsdcld client tracking operations.\n");
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2012-03-21 21:52:07 +08:00
|
|
|
static void
|
|
|
|
nfsd4_remove_cld_pipe(struct net *net)
|
|
|
|
{
|
|
|
|
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
|
|
|
|
struct cld_net *cn = nn->cld_net;
|
|
|
|
|
|
|
|
nfsd4_cld_unregister_net(net, cn->cn_pipe);
|
|
|
|
rpc_destroy_pipe_data(cn->cn_pipe);
|
2019-09-10 04:10:31 +08:00
|
|
|
if (cn->cn_tfm)
|
|
|
|
crypto_free_shash(cn->cn_tfm);
|
2012-03-21 21:52:07 +08:00
|
|
|
kfree(nn->cld_net);
|
|
|
|
nn->cld_net = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct cld_upcall *
|
2019-09-10 04:10:30 +08:00
|
|
|
alloc_cld_upcall(struct nfsd_net *nn)
|
2012-03-21 21:52:07 +08:00
|
|
|
{
|
|
|
|
struct cld_upcall *new, *tmp;
|
2019-09-10 04:10:30 +08:00
|
|
|
struct cld_net *cn = nn->cld_net;
|
2012-03-21 21:52:07 +08:00
|
|
|
|
|
|
|
new = kzalloc(sizeof(*new), GFP_KERNEL);
|
|
|
|
if (!new)
|
|
|
|
return new;
|
|
|
|
|
|
|
|
/* FIXME: hard cap on number in flight? */
|
|
|
|
restart_search:
|
|
|
|
spin_lock(&cn->cn_lock);
|
|
|
|
list_for_each_entry(tmp, &cn->cn_list, cu_list) {
|
2019-09-10 04:10:30 +08:00
|
|
|
if (tmp->cu_u.cu_msg.cm_xid == cn->cn_xid) {
|
2012-03-21 21:52:07 +08:00
|
|
|
cn->cn_xid++;
|
|
|
|
spin_unlock(&cn->cn_lock);
|
|
|
|
goto restart_search;
|
|
|
|
}
|
|
|
|
}
|
2018-11-07 02:35:08 +08:00
|
|
|
init_completion(&new->cu_done);
|
2019-09-10 04:10:30 +08:00
|
|
|
new->cu_u.cu_msg.cm_vers = nn->client_tracking_ops->version;
|
|
|
|
put_unaligned(cn->cn_xid++, &new->cu_u.cu_msg.cm_xid);
|
2012-03-21 21:52:07 +08:00
|
|
|
new->cu_net = cn;
|
|
|
|
list_add(&new->cu_list, &cn->cn_list);
|
|
|
|
spin_unlock(&cn->cn_lock);
|
|
|
|
|
2019-09-10 04:10:30 +08:00
|
|
|
dprintk("%s: allocated xid %u\n", __func__, new->cu_u.cu_msg.cm_xid);
|
2012-03-21 21:52:07 +08:00
|
|
|
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_cld_upcall(struct cld_upcall *victim)
|
|
|
|
{
|
|
|
|
struct cld_net *cn = victim->cu_net;
|
|
|
|
|
|
|
|
spin_lock(&cn->cn_lock);
|
|
|
|
list_del(&victim->cu_list);
|
|
|
|
spin_unlock(&cn->cn_lock);
|
|
|
|
kfree(victim);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ask daemon to create a new record */
|
|
|
|
static void
|
|
|
|
nfsd4_cld_create(struct nfs4_client *clp)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct cld_upcall *cup;
|
2012-11-14 23:21:10 +08:00
|
|
|
struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
|
2012-03-21 21:52:07 +08:00
|
|
|
struct cld_net *cn = nn->cld_net;
|
|
|
|
|
|
|
|
/* Don't upcall if it's already stored */
|
|
|
|
if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
|
|
|
|
return;
|
|
|
|
|
2019-09-10 04:10:30 +08:00
|
|
|
cup = alloc_cld_upcall(nn);
|
2012-03-21 21:52:07 +08:00
|
|
|
if (!cup) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
2019-09-10 04:10:30 +08:00
|
|
|
cup->cu_u.cu_msg.cm_cmd = Cld_Create;
|
|
|
|
cup->cu_u.cu_msg.cm_u.cm_name.cn_len = clp->cl_name.len;
|
|
|
|
memcpy(cup->cu_u.cu_msg.cm_u.cm_name.cn_id, clp->cl_name.data,
|
2012-03-21 21:52:07 +08:00
|
|
|
clp->cl_name.len);
|
|
|
|
|
2020-07-11 04:33:07 +08:00
|
|
|
ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_u.cu_msg, nn);
|
2012-03-21 21:52:07 +08:00
|
|
|
if (!ret) {
|
2019-09-10 04:10:30 +08:00
|
|
|
ret = cup->cu_u.cu_msg.cm_status;
|
2012-03-21 21:52:07 +08:00
|
|
|
set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
free_cld_upcall(cup);
|
|
|
|
out_err:
|
|
|
|
if (ret)
|
|
|
|
printk(KERN_ERR "NFSD: Unable to create client "
|
|
|
|
"record on stable storage: %d\n", ret);
|
|
|
|
}
|
|
|
|
|
2019-09-10 04:10:31 +08:00
|
|
|
/* Ask daemon to create a new record */
|
|
|
|
static void
|
|
|
|
nfsd4_cld_create_v2(struct nfs4_client *clp)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct cld_upcall *cup;
|
|
|
|
struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
|
|
|
|
struct cld_net *cn = nn->cld_net;
|
|
|
|
struct cld_msg_v2 *cmsg;
|
|
|
|
struct crypto_shash *tfm = cn->cn_tfm;
|
|
|
|
struct xdr_netobj cksum;
|
|
|
|
char *principal = NULL;
|
|
|
|
|
|
|
|
/* Don't upcall if it's already stored */
|
|
|
|
if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
|
|
|
|
return;
|
|
|
|
|
|
|
|
cup = alloc_cld_upcall(nn);
|
|
|
|
if (!cup) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmsg = &cup->cu_u.cu_msg_v2;
|
|
|
|
cmsg->cm_cmd = Cld_Create;
|
|
|
|
cmsg->cm_u.cm_clntinfo.cc_name.cn_len = clp->cl_name.len;
|
|
|
|
memcpy(cmsg->cm_u.cm_clntinfo.cc_name.cn_id, clp->cl_name.data,
|
|
|
|
clp->cl_name.len);
|
|
|
|
if (clp->cl_cred.cr_raw_principal)
|
|
|
|
principal = clp->cl_cred.cr_raw_principal;
|
|
|
|
else if (clp->cl_cred.cr_principal)
|
|
|
|
principal = clp->cl_cred.cr_principal;
|
|
|
|
if (principal) {
|
|
|
|
cksum.len = crypto_shash_digestsize(tfm);
|
|
|
|
cksum.data = kmalloc(cksum.len, GFP_KERNEL);
|
|
|
|
if (cksum.data == NULL) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
2020-05-02 13:31:17 +08:00
|
|
|
ret = crypto_shash_tfm_digest(tfm, principal, strlen(principal),
|
|
|
|
cksum.data);
|
2019-09-10 04:10:31 +08:00
|
|
|
if (ret) {
|
|
|
|
kfree(cksum.data);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
cmsg->cm_u.cm_clntinfo.cc_princhash.cp_len = cksum.len;
|
|
|
|
memcpy(cmsg->cm_u.cm_clntinfo.cc_princhash.cp_data,
|
|
|
|
cksum.data, cksum.len);
|
|
|
|
kfree(cksum.data);
|
|
|
|
} else
|
|
|
|
cmsg->cm_u.cm_clntinfo.cc_princhash.cp_len = 0;
|
|
|
|
|
2020-07-11 04:33:07 +08:00
|
|
|
ret = cld_pipe_upcall(cn->cn_pipe, cmsg, nn);
|
2019-09-10 04:10:31 +08:00
|
|
|
if (!ret) {
|
|
|
|
ret = cmsg->cm_status;
|
|
|
|
set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
free_cld_upcall(cup);
|
|
|
|
out_err:
|
|
|
|
if (ret)
|
|
|
|
pr_err("NFSD: Unable to create client record on stable storage: %d\n",
|
|
|
|
ret);
|
|
|
|
}
|
|
|
|
|
2012-03-21 21:52:07 +08:00
|
|
|
/* Ask daemon to create a new record */
|
|
|
|
static void
|
|
|
|
nfsd4_cld_remove(struct nfs4_client *clp)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct cld_upcall *cup;
|
2012-11-14 23:21:10 +08:00
|
|
|
struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
|
2012-03-21 21:52:07 +08:00
|
|
|
struct cld_net *cn = nn->cld_net;
|
|
|
|
|
|
|
|
/* Don't upcall if it's already removed */
|
|
|
|
if (!test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
|
|
|
|
return;
|
|
|
|
|
2019-09-10 04:10:30 +08:00
|
|
|
cup = alloc_cld_upcall(nn);
|
2012-03-21 21:52:07 +08:00
|
|
|
if (!cup) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
2019-09-10 04:10:30 +08:00
|
|
|
cup->cu_u.cu_msg.cm_cmd = Cld_Remove;
|
|
|
|
cup->cu_u.cu_msg.cm_u.cm_name.cn_len = clp->cl_name.len;
|
|
|
|
memcpy(cup->cu_u.cu_msg.cm_u.cm_name.cn_id, clp->cl_name.data,
|
2012-03-21 21:52:07 +08:00
|
|
|
clp->cl_name.len);
|
|
|
|
|
2020-07-11 04:33:07 +08:00
|
|
|
ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_u.cu_msg, nn);
|
2012-03-21 21:52:07 +08:00
|
|
|
if (!ret) {
|
2019-09-10 04:10:30 +08:00
|
|
|
ret = cup->cu_u.cu_msg.cm_status;
|
2012-03-21 21:52:07 +08:00
|
|
|
clear_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
free_cld_upcall(cup);
|
|
|
|
out_err:
|
|
|
|
if (ret)
|
|
|
|
printk(KERN_ERR "NFSD: Unable to remove client "
|
|
|
|
"record from stable storage: %d\n", ret);
|
|
|
|
}
|
|
|
|
|
2019-03-27 06:06:27 +08:00
|
|
|
/*
|
|
|
|
* For older nfsdcld's that do not allow us to "slurp" the clients
|
|
|
|
* from the tracking database during startup.
|
|
|
|
*
|
|
|
|
* Check for presence of a record, and update its timestamp
|
|
|
|
*/
|
2012-03-21 21:52:07 +08:00
|
|
|
static int
|
2019-03-27 06:06:27 +08:00
|
|
|
nfsd4_cld_check_v0(struct nfs4_client *clp)
|
2012-03-21 21:52:07 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct cld_upcall *cup;
|
2012-11-14 23:21:10 +08:00
|
|
|
struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
|
2012-03-21 21:52:07 +08:00
|
|
|
struct cld_net *cn = nn->cld_net;
|
|
|
|
|
|
|
|
/* Don't upcall if one was already stored during this grace pd */
|
|
|
|
if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
|
|
|
|
return 0;
|
|
|
|
|
2019-09-10 04:10:30 +08:00
|
|
|
cup = alloc_cld_upcall(nn);
|
2012-03-21 21:52:07 +08:00
|
|
|
if (!cup) {
|
|
|
|
printk(KERN_ERR "NFSD: Unable to check client record on "
|
|
|
|
"stable storage: %d\n", -ENOMEM);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2019-09-10 04:10:30 +08:00
|
|
|
cup->cu_u.cu_msg.cm_cmd = Cld_Check;
|
|
|
|
cup->cu_u.cu_msg.cm_u.cm_name.cn_len = clp->cl_name.len;
|
|
|
|
memcpy(cup->cu_u.cu_msg.cm_u.cm_name.cn_id, clp->cl_name.data,
|
2012-03-21 21:52:07 +08:00
|
|
|
clp->cl_name.len);
|
|
|
|
|
2020-07-11 04:33:07 +08:00
|
|
|
ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_u.cu_msg, nn);
|
2012-03-21 21:52:07 +08:00
|
|
|
if (!ret) {
|
2019-09-10 04:10:30 +08:00
|
|
|
ret = cup->cu_u.cu_msg.cm_status;
|
2012-03-21 21:52:07 +08:00
|
|
|
set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
free_cld_upcall(cup);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-03-27 06:06:27 +08:00
|
|
|
/*
|
|
|
|
* For newer nfsdcld's that allow us to "slurp" the clients
|
|
|
|
* from the tracking database during startup.
|
|
|
|
*
|
|
|
|
* Check for presence of a record in the reclaim_str_hashtbl
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
nfsd4_cld_check(struct nfs4_client *clp)
|
|
|
|
{
|
|
|
|
struct nfs4_client_reclaim *crp;
|
|
|
|
struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
|
2019-03-27 06:06:30 +08:00
|
|
|
struct cld_net *cn = nn->cld_net;
|
|
|
|
int status;
|
|
|
|
char dname[HEXDIR_LEN];
|
|
|
|
struct xdr_netobj name;
|
2019-03-27 06:06:27 +08:00
|
|
|
|
|
|
|
/* did we already find that this client is stable? */
|
|
|
|
if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* look for it in the reclaim hashtable otherwise */
|
|
|
|
crp = nfsd4_find_reclaim_client(clp->cl_name, nn);
|
2019-03-27 06:06:30 +08:00
|
|
|
if (crp)
|
|
|
|
goto found;
|
|
|
|
|
|
|
|
if (cn->cn_has_legacy) {
|
|
|
|
status = nfs4_make_rec_clidname(dname, &clp->cl_name);
|
|
|
|
if (status)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
name.data = kmemdup(dname, HEXDIR_LEN, GFP_KERNEL);
|
|
|
|
if (!name.data) {
|
|
|
|
dprintk("%s: failed to allocate memory for name.data!\n",
|
|
|
|
__func__);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
name.len = HEXDIR_LEN;
|
|
|
|
crp = nfsd4_find_reclaim_client(name, nn);
|
|
|
|
kfree(name.data);
|
|
|
|
if (crp)
|
|
|
|
goto found;
|
2019-03-27 06:06:27 +08:00
|
|
|
|
2019-03-27 06:06:30 +08:00
|
|
|
}
|
2019-03-27 06:06:27 +08:00
|
|
|
return -ENOENT;
|
2019-03-27 06:06:30 +08:00
|
|
|
found:
|
|
|
|
crp->cr_clp = clp;
|
|
|
|
return 0;
|
2019-03-27 06:06:27 +08:00
|
|
|
}
|
|
|
|
|
2019-09-10 04:10:31 +08:00
|
|
|
static int
|
|
|
|
nfsd4_cld_check_v2(struct nfs4_client *clp)
|
|
|
|
{
|
|
|
|
struct nfs4_client_reclaim *crp;
|
|
|
|
struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
|
|
|
|
struct cld_net *cn = nn->cld_net;
|
|
|
|
int status;
|
|
|
|
char dname[HEXDIR_LEN];
|
|
|
|
struct xdr_netobj name;
|
|
|
|
struct crypto_shash *tfm = cn->cn_tfm;
|
|
|
|
struct xdr_netobj cksum;
|
|
|
|
char *principal = NULL;
|
|
|
|
|
|
|
|
/* did we already find that this client is stable? */
|
|
|
|
if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* look for it in the reclaim hashtable otherwise */
|
|
|
|
crp = nfsd4_find_reclaim_client(clp->cl_name, nn);
|
|
|
|
if (crp)
|
|
|
|
goto found;
|
|
|
|
|
|
|
|
if (cn->cn_has_legacy) {
|
|
|
|
status = nfs4_make_rec_clidname(dname, &clp->cl_name);
|
|
|
|
if (status)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
name.data = kmemdup(dname, HEXDIR_LEN, GFP_KERNEL);
|
|
|
|
if (!name.data) {
|
|
|
|
dprintk("%s: failed to allocate memory for name.data\n",
|
|
|
|
__func__);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
name.len = HEXDIR_LEN;
|
|
|
|
crp = nfsd4_find_reclaim_client(name, nn);
|
|
|
|
kfree(name.data);
|
|
|
|
if (crp)
|
|
|
|
goto found;
|
|
|
|
|
|
|
|
}
|
|
|
|
return -ENOENT;
|
|
|
|
found:
|
|
|
|
if (crp->cr_princhash.len) {
|
|
|
|
if (clp->cl_cred.cr_raw_principal)
|
|
|
|
principal = clp->cl_cred.cr_raw_principal;
|
|
|
|
else if (clp->cl_cred.cr_principal)
|
|
|
|
principal = clp->cl_cred.cr_principal;
|
|
|
|
if (principal == NULL)
|
|
|
|
return -ENOENT;
|
|
|
|
cksum.len = crypto_shash_digestsize(tfm);
|
|
|
|
cksum.data = kmalloc(cksum.len, GFP_KERNEL);
|
|
|
|
if (cksum.data == NULL)
|
|
|
|
return -ENOENT;
|
2020-05-02 13:31:17 +08:00
|
|
|
status = crypto_shash_tfm_digest(tfm, principal,
|
|
|
|
strlen(principal), cksum.data);
|
2019-09-10 04:10:31 +08:00
|
|
|
if (status) {
|
|
|
|
kfree(cksum.data);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
if (memcmp(crp->cr_princhash.data, cksum.data,
|
|
|
|
crp->cr_princhash.len)) {
|
|
|
|
kfree(cksum.data);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
kfree(cksum.data);
|
|
|
|
}
|
|
|
|
crp->cr_clp = clp;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-27 06:06:27 +08:00
|
|
|
static int
|
|
|
|
nfsd4_cld_grace_start(struct nfsd_net *nn)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct cld_upcall *cup;
|
|
|
|
struct cld_net *cn = nn->cld_net;
|
|
|
|
|
2019-09-10 04:10:30 +08:00
|
|
|
cup = alloc_cld_upcall(nn);
|
2019-03-27 06:06:27 +08:00
|
|
|
if (!cup) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
2019-09-10 04:10:30 +08:00
|
|
|
cup->cu_u.cu_msg.cm_cmd = Cld_GraceStart;
|
2020-07-11 04:33:07 +08:00
|
|
|
ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_u.cu_msg, nn);
|
2019-03-27 06:06:27 +08:00
|
|
|
if (!ret)
|
2019-09-10 04:10:30 +08:00
|
|
|
ret = cup->cu_u.cu_msg.cm_status;
|
2019-03-27 06:06:27 +08:00
|
|
|
|
|
|
|
free_cld_upcall(cup);
|
|
|
|
out_err:
|
|
|
|
if (ret)
|
|
|
|
dprintk("%s: Unable to get clients from userspace: %d\n",
|
|
|
|
__func__, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* For older nfsdcld's that need cm_gracetime */
|
2012-03-21 21:52:07 +08:00
|
|
|
static void
|
2019-03-27 06:06:27 +08:00
|
|
|
nfsd4_cld_grace_done_v0(struct nfsd_net *nn)
|
2012-03-21 21:52:07 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct cld_upcall *cup;
|
|
|
|
struct cld_net *cn = nn->cld_net;
|
|
|
|
|
2019-09-10 04:10:30 +08:00
|
|
|
cup = alloc_cld_upcall(nn);
|
2012-03-21 21:52:07 +08:00
|
|
|
if (!cup) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
2019-09-10 04:10:30 +08:00
|
|
|
cup->cu_u.cu_msg.cm_cmd = Cld_GraceDone;
|
2019-10-31 22:53:13 +08:00
|
|
|
cup->cu_u.cu_msg.cm_u.cm_gracetime = nn->boot_time;
|
2020-07-11 04:33:07 +08:00
|
|
|
ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_u.cu_msg, nn);
|
2012-03-21 21:52:07 +08:00
|
|
|
if (!ret)
|
2019-09-10 04:10:30 +08:00
|
|
|
ret = cup->cu_u.cu_msg.cm_status;
|
2012-03-21 21:52:07 +08:00
|
|
|
|
|
|
|
free_cld_upcall(cup);
|
|
|
|
out_err:
|
|
|
|
if (ret)
|
|
|
|
printk(KERN_ERR "NFSD: Unable to end grace period: %d\n", ret);
|
|
|
|
}
|
|
|
|
|
2019-03-27 06:06:27 +08:00
|
|
|
/*
|
|
|
|
* For newer nfsdcld's that do not need cm_gracetime. We also need to call
|
|
|
|
* nfs4_release_reclaim() to clear out the reclaim_str_hashtbl.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
nfsd4_cld_grace_done(struct nfsd_net *nn)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct cld_upcall *cup;
|
|
|
|
struct cld_net *cn = nn->cld_net;
|
|
|
|
|
2019-09-10 04:10:30 +08:00
|
|
|
cup = alloc_cld_upcall(nn);
|
2019-03-27 06:06:27 +08:00
|
|
|
if (!cup) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
2019-09-10 04:10:30 +08:00
|
|
|
cup->cu_u.cu_msg.cm_cmd = Cld_GraceDone;
|
2020-07-11 04:33:07 +08:00
|
|
|
ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_u.cu_msg, nn);
|
2019-03-27 06:06:27 +08:00
|
|
|
if (!ret)
|
2019-09-10 04:10:30 +08:00
|
|
|
ret = cup->cu_u.cu_msg.cm_status;
|
2019-03-27 06:06:27 +08:00
|
|
|
|
|
|
|
free_cld_upcall(cup);
|
|
|
|
out_err:
|
|
|
|
nfs4_release_reclaim(nn);
|
|
|
|
if (ret)
|
|
|
|
printk(KERN_ERR "NFSD: Unable to end grace period: %d\n", ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nfs4_cld_state_init(struct net *net)
|
|
|
|
{
|
|
|
|
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
nn->reclaim_str_hashtbl = kmalloc_array(CLIENT_HASH_SIZE,
|
|
|
|
sizeof(struct list_head),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!nn->reclaim_str_hashtbl)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
for (i = 0; i < CLIENT_HASH_SIZE; i++)
|
|
|
|
INIT_LIST_HEAD(&nn->reclaim_str_hashtbl[i]);
|
|
|
|
nn->reclaim_str_hashtbl_size = 0;
|
2019-03-27 06:06:28 +08:00
|
|
|
nn->track_reclaim_completes = true;
|
|
|
|
atomic_set(&nn->nr_reclaim_complete, 0);
|
2019-03-27 06:06:27 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nfs4_cld_state_shutdown(struct net *net)
|
|
|
|
{
|
|
|
|
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
|
|
|
|
|
2019-03-27 06:06:28 +08:00
|
|
|
nn->track_reclaim_completes = false;
|
2019-03-27 06:06:27 +08:00
|
|
|
kfree(nn->reclaim_str_hashtbl);
|
|
|
|
}
|
|
|
|
|
2019-03-27 06:06:29 +08:00
|
|
|
static bool
|
|
|
|
cld_running(struct nfsd_net *nn)
|
|
|
|
{
|
|
|
|
struct cld_net *cn = nn->cld_net;
|
|
|
|
struct rpc_pipe *pipe = cn->cn_pipe;
|
|
|
|
|
|
|
|
return pipe->nreaders || pipe->nwriters;
|
|
|
|
}
|
|
|
|
|
2019-09-10 04:10:30 +08:00
|
|
|
static int
|
|
|
|
nfsd4_cld_get_version(struct nfsd_net *nn)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct cld_upcall *cup;
|
|
|
|
struct cld_net *cn = nn->cld_net;
|
|
|
|
uint8_t version;
|
|
|
|
|
|
|
|
cup = alloc_cld_upcall(nn);
|
|
|
|
if (!cup) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
cup->cu_u.cu_msg.cm_cmd = Cld_GetVersion;
|
2020-07-11 04:33:07 +08:00
|
|
|
ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_u.cu_msg, nn);
|
2019-09-10 04:10:30 +08:00
|
|
|
if (!ret) {
|
|
|
|
ret = cup->cu_u.cu_msg.cm_status;
|
|
|
|
if (ret)
|
|
|
|
goto out_free;
|
|
|
|
version = cup->cu_u.cu_msg.cm_u.cm_version;
|
|
|
|
dprintk("%s: userspace returned version %u\n",
|
|
|
|
__func__, version);
|
|
|
|
if (version < 1)
|
|
|
|
version = 1;
|
|
|
|
else if (version > CLD_UPCALL_VERSION)
|
|
|
|
version = CLD_UPCALL_VERSION;
|
|
|
|
|
|
|
|
switch (version) {
|
|
|
|
case 1:
|
|
|
|
nn->client_tracking_ops = &nfsd4_cld_tracking_ops;
|
|
|
|
break;
|
2019-09-10 04:10:31 +08:00
|
|
|
case 2:
|
|
|
|
nn->client_tracking_ops = &nfsd4_cld_tracking_ops_v2;
|
|
|
|
break;
|
2019-09-10 04:10:30 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out_free:
|
|
|
|
free_cld_upcall(cup);
|
|
|
|
out_err:
|
|
|
|
if (ret)
|
|
|
|
dprintk("%s: Unable to get version from userspace: %d\n",
|
|
|
|
__func__, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-03-27 06:06:27 +08:00
|
|
|
static int
|
|
|
|
nfsd4_cld_tracking_init(struct net *net)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
|
2019-03-27 06:06:29 +08:00
|
|
|
bool running;
|
|
|
|
int retries = 10;
|
2019-11-13 03:01:43 +08:00
|
|
|
struct crypto_shash *tfm;
|
2019-03-27 06:06:27 +08:00
|
|
|
|
|
|
|
status = nfs4_cld_state_init(net);
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
|
2019-03-27 06:06:29 +08:00
|
|
|
status = __nfsd4_init_cld_pipe(net);
|
2019-03-27 06:06:27 +08:00
|
|
|
if (status)
|
|
|
|
goto err_shutdown;
|
|
|
|
|
2019-03-27 06:06:29 +08:00
|
|
|
/*
|
|
|
|
* rpc pipe upcalls take 30 seconds to time out, so we don't want to
|
|
|
|
* queue an upcall unless we know that nfsdcld is running (because we
|
|
|
|
* want this to fail fast so that nfsd4_client_tracking_init() can try
|
|
|
|
* the next client tracking method). nfsdcld should already be running
|
|
|
|
* before nfsd is started, so the wait here is for nfsdcld to open the
|
|
|
|
* pipefs file we just created.
|
|
|
|
*/
|
|
|
|
while (!(running = cld_running(nn)) && retries--)
|
|
|
|
msleep(100);
|
|
|
|
|
|
|
|
if (!running) {
|
|
|
|
status = -ETIMEDOUT;
|
|
|
|
goto err_remove;
|
|
|
|
}
|
2019-11-13 03:01:43 +08:00
|
|
|
tfm = crypto_alloc_shash("sha256", 0, 0);
|
|
|
|
if (IS_ERR(tfm)) {
|
|
|
|
status = PTR_ERR(tfm);
|
|
|
|
goto err_remove;
|
|
|
|
}
|
|
|
|
nn->cld_net->cn_tfm = tfm;
|
2019-03-27 06:06:29 +08:00
|
|
|
|
2019-09-10 04:10:30 +08:00
|
|
|
status = nfsd4_cld_get_version(nn);
|
|
|
|
if (status == -EOPNOTSUPP)
|
|
|
|
pr_warn("NFSD: nfsdcld GetVersion upcall failed. Please upgrade nfsdcld.\n");
|
|
|
|
|
2019-03-27 06:06:27 +08:00
|
|
|
status = nfsd4_cld_grace_start(nn);
|
|
|
|
if (status) {
|
|
|
|
if (status == -EOPNOTSUPP)
|
2019-09-10 04:10:30 +08:00
|
|
|
pr_warn("NFSD: nfsdcld GraceStart upcall failed. Please upgrade nfsdcld.\n");
|
2019-03-27 06:06:27 +08:00
|
|
|
nfs4_release_reclaim(nn);
|
|
|
|
goto err_remove;
|
2019-03-27 06:06:29 +08:00
|
|
|
} else
|
|
|
|
printk("NFSD: Using nfsdcld client tracking operations.\n");
|
2019-03-27 06:06:27 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_remove:
|
|
|
|
nfsd4_remove_cld_pipe(net);
|
|
|
|
err_shutdown:
|
|
|
|
nfs4_cld_state_shutdown(net);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nfsd4_cld_tracking_exit(struct net *net)
|
|
|
|
{
|
|
|
|
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
|
|
|
|
|
|
|
|
nfs4_release_reclaim(nn);
|
|
|
|
nfsd4_remove_cld_pipe(net);
|
|
|
|
nfs4_cld_state_shutdown(net);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* For older nfsdcld's */
|
|
|
|
static const struct nfsd4_client_tracking_ops nfsd4_cld_tracking_ops_v0 = {
|
2012-03-21 21:52:07 +08:00
|
|
|
.init = nfsd4_init_cld_pipe,
|
|
|
|
.exit = nfsd4_remove_cld_pipe,
|
|
|
|
.create = nfsd4_cld_create,
|
|
|
|
.remove = nfsd4_cld_remove,
|
2019-03-27 06:06:27 +08:00
|
|
|
.check = nfsd4_cld_check_v0,
|
|
|
|
.grace_done = nfsd4_cld_grace_done_v0,
|
2019-09-10 04:10:30 +08:00
|
|
|
.version = 1,
|
|
|
|
.msglen = sizeof(struct cld_msg),
|
2019-03-27 06:06:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* For newer nfsdcld's */
|
|
|
|
static const struct nfsd4_client_tracking_ops nfsd4_cld_tracking_ops = {
|
|
|
|
.init = nfsd4_cld_tracking_init,
|
|
|
|
.exit = nfsd4_cld_tracking_exit,
|
|
|
|
.create = nfsd4_cld_create,
|
|
|
|
.remove = nfsd4_cld_remove,
|
2012-03-21 21:52:07 +08:00
|
|
|
.check = nfsd4_cld_check,
|
|
|
|
.grace_done = nfsd4_cld_grace_done,
|
2019-09-10 04:10:30 +08:00
|
|
|
.version = 1,
|
|
|
|
.msglen = sizeof(struct cld_msg),
|
2012-03-21 21:52:07 +08:00
|
|
|
};
|
|
|
|
|
2019-09-10 04:10:31 +08:00
|
|
|
/* v2 create/check ops include the principal, if available */
|
|
|
|
static const struct nfsd4_client_tracking_ops nfsd4_cld_tracking_ops_v2 = {
|
|
|
|
.init = nfsd4_cld_tracking_init,
|
|
|
|
.exit = nfsd4_cld_tracking_exit,
|
|
|
|
.create = nfsd4_cld_create_v2,
|
|
|
|
.remove = nfsd4_cld_remove,
|
|
|
|
.check = nfsd4_cld_check_v2,
|
|
|
|
.grace_done = nfsd4_cld_grace_done,
|
|
|
|
.version = 2,
|
|
|
|
.msglen = sizeof(struct cld_msg_v2),
|
|
|
|
};
|
|
|
|
|
2012-11-13 04:00:48 +08:00
|
|
|
/* upcall via usermodehelper */
|
|
|
|
static char cltrack_prog[PATH_MAX] = "/sbin/nfsdcltrack";
|
|
|
|
module_param_string(cltrack_prog, cltrack_prog, sizeof(cltrack_prog),
|
|
|
|
S_IRUGO|S_IWUSR);
|
|
|
|
MODULE_PARM_DESC(cltrack_prog, "Path to the nfsdcltrack upcall program");
|
|
|
|
|
2012-11-13 04:00:50 +08:00
|
|
|
static bool cltrack_legacy_disable;
|
|
|
|
module_param(cltrack_legacy_disable, bool, S_IRUGO|S_IWUSR);
|
|
|
|
MODULE_PARM_DESC(cltrack_legacy_disable,
|
|
|
|
"Disable legacy recoverydir conversion. Default: false");
|
|
|
|
|
|
|
|
#define LEGACY_TOPDIR_ENV_PREFIX "NFSDCLTRACK_LEGACY_TOPDIR="
|
|
|
|
#define LEGACY_RECDIR_ENV_PREFIX "NFSDCLTRACK_LEGACY_RECDIR="
|
2014-09-13 04:40:21 +08:00
|
|
|
#define HAS_SESSION_ENV_PREFIX "NFSDCLTRACK_CLIENT_HAS_SESSION="
|
|
|
|
#define GRACE_START_ENV_PREFIX "NFSDCLTRACK_GRACE_START="
|
2012-11-13 04:00:50 +08:00
|
|
|
|
|
|
|
static char *
|
|
|
|
nfsd4_cltrack_legacy_topdir(void)
|
|
|
|
{
|
|
|
|
int copied;
|
|
|
|
size_t len;
|
|
|
|
char *result;
|
|
|
|
|
|
|
|
if (cltrack_legacy_disable)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
len = strlen(LEGACY_TOPDIR_ENV_PREFIX) +
|
|
|
|
strlen(nfs4_recoverydir()) + 1;
|
|
|
|
|
|
|
|
result = kmalloc(len, GFP_KERNEL);
|
|
|
|
if (!result)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
copied = snprintf(result, len, LEGACY_TOPDIR_ENV_PREFIX "%s",
|
|
|
|
nfs4_recoverydir());
|
|
|
|
if (copied >= len) {
|
|
|
|
/* just return nothing if output was truncated */
|
|
|
|
kfree(result);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2012-11-13 04:00:57 +08:00
|
|
|
nfsd4_cltrack_legacy_recdir(const struct xdr_netobj *name)
|
2012-11-13 04:00:50 +08:00
|
|
|
{
|
|
|
|
int copied;
|
|
|
|
size_t len;
|
|
|
|
char *result;
|
|
|
|
|
|
|
|
if (cltrack_legacy_disable)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* +1 is for '/' between "topdir" and "recdir" */
|
|
|
|
len = strlen(LEGACY_RECDIR_ENV_PREFIX) +
|
|
|
|
strlen(nfs4_recoverydir()) + 1 + HEXDIR_LEN;
|
|
|
|
|
|
|
|
result = kmalloc(len, GFP_KERNEL);
|
|
|
|
if (!result)
|
|
|
|
return result;
|
|
|
|
|
2012-11-13 04:00:57 +08:00
|
|
|
copied = snprintf(result, len, LEGACY_RECDIR_ENV_PREFIX "%s/",
|
|
|
|
nfs4_recoverydir());
|
|
|
|
if (copied > (len - HEXDIR_LEN)) {
|
|
|
|
/* just return nothing if output will be truncated */
|
|
|
|
kfree(result);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
copied = nfs4_make_rec_clidname(result + copied, name);
|
|
|
|
if (copied) {
|
2012-11-13 04:00:50 +08:00
|
|
|
kfree(result);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-09-13 04:40:21 +08:00
|
|
|
static char *
|
|
|
|
nfsd4_cltrack_client_has_session(struct nfs4_client *clp)
|
|
|
|
{
|
|
|
|
int copied;
|
|
|
|
size_t len;
|
|
|
|
char *result;
|
|
|
|
|
|
|
|
/* prefix + Y/N character + terminating NULL */
|
|
|
|
len = strlen(HAS_SESSION_ENV_PREFIX) + 1 + 1;
|
|
|
|
|
|
|
|
result = kmalloc(len, GFP_KERNEL);
|
|
|
|
if (!result)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
copied = snprintf(result, len, HAS_SESSION_ENV_PREFIX "%c",
|
|
|
|
clp->cl_minorversion ? 'Y' : 'N');
|
|
|
|
if (copied >= len) {
|
|
|
|
/* just return nothing if output was truncated */
|
|
|
|
kfree(result);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2019-10-31 22:53:13 +08:00
|
|
|
nfsd4_cltrack_grace_start(time64_t grace_start)
|
2014-09-13 04:40:21 +08:00
|
|
|
{
|
|
|
|
int copied;
|
|
|
|
size_t len;
|
|
|
|
char *result;
|
|
|
|
|
|
|
|
/* prefix + max width of int64_t string + terminating NULL */
|
|
|
|
len = strlen(GRACE_START_ENV_PREFIX) + 22 + 1;
|
|
|
|
|
|
|
|
result = kmalloc(len, GFP_KERNEL);
|
|
|
|
if (!result)
|
|
|
|
return result;
|
|
|
|
|
2019-10-31 22:53:13 +08:00
|
|
|
copied = snprintf(result, len, GRACE_START_ENV_PREFIX "%lld",
|
2014-09-13 04:40:21 +08:00
|
|
|
grace_start);
|
|
|
|
if (copied >= len) {
|
|
|
|
/* just return nothing if output was truncated */
|
|
|
|
kfree(result);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-11-13 04:00:48 +08:00
|
|
|
static int
|
2014-09-13 04:40:21 +08:00
|
|
|
nfsd4_umh_cltrack_upcall(char *cmd, char *arg, char *env0, char *env1)
|
2012-11-13 04:00:48 +08:00
|
|
|
{
|
2014-09-13 04:40:21 +08:00
|
|
|
char *envp[3];
|
2012-11-13 04:00:48 +08:00
|
|
|
char *argv[4];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (unlikely(!cltrack_prog[0])) {
|
|
|
|
dprintk("%s: cltrack_prog is disabled\n", __func__);
|
|
|
|
return -EACCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
dprintk("%s: cmd: %s\n", __func__, cmd);
|
|
|
|
dprintk("%s: arg: %s\n", __func__, arg ? arg : "(null)");
|
2014-09-13 04:40:21 +08:00
|
|
|
dprintk("%s: env0: %s\n", __func__, env0 ? env0 : "(null)");
|
|
|
|
dprintk("%s: env1: %s\n", __func__, env1 ? env1 : "(null)");
|
2012-11-13 04:00:50 +08:00
|
|
|
|
2014-09-13 04:40:21 +08:00
|
|
|
envp[0] = env0;
|
|
|
|
envp[1] = env1;
|
|
|
|
envp[2] = NULL;
|
2012-11-13 04:00:48 +08:00
|
|
|
|
|
|
|
argv[0] = (char *)cltrack_prog;
|
|
|
|
argv[1] = cmd;
|
|
|
|
argv[2] = arg;
|
|
|
|
argv[3] = NULL;
|
|
|
|
|
|
|
|
ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
|
|
|
|
/*
|
|
|
|
* Disable the upcall mechanism if we're getting an ENOENT or EACCES
|
|
|
|
* error. The admin can re-enable it on the fly by using sysfs
|
|
|
|
* once the problem has been fixed.
|
|
|
|
*/
|
|
|
|
if (ret == -ENOENT || ret == -EACCES) {
|
|
|
|
dprintk("NFSD: %s was not found or isn't executable (%d). "
|
|
|
|
"Setting cltrack_prog to blank string!",
|
|
|
|
cltrack_prog, ret);
|
|
|
|
cltrack_prog[0] = '\0';
|
|
|
|
}
|
|
|
|
dprintk("%s: %s return value: %d\n", __func__, cltrack_prog, ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
bin_to_hex_dup(const unsigned char *src, int srclen)
|
|
|
|
{
|
2019-10-12 00:02:58 +08:00
|
|
|
char *buf;
|
2012-11-13 04:00:48 +08:00
|
|
|
|
|
|
|
/* +1 for terminating NULL */
|
2019-10-12 00:02:58 +08:00
|
|
|
buf = kzalloc((srclen * 2) + 1, GFP_KERNEL);
|
2012-11-13 04:00:48 +08:00
|
|
|
if (!buf)
|
|
|
|
return buf;
|
|
|
|
|
2019-10-12 00:02:58 +08:00
|
|
|
bin2hex(buf, src, srclen);
|
2012-11-13 04:00:48 +08:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-09-13 04:40:21 +08:00
|
|
|
nfsd4_umh_cltrack_init(struct net *net)
|
2012-11-13 04:00:48 +08:00
|
|
|
{
|
2014-09-13 04:40:21 +08:00
|
|
|
int ret;
|
|
|
|
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
|
|
|
|
char *grace_start = nfsd4_cltrack_grace_start(nn->boot_time);
|
|
|
|
|
2013-02-01 20:56:22 +08:00
|
|
|
/* XXX: The usermode helper s not working in container yet. */
|
|
|
|
if (net != &init_net) {
|
nfsd: don't WARN/backtrace for invalid container deployment.
These messages, combined with the backtrace they trigger, makes it seem
like a serious problem, though a quick search shows distros marking
it as a "won't fix" non-issue when the problem is reported by users.
The backtrace is overkill, and only really manages to show that if
you follow the code path, you can't really avoid it with bootargs
or configuration settings in the container.
Given that, lets tone it down a bit and get rid of the WARN severity,
and the associated backtrace, so people aren't needlessly alarmed.
Also, lets drop the split printk line, since they are grep unfriendly.
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
2015-08-26 04:59:16 +08:00
|
|
|
pr_warn("NFSD: attempt to initialize umh client tracking in a container ignored.\n");
|
2016-03-07 18:10:03 +08:00
|
|
|
kfree(grace_start);
|
2013-02-01 20:56:22 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2014-09-13 04:40:21 +08:00
|
|
|
|
|
|
|
ret = nfsd4_umh_cltrack_upcall("init", NULL, grace_start, NULL);
|
|
|
|
kfree(grace_start);
|
2019-03-27 06:06:29 +08:00
|
|
|
if (!ret)
|
|
|
|
printk("NFSD: Using UMH upcall client tracking operations.\n");
|
2014-09-13 04:40:21 +08:00
|
|
|
return ret;
|
2012-11-13 04:00:48 +08:00
|
|
|
}
|
|
|
|
|
2014-09-13 04:40:21 +08:00
|
|
|
static void
|
|
|
|
nfsd4_cltrack_upcall_lock(struct nfs4_client *clp)
|
|
|
|
{
|
|
|
|
wait_on_bit_lock(&clp->cl_flags, NFSD4_CLIENT_UPCALL_LOCK,
|
|
|
|
TASK_UNINTERRUPTIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nfsd4_cltrack_upcall_unlock(struct nfs4_client *clp)
|
|
|
|
{
|
|
|
|
smp_mb__before_atomic();
|
|
|
|
clear_bit(NFSD4_CLIENT_UPCALL_LOCK, &clp->cl_flags);
|
|
|
|
smp_mb__after_atomic();
|
|
|
|
wake_up_bit(&clp->cl_flags, NFSD4_CLIENT_UPCALL_LOCK);
|
|
|
|
}
|
|
|
|
|
2012-11-13 04:00:48 +08:00
|
|
|
static void
|
|
|
|
nfsd4_umh_cltrack_create(struct nfs4_client *clp)
|
|
|
|
{
|
2014-09-13 04:40:21 +08:00
|
|
|
char *hexid, *has_session, *grace_start;
|
|
|
|
struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
|
2012-11-13 04:00:48 +08:00
|
|
|
|
2014-09-13 04:40:22 +08:00
|
|
|
/*
|
|
|
|
* With v4.0 clients, there's little difference in outcome between a
|
|
|
|
* create and check operation, and we can end up calling into this
|
|
|
|
* function multiple times per client (once for each openowner). So,
|
|
|
|
* for v4.0 clients skip upcalling once the client has been recorded
|
|
|
|
* on stable storage.
|
|
|
|
*
|
|
|
|
* For v4.1+ clients, the outcome of the two operations is different,
|
|
|
|
* so we must ensure that we upcall for the create operation. v4.1+
|
|
|
|
* clients call this on RECLAIM_COMPLETE though, so we should only end
|
|
|
|
* up doing a single create upcall per client.
|
|
|
|
*/
|
|
|
|
if (clp->cl_minorversion == 0 &&
|
|
|
|
test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
|
|
|
|
return;
|
|
|
|
|
2012-11-13 04:00:48 +08:00
|
|
|
hexid = bin_to_hex_dup(clp->cl_name.data, clp->cl_name.len);
|
|
|
|
if (!hexid) {
|
|
|
|
dprintk("%s: can't allocate memory for upcall!\n", __func__);
|
|
|
|
return;
|
|
|
|
}
|
2014-09-13 04:40:21 +08:00
|
|
|
|
2014-09-13 04:40:21 +08:00
|
|
|
has_session = nfsd4_cltrack_client_has_session(clp);
|
|
|
|
grace_start = nfsd4_cltrack_grace_start(nn->boot_time);
|
2014-09-13 04:40:21 +08:00
|
|
|
|
|
|
|
nfsd4_cltrack_upcall_lock(clp);
|
2014-09-13 04:40:21 +08:00
|
|
|
if (!nfsd4_umh_cltrack_upcall("create", hexid, has_session, grace_start))
|
|
|
|
set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
|
2014-09-13 04:40:21 +08:00
|
|
|
nfsd4_cltrack_upcall_unlock(clp);
|
|
|
|
|
2014-09-13 04:40:21 +08:00
|
|
|
kfree(has_session);
|
|
|
|
kfree(grace_start);
|
2012-11-13 04:00:48 +08:00
|
|
|
kfree(hexid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nfsd4_umh_cltrack_remove(struct nfs4_client *clp)
|
|
|
|
{
|
|
|
|
char *hexid;
|
|
|
|
|
2014-09-13 04:40:21 +08:00
|
|
|
if (!test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
|
|
|
|
return;
|
|
|
|
|
2012-11-13 04:00:48 +08:00
|
|
|
hexid = bin_to_hex_dup(clp->cl_name.data, clp->cl_name.len);
|
|
|
|
if (!hexid) {
|
|
|
|
dprintk("%s: can't allocate memory for upcall!\n", __func__);
|
|
|
|
return;
|
|
|
|
}
|
2014-09-13 04:40:21 +08:00
|
|
|
|
|
|
|
nfsd4_cltrack_upcall_lock(clp);
|
2014-09-13 04:40:21 +08:00
|
|
|
if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags) &&
|
|
|
|
nfsd4_umh_cltrack_upcall("remove", hexid, NULL, NULL) == 0)
|
|
|
|
clear_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
|
2014-09-13 04:40:21 +08:00
|
|
|
nfsd4_cltrack_upcall_unlock(clp);
|
|
|
|
|
2012-11-13 04:00:48 +08:00
|
|
|
kfree(hexid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nfsd4_umh_cltrack_check(struct nfs4_client *clp)
|
|
|
|
{
|
|
|
|
int ret;
|
2014-09-13 04:40:21 +08:00
|
|
|
char *hexid, *has_session, *legacy;
|
2012-11-13 04:00:48 +08:00
|
|
|
|
2014-09-13 04:40:21 +08:00
|
|
|
if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
|
|
|
|
return 0;
|
|
|
|
|
2012-11-13 04:00:48 +08:00
|
|
|
hexid = bin_to_hex_dup(clp->cl_name.data, clp->cl_name.len);
|
|
|
|
if (!hexid) {
|
|
|
|
dprintk("%s: can't allocate memory for upcall!\n", __func__);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2014-09-13 04:40:21 +08:00
|
|
|
|
|
|
|
has_session = nfsd4_cltrack_client_has_session(clp);
|
2012-11-13 04:00:57 +08:00
|
|
|
legacy = nfsd4_cltrack_legacy_recdir(&clp->cl_name);
|
2014-09-13 04:40:21 +08:00
|
|
|
|
|
|
|
nfsd4_cltrack_upcall_lock(clp);
|
2014-09-13 04:40:21 +08:00
|
|
|
if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags)) {
|
|
|
|
ret = 0;
|
|
|
|
} else {
|
|
|
|
ret = nfsd4_umh_cltrack_upcall("check", hexid, has_session, legacy);
|
|
|
|
if (ret == 0)
|
|
|
|
set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
|
|
|
|
}
|
2014-09-13 04:40:21 +08:00
|
|
|
nfsd4_cltrack_upcall_unlock(clp);
|
2014-09-13 04:40:21 +08:00
|
|
|
kfree(has_session);
|
2012-11-13 04:00:50 +08:00
|
|
|
kfree(legacy);
|
2012-11-13 04:00:48 +08:00
|
|
|
kfree(hexid);
|
2014-09-13 04:40:21 +08:00
|
|
|
|
2012-11-13 04:00:48 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-09-13 04:40:20 +08:00
|
|
|
nfsd4_umh_cltrack_grace_done(struct nfsd_net *nn)
|
2012-11-13 04:00:48 +08:00
|
|
|
{
|
2012-11-13 04:00:50 +08:00
|
|
|
char *legacy;
|
2012-11-13 04:00:48 +08:00
|
|
|
char timestr[22]; /* FIXME: better way to determine max size? */
|
|
|
|
|
2019-10-31 22:53:13 +08:00
|
|
|
sprintf(timestr, "%lld", nn->boot_time);
|
2012-11-13 04:00:50 +08:00
|
|
|
legacy = nfsd4_cltrack_legacy_topdir();
|
2014-09-13 04:40:21 +08:00
|
|
|
nfsd4_umh_cltrack_upcall("gracedone", timestr, legacy, NULL);
|
2012-11-13 04:00:50 +08:00
|
|
|
kfree(legacy);
|
2012-11-13 04:00:48 +08:00
|
|
|
}
|
|
|
|
|
2015-11-22 15:22:10 +08:00
|
|
|
static const struct nfsd4_client_tracking_ops nfsd4_umh_tracking_ops = {
|
2012-11-13 04:00:48 +08:00
|
|
|
.init = nfsd4_umh_cltrack_init,
|
|
|
|
.exit = NULL,
|
|
|
|
.create = nfsd4_umh_cltrack_create,
|
|
|
|
.remove = nfsd4_umh_cltrack_remove,
|
|
|
|
.check = nfsd4_umh_cltrack_check,
|
|
|
|
.grace_done = nfsd4_umh_cltrack_grace_done,
|
2019-09-10 04:10:30 +08:00
|
|
|
.version = 1,
|
|
|
|
.msglen = 0,
|
2012-11-13 04:00:48 +08:00
|
|
|
};
|
|
|
|
|
2012-03-22 04:42:43 +08:00
|
|
|
int
|
|
|
|
nfsd4_client_tracking_init(struct net *net)
|
|
|
|
{
|
|
|
|
int status;
|
2012-03-21 21:52:07 +08:00
|
|
|
struct path path;
|
2012-12-04 19:29:27 +08:00
|
|
|
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
|
2012-03-22 04:42:43 +08:00
|
|
|
|
2012-11-13 04:00:49 +08:00
|
|
|
/* just run the init if it the method is already decided */
|
2012-12-04 19:29:27 +08:00
|
|
|
if (nn->client_tracking_ops)
|
2012-11-13 04:00:49 +08:00
|
|
|
goto do_init;
|
|
|
|
|
2019-03-27 06:06:29 +08:00
|
|
|
/* First, try to use nfsdcld */
|
|
|
|
nn->client_tracking_ops = &nfsd4_cld_tracking_ops;
|
|
|
|
status = nn->client_tracking_ops->init(net);
|
|
|
|
if (!status)
|
|
|
|
return status;
|
|
|
|
if (status != -ETIMEDOUT) {
|
|
|
|
nn->client_tracking_ops = &nfsd4_cld_tracking_ops_v0;
|
|
|
|
status = nn->client_tracking_ops->init(net);
|
|
|
|
if (!status)
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2012-11-13 04:00:49 +08:00
|
|
|
/*
|
2019-03-27 06:06:29 +08:00
|
|
|
* Next, try the UMH upcall.
|
2012-11-13 04:00:49 +08:00
|
|
|
*/
|
2012-12-04 19:29:27 +08:00
|
|
|
nn->client_tracking_ops = &nfsd4_umh_tracking_ops;
|
|
|
|
status = nn->client_tracking_ops->init(net);
|
2012-11-13 04:00:49 +08:00
|
|
|
if (!status)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
/*
|
2019-03-27 06:06:29 +08:00
|
|
|
* Finally, See if the recoverydir exists and is a directory.
|
|
|
|
* If it is, then use the legacy ops.
|
2012-11-13 04:00:49 +08:00
|
|
|
*/
|
2012-12-04 19:29:27 +08:00
|
|
|
nn->client_tracking_ops = &nfsd4_legacy_tracking_ops;
|
2012-11-13 04:00:49 +08:00
|
|
|
status = kern_path(nfs4_recoverydir(), LOOKUP_FOLLOW, &path);
|
|
|
|
if (!status) {
|
VFS: (Scripted) Convert S_ISLNK/DIR/REG(dentry->d_inode) to d_is_*(dentry)
Convert the following where appropriate:
(1) S_ISLNK(dentry->d_inode) to d_is_symlink(dentry).
(2) S_ISREG(dentry->d_inode) to d_is_reg(dentry).
(3) S_ISDIR(dentry->d_inode) to d_is_dir(dentry). This is actually more
complicated than it appears as some calls should be converted to
d_can_lookup() instead. The difference is whether the directory in
question is a real dir with a ->lookup op or whether it's a fake dir with
a ->d_automount op.
In some circumstances, we can subsume checks for dentry->d_inode not being
NULL into this, provided we the code isn't in a filesystem that expects
d_inode to be NULL if the dirent really *is* negative (ie. if we're going to
use d_inode() rather than d_backing_inode() to get the inode pointer).
Note that the dentry type field may be set to something other than
DCACHE_MISS_TYPE when d_inode is NULL in the case of unionmount, where the VFS
manages the fall-through from a negative dentry to a lower layer. In such a
case, the dentry type of the negative union dentry is set to the same as the
type of the lower dentry.
However, if you know d_inode is not NULL at the call site, then you can use
the d_is_xxx() functions even in a filesystem.
There is one further complication: a 0,0 chardev dentry may be labelled
DCACHE_WHITEOUT_TYPE rather than DCACHE_SPECIAL_TYPE. Strictly, this was
intended for special directory entry types that don't have attached inodes.
The following perl+coccinelle script was used:
use strict;
my @callers;
open($fd, 'git grep -l \'S_IS[A-Z].*->d_inode\' |') ||
die "Can't grep for S_ISDIR and co. callers";
@callers = <$fd>;
close($fd);
unless (@callers) {
print "No matches\n";
exit(0);
}
my @cocci = (
'@@',
'expression E;',
'@@',
'',
'- S_ISLNK(E->d_inode->i_mode)',
'+ d_is_symlink(E)',
'',
'@@',
'expression E;',
'@@',
'',
'- S_ISDIR(E->d_inode->i_mode)',
'+ d_is_dir(E)',
'',
'@@',
'expression E;',
'@@',
'',
'- S_ISREG(E->d_inode->i_mode)',
'+ d_is_reg(E)' );
my $coccifile = "tmp.sp.cocci";
open($fd, ">$coccifile") || die $coccifile;
print($fd "$_\n") || die $coccifile foreach (@cocci);
close($fd);
foreach my $file (@callers) {
chomp $file;
print "Processing ", $file, "\n";
system("spatch", "--sp-file", $coccifile, $file, "--in-place", "--no-show-diff") == 0 ||
die "spatch failed";
}
[AV: overlayfs parts skipped]
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2015-01-29 20:02:35 +08:00
|
|
|
status = d_is_dir(path.dentry);
|
2012-11-13 04:00:49 +08:00
|
|
|
path_put(&path);
|
2019-03-27 06:06:29 +08:00
|
|
|
if (!status) {
|
|
|
|
status = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2012-03-21 21:52:07 +08:00
|
|
|
}
|
2012-03-22 04:42:43 +08:00
|
|
|
|
2012-11-13 04:00:49 +08:00
|
|
|
do_init:
|
2012-12-04 19:29:27 +08:00
|
|
|
status = nn->client_tracking_ops->init(net);
|
2019-03-27 06:06:29 +08:00
|
|
|
out:
|
2012-03-22 04:42:43 +08:00
|
|
|
if (status) {
|
|
|
|
printk(KERN_WARNING "NFSD: Unable to initialize client "
|
|
|
|
"recovery tracking! (%d)\n", status);
|
2012-12-04 19:29:27 +08:00
|
|
|
nn->client_tracking_ops = NULL;
|
2012-03-22 04:42:43 +08:00
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nfsd4_client_tracking_exit(struct net *net)
|
|
|
|
{
|
2012-12-04 19:29:27 +08:00
|
|
|
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
|
|
|
|
|
|
|
|
if (nn->client_tracking_ops) {
|
|
|
|
if (nn->client_tracking_ops->exit)
|
|
|
|
nn->client_tracking_ops->exit(net);
|
|
|
|
nn->client_tracking_ops = NULL;
|
2012-03-22 04:42:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nfsd4_client_record_create(struct nfs4_client *clp)
|
|
|
|
{
|
2012-12-04 19:29:27 +08:00
|
|
|
struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
|
|
|
|
|
|
|
|
if (nn->client_tracking_ops)
|
|
|
|
nn->client_tracking_ops->create(clp);
|
2012-03-22 04:42:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nfsd4_client_record_remove(struct nfs4_client *clp)
|
|
|
|
{
|
2012-12-04 19:29:27 +08:00
|
|
|
struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
|
|
|
|
|
|
|
|
if (nn->client_tracking_ops)
|
|
|
|
nn->client_tracking_ops->remove(clp);
|
2012-03-22 04:42:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nfsd4_client_record_check(struct nfs4_client *clp)
|
|
|
|
{
|
2012-12-04 19:29:27 +08:00
|
|
|
struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
|
|
|
|
|
|
|
|
if (nn->client_tracking_ops)
|
|
|
|
return nn->client_tracking_ops->check(clp);
|
2012-03-22 04:42:43 +08:00
|
|
|
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-13 04:40:20 +08:00
|
|
|
nfsd4_record_grace_done(struct nfsd_net *nn)
|
2012-03-22 04:42:43 +08:00
|
|
|
{
|
2012-12-04 19:29:27 +08:00
|
|
|
if (nn->client_tracking_ops)
|
2014-09-13 04:40:20 +08:00
|
|
|
nn->client_tracking_ops->grace_done(nn);
|
2012-03-22 04:42:43 +08:00
|
|
|
}
|
2012-03-21 21:52:08 +08:00
|
|
|
|
|
|
|
static int
|
|
|
|
rpc_pipefs_event(struct notifier_block *nb, unsigned long event, void *ptr)
|
|
|
|
{
|
|
|
|
struct super_block *sb = ptr;
|
|
|
|
struct net *net = sb->s_fs_info;
|
|
|
|
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
|
|
|
|
struct cld_net *cn = nn->cld_net;
|
|
|
|
struct dentry *dentry;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (!try_module_get(THIS_MODULE))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!cn) {
|
|
|
|
module_put(THIS_MODULE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
case RPC_PIPEFS_MOUNT:
|
|
|
|
dentry = nfsd4_cld_register_sb(sb, cn->cn_pipe);
|
|
|
|
if (IS_ERR(dentry)) {
|
|
|
|
ret = PTR_ERR(dentry);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cn->cn_pipe->dentry = dentry;
|
|
|
|
break;
|
|
|
|
case RPC_PIPEFS_UMOUNT:
|
|
|
|
if (cn->cn_pipe->dentry)
|
|
|
|
nfsd4_cld_unregister_sb(cn->cn_pipe);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -ENOTSUPP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
module_put(THIS_MODULE);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-04-26 04:56:22 +08:00
|
|
|
static struct notifier_block nfsd4_cld_block = {
|
2012-03-21 21:52:08 +08:00
|
|
|
.notifier_call = rpc_pipefs_event,
|
|
|
|
};
|
2012-03-29 19:52:49 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
register_cld_notifier(void)
|
|
|
|
{
|
|
|
|
return rpc_pipefs_notifier_register(&nfsd4_cld_block);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
unregister_cld_notifier(void)
|
|
|
|
{
|
|
|
|
rpc_pipefs_notifier_unregister(&nfsd4_cld_block);
|
|
|
|
}
|