Commit c4cc75c3 authored by Linus Torvalds's avatar Linus Torvalds

Merge git://git.infradead.org/users/eparis/audit

Pull audit changes from Eric Paris:
 "Al used to send pull requests every couple of years but he told me to
  just start pushing them to you directly.

  Our touching outside of core audit code is pretty straight forward.  A
  couple of interface changes which hit net/.  A simple argument bug
  calling audit functions in namei.c and the removal of some assembly
  branch prediction code on ppc"

* git://git.infradead.org/users/eparis/audit: (31 commits)
  audit: fix message spacing printing auid
  Revert "audit: move kaudit thread start from auditd registration to kaudit init"
  audit: vfs: fix audit_inode call in O_CREAT case of do_last
  audit: Make testing for a valid loginuid explicit.
  audit: fix event coverage of AUDIT_ANOM_LINK
  audit: use spin_lock in audit_receive_msg to process tty logging
  audit: do not needlessly take a lock in tty_audit_exit
  audit: do not needlessly take a spinlock in copy_signal
  audit: add an option to control logging of passwords with pam_tty_audit
  audit: use spin_lock_irqsave/restore in audit tty code
  helper for some session id stuff
  audit: use a consistent audit helper to log lsm information
  audit: push loginuid and sessionid processing down
  audit: stop pushing loginid, uid, sessionid as arguments
  audit: remove the old depricated kernel interface
  audit: make validity checking generic
  audit: allow checking the type of audit message in the user filter
  audit: fix build break when AUDIT_DEBUG == 2
  audit: remove duplicate export of audit_enabled
  Audit: do not print error when LSMs disabled
  ...
