Skip to content

Commit

Permalink
Merge branch 'stable-4.7' of git://git.infradead.org/users/pcmoore/audit
Browse files Browse the repository at this point in the history
Pull audit fixes from Paul Moore:
 "Two small patches to fix audit problems in 4.7-rcX: the first fixes a
  potential kref leak, the second removes some header file noise.

  The first is an important bug fix that really should go in before 4.7
  is released, the second is not critical, but falls into the very-nice-
  to-have category so I'm including in the pull request.

  Both patches are straightforward, self-contained, and pass our
  testsuite without problem"

* 'stable-4.7' of git://git.infradead.org/users/pcmoore/audit:
  audit: move audit_get_tty to reduce scope and kabi changes
  audit: move calcs after alloc and check when logging set loginuid
  • Loading branch information
torvalds committed Jun 29, 2016
2 parents 32826ac + 3f5be2d commit 89a82a9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 28 deletions.
24 changes: 0 additions & 24 deletions include/linux/audit.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <linux/sched.h>
#include <linux/ptrace.h>
#include <uapi/linux/audit.h>
#include <linux/tty.h>

#define AUDIT_INO_UNSET ((unsigned long)-1)
#define AUDIT_DEV_UNSET ((dev_t)-1)
Expand Down Expand Up @@ -348,23 +347,6 @@ static inline unsigned int audit_get_sessionid(struct task_struct *tsk)
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_set_perm(unsigned long qbytes, uid_t uid, gid_t gid, umode_t mode);
extern void __audit_bprm(struct linux_binprm *bprm);
Expand Down Expand Up @@ -522,12 +504,6 @@ static inline unsigned int audit_get_sessionid(struct task_struct *tsk)
{
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_set_perm(unsigned long qbytes, uid_t uid,
Expand Down
17 changes: 17 additions & 0 deletions kernel/audit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1883,6 +1883,23 @@ void audit_log_d_path_exe(struct audit_buffer *ab,
audit_log_format(ab, " exe=(null)");
}

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;
}

void audit_put_tty(struct tty_struct *tty)
{
tty_kref_put(tty);
}

void audit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk)
{
const struct cred *cred;
Expand Down
4 changes: 4 additions & 0 deletions kernel/audit.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <linux/audit.h>
#include <linux/skbuff.h>
#include <uapi/linux/mqueue.h>
#include <linux/tty.h>

/* 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
Expand Down Expand Up @@ -262,6 +263,9 @@ extern struct audit_entry *audit_dupe_rule(struct audit_krule *old);
extern void audit_log_d_path_exe(struct audit_buffer *ab,
struct mm_struct *mm);

extern struct tty_struct *audit_get_tty(struct task_struct *tsk);
extern void audit_put_tty(struct tty_struct *tty);

/* audit watch functions */
#ifdef CONFIG_AUDIT_WATCH
extern void audit_put_watch(struct audit_watch *watch);
Expand Down
8 changes: 4 additions & 4 deletions kernel/auditsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
#include <asm/unistd.h>
#include <linux/security.h>
#include <linux/list.h>
#include <linux/tty.h>
#include <linux/binfmts.h>
#include <linux/highmem.h>
#include <linux/syscalls.h>
Expand Down Expand Up @@ -1985,14 +1984,15 @@ static void audit_log_set_loginuid(kuid_t koldloginuid, kuid_t kloginuid,
if (!audit_enabled)
return;

ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_LOGIN);
if (!ab)
return;

uid = from_kuid(&init_user_ns, task_uid(current));
oldloginuid = from_kuid(&init_user_ns, koldloginuid);
loginuid = from_kuid(&init_user_ns, kloginuid),
tty = audit_get_tty(current);

ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_LOGIN);
if (!ab)
return;
audit_log_format(ab, "pid=%d uid=%u", task_pid_nr(current), uid);
audit_log_task_context(ab);
audit_log_format(ab, " old-auid=%u auid=%u tty=%s old-ses=%u ses=%u res=%d",
Expand Down

0 comments on commit 89a82a9

Please sign in to comment.