Merge branch 'stable-4.7' of git://git.infradead.org/users/pcmoore/audit
Pull audit updates from Paul Moore: "Four small audit patches for 4.7. Two are simple cleanups around the audit thread management code, one adds a tty field to AUDIT_LOGIN events, and the final patch makes tty_name() usable regardless of CONFIG_TTY. Nothing controversial, and it all passes our regression test" * 'stable-4.7' of git://git.infradead.org/users/pcmoore/audit: tty: provide tty_name() even without CONFIG_TTY audit: add tty field to LOGIN event audit: we don't need to __set_current_state(TASK_RUNNING) audit: cleanup prune_tree_thread
This commit is contained in:
commit
03e1aa1cbb
|
@ -26,6 +26,7 @@
|
||||||
#include <linux/sched.h>
|
#include <linux/sched.h>
|
||||||
#include <linux/ptrace.h>
|
#include <linux/ptrace.h>
|
||||||
#include <uapi/linux/audit.h>
|
#include <uapi/linux/audit.h>
|
||||||
|
#include <linux/tty.h>
|
||||||
|
|
||||||
#define AUDIT_INO_UNSET ((unsigned long)-1)
|
#define AUDIT_INO_UNSET ((unsigned long)-1)
|
||||||
#define AUDIT_DEV_UNSET ((dev_t)-1)
|
#define AUDIT_DEV_UNSET ((dev_t)-1)
|
||||||
|
@ -347,6 +348,23 @@ static inline unsigned int audit_get_sessionid(struct task_struct *tsk)
|
||||||
return tsk->sessionid;
|
return tsk->sessionid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline struct tty_struct *audit_get_tty(struct task_struct *tsk)
|
||||||
|
{
|
||||||
|
struct tty_struct *tty = NULL;
|
||||||
|
unsigned long flags;
|
||||||
|
|
||||||
|
spin_lock_irqsave(&tsk->sighand->siglock, flags);
|
||||||
|
if (tsk->signal)
|
||||||
|
tty = tty_kref_get(tsk->signal->tty);
|
||||||
|
spin_unlock_irqrestore(&tsk->sighand->siglock, flags);
|
||||||
|
return tty;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void audit_put_tty(struct tty_struct *tty)
|
||||||
|
{
|
||||||
|
tty_kref_put(tty);
|
||||||
|
}
|
||||||
|
|
||||||
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 void __audit_bprm(struct linux_binprm *bprm);
|
extern void __audit_bprm(struct linux_binprm *bprm);
|
||||||
|
@ -504,6 +522,12 @@ static inline unsigned int audit_get_sessionid(struct task_struct *tsk)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
static inline struct tty_struct *audit_get_tty(struct task_struct *tsk)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
static inline void audit_put_tty(struct tty_struct *tty)
|
||||||
|
{ }
|
||||||
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,
|
||||||
|
|
|
@ -371,6 +371,7 @@ extern void proc_clear_tty(struct task_struct *p);
|
||||||
extern struct tty_struct *get_current_tty(void);
|
extern struct tty_struct *get_current_tty(void);
|
||||||
/* tty_io.c */
|
/* tty_io.c */
|
||||||
extern int __init tty_init(void);
|
extern int __init tty_init(void);
|
||||||
|
extern const char *tty_name(const struct tty_struct *tty);
|
||||||
#else
|
#else
|
||||||
static inline void console_init(void)
|
static inline void console_init(void)
|
||||||
{ }
|
{ }
|
||||||
|
@ -391,6 +392,8 @@ static inline struct tty_struct *get_current_tty(void)
|
||||||
/* tty_io.c */
|
/* tty_io.c */
|
||||||
static inline int __init tty_init(void)
|
static inline int __init tty_init(void)
|
||||||
{ return 0; }
|
{ return 0; }
|
||||||
|
static inline const char *tty_name(const struct tty_struct *tty)
|
||||||
|
{ return "(none)"; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern struct ktermios tty_std_termios;
|
extern struct ktermios tty_std_termios;
|
||||||
|
@ -415,7 +418,6 @@ static inline struct tty_struct *tty_kref_get(struct tty_struct *tty)
|
||||||
return tty;
|
return tty;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern const char *tty_name(const struct tty_struct *tty);
|
|
||||||
extern const char *tty_driver_name(const struct tty_struct *tty);
|
extern const char *tty_driver_name(const struct tty_struct *tty);
|
||||||
extern void tty_wait_until_sent(struct tty_struct *tty, long timeout);
|
extern void tty_wait_until_sent(struct tty_struct *tty, long timeout);
|
||||||
extern int __tty_check_change(struct tty_struct *tty, int sig);
|
extern int __tty_check_change(struct tty_struct *tty, int sig);
|
||||||
|
|
|
@ -64,7 +64,6 @@
|
||||||
#include <linux/security.h>
|
#include <linux/security.h>
|
||||||
#endif
|
#endif
|
||||||
#include <linux/freezer.h>
|
#include <linux/freezer.h>
|
||||||
#include <linux/tty.h>
|
|
||||||
#include <linux/pid_namespace.h>
|
#include <linux/pid_namespace.h>
|
||||||
#include <net/netns/generic.h>
|
#include <net/netns/generic.h>
|
||||||
|
|
||||||
|
@ -430,7 +429,6 @@ restart:
|
||||||
attempts, audit_pid);
|
attempts, audit_pid);
|
||||||
set_current_state(TASK_INTERRUPTIBLE);
|
set_current_state(TASK_INTERRUPTIBLE);
|
||||||
schedule();
|
schedule();
|
||||||
__set_current_state(TASK_RUNNING);
|
|
||||||
goto restart;
|
goto restart;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1341,15 +1339,14 @@ static inline void audit_get_stamp(struct audit_context *ctx,
|
||||||
static long wait_for_auditd(long sleep_time)
|
static long wait_for_auditd(long sleep_time)
|
||||||
{
|
{
|
||||||
DECLARE_WAITQUEUE(wait, current);
|
DECLARE_WAITQUEUE(wait, current);
|
||||||
set_current_state(TASK_UNINTERRUPTIBLE);
|
|
||||||
add_wait_queue_exclusive(&audit_backlog_wait, &wait);
|
|
||||||
|
|
||||||
if (audit_backlog_limit &&
|
if (audit_backlog_limit &&
|
||||||
skb_queue_len(&audit_skb_queue) > audit_backlog_limit)
|
skb_queue_len(&audit_skb_queue) > audit_backlog_limit) {
|
||||||
|
add_wait_queue_exclusive(&audit_backlog_wait, &wait);
|
||||||
|
set_current_state(TASK_UNINTERRUPTIBLE);
|
||||||
sleep_time = schedule_timeout(sleep_time);
|
sleep_time = schedule_timeout(sleep_time);
|
||||||
|
remove_wait_queue(&audit_backlog_wait, &wait);
|
||||||
__set_current_state(TASK_RUNNING);
|
}
|
||||||
remove_wait_queue(&audit_backlog_wait, &wait);
|
|
||||||
|
|
||||||
return sleep_time;
|
return sleep_time;
|
||||||
}
|
}
|
||||||
|
@ -1890,21 +1887,14 @@ void audit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk)
|
||||||
{
|
{
|
||||||
const struct cred *cred;
|
const struct cred *cred;
|
||||||
char comm[sizeof(tsk->comm)];
|
char comm[sizeof(tsk->comm)];
|
||||||
char *tty;
|
struct tty_struct *tty;
|
||||||
|
|
||||||
if (!ab)
|
if (!ab)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* tsk == current */
|
/* tsk == current */
|
||||||
cred = current_cred();
|
cred = current_cred();
|
||||||
|
tty = audit_get_tty(tsk);
|
||||||
spin_lock_irq(&tsk->sighand->siglock);
|
|
||||||
if (tsk->signal && tsk->signal->tty && tsk->signal->tty->name)
|
|
||||||
tty = tsk->signal->tty->name;
|
|
||||||
else
|
|
||||||
tty = "(none)";
|
|
||||||
spin_unlock_irq(&tsk->sighand->siglock);
|
|
||||||
|
|
||||||
audit_log_format(ab,
|
audit_log_format(ab,
|
||||||
" ppid=%d pid=%d auid=%u uid=%u gid=%u"
|
" ppid=%d pid=%d auid=%u uid=%u gid=%u"
|
||||||
" euid=%u suid=%u fsuid=%u"
|
" euid=%u suid=%u fsuid=%u"
|
||||||
|
@ -1920,11 +1910,11 @@ void audit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk)
|
||||||
from_kgid(&init_user_ns, cred->egid),
|
from_kgid(&init_user_ns, cred->egid),
|
||||||
from_kgid(&init_user_ns, cred->sgid),
|
from_kgid(&init_user_ns, cred->sgid),
|
||||||
from_kgid(&init_user_ns, cred->fsgid),
|
from_kgid(&init_user_ns, cred->fsgid),
|
||||||
tty, audit_get_sessionid(tsk));
|
tty ? tty_name(tty) : "(none)",
|
||||||
|
audit_get_sessionid(tsk));
|
||||||
|
audit_put_tty(tty);
|
||||||
audit_log_format(ab, " comm=");
|
audit_log_format(ab, " comm=");
|
||||||
audit_log_untrustedstring(ab, get_task_comm(comm, tsk));
|
audit_log_untrustedstring(ab, get_task_comm(comm, tsk));
|
||||||
|
|
||||||
audit_log_d_path_exe(ab, tsk->mm);
|
audit_log_d_path_exe(ab, tsk->mm);
|
||||||
audit_log_task_context(ab);
|
audit_log_task_context(ab);
|
||||||
}
|
}
|
||||||
|
|
|
@ -661,10 +661,10 @@ static int tag_mount(struct vfsmount *mnt, void *arg)
|
||||||
static int prune_tree_thread(void *unused)
|
static int prune_tree_thread(void *unused)
|
||||||
{
|
{
|
||||||
for (;;) {
|
for (;;) {
|
||||||
set_current_state(TASK_INTERRUPTIBLE);
|
if (list_empty(&prune_list)) {
|
||||||
if (list_empty(&prune_list))
|
set_current_state(TASK_INTERRUPTIBLE);
|
||||||
schedule();
|
schedule();
|
||||||
__set_current_state(TASK_RUNNING);
|
}
|
||||||
|
|
||||||
mutex_lock(&audit_cmd_mutex);
|
mutex_lock(&audit_cmd_mutex);
|
||||||
mutex_lock(&audit_filter_mutex);
|
mutex_lock(&audit_filter_mutex);
|
||||||
|
@ -693,16 +693,14 @@ static int audit_launch_prune(void)
|
||||||
{
|
{
|
||||||
if (prune_thread)
|
if (prune_thread)
|
||||||
return 0;
|
return 0;
|
||||||
prune_thread = kthread_create(prune_tree_thread, NULL,
|
prune_thread = kthread_run(prune_tree_thread, NULL,
|
||||||
"audit_prune_tree");
|
"audit_prune_tree");
|
||||||
if (IS_ERR(prune_thread)) {
|
if (IS_ERR(prune_thread)) {
|
||||||
pr_err("cannot start thread audit_prune_tree");
|
pr_err("cannot start thread audit_prune_tree");
|
||||||
prune_thread = NULL;
|
prune_thread = NULL;
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
} else {
|
|
||||||
wake_up_process(prune_thread);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* called with audit_filter_mutex */
|
/* called with audit_filter_mutex */
|
||||||
|
|
|
@ -1980,6 +1980,7 @@ static void audit_log_set_loginuid(kuid_t koldloginuid, kuid_t kloginuid,
|
||||||
{
|
{
|
||||||
struct audit_buffer *ab;
|
struct audit_buffer *ab;
|
||||||
uid_t uid, oldloginuid, loginuid;
|
uid_t uid, oldloginuid, loginuid;
|
||||||
|
struct tty_struct *tty;
|
||||||
|
|
||||||
if (!audit_enabled)
|
if (!audit_enabled)
|
||||||
return;
|
return;
|
||||||
|
@ -1987,14 +1988,17 @@ static void audit_log_set_loginuid(kuid_t koldloginuid, kuid_t kloginuid,
|
||||||
uid = from_kuid(&init_user_ns, task_uid(current));
|
uid = from_kuid(&init_user_ns, task_uid(current));
|
||||||
oldloginuid = from_kuid(&init_user_ns, koldloginuid);
|
oldloginuid = from_kuid(&init_user_ns, koldloginuid);
|
||||||
loginuid = from_kuid(&init_user_ns, kloginuid),
|
loginuid = from_kuid(&init_user_ns, kloginuid),
|
||||||
|
tty = audit_get_tty(current);
|
||||||
|
|
||||||
ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_LOGIN);
|
ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_LOGIN);
|
||||||
if (!ab)
|
if (!ab)
|
||||||
return;
|
return;
|
||||||
audit_log_format(ab, "pid=%d uid=%u", task_pid_nr(current), uid);
|
audit_log_format(ab, "pid=%d uid=%u", task_pid_nr(current), uid);
|
||||||
audit_log_task_context(ab);
|
audit_log_task_context(ab);
|
||||||
audit_log_format(ab, " old-auid=%u auid=%u old-ses=%u ses=%u res=%d",
|
audit_log_format(ab, " old-auid=%u auid=%u tty=%s old-ses=%u ses=%u res=%d",
|
||||||
oldloginuid, loginuid, oldsessionid, sessionid, !rc);
|
oldloginuid, loginuid, tty ? tty_name(tty) : "(none)",
|
||||||
|
oldsessionid, sessionid, !rc);
|
||||||
|
audit_put_tty(tty);
|
||||||
audit_log_end(ab);
|
audit_log_end(ab);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue