Skip to content

Commit 451f921

Browse files
rgbriggsdavem330
authored andcommitted
audit: add netlink multicast group for log read
Add a netlink multicast socket with one group to kaudit for "best-effort" delivery to read-only userspace clients such as systemd, in addition to the existing bidirectional unicast auditd userspace client. Currently, auditd is intended to use the CAP_AUDIT_CONTROL and CAP_AUDIT_WRITE capabilities, but actually uses CAP_NET_ADMIN. The CAP_AUDIT_READ capability is added for use by read-only AUDIT_NLGRP_READLOG netlink multicast group clients to the kaudit subsystem. This will safely give access to services such as systemd to consume audit logs while ensuring write access remains restricted for integrity. Signed-off-by: Richard Guy Briggs <rgb@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 3a101b8 commit 451f921

2 files changed

Lines changed: 55 additions & 4 deletions

File tree

‎include/uapi/linux/audit.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,14 @@ enum {
373373
*/
374374
#define AUDIT_MESSAGE_TEXT_MAX 8560
375375

376+
/* Multicast Netlink socket groups (default up to 32) */
377+
enum audit_nlgrps {
378+
AUDIT_NLGRP_NONE, /* Group 0 not used */
379+
AUDIT_NLGRP_READLOG, /* "best effort" read only socket */
380+
__AUDIT_NLGRP_MAX
381+
};
382+
#define AUDIT_NLGRP_MAX (__AUDIT_NLGRP_MAX - 1)
383+
376384
struct audit_status {
377385
__u32 mask; /* Bit mask for valid entries */
378386
__u32 enabled; /* 1 = enabled, 0 = disabled */

‎kernel/audit.c‎

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,35 @@ static void kauditd_send_skb(struct sk_buff *skb)
423423
consume_skb(skb);
424424
}
425425

426+
/*
427+
* kauditd_send_multicast_skb - send the skb to multicast userspace listeners
428+
*
429+
* This function doesn't consume an skb as might be expected since it has to
430+
* copy it anyways.
431+
*/
432+
static void kauditd_send_multicast_skb(struct sk_buff *skb)
433+
{
434+
struct sk_buff *copy;
435+
struct audit_net *aunet = net_generic(&init_net, audit_net_id);
436+
struct sock *sock = aunet->nlsk;
437+
438+
/*
439+
* The seemingly wasteful skb_copy() rather than bumping the refcount
440+
* using skb_get() is necessary because non-standard mods are made to
441+
* the skb by the original kaudit unicast socket send routine. The
442+
* existing auditd daemon assumes this breakage. Fixing this would
443+
* require co-ordinating a change in the established protocol between
444+
* the kaudit kernel subsystem and the auditd userspace code. There is
445+
* no reason for new multicast clients to continue with this
446+
* non-compliance.
447+
*/
448+
copy = skb_copy(skb, GFP_KERNEL);
449+
if (!copy)
450+
return;
451+
452+
nlmsg_multicast(sock, copy, 0, AUDIT_NLGRP_READLOG, GFP_KERNEL);
453+
}
454+
426455
/*
427456
* flush_hold_queue - empty the hold queue if auditd appears
428457
*
@@ -1090,6 +1119,8 @@ static int __net_init audit_net_init(struct net *net)
10901119
struct netlink_kernel_cfg cfg = {
10911120
.input = audit_receive,
10921121
.bind = audit_bind,
1122+
.flags = NL_CFG_F_NONROOT_RECV,
1123+
.groups = AUDIT_NLGRP_MAX,
10931124
};
10941125

10951126
struct audit_net *aunet = net_generic(net, audit_net_id);
@@ -1911,10 +1942,10 @@ void audit_log_link_denied(const char *operation, struct path *link)
19111942
* audit_log_end - end one audit record
19121943
* @ab: the audit_buffer
19131944
*
1914-
* The netlink_* functions cannot be called inside an irq context, so
1915-
* the audit buffer is placed on a queue and a tasklet is scheduled to
1916-
* remove them from the queue outside the irq context. May be called in
1917-
* any context.
1945+
* netlink_unicast() cannot be called inside an irq context because it blocks
1946+
* (last arg, flags, is not set to MSG_DONTWAIT), so the audit buffer is placed
1947+
* on a queue and a tasklet is scheduled to remove them from the queue outside
1948+
* the irq context. May be called in any context.
19181949
*/
19191950
void audit_log_end(struct audit_buffer *ab)
19201951
{
@@ -1924,6 +1955,18 @@ void audit_log_end(struct audit_buffer *ab)
19241955
audit_log_lost("rate limit exceeded");
19251956
} else {
19261957
struct nlmsghdr *nlh = nlmsg_hdr(ab->skb);
1958+
1959+
kauditd_send_multicast_skb(ab->skb);
1960+
1961+
/*
1962+
* The original kaudit unicast socket sends up messages with
1963+
* nlmsg_len set to the payload length rather than the entire
1964+
* message length. This breaks the standard set by netlink.
1965+
* The existing auditd daemon assumes this breakage. Fixing
1966+
* this would require co-ordinating a change in the established
1967+
* protocol between the kaudit kernel subsystem and the auditd
1968+
* userspace code.
1969+
*/
19271970
nlh->nlmsg_len = ab->skb->len - NLMSG_HDRLEN;
19281971

19291972
if (audit_pid) {

0 commit comments

Comments
 (0)