Skip to content

Commit 46e959e

Browse files
rgbriggseparis
authored andcommitted
audit: add an option to control logging of passwords with pam_tty_audit
Most commands are entered one line at a time and processed as complete lines in non-canonical mode. Commands that interactively require a password, enter canonical mode to do this while shutting off echo. This pair of features (icanon and !echo) can be used to avoid logging passwords by audit while still logging the rest of the command. Adding a member (log_passwd) to the struct audit_tty_status passed in by pam_tty_audit allows control of canonical mode without echo per task. Signed-off-by: Richard Guy Briggs <rgb@redhat.com> Signed-off-by: Eric Paris <eparis@redhat.com>
1 parent bde02ca commit 46e959e

4 files changed

Lines changed: 22 additions & 7 deletions

File tree

‎drivers/tty/tty_audit.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ void tty_audit_fork(struct signal_struct *sig)
138138

139139
spin_lock_irqsave(&current->sighand->siglock, flags);
140140
sig->audit_tty = current->signal->audit_tty;
141+
sig->audit_tty_log_passwd = current->signal->audit_tty_log_passwd;
141142
spin_unlock_irqrestore(&current->sighand->siglock, flags);
142143
}
143144

@@ -275,10 +276,18 @@ void tty_audit_add_data(struct tty_struct *tty, unsigned char *data,
275276
{
276277
struct tty_audit_buf *buf;
277278
int major, minor;
279+
int audit_log_tty_passwd;
280+
unsigned long flags;
278281

279282
if (unlikely(size == 0))
280283
return;
281284

285+
spin_lock_irqsave(&current->sighand->siglock, flags);
286+
audit_log_tty_passwd = current->signal->audit_tty_log_passwd;
287+
spin_unlock_irqrestore(&current->sighand->siglock, flags);
288+
if (!audit_log_tty_passwd && icanon && !L_ECHO(tty))
289+
return;
290+
282291
if (tty->driver->type == TTY_DRIVER_TYPE_PTY
283292
&& tty->driver->subtype == PTY_TYPE_MASTER)
284293
return;

‎include/linux/sched.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ struct signal_struct {
641641
#endif
642642
#ifdef CONFIG_AUDIT
643643
unsigned audit_tty;
644+
unsigned audit_tty_log_passwd;
644645
struct tty_audit_buf *tty_audit_buf;
645646
#endif
646647
#ifdef CONFIG_CGROUPS

‎include/uapi/linux/audit.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,8 @@ struct audit_status {
369369
};
370370

371371
struct audit_tty_status {
372-
__u32 enabled; /* 1 = enabled, 0 = disabled */
372+
__u32 enabled; /* 1 = enabled, 0 = disabled */
373+
__u32 log_passwd; /* 1 = enabled, 0 = disabled */
373374
};
374375

375376
/* audit_rule_data supports filter rules with both integer and string

‎kernel/audit.c‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include <linux/slab.h>
5050
#include <linux/err.h>
5151
#include <linux/kthread.h>
52+
#include <linux/kernel.h>
5253

5354
#include <linux/audit.h>
5455

@@ -808,25 +809,28 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
808809

809810
spin_lock_irqsave(&tsk->sighand->siglock, flags);
810811
s.enabled = tsk->signal->audit_tty != 0;
812+
s.log_passwd = tsk->signal->audit_tty_log_passwd;
811813
spin_unlock_irqrestore(&tsk->sighand->siglock, flags);
812814

813815
audit_send_reply(NETLINK_CB(skb).portid, seq,
814816
AUDIT_TTY_GET, 0, 0, &s, sizeof(s));
815817
break;
816818
}
817819
case AUDIT_TTY_SET: {
818-
struct audit_tty_status *s;
820+
struct audit_tty_status s;
819821
struct task_struct *tsk = current;
820822
unsigned long flags;
821823

822-
if (nlh->nlmsg_len < sizeof(struct audit_tty_status))
823-
return -EINVAL;
824-
s = data;
825-
if (s->enabled != 0 && s->enabled != 1)
824+
memset(&s, 0, sizeof(s));
825+
/* guard against past and future API changes */
826+
memcpy(&s, data, min(sizeof(s), (size_t)nlh->nlmsg_len));
827+
if ((s.enabled != 0 && s.enabled != 1) ||
828+
(s.log_passwd != 0 && s.log_passwd != 1))
826829
return -EINVAL;
827830

828831
spin_lock_irqsave(&tsk->sighand->siglock, flags);
829-
tsk->signal->audit_tty = s->enabled != 0;
832+
tsk->signal->audit_tty = s.enabled;
833+
tsk->signal->audit_tty_log_passwd = s.log_passwd;
830834
spin_unlock_irqrestore(&tsk->sighand->siglock, flags);
831835
break;
832836
}

0 commit comments

Comments
 (0)