10000 Merge branch 'stable-4.7' of git://git.infradead.org/users/pcmoore/audit · bsd-unix/linux@89a82a9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 89a82a9

Browse files
committed
Merge branch 'stable-4.7' of git://git.infradead.org/users/pcmoore/audit
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
2 parents 32826ac + 3f5be2d commit 89a82a9

File tree

4 files changed

+25
-28
lines changed

4 files changed

+25
-28
lines changed

include/linux/audit.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <linux/sched.h>
2727
#include <linux/ptrace.h>
2828
#include <uapi/linux/audit.h>
29-
#include <linux/tty.h>
3029

3130
#define AUDIT_INO_UNSET ((unsigned long)-1)
3231
#define AUDIT_DEV_UNSET ((dev_t)-1)
@@ -348,23 +347,6 @@ static inline unsigned int audit_get_sessionid(struct task_struct *tsk)
348347
return tsk->sessionid;
349348
}
350349

351-
static inline struct tty_struct *audit_get_tty(struct task_struct *tsk)
352-
{
353-
struct tty_struct *tty = NULL;
354-
unsigned long flags;
355-
356-
spin_lock_irqsave(&tsk->sighand->siglock, flags);
357-
if (tsk->signal)
358-
tty = tty_kref_get(tsk->signal->tty);
359-
spin_unlock_irqrestore(&tsk->sighand->siglock, flags);
360-
return tty;
361-
}
362-
363-
static inline void audit_put_tty(struct tty_struct *tty)
364-
{
365-
tty_kref_put(tty);
366-
}
367-
368350
extern void __audit_ipc_obj(struct kern_ipc_perm *ipcp);
369351
extern void __audit_ipc_set_perm(unsigned long qbytes, uid_t uid, gid_t gid, umode_t mode);
370352
extern void __audit_bprm(struct linux_binprm *bprm);
@@ -522,12 +504,6 @@ static inline unsigned int audit_get_sessionid(struct task_struct *tsk)
522504
{
523505
return -1;
524506
}
525-
static inline struct tty_struct *audit_get_tty(struct task_struct *tsk)
526-
{
527-
return NULL;
528-
}
529-
static inline void audit_put_tty(struct tty_struct *tty)
530-
{ }
531507
static inline void audit_ipc_obj(struct kern_ipc_perm *ipcp)
532508
{ }
533509
static inline void audit_ipc_set_perm(unsigned long qbytes, uid_t uid,

kernel/audit.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,6 +1883,23 @@ void audit_log_d_path_exe(struct audit_buffer *ab,
18831883
audit_log_format(ab, " exe=(null)");
18841884
}
18851885

1886+
struct tty_struct *audit_get_tty(struct task_struct *tsk)
1887+
{
1888+
struct tty_struct *tty = NULL;
1889+
unsigned long flags;
1890+
1891+
spin_lock_irqsave(&tsk->sighand->siglock, flags);
1892+
if (tsk->signal)
1893+
tty = tty_kref_get(tsk->signal->tty);
1894+
spin_unlock_irqrestore(&tsk->sighand->siglock, flags);
1895+
return tty;
1896+
}
1897+
1898+
void audit_put_tty(struct tty_struct *tty)
1899+
{
1900+
tty_kref_put(tty);
1901+
}
1902+
18861903
void audit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk)
18871904
{
18881905
const struct cred *cred;

kernel/audit.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/audit.h>
2424
#include <linux/skbuff.h>
2525
#include <uapi/linux/mqueue.h>
26+
#include <linux/tty.h>
2627

2728
/* AUDIT_NAMES is the number of slots we reserve in the audit_context
2829
* for saving names from getname(). If we get more names we will allocate
@@ -262,6 +263,9 @@ extern struct audit_entry *audit_dupe_rule(struct audit_krule *old);
262263
extern void audit_log_d_path_exe(struct audit_buffer *ab,
263264
struct mm_struct *mm);
264265

266+
extern struct tty_struct *audit_get_tty(struct task_struct *tsk);
267+
extern void audit_put_tty(struct tty_struct *tty);
268+
265269
/* audit watch functions */
266270
#ifdef CONFIG_AUDIT_WATCH
267271
extern void audit_put_watch(struct audit_watch *watch);

kernel/auditsc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
#include <asm/unistd.h>
6464
#include <linux/security.h>
6565
#include <linux/list.h>
66-
#include <linux/tty.h>
6766
#include <linux/binfmts.h>
6867
#include <linux/highmem.h>
6968
#include <linux/syscalls.h>
@@ -1985,14 +1984,15 @@ static void audit_log_set_loginuid(kuid_t koldloginuid, kuid_t kloginuid,
19851984
if (!audit_enabled)
19861985
return;
19871986

1987+
ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_LOGIN);
1988+
if (!ab)
1989+
return;
1990+
19881991
uid = from_kuid(&init_user_ns, task_uid(current));
19891992
oldloginuid = from_kuid(&init_user_ns, koldloginuid);
19901993
loginuid = from_kuid(&init_user_ns, kloginuid),
19911994
tty = audit_get_tty(current);
19921995

1993-
ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_LOGIN);
1994-
if (!ab)
1995-
return;
19961996
audit_log_format(ab, "pid=%d uid=%u", task_pid_nr(current), uid);
19971997
audit_log_task_context(ab);
19981998
audit_log_format(ab, " old-auid=%u auid=%u tty=%s old-ses=%u ses=%u res=%d",

0 commit comments

Comments
 (0)
0