parents 2dbd3cac 2a0b4be6
...@@ -150,7 +150,7 @@ END_FW_FTR_SECTION_IFSET(FW_FEATURE_SPLPAR) ...@@ -150,7 +150,7 @@ END_FW_FTR_SECTION_IFSET(FW_FEATURE_SPLPAR)
CURRENT_THREAD_INFO(r11, r1) CURRENT_THREAD_INFO(r11, r1)
ld r10,TI_FLAGS(r11) ld r10,TI_FLAGS(r11)
andi. r11,r10,_TIF_SYSCALL_T_OR_A andi. r11,r10,_TIF_SYSCALL_T_OR_A
bne- syscall_dotrace bne syscall_dotrace
.Lsyscall_dotrace_cont: .Lsyscall_dotrace_cont:
cmpldi 0,r0,NR_syscalls cmpldi 0,r0,NR_syscalls
bge- syscall_enosys bge- syscall_enosys
......
...@@ -60,24 +60,22 @@ static void tty_audit_buf_put(struct tty_audit_buf *buf) ...@@ -60,24 +60,22 @@ static void tty_audit_buf_put(struct tty_audit_buf *buf)
tty_audit_buf_free(buf); tty_audit_buf_free(buf);
} }
static void tty_audit_log(const char *description, struct task_struct *tsk, static void tty_audit_log(const char *description, int major, int minor,
kuid_t loginuid, unsigned sessionid, int major, unsigned char *data, size_t size)
int minor, unsigned char *data, size_t size)
{ {
struct audit_buffer *ab; struct audit_buffer *ab;
struct task_struct *tsk = current;
uid_t uid = from_kuid(&init_user_ns, task_uid(tsk));
uid_t loginuid = from_kuid(&init_user_ns, audit_get_loginuid(tsk));
u32 sessionid = audit_get_sessionid(tsk);
ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_TTY); ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_TTY);
if (ab) { if (ab) {
char name[sizeof(tsk->comm)]; char name[sizeof(tsk->comm)];
kuid_t uid = task_uid(tsk);
audit_log_format(ab, "%s pid=%u uid=%u auid=%u ses=%u major=%d"
audit_log_format(ab, "%s pid=%u uid=%u auid=%u ses=%u " " minor=%d comm=", description, tsk->pid, uid,
"major=%d minor=%d comm=", description, loginuid, sessionid, major, minor);
tsk->pid,
from_kuid(&init_user_ns, uid),
from_kuid(&init_user_ns, loginuid),
sessionid,
major, minor);
get_task_comm(name, tsk); get_task_comm(name, tsk);
audit_log_untrustedstring(ab, name); audit_log_untrustedstring(ab, name);
audit_log_format(ab, " data="); audit_log_format(ab, " data=");
...@@ -90,11 +88,9 @@ static void tty_audit_log(const char *description, struct task_struct *tsk, ...@@ -90,11 +88,9 @@ static void tty_audit_log(const char *description, struct task_struct *tsk,
* tty_audit_buf_push - Push buffered data out * tty_audit_buf_push - Push buffered data out
* *
* Generate an audit message from the contents of @buf, which is owned by * Generate an audit message from the contents of @buf, which is owned by
* @tsk with @loginuid. @buf->mutex must be locked. * the current task. @buf->mutex must be locked.
*/ */
static void tty_audit_buf_push(struct task_struct *tsk, kuid_t loginuid, static void tty_audit_buf_push(struct tty_audit_buf *buf)
unsigned int sessionid,
struct tty_audit_buf *buf)
{ {
if (buf->valid == 0) if (buf->valid == 0)
return; return;
...@@ -102,24 +98,10 @@ static void tty_audit_buf_push(struct task_struct *tsk, kuid_t loginuid, ...@@ -102,24 +98,10 @@ static void tty_audit_buf_push(struct task_struct *tsk, kuid_t loginuid,
buf->valid = 0; buf->valid = 0;
return; return;
} }
tty_audit_log("tty", tsk, loginuid, sessionid, buf->major, buf->minor, tty_audit_log("tty", buf->major, buf->minor, buf->data, buf->valid);
buf->data, buf->valid);
buf->valid = 0; buf->valid = 0;
} }
/**
* tty_audit_buf_push_current - Push buffered data out
*
* Generate an audit message from the contents of @buf, which is owned by
* the current task. @buf->mutex must be locked.
*/
static void tty_audit_buf_push_current(struct tty_audit_buf *buf)
{
kuid_t auid = audit_get_loginuid(current);
unsigned int sessionid = audit_get_sessionid(current);
tty_audit_buf_push(current, auid, sessionid, buf);
}
/** /**
* tty_audit_exit - Handle a task exit * tty_audit_exit - Handle a task exit
* *
...@@ -130,15 +112,13 @@ void tty_audit_exit(void) ...@@ -130,15 +112,13 @@ void tty_audit_exit(void)
{ {
struct tty_audit_buf *buf; struct tty_audit_buf *buf;
spin_lock_irq(&current->sighand->siglock);
buf = current->signal->tty_audit_buf; buf = current->signal->tty_audit_buf;
current->signal->tty_audit_buf = NULL; current->signal->tty_audit_buf = NULL;
spin_unlock_irq(&current->sighand->siglock);
if (!buf) if (!buf)
return; return;
mutex_lock(&buf->mutex); mutex_lock(&buf->mutex);
tty_audit_buf_push_current(buf); tty_audit_buf_push(buf);
mutex_unlock(&buf->mutex); mutex_unlock(&buf->mutex);
tty_audit_buf_put(buf); tty_audit_buf_put(buf);
...@@ -151,9 +131,8 @@ void tty_audit_exit(void) ...@@ -151,9 +131,8 @@ void tty_audit_exit(void)
*/ */
void tty_audit_fork(struct signal_struct *sig) void tty_audit_fork(struct signal_struct *sig)
{ {
spin_lock_irq(&current->sighand->siglock);
sig->audit_tty = current->signal->audit_tty; sig->audit_tty = current->signal->audit_tty;
spin_unlock_irq(&current->sighand->siglock); sig->audit_tty_log_passwd = current->signal->audit_tty_log_passwd;
} }
/** /**
...@@ -163,20 +142,21 @@ void tty_audit_tiocsti(struct tty_struct *tty, char ch) ...@@ -163,20 +142,21 @@ void tty_audit_tiocsti(struct tty_struct *tty, char ch)
{ {
struct tty_audit_buf *buf; struct tty_audit_buf *buf;
int major, minor, should_audit; int major, minor, should_audit;
unsigned long flags;
spin_lock_irq(&current->sighand->siglock); spin_lock_irqsave(&current->sighand->siglock, flags);
should_audit = current->signal->audit_tty; should_audit = current->signal->audit_tty;
buf = current->signal->tty_audit_buf; buf = current->signal->tty_audit_buf;
if (buf) if (buf)
atomic_inc(&buf->count); atomic_inc(&buf->count);
spin_unlock_irq(&current->sighand->siglock); spin_unlock_irqrestore(&current->sighand->siglock, flags);
major = tty->driver->major; major = tty->driver->major;
minor = tty->driver->minor_start + tty->index; minor = tty->driver->minor_start + tty->index;
if (buf) { if (buf) {
mutex_lock(&buf->mutex); mutex_lock(&buf->mutex);
if (buf->major == major && buf->minor == minor) if (buf->major == major && buf->minor == minor)
tty_audit_buf_push_current(buf); tty_audit_buf_push(buf);
mutex_unlock(&buf->mutex); mutex_unlock(&buf->mutex);
tty_audit_buf_put(buf); tty_audit_buf_put(buf);
} }
...@@ -187,24 +167,20 @@ void tty_audit_tiocsti(struct tty_struct *tty, char ch) ...@@ -187,24 +167,20 @@ void tty_audit_tiocsti(struct tty_struct *tty, char ch)
auid = audit_get_loginuid(current); auid = audit_get_loginuid(current);
sessionid = audit_get_sessionid(current); sessionid = audit_get_sessionid(current);
tty_audit_log("ioctl=TIOCSTI", current, auid, sessionid, major, tty_audit_log("ioctl=TIOCSTI", major, minor, &ch, 1);
minor, &ch, 1);
} }
} }
/** /**
* tty_audit_push_task - Flush task's pending audit data * tty_audit_push_current - Flush current's pending audit data
* @tsk: task pointer
* @loginuid: sender login uid
* @sessionid: sender session id
* *
* Called with a ref on @tsk held. Try to lock sighand and get a * Try to lock sighand and get a reference to the tty audit buffer if available.
* reference to the tty audit buffer if available.
* Flush the buffer or return an appropriate error code. * Flush the buffer or return an appropriate error code.
*/ */
int tty_audit_push_task(struct task_struct *tsk, kuid_t loginuid, u32 sessionid) int tty_audit_push_current(void)
{ {
struct tty_audit_buf *buf = ERR_PTR(-EPERM); struct tty_audit_buf *buf = ERR_PTR(-EPERM);
struct task_struct *tsk = current;
unsigned long flags; unsigned long flags;
if (!lock_task_sighand(tsk, &flags)) if (!lock_task_sighand(tsk, &flags))
...@@ -225,7 +201,7 @@ int tty_audit_push_task(struct task_struct *tsk, kuid_t loginuid, u32 sessionid) ...@@ -225,7 +201,7 @@ int tty_audit_push_task(struct task_struct *tsk, kuid_t loginuid, u32 sessionid)
return PTR_ERR(buf); return PTR_ERR(buf);
mutex_lock(&buf->mutex); mutex_lock(&buf->mutex);
tty_audit_buf_push(tsk, loginuid, sessionid, buf); tty_audit_buf_push(buf);
mutex_unlock(&buf->mutex); mutex_unlock(&buf->mutex);
tty_audit_buf_put(buf); tty_audit_buf_put(buf);
...@@ -243,10 +219,11 @@ static struct tty_audit_buf *tty_audit_buf_get(struct tty_struct *tty, ...@@ -243,10 +219,11 @@ static struct tty_audit_buf *tty_audit_buf_get(struct tty_struct *tty,
unsigned icanon) unsigned icanon)
{ {
struct tty_audit_buf *buf, *buf2; struct tty_audit_buf *buf, *buf2;
unsigned long flags;
buf = NULL; buf = NULL;
buf2 = NULL; buf2 = NULL;
spin_lock_irq(&current->sighand->siglock); spin_lock_irqsave(&current->sighand->siglock, flags);
if (likely(!current->signal->audit_tty)) if (likely(!current->signal->audit_tty))
goto out; goto out;
buf = current->signal->tty_audit_buf; buf = current->signal->tty_audit_buf;
...@@ -254,7 +231,7 @@ static struct tty_audit_buf *tty_audit_buf_get(struct tty_struct *tty, ...@@ -254,7 +231,7 @@ static struct tty_audit_buf *tty_audit_buf_get(struct tty_struct *tty,
atomic_inc(&buf->count); atomic_inc(&buf->count);
goto out; goto out;
} }
spin_unlock_irq(&current->sighand->siglock); spin_unlock_irqrestore(&current->sighand->siglock, flags);
buf2 = tty_audit_buf_alloc(tty->driver->major, buf2 = tty_audit_buf_alloc(tty->driver->major,
tty->driver->minor_start + tty->index, tty->driver->minor_start + tty->index,
...@@ -264,7 +241,7 @@ static struct tty_audit_buf *tty_audit_buf_get(struct tty_struct *tty, ...@@ -264,7 +241,7 @@ static struct tty_audit_buf *tty_audit_buf_get(struct tty_struct *tty,
return NULL; return NULL;
} }
spin_lock_irq(&current->sighand->siglock); spin_lock_irqsave(&current->sighand->siglock, flags);
if (!current->signal->audit_tty) if (!current->signal->audit_tty)
goto out; goto out;
buf = current->signal->tty_audit_buf; buf = current->signal->tty_audit_buf;
...@@ -276,7 +253,7 @@ static struct tty_audit_buf *tty_audit_buf_get(struct tty_struct *tty, ...@@ -276,7 +253,7 @@ static struct tty_audit_buf *tty_audit_buf_get(struct tty_struct *tty,
atomic_inc(&buf->count); atomic_inc(&buf->count);
/* Fall through */ /* Fall through */
out: out:
spin_unlock_irq(&current->sighand->siglock); spin_unlock_irqrestore(&current->sighand->siglock, flags);
if (buf2) if (buf2)
tty_audit_buf_free(buf2); tty_audit_buf_free(buf2);
return buf; return buf;
...@@ -292,10 +269,18 @@ void tty_audit_add_data(struct tty_struct *tty, unsigned char *data, ...@@ -292,10 +269,18 @@ void tty_audit_add_data(struct tty_struct *tty, unsigned char *data,
{ {
struct tty_audit_buf *buf; struct tty_audit_buf *buf;
int major, minor; int major, minor;
int audit_log_tty_passwd;
unsigned long flags;
if (unlikely(size == 0)) if (unlikely(size == 0))
return; return;
spin_lock_irqsave(&current->sighand->siglock, flags);
audit_log_tty_passwd = current->signal->audit_tty_log_passwd;
spin_unlock_irqrestore(&current->sighand->siglock, flags);
if (!audit_log_tty_passwd && icanon && !L_ECHO(tty))
return;
if (tty->driver->type == TTY_DRIVER_TYPE_PTY if (tty->driver->type == TTY_DRIVER_TYPE_PTY
&& tty->driver->subtype == PTY_TYPE_MASTER) && tty->driver->subtype == PTY_TYPE_MASTER)
return; return;
...@@ -309,7 +294,7 @@ void tty_audit_add_data(struct tty_struct *tty, unsigned char *data, ...@@ -309,7 +294,7 @@ void tty_audit_add_data(struct tty_struct *tty, unsigned char *data,
minor = tty->driver->minor_start + tty->index; minor = tty->driver->minor_start + tty->index;
if (buf->major != major || buf->minor != minor if (buf->major != major || buf->minor != minor
|| buf->icanon != icanon) { || buf->icanon != icanon) {
tty_audit_buf_push_current(buf); tty_audit_buf_push(buf);
buf->major = major; buf->major = major;
buf->minor = minor; buf->minor = minor;
buf->icanon = icanon; buf->icanon = icanon;
...@@ -325,7 +310,7 @@ void tty_audit_add_data(struct tty_struct *tty, unsigned char *data, ...@@ -325,7 +310,7 @@ void tty_audit_add_data(struct tty_struct *tty, unsigned char *data,
data += run; data += run;
size -= run; size -= run;
if (buf->valid == N_TTY_BUF_SIZE) if (buf->valid == N_TTY_BUF_SIZE)
tty_audit_buf_push_current(buf); tty_audit_buf_push(buf);
} while (size != 0); } while (size != 0);
mutex_unlock(&buf->mutex); mutex_unlock(&buf->mutex);
tty_audit_buf_put(buf); tty_audit_buf_put(buf);
...@@ -339,16 +324,17 @@ void tty_audit_add_data(struct tty_struct *tty, unsigned char *data, ...@@ -339,16 +324,17 @@ void tty_audit_add_data(struct tty_struct *tty, unsigned char *data,
void tty_audit_push(struct tty_struct *tty) void tty_audit_push(struct tty_struct *tty)
{ {
struct tty_audit_buf *buf; struct tty_audit_buf *buf;
unsigned long flags;
spin_lock_irq(&current->sighand->siglock); spin_lock_irqsave(&current->sighand->siglock, flags);
if (likely(!current->signal->audit_tty)) { if (likely(!current->signal->audit_tty)) {
spin_unlock_irq(&current->sighand->siglock); spin_unlock_irqrestore(&current->sighand->siglock, flags);
return; return;
} }
buf = current->signal->tty_audit_buf; buf = current->signal->tty_audit_buf;
if (buf) if (buf)
atomic_inc(&buf->count); atomic_inc(&buf->count);
spin_unlock_irq(&current->sighand->siglock); spin_unlock_irqrestore(&current->sighand->siglock, flags);
if (buf) { if (buf) {
int major, minor; int major, minor;
...@@ -357,7 +343,7 @@ void tty_audit_push(struct tty_struct *tty) ...@@ -357,7 +343,7 @@ void tty_audit_push(struct tty_struct *tty)
minor = tty->driver->minor_start + tty->index; minor = tty->driver->minor_start + tty->index;
mutex_lock(&buf->mutex); mutex_lock(&buf->mutex);
if (buf->major == major && buf->minor == minor) if (buf->major == major && buf->minor == minor)
tty_audit_buf_push_current(buf); tty_audit_buf_push(buf);
mutex_unlock(&buf->mutex); mutex_unlock(&buf->mutex);
tty_audit_buf_put(buf); tty_audit_buf_put(buf);
} }
......
...@@ -2740,7 +2740,7 @@ static int do_last(struct nameidata *nd, struct path *path, ...@@ -2740,7 +2740,7 @@ static int do_last(struct nameidata *nd, struct path *path,
if (error) if (error)
return error; return error;
audit_inode(name, dir, 0); audit_inode(name, dir, LOOKUP_PARENT);
error = -EISDIR; error = -EISDIR;
/* trailing slashes? */ /* trailing slashes? */
if (nd->last.name[nd->last.len]) if (nd->last.name[nd->last.len])
......
...@@ -84,8 +84,13 @@ extern int audit_classify_arch(int arch); ...@@ -84,8 +84,13 @@ extern int audit_classify_arch(int arch);
#define AUDIT_TYPE_CHILD_DELETE 3 /* a child being deleted */ #define AUDIT_TYPE_CHILD_DELETE 3 /* a child being deleted */
#define AUDIT_TYPE_CHILD_CREATE 4 /* a child being created */ #define AUDIT_TYPE_CHILD_CREATE 4 /* a child being created */
/* maximized args number that audit_socketcall can process */
#define AUDITSC_ARGS 6
struct filename; struct filename;
extern void audit_log_session_info(struct audit_buffer *ab);
#ifdef CONFIG_AUDITSYSCALL #ifdef CONFIG_AUDITSYSCALL
/* These are defined in auditsc.c */ /* These are defined in auditsc.c */
/* Public API */ /* Public API */
...@@ -120,7 +125,7 @@ static inline void audit_syscall_entry(int arch, int major, unsigned long a0, ...@@ -120,7 +125,7 @@ static inline void audit_syscall_entry(int arch, int major, unsigned long a0,
unsigned long a1, unsigned long a2, unsigned long a1, unsigned long a2,
unsigned long a3) unsigned long a3)
{ {
if (unlikely(!audit_dummy_context())) if (unlikely(current->audit_context))
__audit_syscall_entry(arch, major, a0, a1, a2, a3); __audit_syscall_entry(arch, major, a0, a1, a2, a3);
} }
static inline void audit_syscall_exit(void *pt_regs) static inline void audit_syscall_exit(void *pt_regs)
...@@ -185,12 +190,10 @@ static inline int audit_get_sessionid(struct task_struct *tsk) ...@@ -185,12 +190,10 @@ static inline int audit_get_sessionid(struct task_struct *tsk)
return tsk->sessionid; return tsk->sessionid;
} }
extern void audit_log_task_context(struct audit_buffer *ab);
extern void audit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk);
extern void __audit_ipc_obj(struct kern_ipc_perm *ipcp); extern void __audit_ipc_obj(struct kern_ipc_perm *ipcp);
extern void __audit_ipc_set_perm(unsigned long qbytes, uid_t uid, gid_t gid, umode_t mode); extern void __audit_ipc_set_perm(unsigned long qbytes, uid_t uid, gid_t gid, umode_t mode);
extern int __audit_bprm(struct linux_binprm *bprm); extern int __audit_bprm(struct linux_binprm *bprm);
extern void __audit_socketcall(int nargs, unsigned long *args); extern int __audit_socketcall(int nargs, unsigned long *args);
extern int __audit_sockaddr(int len, void *addr); extern int __audit_sockaddr(int len, void *addr);
extern void __audit_fd_pair(int fd1, int fd2); extern void __audit_fd_pair(int fd1, int fd2);
extern void __audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr); extern void __audit_mq_open(int oflag, umode_t mode, struct mq_attr *attr);
...@@ -224,10 +227,11 @@ static inline int audit_bprm(struct linux_binprm *bprm) ...@@ -224,10 +227,11 @@ static inline int audit_bprm(struct linux_binprm *bprm)
return __audit_bprm(bprm); return __audit_bprm(bprm);
return 0; return 0;
} }
static inline void audit_socketcall(int nargs, unsigned long *args) static inline int audit_socketcall(int nargs, unsigned long *args)
{ {
if (unlikely(!audit_dummy_context())) if (unlikely(!audit_dummy_context()))
__audit_socketcall(nargs, args); return __audit_socketcall(nargs, args);
return 0;
} }
static inline int audit_sockaddr(int len, void *addr) static inline int audit_sockaddr(int len, void *addr)
{ {
...@@ -340,11 +344,6 @@ static inline int audit_get_sessionid(struct task_struct *tsk) ...@@ -340,11 +344,6 @@ static inline int audit_get_sessionid(struct task_struct *tsk)
{ {
return -1; return -1;
} }
static inline void audit_log_task_context(struct audit_buffer *ab)
{ }
static inline void audit_log_task_info(struct audit_buffer *ab,
struct task_struct *tsk)
{ }
static inline void audit_ipc_obj(struct kern_ipc_perm *ipcp) static inline void audit_ipc_obj(struct kern_ipc_perm *ipcp)
{ } { }
static inline void audit_ipc_set_perm(unsigned long qbytes, uid_t uid, static inline void audit_ipc_set_perm(unsigned long qbytes, uid_t uid,
...@@ -354,8 +353,10 @@ static inline int audit_bprm(struct linux_binprm *bprm) ...@@ -354,8 +353,10 @@ static inline int audit_bprm(struct linux_binprm *bprm)
{ {
return 0; return 0;
} }
static inline void audit_socketcall(int nargs, unsigned long *args) static inline int audit_socketcall(int nargs, unsigned long *args)
{ } {
return 0;
}
static inline void audit_fd_pair(int fd1, int fd2) static inline void audit_fd_pair(int fd1, int fd2)
{ } { }
static inline int audit_sockaddr(int len, void *addr) static inline int audit_sockaddr(int len, void *addr)
...@@ -390,6 +391,11 @@ static inline void audit_ptrace(struct task_struct *t) ...@@ -390,6 +391,11 @@ static inline void audit_ptrace(struct task_struct *t)
#define audit_signals 0 #define audit_signals 0
#endif /* CONFIG_AUDITSYSCALL */ #endif /* CONFIG_AUDITSYSCALL */
static inline bool audit_loginuid_set(struct task_struct *tsk)
{
return uid_valid(audit_get_loginuid(tsk));
}
#ifdef CONFIG_AUDIT #ifdef CONFIG_AUDIT
/* These are defined in audit.c */ /* These are defined in audit.c */
/* Public API */ /* Public API */
...@@ -429,14 +435,17 @@ static inline void audit_log_secctx(struct audit_buffer *ab, u32 secid) ...@@ -429,14 +435,17 @@ static inline void audit_log_secctx(struct audit_buffer *ab, u32 secid)
{ } { }
#endif #endif
extern int audit_log_task_context(struct audit_buffer *ab);
extern void audit_log_task_info(struct audit_buffer *ab,
struct task_struct *tsk);
extern int audit_update_lsm_rules(void); extern int audit_update_lsm_rules(void);
/* Private API (for audit.c only) */ /* Private API (for audit.c only) */
extern int audit_filter_user(void); extern int audit_filter_user(int type);
extern int audit_filter_type(int type); extern int audit_filter_type(int type);
extern int audit_receive_filter(int type, int pid, int seq, extern int audit_receive_filter(int type, int pid, int seq,
void *data, size_t datasz, kuid_t loginuid, void *data, size_t datasz);
u32 sessionid, u32 sid);
extern int audit_enabled; extern int audit_enabled;
#else /* CONFIG_AUDIT */ #else /* CONFIG_AUDIT */
static inline __printf(4, 5) static inline __printf(4, 5)
...@@ -476,6 +485,13 @@ static inline void audit_log_link_denied(const char *string, ...@@ -476,6 +485,13 @@ static inline void audit_log_link_denied(const char *string,
{ } { }
static inline void audit_log_secctx(struct audit_buffer *ab, u32 secid) static inline void audit_log_secctx(struct audit_buffer *ab, u32 secid)
{ } { }
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)
{ }
#define audit_enabled 0 #define audit_enabled 0
#endif /* CONFIG_AUDIT */ #endif /* CONFIG_AUDIT */
static inline void audit_log_string(struct audit_buffer *ab, const char *buf) static inline void audit_log_string(struct audit_buffer *ab, const char *buf)
......
...@@ -593,6 +593,7 @@ struct signal_struct { ...@@ -593,6 +593,7 @@ struct signal_struct {
#endif #endif
#ifdef CONFIG_AUDIT #ifdef CONFIG_AUDIT
unsigned audit_tty; unsigned audit_tty;
unsigned audit_tty_log_passwd;
struct tty_audit_buf *tty_audit_buf; struct tty_audit_buf *tty_audit_buf;
#endif #endif
#ifdef CONFIG_CGROUPS #ifdef CONFIG_CGROUPS
......
...@@ -575,8 +575,7 @@ extern void tty_audit_exit(void); ...@@ -575,8 +575,7 @@ extern void tty_audit_exit(void);
extern void tty_audit_fork(struct signal_struct *sig); extern void tty_audit_fork(struct signal_struct *sig);
extern void tty_audit_tiocsti(struct tty_struct *tty, char ch); extern void tty_audit_tiocsti(struct tty_struct *tty, char ch);
extern void tty_audit_push(struct tty_struct *tty); extern void tty_audit_push(struct tty_struct *tty);
extern int tty_audit_push_task(struct task_struct *tsk, extern int tty_audit_push_current(void);
kuid_t loginuid, u32 sessionid);
#else #else
static inline void tty_audit_add_data(struct tty_struct *tty, static inline void tty_audit_add_data(struct tty_struct *tty,
unsigned char *data, size_t size, unsigned icanon) unsigned char *data, size_t size, unsigned icanon)
...@@ -594,8 +593,7 @@ static inline void tty_audit_fork(struct signal_struct *sig) ...@@ -594,8 +593,7 @@ static inline void tty_audit_fork(struct signal_struct *sig)
static inline void tty_audit_push(struct tty_struct *tty) static inline void tty_audit_push(struct tty_struct *tty)
{ {
} }
static inline int tty_audit_push_task(struct task_struct *tsk, static inline int tty_audit_push_current(void)
kuid_t loginuid, u32 sessionid)
{ {
return 0; return 0;
} }
......
...@@ -246,6 +246,7 @@ ...@@ -246,6 +246,7 @@
#define AUDIT_OBJ_TYPE 21 #define AUDIT_OBJ_TYPE 21
#define AUDIT_OBJ_LEV_LOW 22 #define AUDIT_OBJ_LEV_LOW 22
#define AUDIT_OBJ_LEV_HIGH 23 #define AUDIT_OBJ_LEV_HIGH 23
#define AUDIT_LOGINUID_SET 24
/* These are ONLY useful when checking /* These are ONLY useful when checking
* at syscall exit time (AUDIT_AT_EXIT). */ * at syscall exit time (AUDIT_AT_EXIT). */
...@@ -370,6 +371,7 @@ struct audit_status { ...@@ -370,6 +371,7 @@ struct audit_status {
struct audit_tty_status { struct audit_tty_status {
__u32 enabled; /* 1 = enabled, 0 = disabled */ __u32 enabled; /* 1 = enabled, 0 = disabled */
__u32 log_passwd; /* 1 = enabled, 0 = disabled */
}; };
/* audit_rule_data supports filter rules with both integer and string /* audit_rule_data supports filter rules with both integer and string
......
This diff is collapsed.
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/audit.h> #include <linux/audit.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <uapi/linux/mqueue.h>
/* 0 = no checking /* 0 = no checking
1 = put_count checking 1 = put_count checking
...@@ -29,6 +30,11 @@ ...@@ -29,6 +30,11 @@
*/ */
#define AUDIT_DEBUG 0 #define AUDIT_DEBUG 0
/* AUDIT_NAMES is the number of slots we reserve in the audit_context
* for saving names from getname(). If we get more names we will allocate
* a name dynamically and also add those to the list anchored by names_list. */
#define AUDIT_NAMES 5
/* At task start time, the audit_state is set in the audit_context using /* At task start time, the audit_state is set in the audit_context using
a per-task filter. At syscall entry, the audit_state is augmented by a per-task filter. At syscall entry, the audit_state is augmented by
the syscall filter. */ the syscall filter. */
...@@ -59,8 +65,158 @@ struct audit_entry { ...@@ -59,8 +65,158 @@ struct audit_entry {
struct audit_krule rule; struct audit_krule rule;
}; };
struct audit_cap_data {
kernel_cap_t permitted;
kernel_cap_t inheritable;
union {
unsigned int fE; /* effective bit of file cap */
kernel_cap_t effective; /* effective set of process */
};
};
/* When fs/namei.c:getname() is called, we store the pointer in name and
* we don't let putname() free it (instead we free all of the saved
* pointers at syscall exit time).
*
* Further, in fs/namei.c:path_lookup() we store the inode and device.
*/
struct audit_names {
struct list_head list; /* audit_context->names_list */
struct filename *name;
int name_len; /* number of chars to log */
bool name_put; /* call __putname()? */
unsigned long ino;
dev_t dev;
umode_t mode;
kuid_t uid;
kgid_t gid;
dev_t rdev;
u32 osid;
struct audit_cap_data fcap;
unsigned int fcap_ver;
unsigned char type; /* record type */
/*
* This was an allocated audit_names and not from the array of
* names allocated in the task audit context. Thus this name
* should be freed on syscall exit.
*/
bool should_free;
};
/* The per-task audit context. */
struct audit_context {
int dummy; /* must be the first element */
int in_syscall; /* 1 if task is in a syscall */
enum audit_state state, current_state;
unsigned int serial; /* serial number for record */
int major; /* syscall number */
struct timespec ctime; /* time of syscall entry */
unsigned long argv[4]; /* syscall arguments */
long return_code;/* syscall return code */
u64 prio;
int return_valid; /* return code is valid */
/*
* The names_list is the list of all audit_names collected during this
* syscall. The first AUDIT_NAMES entries in the names_list will
* actually be from the preallocated_names array for performance
* reasons. Except during allocation they should never be referenced
* through the preallocated_names array and should only be found/used
* by running the names_list.
*/
struct audit_names preallocated_names[AUDIT_NAMES];
int name_count; /* total records in names_list */
struct list_head names_list; /* struct audit_names->list anchor */
char *filterkey; /* key for rule that triggered record */
struct path pwd;
struct audit_aux_data *aux;
struct audit_aux_data *aux_pids;
struct sockaddr_storage *sockaddr;
size_t sockaddr_len;
/* Save things to print about task_struct */
pid_t pid, ppid;
kuid_t uid, euid, suid, fsuid;
kgid_t gid, egid, sgid, fsgid;
unsigned long personality;
int arch;
pid_t target_pid;
kuid_t target_auid;
kuid_t target_uid;
unsigned int target_sessionid;
u32 target_sid;
char target_comm[TASK_COMM_LEN];
struct audit_tree_refs *trees, *first_trees;
struct list_head killed_trees;
int tree_count;
int type;
union {
struct {
int nargs;
long args[6];
} socketcall;
struct {
kuid_t uid;
kgid_t gid;
umode_t mode;
u32 osid;
int has_perm;
uid_t perm_uid;
gid_t perm_gid;
umode_t perm_mode;
unsigned long qbytes;
} ipc;
struct {
mqd_t mqdes;
struct mq_attr mqstat;
} mq_getsetattr;
struct {
mqd_t mqdes;
int sigev_signo;
} mq_notify;
struct {
mqd_t mqdes;
size_t msg_len;
unsigned int msg_prio;
struct timespec abs_timeout;
} mq_sendrecv;
struct {
int oflag;
umode_t mode;
struct mq_attr attr;
} mq_open;
struct {
pid_t pid;
struct audit_cap_data cap;
} capset;
struct {
int fd;
int flags;
} mmap;
};
int fds[2];
#if AUDIT_DEBUG
int put_count;
int ino_count;
#endif
};
extern int audit_ever_enabled; extern int audit_ever_enabled;
extern void audit_copy_inode(struct audit_names *name,
const struct dentry *dentry,
const struct inode *inode);
extern void audit_log_cap(struct audit_buffer *ab, char *prefix,
kernel_cap_t *cap);
extern void audit_log_fcaps(struct audit_buffer *ab, struct audit_names *name);
extern void audit_log_name(struct audit_context *context,
struct audit_names *n, struct path *path,
int record_num, int *call_panic);
extern int audit_pid; extern int audit_pid;
#define AUDIT_INODE_BUCKETS 32 #define AUDIT_INODE_BUCKETS 32
......
This diff is collapsed.
This diff is collapsed.
...@@ -2412,7 +2412,7 @@ static const unsigned char nargs[21] = { ...@@ -2412,7 +2412,7 @@ static const unsigned char nargs[21] = {
SYSCALL_DEFINE2(socketcall, int, call, unsigned long __user *, args) SYSCALL_DEFINE2(socketcall, int, call, unsigned long __user *, args)
{ {
unsigned long a[6]; unsigned long a[AUDITSC_ARGS];
unsigned long a0, a1; unsigned long a0, a1;
int err; int err;
unsigned int len; unsigned int len;
...@@ -2428,7 +2428,9 @@ SYSCALL_DEFINE2(socketcall, int, call, unsigned long __user *, args) ...@@ -2428,7 +2428,9 @@ SYSCALL_DEFINE2(socketcall, int, call, unsigned long __user *, args)
if (copy_from_user(a, args, len)) if (copy_from_user(a, args, len))
return -EFAULT; return -EFAULT;
audit_socketcall(nargs[call] / sizeof(unsigned long), a); err = audit_socketcall(nargs[call] / sizeof(unsigned long), a);
if (err)
return err;
a0 = a[0]; a0 = a[0];
a1 = a[1]; a1 = a[1];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment