2005-04-29 23:23:29 +08:00
|
|
|
/* audit.h -- Auditing support
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Copyright 2003-2004 Red Hat Inc., Durham, North Carolina.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* Written by Rickard E. (Rik) Faith <faith@redhat.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#ifndef _LINUX_AUDIT_H_
|
|
|
|
#define _LINUX_AUDIT_H_
|
|
|
|
|
2006-04-27 07:11:01 +08:00
|
|
|
#include <linux/sched.h>
|
2013-01-12 06:32:13 +08:00
|
|
|
#include <linux/ptrace.h>
|
2012-10-13 17:46:48 +08:00
|
|
|
#include <uapi/linux/audit.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-05-06 19:38:39 +08:00
|
|
|
struct audit_sig_info {
|
|
|
|
uid_t uid;
|
|
|
|
pid_t pid;
|
2006-05-25 22:19:47 +08:00
|
|
|
char ctx[0];
|
2005-05-06 19:38:39 +08:00
|
|
|
};
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
struct audit_buffer;
|
|
|
|
struct audit_context;
|
|
|
|
struct inode;
|
2005-06-24 21:14:05 +08:00
|
|
|
struct netlink_skb_parms;
|
2011-01-10 14:17:10 +08:00
|
|
|
struct path;
|
2006-04-27 02:04:08 +08:00
|
|
|
struct linux_binprm;
|
2006-05-25 05:09:55 +08:00
|
|
|
struct mq_attr;
|
|
|
|
struct mqstat;
|
2008-03-02 04:03:14 +08:00
|
|
|
struct audit_watch;
|
|
|
|
struct audit_tree;
|
|
|
|
|
|
|
|
struct audit_krule {
|
|
|
|
int vers_ops;
|
|
|
|
u32 flags;
|
|
|
|
u32 listnr;
|
|
|
|
u32 action;
|
|
|
|
u32 mask[AUDIT_BITMASK_SIZE];
|
|
|
|
u32 buflen; /* for data alloc on list rules */
|
|
|
|
u32 field_count;
|
|
|
|
char *filterkey; /* ties events to rules */
|
|
|
|
struct audit_field *fields;
|
|
|
|
struct audit_field *arch_f; /* quick access to arch field */
|
|
|
|
struct audit_field *inode_f; /* quick access to an inode field */
|
|
|
|
struct audit_watch *watch; /* associated watch */
|
|
|
|
struct audit_tree *tree; /* associated watched tree */
|
|
|
|
struct list_head rlist; /* entry in audit_{watch,tree}.rules list */
|
2008-12-15 14:17:50 +08:00
|
|
|
struct list_head list; /* for AUDIT_LIST* purposes only */
|
2008-12-15 12:45:27 +08:00
|
|
|
u64 prio;
|
2008-03-02 04:03:14 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct audit_field {
|
|
|
|
u32 type;
|
|
|
|
u32 val;
|
2012-09-11 17:18:08 +08:00
|
|
|
kuid_t uid;
|
|
|
|
kgid_t gid;
|
2008-03-02 04:03:14 +08:00
|
|
|
u32 op;
|
2008-04-19 07:59:43 +08:00
|
|
|
char *lsm_str;
|
|
|
|
void *lsm_rule;
|
2008-03-02 04:03:14 +08:00
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-05-23 00:54:49 +08:00
|
|
|
extern int is_audit_feature_set(int which);
|
|
|
|
|
2006-07-01 15:56:16 +08:00
|
|
|
extern int __init audit_register_class(int class, unsigned *list);
|
2006-09-01 07:26:40 +08:00
|
|
|
extern int audit_classify_syscall(int abi, unsigned syscall);
|
2007-03-30 06:01:04 +08:00
|
|
|
extern int audit_classify_arch(int arch);
|
2012-10-11 03:25:22 +08:00
|
|
|
|
|
|
|
/* audit_names->type values */
|
|
|
|
#define AUDIT_TYPE_UNKNOWN 0 /* we don't know yet */
|
|
|
|
#define AUDIT_TYPE_NORMAL 1 /* a "normal" audit record */
|
2012-10-11 03:25:23 +08:00
|
|
|
#define AUDIT_TYPE_PARENT 2 /* a parent audit record */
|
2012-10-11 03:25:25 +08:00
|
|
|
#define AUDIT_TYPE_CHILD_DELETE 3 /* a child being deleted */
|
|
|
|
#define AUDIT_TYPE_CHILD_CREATE 4 /* a child being created */
|
2012-10-11 03:25:22 +08:00
|
|
|
|
2013-04-07 16:55:23 +08:00
|
|
|
/* maximized args number that audit_socketcall can process */
|
|
|
|
#define AUDITSC_ARGS 6
|
|
|
|
|
2012-10-11 03:25:28 +08:00
|
|
|
struct filename;
|
|
|
|
|
2013-04-30 21:53:34 +08:00
|
|
|
extern void audit_log_session_info(struct audit_buffer *ab);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef CONFIG_AUDITSYSCALL
|
|
|
|
/* These are defined in auditsc.c */
|
|
|
|
/* Public API */
|
|
|
|
extern int audit_alloc(struct task_struct *task);
|
2012-01-04 03:23:07 +08:00
|
|
|
extern void __audit_free(struct task_struct *task);
|
2012-01-04 03:23:06 +08:00
|
|
|
extern void __audit_syscall_entry(int arch,
|
|
|
|
int major, unsigned long a0, unsigned long a1,
|
|
|
|
unsigned long a2, unsigned long a3);
|
2012-01-04 03:23:06 +08:00
|
|
|
extern void __audit_syscall_exit(int ret_success, long ret_value);
|
2012-10-11 03:25:28 +08:00
|
|
|
extern struct filename *__audit_reusename(const __user char *uptr);
|
2012-10-11 03:25:28 +08:00
|
|
|
extern void __audit_getname(struct filename *name);
|
|
|
|
extern void audit_putname(struct filename *name);
|
2013-07-09 06:59:36 +08:00
|
|
|
|
|
|
|
#define AUDIT_INODE_PARENT 1 /* dentry represents the parent */
|
|
|
|
#define AUDIT_INODE_HIDDEN 2 /* audit record should be hidden */
|
2012-10-11 04:43:13 +08:00
|
|
|
extern void __audit_inode(struct filename *name, const struct dentry *dentry,
|
2013-07-09 06:59:36 +08:00
|
|
|
unsigned int flags);
|
2012-10-11 03:25:21 +08:00
|
|
|
extern void __audit_inode_child(const struct inode *parent,
|
2012-10-11 03:25:25 +08:00
|
|
|
const struct dentry *dentry,
|
|
|
|
const unsigned char type);
|
2012-04-13 05:47:58 +08:00
|
|
|
extern void __audit_seccomp(unsigned long syscall, long signr, int code);
|
2007-03-21 01:58:35 +08:00
|
|
|
extern void __audit_ptrace(struct task_struct *t);
|
|
|
|
|
2006-08-03 22:59:26 +08:00
|
|
|
static inline int audit_dummy_context(void)
|
|
|
|
{
|
|
|
|
void *p = current->audit_context;
|
|
|
|
return !p || *(int *)p;
|
|
|
|
}
|
2012-01-04 03:23:07 +08:00
|
|
|
static inline void audit_free(struct task_struct *task)
|
|
|
|
{
|
|
|
|
if (unlikely(task->audit_context))
|
|
|
|
__audit_free(task);
|
|
|
|
}
|
2012-01-04 03:23:06 +08:00
|
|
|
static inline void audit_syscall_entry(int arch, int major, unsigned long a0,
|
|
|
|
unsigned long a1, unsigned long a2,
|
|
|
|
unsigned long a3)
|
|
|
|
{
|
2013-01-09 07:46:17 +08:00
|
|
|
if (unlikely(current->audit_context))
|
2012-01-04 03:23:06 +08:00
|
|
|
__audit_syscall_entry(arch, major, a0, a1, a2, a3);
|
|
|
|
}
|
2012-01-04 03:23:06 +08:00
|
|
|
static inline void audit_syscall_exit(void *pt_regs)
|
|
|
|
{
|
|
|
|
if (unlikely(current->audit_context)) {
|
|
|
|
int success = is_syscall_success(pt_regs);
|
2014-01-14 05:33:09 +08:00
|
|
|
long return_code = regs_return_value(pt_regs);
|
2012-01-04 03:23:06 +08:00
|
|
|
|
|
|
|
__audit_syscall_exit(success, return_code);
|
|
|
|
}
|
|
|
|
}
|
2012-10-11 03:25:28 +08:00
|
|
|
static inline struct filename *audit_reusename(const __user char *name)
|
|
|
|
{
|
|
|
|
if (unlikely(!audit_dummy_context()))
|
|
|
|
return __audit_reusename(name);
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-10-11 03:25:28 +08:00
|
|
|
static inline void audit_getname(struct filename *name)
|
2006-05-19 04:01:30 +08:00
|
|
|
{
|
2006-07-16 18:38:45 +08:00
|
|
|
if (unlikely(!audit_dummy_context()))
|
2006-05-19 04:01:30 +08:00
|
|
|
__audit_getname(name);
|
|
|
|
}
|
2013-07-09 06:59:36 +08:00
|
|
|
static inline void audit_inode(struct filename *name,
|
|
|
|
const struct dentry *dentry,
|
2012-10-11 03:25:23 +08:00
|
|
|
unsigned int parent) {
|
2013-07-09 06:59:36 +08:00
|
|
|
if (unlikely(!audit_dummy_context())) {
|
|
|
|
unsigned int flags = 0;
|
|
|
|
if (parent)
|
|
|
|
flags |= AUDIT_INODE_PARENT;
|
|
|
|
__audit_inode(name, dentry, flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static inline void audit_inode_parent_hidden(struct filename *name,
|
|
|
|
const struct dentry *dentry)
|
|
|
|
{
|
2006-07-16 18:38:45 +08:00
|
|
|
if (unlikely(!audit_dummy_context()))
|
2013-07-09 06:59:36 +08:00
|
|
|
__audit_inode(name, dentry,
|
|
|
|
AUDIT_INODE_PARENT | AUDIT_INODE_HIDDEN);
|
2005-11-04 00:00:25 +08:00
|
|
|
}
|
2012-10-11 03:25:21 +08:00
|
|
|
static inline void audit_inode_child(const struct inode *parent,
|
2012-10-11 03:25:25 +08:00
|
|
|
const struct dentry *dentry,
|
|
|
|
const unsigned char type) {
|
2006-07-16 18:38:45 +08:00
|
|
|
if (unlikely(!audit_dummy_context()))
|
2012-10-11 03:25:25 +08:00
|
|
|
__audit_inode_child(parent, dentry, type);
|
2005-11-04 00:00:25 +08:00
|
|
|
}
|
2007-04-19 22:28:21 +08:00
|
|
|
void audit_core_dumps(long signr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-04-13 05:47:58 +08:00
|
|
|
static inline void audit_seccomp(unsigned long syscall, long signr, int code)
|
2012-01-04 03:23:05 +08:00
|
|
|
{
|
2013-01-12 06:32:05 +08:00
|
|
|
/* Force a record to be reported if a signal was delivered. */
|
|
|
|
if (signr || unlikely(!audit_dummy_context()))
|
2012-04-13 05:47:58 +08:00
|
|
|
__audit_seccomp(syscall, signr, code);
|
2012-01-04 03:23:05 +08:00
|
|
|
}
|
|
|
|
|
2007-03-21 01:58:35 +08:00
|
|
|
static inline void audit_ptrace(struct task_struct *t)
|
|
|
|
{
|
|
|
|
if (unlikely(!audit_dummy_context()))
|
|
|
|
__audit_ptrace(t);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Private API (for audit.c only) */
|
2005-05-22 04:08:09 +08:00
|
|
|
extern unsigned int audit_serial(void);
|
2008-12-06 14:05:50 +08:00
|
|
|
extern int auditsc_get_stamp(struct audit_context *ctx,
|
2005-05-22 04:08:09 +08:00
|
|
|
struct timespec *t, unsigned int *serial);
|
2012-10-05 08:11:11 +08:00
|
|
|
extern int audit_set_loginuid(kuid_t loginuid);
|
|
|
|
|
|
|
|
static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
|
|
|
|
{
|
|
|
|
return tsk->loginuid;
|
|
|
|
}
|
|
|
|
|
2013-11-27 07:01:36 +08:00
|
|
|
static inline unsigned int audit_get_sessionid(struct task_struct *tsk)
|
2012-10-05 08:11:11 +08:00
|
|
|
{
|
|
|
|
return tsk->sessionid;
|
|
|
|
}
|
|
|
|
|
2008-12-10 16:40:06 +08:00
|
|
|
extern void __audit_ipc_obj(struct kern_ipc_perm *ipcp);
|
2011-07-28 02:03:22 +08:00
|
|
|
extern void __audit_ipc_set_perm(unsigned long qbytes, uid_t uid, gid_t gid, umode_t mode);
|
2013-10-31 05:56:13 +08:00
|
|
|
extern void __audit_bprm(struct linux_binprm *bprm);
|
2013-04-07 16:55:23 +08:00
|
|
|
extern int __audit_socketcall(int nargs, unsigned long *args);
|
2012-01-04 03:23:07 +08:00
|
|
|
extern int __audit_sockaddr(int len, void *addr);
|
2008-12-14 17:57:47 +08:00
|
|
|
extern void __audit_fd_pair(int fd1, int fd2);
|
2011-07-26 17:26:10 +08:00
|
|
|
extern void __audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr);
|
2008-12-14 16:46:48 +08:00
|
|
|
extern void __audit_mq_sendrecv(mqd_t mqdes, size_t msg_len, unsigned int msg_prio, const struct timespec *abs_timeout);
|
2008-12-10 20:16:12 +08:00
|
|
|
extern void __audit_mq_notify(mqd_t mqdes, const struct sigevent *notification);
|
2008-12-10 19:58:59 +08:00
|
|
|
extern void __audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat);
|
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
|
|
|
extern int __audit_log_bprm_fcaps(struct linux_binprm *bprm,
|
|
|
|
const struct cred *new,
|
|
|
|
const struct cred *old);
|
2013-03-19 15:02:25 +08:00
|
|
|
extern void __audit_log_capset(const struct cred *new, const struct cred *old);
|
2010-10-30 14:54:44 +08:00
|
|
|
extern void __audit_mmap_fd(int fd, int flags);
|
2006-05-19 04:01:30 +08:00
|
|
|
|
2008-12-10 16:40:06 +08:00
|
|
|
static inline void audit_ipc_obj(struct kern_ipc_perm *ipcp)
|
2006-05-19 04:01:30 +08:00
|
|
|
{
|
2006-07-16 18:38:45 +08:00
|
|
|
if (unlikely(!audit_dummy_context()))
|
2008-12-10 16:40:06 +08:00
|
|
|
__audit_ipc_obj(ipcp);
|
2007-02-07 14:48:00 +08:00
|
|
|
}
|
2008-12-14 17:57:47 +08:00
|
|
|
static inline void audit_fd_pair(int fd1, int fd2)
|
2006-05-19 04:01:30 +08:00
|
|
|
{
|
2006-07-16 18:38:45 +08:00
|
|
|
if (unlikely(!audit_dummy_context()))
|
2008-12-14 17:57:47 +08:00
|
|
|
__audit_fd_pair(fd1, fd2);
|
2006-05-19 04:01:30 +08:00
|
|
|
}
|
2011-07-28 02:03:22 +08:00
|
|
|
static inline void audit_ipc_set_perm(unsigned long qbytes, uid_t uid, gid_t gid, umode_t mode)
|
2006-05-25 05:09:55 +08:00
|
|
|
{
|
2006-07-16 18:38:45 +08:00
|
|
|
if (unlikely(!audit_dummy_context()))
|
2008-12-10 16:47:15 +08:00
|
|
|
__audit_ipc_set_perm(qbytes, uid, gid, mode);
|
2006-05-25 05:09:55 +08:00
|
|
|
}
|
2013-10-31 06:05:24 +08:00
|
|
|
static inline void audit_bprm(struct linux_binprm *bprm)
|
2012-01-04 03:23:07 +08:00
|
|
|
{
|
|
|
|
if (unlikely(!audit_dummy_context()))
|
2013-10-31 05:56:13 +08:00
|
|
|
__audit_bprm(bprm);
|
2012-01-04 03:23:07 +08:00
|
|
|
}
|
2013-04-07 16:55:23 +08:00
|
|
|
static inline int audit_socketcall(int nargs, unsigned long *args)
|
2012-01-04 03:23:07 +08:00
|
|
|
{
|
|
|
|
if (unlikely(!audit_dummy_context()))
|
2013-04-07 16:55:23 +08:00
|
|
|
return __audit_socketcall(nargs, args);
|
|
|
|
return 0;
|
2012-01-04 03:23:07 +08:00
|
|
|
}
|
|
|
|
static inline int audit_sockaddr(int len, void *addr)
|
|
|
|
{
|
|
|
|
if (unlikely(!audit_dummy_context()))
|
|
|
|
return __audit_sockaddr(len, addr);
|
|
|
|
return 0;
|
|
|
|
}
|
2011-07-26 17:26:10 +08:00
|
|
|
static inline void audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr)
|
2006-05-25 05:09:55 +08:00
|
|
|
{
|
2006-07-16 18:38:45 +08:00
|
|
|
if (unlikely(!audit_dummy_context()))
|
2008-12-14 17:02:26 +08:00
|
|
|
__audit_mq_open(oflag, mode, attr);
|
2006-05-25 05:09:55 +08:00
|
|
|
}
|
2008-12-14 16:46:48 +08:00
|
|
|
static inline void audit_mq_sendrecv(mqd_t mqdes, size_t msg_len, unsigned int msg_prio, const struct timespec *abs_timeout)
|
2006-05-25 05:09:55 +08:00
|
|
|
{
|
2006-07-16 18:38:45 +08:00
|
|
|
if (unlikely(!audit_dummy_context()))
|
2008-12-14 16:46:48 +08:00
|
|
|
__audit_mq_sendrecv(mqdes, msg_len, msg_prio, abs_timeout);
|
2006-05-25 05:09:55 +08:00
|
|
|
}
|
2008-12-10 20:16:12 +08:00
|
|
|
static inline void audit_mq_notify(mqd_t mqdes, const struct sigevent *notification)
|
2006-05-25 05:09:55 +08:00
|
|
|
{
|
2006-07-16 18:38:45 +08:00
|
|
|
if (unlikely(!audit_dummy_context()))
|
2008-12-10 20:16:12 +08:00
|
|
|
__audit_mq_notify(mqdes, notification);
|
2006-05-25 05:09:55 +08:00
|
|
|
}
|
2008-12-10 19:58:59 +08:00
|
|
|
static inline void audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat)
|
2006-05-25 05:09:55 +08:00
|
|
|
{
|
2006-07-16 18:38:45 +08:00
|
|
|
if (unlikely(!audit_dummy_context()))
|
2008-12-10 19:58:59 +08:00
|
|
|
__audit_mq_getsetattr(mqdes, mqstat);
|
2006-05-25 05:09:55 +08:00
|
|
|
}
|
2008-11-11 18:48:18 +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 inline int audit_log_bprm_fcaps(struct linux_binprm *bprm,
|
|
|
|
const struct cred *new,
|
|
|
|
const struct cred *old)
|
2008-11-11 18:48:18 +08:00
|
|
|
{
|
|
|
|
if (unlikely(!audit_dummy_context()))
|
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
|
|
|
return __audit_log_bprm_fcaps(bprm, new, old);
|
|
|
|
return 0;
|
2008-11-11 18:48:18 +08:00
|
|
|
}
|
|
|
|
|
2013-03-19 15:02:25 +08:00
|
|
|
static inline void audit_log_capset(const struct cred *new,
|
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 *old)
|
2008-11-11 18:48:22 +08:00
|
|
|
{
|
|
|
|
if (unlikely(!audit_dummy_context()))
|
2013-03-19 15:02:25 +08:00
|
|
|
__audit_log_capset(new, old);
|
2008-11-11 18:48:22 +08:00
|
|
|
}
|
|
|
|
|
2010-10-30 14:54:44 +08:00
|
|
|
static inline void audit_mmap_fd(int fd, int flags)
|
|
|
|
{
|
|
|
|
if (unlikely(!audit_dummy_context()))
|
|
|
|
__audit_mmap_fd(fd, flags);
|
|
|
|
}
|
|
|
|
|
2006-07-10 20:29:24 +08:00
|
|
|
extern int audit_n_rules;
|
2007-03-30 06:01:04 +08:00
|
|
|
extern int audit_signals;
|
2012-01-04 03:23:06 +08:00
|
|
|
#else /* CONFIG_AUDITSYSCALL */
|
2012-10-05 08:11:11 +08:00
|
|
|
static inline int audit_alloc(struct task_struct *task)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
static inline void audit_free(struct task_struct *task)
|
|
|
|
{ }
|
|
|
|
static inline void audit_syscall_entry(int arch, int major, unsigned long a0,
|
|
|
|
unsigned long a1, unsigned long a2,
|
|
|
|
unsigned long a3)
|
|
|
|
{ }
|
|
|
|
static inline void audit_syscall_exit(void *pt_regs)
|
|
|
|
{ }
|
|
|
|
static inline int audit_dummy_context(void)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2012-10-11 03:25:28 +08:00
|
|
|
static inline struct filename *audit_reusename(const __user char *name)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-10-11 03:25:28 +08:00
|
|
|
static inline void audit_getname(struct filename *name)
|
2012-10-05 08:11:11 +08:00
|
|
|
{ }
|
2012-10-11 03:25:28 +08:00
|
|
|
static inline void audit_putname(struct filename *name)
|
2012-10-05 08:11:11 +08:00
|
|
|
{ }
|
2012-10-11 04:43:13 +08:00
|
|
|
static inline void __audit_inode(struct filename *name,
|
|
|
|
const struct dentry *dentry,
|
2013-07-09 06:59:36 +08:00
|
|
|
unsigned int flags)
|
2012-10-05 08:11:11 +08:00
|
|
|
{ }
|
2012-10-11 03:25:21 +08:00
|
|
|
static inline void __audit_inode_child(const struct inode *parent,
|
2012-10-11 03:25:25 +08:00
|
|
|
const struct dentry *dentry,
|
|
|
|
const unsigned char type)
|
2012-10-05 08:11:11 +08:00
|
|
|
{ }
|
2012-10-11 04:43:13 +08:00
|
|
|
static inline void audit_inode(struct filename *name,
|
|
|
|
const struct dentry *dentry,
|
2012-10-11 03:25:23 +08:00
|
|
|
unsigned int parent)
|
2012-10-05 08:11:11 +08:00
|
|
|
{ }
|
2013-07-09 06:59:36 +08:00
|
|
|
static inline void audit_inode_parent_hidden(struct filename *name,
|
|
|
|
const struct dentry *dentry)
|
|
|
|
{ }
|
2012-10-11 03:25:21 +08:00
|
|
|
static inline void audit_inode_child(const struct inode *parent,
|
2012-10-11 03:25:25 +08:00
|
|
|
const struct dentry *dentry,
|
|
|
|
const unsigned char type)
|
2012-10-05 08:11:11 +08:00
|
|
|
{ }
|
|
|
|
static inline void audit_core_dumps(long signr)
|
|
|
|
{ }
|
|
|
|
static inline void __audit_seccomp(unsigned long syscall, long signr, int code)
|
|
|
|
{ }
|
|
|
|
static inline void audit_seccomp(unsigned long syscall, long signr, int code)
|
|
|
|
{ }
|
|
|
|
static inline int auditsc_get_stamp(struct audit_context *ctx,
|
|
|
|
struct timespec *t, unsigned int *serial)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
|
|
|
|
{
|
|
|
|
return INVALID_UID;
|
|
|
|
}
|
2013-11-27 07:01:36 +08:00
|
|
|
static inline unsigned int audit_get_sessionid(struct task_struct *tsk)
|
2012-10-05 08:11:11 +08:00
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
static inline void audit_ipc_obj(struct kern_ipc_perm *ipcp)
|
|
|
|
{ }
|
|
|
|
static inline void audit_ipc_set_perm(unsigned long qbytes, uid_t uid,
|
|
|
|
gid_t gid, umode_t mode)
|
|
|
|
{ }
|
2013-10-31 06:05:24 +08:00
|
|
|
static inline void audit_bprm(struct linux_binprm *bprm)
|
|
|
|
{ }
|
2013-04-07 16:55:23 +08:00
|
|
|
static inline int audit_socketcall(int nargs, unsigned long *args)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2012-10-05 08:11:11 +08:00
|
|
|
static inline void audit_fd_pair(int fd1, int fd2)
|
|
|
|
{ }
|
|
|
|
static inline int audit_sockaddr(int len, void *addr)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
static inline void audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr)
|
|
|
|
{ }
|
|
|
|
static inline void audit_mq_sendrecv(mqd_t mqdes, size_t msg_len,
|
|
|
|
unsigned int msg_prio,
|
|
|
|
const struct timespec *abs_timeout)
|
|
|
|
{ }
|
|
|
|
static inline void audit_mq_notify(mqd_t mqdes,
|
|
|
|
const struct sigevent *notification)
|
|
|
|
{ }
|
|
|
|
static inline void audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat)
|
|
|
|
{ }
|
|
|
|
static inline int audit_log_bprm_fcaps(struct linux_binprm *bprm,
|
|
|
|
const struct cred *new,
|
|
|
|
const struct cred *old)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2013-03-19 15:02:25 +08:00
|
|
|
static inline void audit_log_capset(const struct cred *new,
|
|
|
|
const struct cred *old)
|
2012-10-05 08:11:11 +08:00
|
|
|
{ }
|
|
|
|
static inline void audit_mmap_fd(int fd, int flags)
|
|
|
|
{ }
|
|
|
|
static inline void audit_ptrace(struct task_struct *t)
|
|
|
|
{ }
|
2006-07-10 20:29:24 +08:00
|
|
|
#define audit_n_rules 0
|
2007-03-30 06:01:04 +08:00
|
|
|
#define audit_signals 0
|
2012-01-04 03:23:06 +08:00
|
|
|
#endif /* CONFIG_AUDITSYSCALL */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-04-09 17:22:10 +08:00
|
|
|
static inline bool audit_loginuid_set(struct task_struct *tsk)
|
|
|
|
{
|
|
|
|
return uid_valid(audit_get_loginuid(tsk));
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef CONFIG_AUDIT
|
|
|
|
/* These are defined in audit.c */
|
|
|
|
/* Public API */
|
2011-11-01 08:11:33 +08:00
|
|
|
extern __printf(4, 5)
|
|
|
|
void audit_log(struct audit_context *ctx, gfp_t gfp_mask, int type,
|
|
|
|
const char *fmt, ...);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-10-21 15:22:03 +08:00
|
|
|
extern struct audit_buffer *audit_log_start(struct audit_context *ctx, gfp_t gfp_mask, int type);
|
2011-11-01 08:11:33 +08:00
|
|
|
extern __printf(2, 3)
|
|
|
|
void audit_log_format(struct audit_buffer *ab, const char *fmt, ...);
|
2005-04-17 06:20:36 +08:00
|
|
|
extern void audit_log_end(struct audit_buffer *ab);
|
2008-01-08 03:31:58 +08:00
|
|
|
extern int audit_string_contains_control(const char *string,
|
|
|
|
size_t len);
|
2008-04-18 22:12:59 +08:00
|
|
|
extern void audit_log_n_hex(struct audit_buffer *ab,
|
|
|
|
const unsigned char *buf,
|
|
|
|
size_t len);
|
|
|
|
extern void audit_log_n_string(struct audit_buffer *ab,
|
|
|
|
const char *buf,
|
|
|
|
size_t n);
|
|
|
|
extern void audit_log_n_untrustedstring(struct audit_buffer *ab,
|
|
|
|
const char *string,
|
|
|
|
size_t n);
|
2008-01-08 03:31:58 +08:00
|
|
|
extern void audit_log_untrustedstring(struct audit_buffer *ab,
|
2005-04-29 22:54:44 +08:00
|
|
|
const char *string);
|
2005-04-17 06:20:36 +08:00
|
|
|
extern void audit_log_d_path(struct audit_buffer *ab,
|
|
|
|
const char *prefix,
|
2012-03-15 09:48:20 +08:00
|
|
|
const struct path *path);
|
2009-06-12 02:31:37 +08:00
|
|
|
extern void audit_log_key(struct audit_buffer *ab,
|
|
|
|
char *key);
|
2012-07-26 08:29:08 +08:00
|
|
|
extern void audit_log_link_denied(const char *operation,
|
|
|
|
struct path *link);
|
Audit: add TTY input auditing
Add TTY input auditing, used to audit system administrator's actions. This is
required by various security standards such as DCID 6/3 and PCI to provide
non-repudiation of administrator's actions and to allow a review of past
actions if the administrator seems to overstep their duties or if the system
becomes misconfigured for unknown reasons. These requirements do not make it
necessary to audit TTY output as well.
Compared to an user-space keylogger, this approach records TTY input using the
audit subsystem, correlated with other audit events, and it is completely
transparent to the user-space application (e.g. the console ioctls still
work).
TTY input auditing works on a higher level than auditing all system calls
within the session, which would produce an overwhelming amount of mostly
useless audit events.
Add an "audit_tty" attribute, inherited across fork (). Data read from TTYs
by process with the attribute is sent to the audit subsystem by the kernel.
The audit netlink interface is extended to allow modifying the audit_tty
attribute, and to allow sending explanatory audit events from user-space (for
example, a shell might send an event containing the final command, after the
interactive command-line editing and history expansion is performed, which
might be difficult to decipher from the TTY input alone).
Because the "audit_tty" attribute is inherited across fork (), it would be set
e.g. for sshd restarted within an audited session. To prevent this, the
audit_tty attribute is cleared when a process with no open TTY file
descriptors (e.g. after daemon startup) opens a TTY.
See https://www.redhat.com/archives/linux-audit/2007-June/msg00000.html for a
more detailed rationale document for an older version of this patch.
[akpm@linux-foundation.org: build fix]
Signed-off-by: Miloslav Trmac <mitr@redhat.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: Paul Fulghum <paulkf@microgate.com>
Cc: Casey Schaufler <casey@schaufler-ca.com>
Cc: Steve Grubb <sgrubb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-16 14:40:56 +08:00
|
|
|
extern void audit_log_lost(const char *message);
|
2011-06-30 19:31:57 +08:00
|
|
|
#ifdef CONFIG_SECURITY
|
|
|
|
extern void audit_log_secctx(struct audit_buffer *ab, u32 secid);
|
|
|
|
#else
|
2012-10-05 08:11:11 +08:00
|
|
|
static inline void audit_log_secctx(struct audit_buffer *ab, u32 secid)
|
|
|
|
{ }
|
2011-06-30 19:31:57 +08:00
|
|
|
#endif
|
|
|
|
|
2013-05-01 03:30:32 +08:00
|
|
|
extern int audit_log_task_context(struct audit_buffer *ab);
|
|
|
|
extern void audit_log_task_info(struct audit_buffer *ab,
|
|
|
|
struct task_struct *tsk);
|
|
|
|
|
2008-03-02 04:03:14 +08:00
|
|
|
extern int audit_update_lsm_rules(void);
|
|
|
|
|
2005-12-16 02:33:52 +08:00
|
|
|
/* Private API (for audit.c only) */
|
2013-04-17 01:08:43 +08:00
|
|
|
extern int audit_filter_user(int type);
|
2005-12-16 02:33:52 +08:00
|
|
|
extern int audit_filter_type(int type);
|
2013-11-21 03:01:53 +08:00
|
|
|
extern int audit_rule_change(int type, __u32 portid, int seq,
|
2013-04-20 01:23:09 +08:00
|
|
|
void *data, size_t datasz);
|
2013-11-21 03:01:53 +08:00
|
|
|
extern int audit_list_rules_send(__u32 portid, int seq);
|
|
|
|
|
2014-01-15 02:33:13 +08:00
|
|
|
extern u32 audit_enabled;
|
2012-10-05 08:11:11 +08:00
|
|
|
#else /* CONFIG_AUDIT */
|
|
|
|
static inline __printf(4, 5)
|
|
|
|
void audit_log(struct audit_context *ctx, gfp_t gfp_mask, int type,
|
|
|
|
const char *fmt, ...)
|
|
|
|
{ }
|
|
|
|
static inline struct audit_buffer *audit_log_start(struct audit_context *ctx,
|
|
|
|
gfp_t gfp_mask, int type)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
static inline __printf(2, 3)
|
|
|
|
void audit_log_format(struct audit_buffer *ab, const char *fmt, ...)
|
|
|
|
{ }
|
|
|
|
static inline void audit_log_end(struct audit_buffer *ab)
|
|
|
|
{ }
|
|
|
|
static inline void audit_log_n_hex(struct audit_buffer *ab,
|
|
|
|
const unsigned char *buf, size_t len)
|
|
|
|
{ }
|
|
|
|
static inline void audit_log_n_string(struct audit_buffer *ab,
|
|
|
|
const char *buf, size_t n)
|
|
|
|
{ }
|
|
|
|
static inline void audit_log_n_untrustedstring(struct audit_buffer *ab,
|
|
|
|
const char *string, size_t n)
|
|
|
|
{ }
|
|
|
|
static inline void audit_log_untrustedstring(struct audit_buffer *ab,
|
|
|
|
const char *string)
|
|
|
|
{ }
|
|
|
|
static inline void audit_log_d_path(struct audit_buffer *ab,
|
|
|
|
const char *prefix,
|
|
|
|
const struct path *path)
|
|
|
|
{ }
|
|
|
|
static inline void audit_log_key(struct audit_buffer *ab, char *key)
|
|
|
|
{ }
|
|
|
|
static inline void audit_log_link_denied(const char *string,
|
|
|
|
const struct path *link)
|
|
|
|
{ }
|
|
|
|
static inline void audit_log_secctx(struct audit_buffer *ab, u32 secid)
|
|
|
|
{ }
|
2013-05-01 03:30:32 +08:00
|
|
|
static inline int audit_log_task_context(struct audit_buffer *ab)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
static inline void audit_log_task_info(struct audit_buffer *ab,
|
|
|
|
struct task_struct *tsk)
|
|
|
|
{ }
|
Audit: add TTY input auditing
Add TTY input auditing, used to audit system administrator's actions. This is
required by various security standards such as DCID 6/3 and PCI to provide
non-repudiation of administrator's actions and to allow a review of past
actions if the administrator seems to overstep their duties or if the system
becomes misconfigured for unknown reasons. These requirements do not make it
necessary to audit TTY output as well.
Compared to an user-space keylogger, this approach records TTY input using the
audit subsystem, correlated with other audit events, and it is completely
transparent to the user-space application (e.g. the console ioctls still
work).
TTY input auditing works on a higher level than auditing all system calls
within the session, which would produce an overwhelming amount of mostly
useless audit events.
Add an "audit_tty" attribute, inherited across fork (). Data read from TTYs
by process with the attribute is sent to the audit subsystem by the kernel.
The audit netlink interface is extended to allow modifying the audit_tty
attribute, and to allow sending explanatory audit events from user-space (for
example, a shell might send an event containing the final command, after the
interactive command-line editing and history expansion is performed, which
might be difficult to decipher from the TTY input alone).
Because the "audit_tty" attribute is inherited across fork (), it would be set
e.g. for sshd restarted within an audited session. To prevent this, the
audit_tty attribute is cleared when a process with no open TTY file
descriptors (e.g. after daemon startup) opens a TTY.
See https://www.redhat.com/archives/linux-audit/2007-June/msg00000.html for a
more detailed rationale document for an older version of this patch.
[akpm@linux-foundation.org: build fix]
Signed-off-by: Miloslav Trmac <mitr@redhat.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: Paul Fulghum <paulkf@microgate.com>
Cc: Casey Schaufler <casey@schaufler-ca.com>
Cc: Steve Grubb <sgrubb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-16 14:40:56 +08:00
|
|
|
#define audit_enabled 0
|
2012-10-05 08:11:11 +08:00
|
|
|
#endif /* CONFIG_AUDIT */
|
|
|
|
static inline void audit_log_string(struct audit_buffer *ab, const char *buf)
|
|
|
|
{
|
|
|
|
audit_log_n_string(ab, buf, strlen(buf));
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|