Skip to content

Commit 9d2161b

Browse files
rgbriggspcmoore
authored andcommitted
audit: log audit netlink multicast bind and unbind
Log information about programs connecting to and disconnecting from the audit netlink multicast socket. This is needed so that during investigations a security officer can tell who or what had access to the audit trail. This helps to meet the FAU_SAR.2 requirement for Common Criteria. Here is the systemd startup event: type=PROCTITLE msg=audit(2020-04-22 10:10:21.787:10) : proctitle=/init type=SYSCALL msg=audit(2020-04-22 10:10:21.787:10) : arch=x86_64 syscall=bind success=yes exit=0 a0=0x19 a1=0x555f4aac7e90 a2=0xc a3=0x7ffcb792ff44 items=0 ppid=0 pid=1 auid=unset uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=(none) ses=unset comm=systemd exe=/usr/lib/systemd/systemd subj=kernel key=(null) type=UNKNOWN[1335] msg=audit(2020-04-22 10:10:21.787:10) : pid=1 uid=root auid=unset tty=(none) ses=unset subj=kernel comm=systemd exe=/usr/lib/systemd/systemd nl-mcgrp=1 op=connect res=yes And events from the test suite that just uses close(): type=PROCTITLE msg=audit(2020-04-22 11:47:08.501:442) : proctitle=/usr/bin/perl -w amcast_joinpart/test type=SYSCALL msg=audit(2020-04-22 11:47:08.501:442) : arch=x86_64 syscall=bind success=yes exit=0 a0=0x7 a1=0x563004378760 a2=0xc a3=0x0 items=0 ppid=815 pid=818 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=perl exe=/usr/bin/perl subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=(null) type=UNKNOWN[1335] msg=audit(2020-04-22 11:47:08.501:442) : pid=818 uid=root auid=root tty=ttyS0 ses=1 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 comm=perl exe=/usr/bin/perl nl-mcgrp=1 op=connect res=yes type=UNKNOWN[1335] msg=audit(2020-04-22 11:47:08.501:443) : pid=818 uid=root auid=root tty=ttyS0 ses=1 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 comm=perl exe=/usr/bin/perl nl-mcgrp=1 op=disconnect res=yes And the events from the test suite using setsockopt with NETLINK_DROP_MEMBERSHIP: type=PROCTITLE msg=audit(2020-04-22 11:39:53.291:439) : proctitle=/usr/bin/perl -w amcast_joinpart/test type=SYSCALL msg=audit(2020-04-22 11:39:53.291:439) : arch=x86_64 syscall=bind success=yes exit=0 a0=0x7 a1=0x5560877c2d20 a2=0xc a3=0x0 items=0 ppid=772 pid=775 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=perl exe=/usr/bin/perl subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=(null) type=UNKNOWN[1335] msg=audit(2020-04-22 11:39:53.291:439) : pid=775 uid=root auid=root tty=ttyS0 ses=1 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 comm=perl exe=/usr/bin/perl nl-mcgrp=1 op=connect res=yes type=PROCTITLE msg=audit(2020-04-22 11:39:53.292:440) : proctitle=/usr/bin/perl -w amcast_joinpart/test type=SYSCALL msg=audit(2020-04-22 11:39:53.292:440) : arch=x86_64 syscall=setsockopt success=yes exit=0 a0=0x7 a1=SOL_NETLINK a2=0x2 a3=0x7ffc8366f000 items=0 ppid=772 pid=775 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=ttyS0 ses=1 comm=perl exe=/usr/bin/perl subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=(null) type=UNKNOWN[1335] msg=audit(2020-04-22 11:39:53.292:440) : pid=775 uid=root auid=root tty=ttyS0 ses=1 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 comm=perl exe=/usr/bin/perl nl-mcgrp=1 op=disconnect res=yes Please see the upstream issue tracker at linux-audit/audit-kernel#28 With the feature description at https://github.com/linux-audit/audit-kernel/wiki/RFE-Audit-Multicast-Socket-Join-Part The testsuite support is at https://github.com/rgbriggs/audit-testsuite/compare/ghak28-mcast-part-join linux-audit/audit-testsuite#93 And the userspace support patch is at linux-audit/audit-userspace#114 Signed-off-by: Richard Guy Briggs <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 3054d06 commit 9d2161b

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

include/uapi/linux/audit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
#define AUDIT_TIME_INJOFFSET 1332 /* Timekeeping offset injected */
118118
#define AUDIT_TIME_ADJNTPVAL 1333 /* NTP value adjustment */
119119
#define AUDIT_BPF 1334 /* BPF subsystem */
120+
#define AUDIT_EVENT_LISTENER 1335 /* Task joined multicast read socket */
120121

121122
#define AUDIT_AVC 1400 /* SE Linux avc denial or grant */
122123
#define AUDIT_SELINUX_ERR 1401 /* Internal SE Linux Errors */

kernel/audit.c

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,20 +1530,60 @@ static void audit_receive(struct sk_buff *skb)
15301530
audit_ctl_unlock();
15311531
}
15321532

1533+
/* Log information about who is connecting to the audit multicast socket */
1534+
static void audit_log_multicast(int group, const char *op, int err)
1535+
{
1536+
const struct cred *cred;
1537+
struct tty_struct *tty;
1538+
char comm[sizeof(current->comm)];
1539+
struct audit_buffer *ab;
1540+
1541+
if (!audit_enabled)
1542+
return;
1543+
1544+
ab = audit_log_start(audit_context(), GFP_KERNEL, AUDIT_EVENT_LISTENER);
1545+
if (!ab)
1546+
return;
1547+
1548+
cred = current_cred();
1549+
tty = audit_get_tty();
1550+
audit_log_format(ab, "pid=%u uid=%u auid=%u tty=%s ses=%u",
1551+
task_pid_nr(current),
1552+
from_kuid(&init_user_ns, cred->uid),
1553+
from_kuid(&init_user_ns, audit_get_loginuid(current)),
1554+
tty ? tty_name(tty) : "(none)",
1555+
audit_get_sessionid(current));
1556+
audit_put_tty(tty);
1557+
audit_log_task_context(ab); /* subj= */
1558+
audit_log_format(ab, " comm=");
1559+
audit_log_untrustedstring(ab, get_task_comm(comm, current));
1560+
audit_log_d_path_exe(ab, current->mm); /* exe= */
1561+
audit_log_format(ab, " nl-mcgrp=%d op=%s res=%d", group, op, !err);
1562+
audit_log_end(ab);
1563+
}
1564+
15331565
/* Run custom bind function on netlink socket group connect or bind requests. */
1534-
static int audit_bind(struct net *net, int group)
1566+
static int audit_multicast_bind(struct net *net, int group)
15351567
{
1568+
int err = 0;
1569+
15361570
if (!capable(CAP_AUDIT_READ))
1537-
return -EPERM;
1571+
err = -EPERM;
1572+
audit_log_multicast(group, "connect", err);
1573+
return err;
1574+
}
15381575

1539-
return 0;
1576+
static void audit_multicast_unbind(struct net *net, int group)
1577+
{
1578+
audit_log_multicast(group, "disconnect", 0);
15401579
}
15411580

15421581
static int __net_init audit_net_init(struct net *net)
15431582
{
15441583
struct netlink_kernel_cfg cfg = {
15451584
.input = audit_receive,
1546-
.bind = audit_bind,
1585+
.bind = audit_multicast_bind,
1586+
.unbind = audit_multicast_unbind,
15471587
.flags = NL_CFG_F_NONROOT_RECV,
15481588
.groups = AUDIT_NLGRP_MAX,
15491589
};

0 commit comments

Comments
 (0)