add support for audit container identifier
Subsystems (2)
v8 cover add support for audit container identifier
Add support for audit kernel container identifiers to userspace tools.
The first and second add new record types. The third adds filter support. The fourth and 5th start to add search support.
The 6th is to read the calling process' audit container identifier from the /proc filesystem matching the kernel /proc read patch.
The 7th is to fix signal support and the 8th is to learn the audit container identifier of the process that signals the audit daemon.
The 9th is a touch up to allow the contid field to be interpreted as a CSV list.
The 10th and 11th add audit contid list support to ausearch.
The 12th and 13th add support to auditctl for setting the limits for nesting depth and netns contid counts to prevent overflowing the contid text fields in CONTAINER_* records.
The last adds audit library support to allow a process to give permission to a container orchestrator in a non-init user namespace via audit netlink messages.
See: https://github.com/linux-audit/audit-userspace/issues/51
See: https://github.com/linux-audit/audit-userspace/issues/40
See: https://github.com/linux-audit/audit-kernel/issues/90
See: https://github.com/linux-audit/audit-kernel/issues/91
See: https://github.com/linux-audit/audit-testsuite/issues/64
https://githu.com/linux-audit/audit-testsuite/pull/91
https://github.com/rgbriggs/audit-testsuite/tree/ghat64-contid
See: https://github.com/linux-audit/audit-kernel/wiki/RFE-Audit-Container-ID
A repo of the code is here:
[email protected]:rgbriggs/audit-userspace.git ghau40-containerid-filter.v8
And test rpms built from it are here:
people.redhat.com/~rbriggs/ghak90/git-47ad4ca
Changelog:
v8
- renumber contid records and drop netlink contid set/get support
- remove subject attributes from parse_container_op()
- fix audit_request_signal_info.3 manpage
- add manpage for audit_set_capcontid()
- implement clist for contid list search
- rebase on audit_bpf patches (bump CONTAINER_ID to 1335)
- implement control for audit container identifier nesting depth limit with manpage
- implent control for audit container identifier netns count limit with manpage
v7
- rebase on ghau90 and touchup
- rebase on ghak10 support (change AUDIT_CONTAINER_ID to 1334)
- render type contid as a CSV
- switch from /proc to audit netlink to set/get contid, auid/sessionid
- add support for capcontid
v6
- auditd signaller tracking was moved to a new AUDIT_SIGNAL_INFO2 request and record
- swap CONTAINER_OP contid/old-contid to ease parsing
- add to auparse
v5
- updated aux record from AUDIT_CONTAINER to AUDIT_CONTAINER_ID
- add AUDIT_CONTAINER_ID to normalization
- rebase on AUDIT_ANOM_LINK and AUDIT_MAC_CALIPSO_ADD
v4
- change from AUDIT_CONTAINER_ID to AUDIT_CONTAINER_OP
- change from AUDIT_FEATURE_BITMAP_CONTAINERID_FILTER to AUDIT_FEATURE_BITMAP_CONTAINERID
- change from event_container_id to event_contid internally
- change from container_id to contid and event_container_id to event_contid internally
- change command line option from --container-id to --contid
v3
- change from AUDIT_CONTAINER to AUDIT_CONTAINER_ID
- change from AUDIT_CONTAINER_INFO to AUDIT_CONTAINER
- change from AUDIT_CONTAINERID to AUDIT_CONTID
- update github issue refs
- add audit_get_containerid
- change event_container_id default value
- add --containerid to ausearch options help text
- update ausearch parser and error codes
v2
- rebase on UINT_MAX patch
- add patches for AUDIT_CONTAINER, AUDIT_CONTAINER_INFO, ausearch, normalization
Richard Guy Briggs (14):
AUDIT_CONTAINER_OP message type basic support AUDIT_CONTAINER_ID message type basic support
auditctl: add support for AUDIT_CONTID filter
add ausearch containerid support
start normalization containerid support
libaudit: add support to get the task audit container identifier
signal_info: only print context if it is available.
add support for audit_signal_info2
contid: interpret correctly CONTAINER_ID contid field csv
ausearch: convert contid to comma/carrat-sep list
ausearch: convert contid to comma/carrat-sep cnode/clist
auditctl: add a config parameter to limit the contid nesting depth
auditctl: add a config parameter to limit the contid netns count
libaudit: add support to get and set capcontid on a task
auparse/auditd-config.c | 1 + auparse/auparse-defs.h | 3 +- auparse/interpret.c | 10 ++ auparse/normalize_record_map.h | 2 + auparse/typetab.h | 2 + bindings/python/auparse_python.c | 1 + configure.ac | 2 + docs/Makefile.am | 6 +- docs/audit_get_capcontid.3 | 25 ++++ docs/audit_get_containerid.3 | 25 ++++ docs/audit_request_signal_info.3 | 11 ++ docs/audit_set_capcontid.3 | 24 ++++ docs/audit_set_contid_depth_limit.3 | 26 ++++ docs/audit_set_contid_netns_limit.3 | 25 ++++ docs/auditctl.8 | 9 ++ lib/fieldtab.h | 1 + lib/libaudit.c | 230 ++++++++++++++++++++++++++++++++++-- lib/libaudit.h | 36 ++++++ lib/msg_typetab.h | 4 + lib/netlink.c | 5 + src/Makefile.am | 6 +- src/auditctl-listing.c | 29 +++++ src/auditctl.c | 66 +++++++++++ src/auditd-config.c | 1 + src/auditd-config.h | 1 + src/auditd-event.c | 28 ++++- src/auditd-reconfig.c | 25 ++-- src/auditd.c | 3 +- src/aureport-options.c | 1 + src/ausearch-contid.c | 171 +++++++++++++++++++++++++++ src/ausearch-contid.h | 61 ++++++++++ src/ausearch-llist.c | 6 + src/ausearch-llist.h | 2 + src/ausearch-match.c | 35 ++++++ src/ausearch-options.c | 77 +++++++++++- src/ausearch-options.h | 2 + src/ausearch-parse.c | 131 ++++++++++++++++++++ src/ausearch-report.c | 6 +- 38 files changed, 1068 insertions(+), 31 deletions(-) create mode 100644 docs/audit_get_capcontid.3 create mode 100644 docs/audit_get_containerid.3 create mode 100644 docs/audit_set_capcontid.3 create mode 100644 docs/audit_set_contid_depth_limit.3 create mode 100644 docs/audit_set_contid_netns_limit.3 create mode 100644 src/ausearch-contid.c create mode 100644 src/ausearch-contid.h
Signature · 1 line
1.8.3.1
PATCH v8 1/14 AUDIT_CONTAINER_OP message type basic support
This defines the message number for the audit container identifier registration record should the kernel headers not be up to date, gives the record number a name for printing and allows the record to be interpreted since it is in the 1000 range like AUDIT_LOGIN.
See: https://github.com/linux-audit/audit-userspace/issues/51
See: https://github.com/linux-audit/audit-kernel/issues/90
See: https://github.com/linux-audit/audit-testsuite/issues/64
See: https://github.com/linux-audit/audit-kernel/wiki/RFE-Audit-Container-ID
--- lib/libaudit.h | 4 ++++ lib/msg_typetab.h | 1 + lib/netlink.c | 1 + 3 files changed, 6 insertions(+)
lib/libaudit.h +4 -0
@@ -246,6 +246,10 @@ extern "C" {#define AUDIT_GET_FEATURE 1019/* Get which features are enabled */ #endif +#ifndef AUDIT_CONTAINER_OP +#define AUDIT_CONTAINER_OP 1020/* Container creation notice */ +#endif +#ifndef AUDIT_MMAP #define AUDIT_MMAP 1323/* Descriptor and flags in mmap */ #endif
lib/msg_typetab.h +1 -0
@@ -44,6 +44,7 @@ _S(AUDIT_LOGIN, "LOGIN" )//_S(AUDIT_TTY_SET, "TTY_SET" ) //_S(AUDIT_SET_FEATURE, "SET_FEATURE" ) //_S(AUDIT_GET_FEATURE, "GET_FEATURE" ) +_S(AUDIT_CONTAINER_OP, "CONTAINER_OP" ) _S(AUDIT_USER_AUTH, "USER_AUTH" ) _S(AUDIT_USER_ACCT, "USER_ACCT" )_S (AUDIT_USER_MGMT ,"USER_MGMT" )
lib/netlink.c +1 -0
@@ -184,6 +184,7 @@ static int adjust_reply(struct audit_reply *rep, int len)break ;case AUDIT_USER :case AUDIT_LOGIN : +case AUDIT_CONTAINER_OP :case AUDIT_KERNEL : case AUDIT_FIRST_USER_MSG...AUDIT_LAST_USER_MSG: case AUDIT_FIRST_USER_MSG2...AUDIT_LAST_USER_MSG2:
Signature · 1 line
1.8.3.1
PATCH v8 2/14 AUDIT_CONTAINER_ID message type basic support
In reply to Richard Guy BriggsThis defines the message number for the audit container identifier information record should the kernel headers not be up to date and gives the record number a name for printing.
See: https://github.com/linux-audit/audit-userspace/issues/51
See: https://github.com/linux-audit/audit-kernel/issues/90
See: https://github.com/linux-audit/audit-testsuite/issues/64
See: https://github.com/linux-audit/audit-kernel/wiki/RFE-Audit-Container-ID
--- lib/libaudit.h | 4 ++++ lib/msg_typetab.h | 1 + 2 files changed, 5 insertions(+)
lib/libaudit.h +4 -0
@@ -298,6 +298,10 @@ extern "C" {#define AUDIT_BPF 1334/* BPF load/unload */ #endif +#ifndef AUDIT_CONTAINER_ID +#define AUDIT_CONTAINER_ID 1335/* Container ID */ +#endif +#ifndef AUDIT_MAC_CALIPSO_ADD #define AUDIT_MAC_CALIPSO_ADD 1418/* NetLabel: add CALIPSO DOI entry */ #endif
lib/msg_typetab.h +1 -0
@@ -127,6 +127,7 @@ _S(AUDIT_FANOTIFY, "FANOTIFY" ) _S(AUDIT_TIME_INJOFFSET, "TIME_INJOFFSET" ) _S(AUDIT_TIME_ADJNTPVAL, "TIME_ADJNTPVAL" ) _S(AUDIT_BPF, "BPF" ) +_S(AUDIT_CONTAINER_ID, "CONTAINER_ID" ) _S(AUDIT_AVC, "AVC" ) _S(AUDIT_SELINUX_ERR, "SELINUX_ERR" )_S (AUDIT_AVC_PATH ,"AVC_PATH" )
Signature · 1 line
1.8.3.1
PATCH v8 3/14 auditctl: add support for AUDIT_CONTID filter
In reply to Richard Guy BriggsA u64 container identifier has been added to the kernel view of tasks. This allows container orchestrators to label tasks with a unique tamperproof identifier that gets inherited by its children to be able to track the provenance of actions by a container.
Add support to libaudit and auditctl for the AUDIT_CONTID field to filter based on audit container identifier. This field is specified with the "contid" field name on the command line.
Since it is a u64 and larger than any other numeric field, send it as a string but do the appropriate conversions on each end in each direction.
See: https://github.com/linux-audit/audit-userspace/issues/40
See: https://github.com/linux-audit/audit-kernel/issues/91
See: https://github.com/linux-audit/audit-testsuite/issues/64
See: https://github.com/linux-audit/audit-kernel/wiki/RFE-Audit-Container-ID
--- docs/auditctl.8 | 3 +++ lib/fieldtab.h | 1 + lib/libaudit.c | 36 ++++++++++++++++++++++++++++++++++++ lib/libaudit.h | 7 +++++++ src/auditctl-listing.c | 21 +++++++++++++++++++++ 5 files changed, 68 insertions(+)
docs/auditctl.8 +3 -0
@@ -216,6 +216,9 @@ Address family number as found in /usr/include/bits/socket.h. For example, IPv4 .B sessionid User's login session ID .TP +.B contid +Process' audit container ID +.TP .B subj_user Program's SE Linux User .TP
lib/fieldtab.h +1 -0
@@ -47,6 +47,7 @@ _S(AUDIT_OBJ_TYPE, "obj_type" ) _S(AUDIT_OBJ_LEV_LOW, "obj_lev_low" ) _S(AUDIT_OBJ_LEV_HIGH, "obj_lev_high" ) _S(AUDIT_SESSIONID, "sessionid" ) +_S(AUDIT_CONTID, "contid" ) _S(AUDIT_DEVMAJOR, "devmajor" )_S (AUDIT_DEVMINOR ,"devminor" )
lib/libaudit.c +36 -0
@@ -1756,6 +1756,42 @@ int audit_rule_fieldpair_data(struct audit_rule_data **rulep, const char *pair,if (rule->values[rule->field_count] >=AF_MAX )return -EAU_FIELDVALTOOBIG ;break ; +case AUDIT_CONTID : { +unsigned long long val; + +if ((audit_get_features () & +AUDIT_FEATURE_BITMAP_CONTAINERID ) ==0 ) +return -EAU_FIELDNOSUPPORT ; +if (flags !=AUDIT_FILTER_EXCLUDE && + flags !=AUDIT_FILTER_USER && + flags !=AUDIT_FILTER_EXIT ) +return -EAU_FIELDNOFILTER ; +if (isdigit ((char )*(v))) + val =strtoull (v,NULL ,0 ); +else if (strlen (v) >=2 && *(v)=='-' && + (isdigit ((char )*(v+1 )))) + val =strtoll (v,NULL ,0 ); +else if (strcmp (v,"unset" ) ==0 ) + val =ULLONG_MAX ; +else +return -EAU_FIELDVALNUM ; +if (errno) +return -EAU_FIELDVALNUM ; + vlen =sizeof (unsigned long long ); + rule->values[rule->field_count] = vlen; + offset = rule->buflen; + rule->buflen += vlen; + *rulep =realloc (rule,sizeof (*rule) + rule->buflen); +if (*rulep ==NULL ) { +free (rule); +audit_msg (LOG_ERR ,"Cannot realloc memory!\n" ); +return -3 ; + }else { + rule = *rulep; + } + *(unsigned long long *)(&rule->buf[offset]) = val; +break ; + } case AUDIT_DEVMAJOR...AUDIT_INODE:case AUDIT_SUCCESS :if (flags !=AUDIT_FILTER_EXIT )
lib/libaudit.h +7 -0
@@ -354,6 +354,9 @@ extern "C" {#ifndef AUDIT_FEATURE_BITMAP_FILTER_FS #define AUDIT_FEATURE_BITMAP_FILTER_FS 0x00000040#endif +#ifndef AUDIT_FEATURE_BITMAP_CONTAINERID +#define AUDIT_FEATURE_BITMAP_CONTAINERID 0x00000080 +#endif /* Defines for interfield comparison update */ #ifndef AUDIT_OBJ_UID
@@ -380,6 +383,10 @@ extern "C" {#define AUDIT_FSTYPE 26#endif +#ifndef AUDIT_CONTID +#define AUDIT_CONTID 27 +#endif +#ifndef AUDIT_COMPARE_UID_TO_OBJ_UID #define AUDIT_COMPARE_UID_TO_OBJ_UID 1#endif
src/auditctl-listing.c +21 -0
@@ -25,6 +25,7 @@#include <stdio.h> #include <stdlib.h> #include <string.h> +#include <limits.h> #include "auditctl-listing.h" #include "private.h" #include "auditctl-llist.h"
@@ -460,6 +461,26 @@ static void print_rule(const struct audit_rule_data *r)audit_operator_to_symbol (op),audit_fstype_to_name ( r->values[i])); + }else if (field ==AUDIT_CONTID ) { +unsigned long long val; + +if (r->values[i] ==sizeof (unsigned long long )) { + val = *(unsigned long long *)(&r->buf[boffset]); + +if (val !=ULLONG_MAX ) +printf (" -F %s%s%llu" , name, +audit_operator_to_symbol (op), + val); +else +printf (" -F %s%s%s" , name, +audit_operator_to_symbol (op), +"unset" ); + }else { +printf (" -F %s%s%s" , name, +audit_operator_to_symbol (op), +"inval" ); + } + boffset += r->values[i]; }else {// The default is signed decimal printf(" -F %s%s%d", name,
Signature · 1 line
1.8.3.1
PATCH v8 4/14 add ausearch containerid support
In reply to Richard Guy BriggsAdd support to ausearch for searching on the containerid field in records.
--- src/aureport-options.c | 1 + src/ausearch-llist.c | 2 ++ src/ausearch-llist.h | 1 + src/ausearch-match.c | 3 +++ src/ausearch-options.c | 47 ++++++++++++++++++++++++++++++++++++++++- src/ausearch-options.h | 1 + src/ausearch-parse.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 111 insertions(+), 1 deletion(-)
src/aureport-options.c +1 -0
@@ -62,6 +62,7 @@ const char *event_vmname = NULL;long long event_exit =0 ;int event_exit_is_set =0 ;int event_ppid =-1 , event_session_id =-2 ; +unsigned long long int event_contid =-1 ;int event_debug =0 , event_machine =-1 ;/* These are used by aureport */
src/ausearch-llist.c +2 -0
@@ -60,6 +60,7 @@ void list_create(llist *l) l->s.arch =0 ; l->s.syscall =0 ; l->s.session_id =-2 ; + l->s.contid =-1 ; l->s.uuid =NULL ; l->s.vmname =NULL ; l->s.tuid =NULL ;
@@ -211,6 +212,7 @@ void list_clear(llist* l) l->s.arch =0 ; l->s.syscall =0 ; l->s.session_id =-2 ; + l->s.contid =-1 ;free (l->s.uuid); l->s.uuid =NULL ;free (l->s.vmname);
src/ausearch-llist.h +1 -0
@@ -56,6 +56,7 @@ typedef structint arch;// arch int syscall;// syscall uint32_t session_id;// Login session id +__u64 contid;// Container id long long exit;// Syscall exit code int exit_is_set;// Syscall exit code is valid char *hostname;// remote hostname
src/ausearch-match.c +3 -0
@@ -113,6 +113,9 @@ int match(llist *l)if ((event_session_id !=-2 ) && (event_session_id != l->s.session_id))return 0 ; +if ((event_contid !=-1 ) && + (event_contid != l->s.contid)) +return 0 ;if (event_exit_is_set) {if (l->s.exit_is_set ==0 )return 0 ;
src/ausearch-options.c +46 -1
77 lines not on this page · raw message
src/ausearch-options.h +1 -0
@@ -40,6 +40,7 @@ extern int line_buffered;extern int event_debug;extern pid_t event_ppid;extern uint32_t event_session_id; +extern unsigned long long int event_contid;extern ilist *event_type;/* Data type to govern output format */
src/ausearch-parse.c +57 -0
81 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v8 5/14 start normalization containerid support
In reply to Richard Guy Briggs--- auparse/auparse-defs.h | 3 ++- auparse/interpret.c | 10 ++++++++++ auparse/normalize_record_map.h | 2 ++ auparse/typetab.h | 2 ++ bindings/python/auparse_python.c | 1 + 5 files changed, 17 insertions(+), 1 deletion(-)
auparse/auparse-defs.h +2 -1
@@ -87,7 +87,8 @@ typedef enum { AUPARSE_TYPE_UNCLASSIFIED, AUPARSE_TYPE_UID, AUPARSE_TYPE_GID,AUPARSE_TYPE_PROCTITLE ,AUPARSE_TYPE_HOOK ,AUPARSE_TYPE_NETACTION ,AUPARSE_TYPE_MACPROTO ,AUPARSE_TYPE_IOCTL_REQ ,AUPARSE_TYPE_ESCAPED_KEY , - AUPARSE_TYPE_ESCAPED_FILE, AUPARSE_TYPE_FANOTIFY } auparse_type_t; +AUPARSE_TYPE_ESCAPED_FILE ,AUPARSE_TYPE_FANOTIFY ,AUPARSE_TYPE_CONTID +} auparse_type_t;/* This type determines what escaping if any gets applied to interpreted fields */ typedef enum { AUPARSE_ESC_RAW, AUPARSE_ESC_TTY, AUPARSE_ESC_SHELL,
auparse/interpret.c +10 -0
@@ -2842,6 +2842,13 @@ static const char *print_seccomp_code(const char *val)return out; } +static const char *print_contid (const char *val) +{ +if (strcmp (val,"18446744073709551615" ) ==0 ) +return strdup ("unset" ); +return strdup (val); +} +int lookup_type (const char *name) {int i;
@@ -3082,6 +3089,9 @@ unknown:case AUPARSE_TYPE_FANOTIFY : out =print_fanotify (id->val);break ; +case AUPARSE_TYPE_CONTID : + out =print_contid (id->val); +break ;case AUPARSE_TYPE_MAC_LABEL :case AUPARSE_TYPE_UNCLASSIFIED :default :
auparse/normalize_record_map.h +2 -0
@@ -25,6 +25,7 @@ _S(AUDIT_USER, "sent-message") _S(AUDIT_LOGIN, "changed-login-id-to") +_S(AUDIT_CONTAINER_OP, "changed-container-id-to") _S(AUDIT_USER_AUTH, "authenticated") _S(AUDIT_USER_ACCT, "was-authorized")_S (AUDIT_USER_MGMT ,"modified-user-account" )
@@ -84,6 +85,7 @@ _S(AUDIT_FEATURE_CHANGE, "changed-audit-feature")//_S(AUDIT_REPLACE,"") _S(AUDIT_KERN_MODULE, "loaded-kernel-module") _S(AUDIT_FANOTIFY, "accessed-policy-controlled-file") +_S(AUDIT_CONTAINER_ID, "has-container-id") _S(AUDIT_AVC, "accessed-mac-policy-controlled-object") _S(AUDIT_MAC_POLICY_LOAD, "loaded-selinux-policy")_S (AUDIT_MAC_STATUS ,"changed-selinux-enforcement-to" )
auparse/typetab.h +2 -0
@@ -142,3 +142,5 @@ _S(AUPARSE_TYPE_IOCTL_REQ, "ioctlcmd" ) _S(AUPARSE_TYPE_FANOTIFY, "resp" ) _S(AUPARSE_TYPE_ESCAPED, "sw" ) _S(AUPARSE_TYPE_ESCAPED, "root_dir" ) +_S(AUPARSE_TYPE_CONTID, "contid" ) +_S (AUPARSE_TYPE_CONTID ,"old-contid" )
bindings/python/auparse_python.c +1 -0
@@ -2391,6 +2391,7 @@ initauparse(void)PyModule_AddIntConstant (m,"AUPARSE_ESC_TTY" ,AUPARSE_ESC_TTY );PyModule_AddIntConstant (m,"AUPARSE_ESC_SHELL" ,AUPARSE_ESC_SHELL );PyModule_AddIntConstant (m,"AUPARSE_ESC_SHELL_QUOTE" ,AUPARSE_ESC_SHELL_QUOTE ); +PyModule_AddIntConstant (m,"AUPARSE_TYPE_CONTID" ,AUPARSE_TYPE_CONTID );#ifdef IS_PY3K return m;
Signature · 1 line
1.8.3.1
PATCH v8 6/14 libaudit: add support to get the task audit container identifier
In reply to Richard Guy BriggsAdd the audit_get_containerid() call analogous to audit_getloginuid() and audit_get_session() calls to get our own audit container identifier.
This is intended as a debug patch, not to be upstreamed.
--- docs/Makefile.am | 2 +- docs/audit_get_containerid.3 | 25 +++++++++++++++++++++++++ lib/libaudit.c | 29 +++++++++++++++++++++++++++++ lib/libaudit.h | 1 + 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 docs/audit_get_containerid.3
docs/Makefile.am +1 -1
@@ -28,7 +28,7 @@ man_MANS = audit_add_rule_data.3 audit_add_watch.3 auditctl.8 auditd.8 \ auditd.conf.5 auditd-plugins.5 \ audit_delete_rule_data.3 audit_detect_machine.3 \ audit_encode_nv_string.3 audit_getloginuid.3 \ -audit_get_reply.3 audit_get_session.3 \ +audit_get_reply.3 audit_get_session.3 audit_get_containerid.3 \ audit_log_acct_message.3 audit_log_user_avc_message.3 \ audit_log_user_command.3 audit_log_user_comm_message.3 \ audit_log_user_message.3 audit_log_semanage_message.3 \
docs/audit_get_containerid.3 new file +25 -0
@@ -0,0 +1,25 @@ +.TH "AUDIT_GET_CONTAINERID" "3" "Feb 2018" "Red Hat" "Linux Audit API" +.SH NAME +audit_get_containerid \- Get a program's container id value +.SH SYNOPSIS +.B #include <libaudit.h> +.sp +uin64_t audit_get_containerid(void); + +.SH DESCRIPTION +This function returns the task's audit container identifier attribute. + +.SH "RETURN VALUE" + +This function returns the audit container identifier value if it was set. It will return a \-1 if the audit container identifier is unset. However, since uint64_t is an unsigned type, you will see the converted value instead of \-1. + +.SH "ERRORS" + +This function returns \-2 on failure. Additionally, in the event of a real error, errno would be set. The function can set errno based on failures of open, read, or strtoull. + +.SH "SEE ALSO" + +.BR audit_getloginuid (3). + +.SH AUTHOR +Richard Guy Briggs
lib/libaudit.c +29 -0
@@ -944,6 +944,35 @@ uint32_t audit_get_session(void)return ses; } +/* +* This function will retrieve the audit container identifier or -2 if +* there is an error. +*/ +uint64_t audit_get_containerid (void ) +{ +uint64_t containerid; +int len, in; +char buf[32 ]; + + errno =0 ; + in =open ("/proc/self/audit_containerid" ,O_NOFOLLOW |O_RDONLY ); +if (in <0 ) +return -2 ; +do { + len =read (in, buf,sizeof (buf)); + }while (len <0 && errno ==EINTR ); +close (in); +if (len <0 || len >=sizeof (buf)) +return -2 ; + buf[len] =0 ; + errno =0 ; + containerid =strtoull (buf,0 ,10 ); +if (errno) +return -2 ; +else +return containerid; +} +int audit_rule_syscall_data (struct audit_rule_data *rule,int scall) {int word =AUDIT_WORD (scall);
lib/libaudit.h +1 -0
@@ -593,6 +593,7 @@ extern int audit_get_reply(int fd, struct audit_reply *rep, reply_t block,extern uid_t audit_getloginuid (void );extern int audit_setloginuid (uid_t uid);extern uint32_t audit_get_session (void ); +extern uint64_t audit_get_containerid (void );extern int audit_detect_machine (void );extern int audit_determine_machine (const char *arch);extern char *audit_format_signal_info (char *buf,int len,char *op,struct audit_reply *rep,char *res);
Signature · 1 line
1.8.3.1
PATCH v8 7/14 signal_info: only print context if it is available.
In reply to Richard Guy Briggs--- src/auditd-event.c | 20 +++++++++++++++----- src/auditd-reconfig.c | 2 -- 2 files changed, 15 insertions(+), 7 deletions(-)
src/auditd-event.c +15 -5
@@ -1323,13 +1323,16 @@ static void reconfigure(struct auditd_event *e)const char *ctx = nconf->sender_ctx;struct timeval tv;char txt[MAX_AUDIT_MESSAGE_LENGTH ]; +int txt_len;char date[40 ];unsigned int seq_num;int need_size_check =0 , need_reopen =0 , need_space_check =0 ; -snprintf (txt,sizeof (txt), -"config change requested by pid=%d auid=%u subj=%s" , - pid, uid, ctx); + txt_len =snprintf (txt,sizeof (txt), +"config change requested by pid=%d auid=%u" , pid, uid); +if (ctx) +snprintf (txt + txt_len,sizeof (txt) - txt_len, +" subj=%s" , ctx);audit_msg (LOG_NOTICE ,"%s" , txt);/* Do the reconfiguring. These are done in a specific
@@ -1578,8 +1581,15 @@ static void reconfigure(struct auditd_event *e) e->reply.type =AUDIT_DAEMON_CONFIG ; e->reply.len =snprintf (e->reply.msg.data,MAX_AUDIT_MESSAGE_LENGTH -2 , -"%s: op=reconfigure state=changed auid=%u pid=%d subj=%s res=success" , - date, uid, pid, ctx ); +"%s: op=reconfigure state=changed auid=%u pid=%d" , + date, uid, pid); +if (ctx) + e->reply.len +=snprintf (e->reply.msg.data + e->reply.len, +MAX_AUDIT_MESSAGE_LENGTH -2 - e->reply.len, +" subj=%s" , ctx); + e->reply.len +=snprintf (e->reply.msg.data + e->reply.len, +MAX_AUDIT_MESSAGE_LENGTH -2 - e->reply.len, +" res=success" ); e->reply.message = e->reply.msg.data;free ((char *)ctx); }
src/auditd-reconfig.c +0 -2
@@ -106,8 +106,6 @@ static void *config_thread_main(void *arg)if (e->reply.len >24 ) new_config.sender_ctx =strdup (e->reply.signal_info->ctx); -else - new_config.sender_ctx =strdup ("?" );memcpy (e->reply.msg.data, &new_config,sizeof (new_config)); e->reply.conf = (struct daemon_conf *)e->reply.msg.data; e->reply.type =AUDIT_DAEMON_RECONFIG ;
Signature · 1 line
1.8.3.1
PATCH v8 8/14 add support for audit_signal_info2
In reply to Richard Guy BriggsSince a process in a container could potentially signal the audit daemon (reconfig, terminate, roll log, resume), that audit container identifier information should be made available to the audit daemon to report the full provenance of the signal. It is not possible to add it to the existing audit_signal_info struct without causing a kABI change. Introduce a new audit message type AUDIT_SIGNAL_INFO2 using a new audit_sig_info2 struct to be able to transfer this information from kernel to userspace.
struct audit_sig_info2 {
uid_t uid;
pid_t pid;
uint64_t cid;
char ctx[0];
};--- auparse/auditd-config.c | 1 + docs/audit_request_signal_info.3 | 11 +++++++++ lib/libaudit.c | 49 +++++++++++++++++++++++++++++++++------- lib/libaudit.h | 14 ++++++++++++ lib/msg_typetab.h | 1 + lib/netlink.c | 4 ++++ src/auditd-config.c | 1 + src/auditd-config.h | 1 + src/auditd-event.c | 10 +++++++- src/auditd-reconfig.c | 23 ++++++++++++++----- src/auditd.c | 3 ++- 11 files changed, 102 insertions(+), 16 deletions(-)
auparse/auditd-config.c +1 -0
@@ -77,6 +77,7 @@ void clear_config(struct daemon_conf *config) config->sender_uid =0 ; config->sender_pid =0 ; config->sender_ctx =NULL ; + config->sender_cid =0 ; config->write_logs =1 ; config->log_file =strdup ("/var/log/audit/audit.log" ); config->log_format =LF_RAW ;
docs/audit_request_signal_info.3 +11 -0
@@ -18,6 +18,17 @@ struct audit_sig_info { }; .fi +If the process has an audit container identifier, the signal info structure is as follows: + +.nf +struct audit_sig_info2 { + uid_t uid; + pid_t pid; + uint64_t cid; + char ctx[0]; +}; +.fi + This function is likely to be used only by audit daemons and shouldn't be called by any other kind of program. .SH "RETURN VALUE"
lib/libaudit.c +41 -8
69 lines not on this page · raw message
lib/libaudit.h +14 -0
@@ -34,6 +34,7 @@ extern "C" {#include <linux/netlink.h> #include <linux/audit.h> #include <stdarg.h> +#include <stdbool.h> #include <syslog.h>
@@ -250,6 +251,10 @@ extern "C" {#define AUDIT_CONTAINER_OP 1020/* Container creation notice */ #endif +#ifndef AUDIT_SIGNAL_INFO2 +#define AUDIT_SIGNAL_INFO2 1021/* auditd signal sender info */ +#endif +#ifndef AUDIT_MMAP #define AUDIT_MMAP 1323/* Descriptor and flags in mmap */ #endif
@@ -494,6 +499,13 @@ struct audit_sig_info {char ctx[0 ]; }; +struct audit_sig_info2 { +uid_t uid; +pid_t pid; +uint64_t cid; +char ctx[0 ]; +}; +/* defines for audit subsystem */ #define MAX_AUDIT_MESSAGE_LENGTH 8970 // PATH_MAX*2+CONTEXT_SIZE*2+11+256+1struct audit_message {
@@ -519,6 +531,7 @@ struct audit_reply {char *message;struct nlmsgerr *error;struct audit_sig_info *signal_info; +struct audit_sig_info2 *signal_info2;struct daemon_conf *conf;#ifdef AUDIT_FEATURE_BITMAP_ALL struct audit_features *features;
@@ -596,6 +609,7 @@ extern uint32_t audit_get_session(void);extern uint64_t audit_get_containerid (void );extern int audit_detect_machine (void );extern int audit_determine_machine (const char *arch); +extern bool audit_signal_info_has_ctx (struct audit_reply *rep);extern char *audit_format_signal_info (char *buf,int len,char *op,struct audit_reply *rep,char *res);/* Translation functions */
lib/msg_typetab.h +1 -0
@@ -44,6 +44,7 @@ _S(AUDIT_LOGIN, "LOGIN" )//_S(AUDIT_TTY_SET, "TTY_SET" ) //_S(AUDIT_SET_FEATURE, "SET_FEATURE" ) //_S(AUDIT_GET_FEATURE, "GET_FEATURE" ) +//_S(AUDIT_SIGNAL_INFO2, "SIGNAL_INFO2" ) _S(AUDIT_CONTAINER_OP, "CONTAINER_OP" ) _S(AUDIT_USER_AUTH, "USER_AUTH" )_S (AUDIT_USER_ACCT ,"USER_ACCT" )
lib/netlink.c +4 -0
@@ -146,6 +146,7 @@ static int adjust_reply(struct audit_reply *rep, int len) rep->message =NULL ; rep->error =NULL ; rep->signal_info =NULL ; + rep->signal_info2 =NULL ; rep->conf =NULL ;#if defined(HAVE_DECL_AUDIT_FEATURE_VERSION ) && \ defined(HAVE_STRUCT_AUDIT_STATUS_FEATURE_BITMAP )
@@ -194,6 +195,9 @@ static int adjust_reply(struct audit_reply *rep, int len)case AUDIT_SIGNAL_INFO : rep->signal_info =NLMSG_DATA (rep->nlh);break ; +case AUDIT_SIGNAL_INFO2 : + rep->signal_info2 =NLMSG_DATA (rep->nlh); +break ; }return len; }
src/auditd-config.c +1 -0
@@ -307,6 +307,7 @@ void clear_config(struct daemon_conf *config) config->sender_uid =0 ; config->sender_pid =0 ; config->sender_ctx =NULL ; + config->sender_cid =0 ; config->write_logs =1 ; config->log_file =strdup ("/var/log/audit/audit.log" ); config->log_format =LF_ENRICHED ;
src/auditd-config.h +1 -0
@@ -49,6 +49,7 @@ struct daemon_confuid_t sender_uid;/* the uid for sender of sighup */ pid_t sender_pid;/* the pid for sender of sighup */ const char *sender_ctx;/* the context for the sender of sighup */ +uint64_t sender_cid;/* the contid for sender of sighup */ unsigned int write_logs;const char *log_file;logging_formats log_format;
src/auditd-event.c +9 -1
@@ -1321,6 +1321,7 @@ static void reconfigure(struct auditd_event *e)uid_t uid = nconf->sender_uid;pid_t pid = nconf->sender_pid;const char *ctx = nconf->sender_ctx; +uint64_t cid = nconf->sender_cid;struct timeval tv;char txt[MAX_AUDIT_MESSAGE_LENGTH ];int txt_len;
@@ -1331,8 +1332,11 @@ static void reconfigure(struct auditd_event *e) txt_len =snprintf (txt,sizeof (txt),"config change requested by pid=%d auid=%u" , pid, uid);if (ctx) + txt_len +=snprintf (txt + txt_len,sizeof (txt) - txt_len, +" subj=%s" , ctx); +if (cid !=-1 )snprintf (txt + txt_len,sizeof (txt) - txt_len, -" subj=%s" , ctx); +" contid=%llu" , (unsigned long long )cid);audit_msg (LOG_NOTICE ,"%s" , txt);/* Do the reconfiguring. These are done in a specific
@@ -1590,6 +1594,10 @@ static void reconfigure(struct auditd_event *e) e->reply.len +=snprintf (e->reply.msg.data + e->reply.len,MAX_AUDIT_MESSAGE_LENGTH -2 - e->reply.len," res=success" ); +if (cid !=-1 ) + e->reply.len +=snprintf (e->reply.msg.data + e->reply.len, +MAX_AUDIT_MESSAGE_LENGTH -2 - e->reply.len, +"contid=%llu" , (unsigned long long )cid); e->reply.message = e->reply.msg.data;free ((char *)ctx); }
src/auditd-reconfig.c +17 -6
@@ -101,11 +101,23 @@ static void *config_thread_main(void *arg)if (load_config (&new_config,TEST_AUDITD ) ==0 ) {/* We will re-use the current reply */ - new_config.sender_uid = e->reply.signal_info->uid; - new_config.sender_pid = e->reply.signal_info->pid; -if (e->reply.len >24 ) - new_config.sender_ctx = -strdup (e->reply.signal_info->ctx); +if (e->reply.type ==AUDIT_SIGNAL_INFO ) { + new_config.sender_uid = e->reply.signal_info->uid; + new_config.sender_pid = e->reply.signal_info->pid; + new_config.sender_cid = (uint64_t )-1 ; + }else { + new_config.sender_uid = e->reply.signal_info2->uid; + new_config.sender_pid = e->reply.signal_info2->pid; + new_config.sender_cid = e->reply.signal_info2->cid; + } +if (audit_signal_info_has_ctx (&e->reply)) { +if (e->reply.type ==AUDIT_SIGNAL_INFO ) + new_config.sender_ctx = +strdup (e->reply.signal_info->ctx); +else + new_config.sender_ctx = +strdup (e->reply.signal_info2->ctx); + }memcpy (e->reply.msg.data, &new_config,sizeof (new_config)); e->reply.conf = (struct daemon_conf *)e->reply.msg.data; e->reply.type =AUDIT_DAEMON_RECONFIG ;
@@ -125,4 +137,3 @@ static void *config_thread_main(void *arg)pthread_mutex_unlock (&config_lock);return NULL ; } -
src/auditd.c +2 -1
@@ -516,6 +516,7 @@ static void netlink_handler(struct ev_loop *loop, struct ev_io *io, case AUDIT_FIRST_DAEMON...AUDIT_LAST_DAEMON:break ;case AUDIT_SIGNAL_INFO : +case AUDIT_SIGNAL_INFO2 :if (hup_info_requested) {char hup[MAX_AUDIT_MESSAGE_LENGTH ]; audit_msg(LOG_DEBUG,
@@ -1077,7 +1078,7 @@ static int get_reply(int fd, struct audit_reply *rep, int seq)continue ;/* If its not what we are expecting, keep looping */ -if (rep->type ==AUDIT_SIGNAL_INFO ) +if (rep->type ==AUDIT_SIGNAL_INFO || rep->type ==AUDIT_SIGNAL_INFO2 )return 1 ;/* If we get done or error, break out */
Signature · 1 line
1.8.3.1
PATCH v8 9/14 contid: interpret correctly CONTAINER_ID contid field csv
In reply to Richard Guy BriggsThe CONTAINER_ID record contid field can contain comma-separated values when accompanying a NETFILTER_PKT record. Records appeared interpreted as such:
Wrong:
CONTAINER_ID msg=audit(2019-04-10 13:20:18.746:1690) : contid=777 666,333 Right: CONTAINER_ID msg=audit(2019-04-10 13:20:18.746:1690) : contid=777,666,333
--- src/ausearch-report.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
src/ausearch-report.c +4 -2
@@ -279,7 +279,7 @@ no_print:if (str && val && (str < val)) {// Value side has commas and another field exists // Known: LABEL_LEVEL_CHANGE banners=none,none -// Known: ROLL_ASSIGN new-role=r,r +// Known: ROLE_ASSIGN new-role=r,r // Known: any MAC LABEL can potentially have commas int ftype =auparse_interp_adjust_type (n->type, name, val);
@@ -293,9 +293,11 @@ no_print: }else if (str && (val ==NULL )) {// Goes all the way to the end. Done parsing // Known: MCS context in PATH rec obj=u:r:t:s0:c2,c7 +// Known: CONTAINER_ID contid can be a comma-separated list int ftype =auparse_interp_adjust_type (n->type, name, ptr); -if (ftype ==AUPARSE_TYPE_MAC_LABEL ) +if (ftype ==AUPARSE_TYPE_MAC_LABEL + || ftype ==AUPARSE_TYPE_CONTID ) str =NULL ;else { *str++ =0 ;
Signature · 1 line
1.8.3.1
PATCH v8 10/14 ausearch: convert contid to comma/carrat-sep list
In reply to Richard Guy BriggsNow that the kernel is able to track container nesting ("audit: track container nesting"), convert the ausearch internals to parse and track the compound list of contids.
--- src/aureport-options.c | 2 +- src/ausearch-llist.c | 8 +++- src/ausearch-llist.h | 2 +- src/ausearch-match.c | 40 ++++++++++++++++- src/ausearch-options.c | 36 ++++++++++++++-- src/ausearch-options.h | 2 +- src/ausearch-parse.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++- src/ausearch-report.c | 2 +- 8 files changed, 195 insertions(+), 12 deletions(-)
src/aureport-options.c +1 -1
@@ -62,7 +62,7 @@ const char *event_vmname = NULL;long long event_exit =0 ;int event_exit_is_set =0 ;int event_ppid =-1 , event_session_id =-2 ; -unsigned long long int event_contid =-1 ; +const char *event_contid =NULL ;int event_debug =0 , event_machine =-1 ;/* These are used by aureport */
src/ausearch-llist.c +6 -2
@@ -60,7 +60,7 @@ void list_create(llist *l) l->s.arch =0 ; l->s.syscall =0 ; l->s.session_id =-2 ; - l->s.contid =-1 ; + l->s.contid =NULL ; l->s.uuid =NULL ; l->s.vmname =NULL ; l->s.tuid =NULL ;
@@ -212,7 +212,11 @@ void list_clear(llist* l) l->s.arch =0 ; l->s.syscall =0 ; l->s.session_id =-2 ; - l->s.contid =-1 ; +if (l->s.contid) { +slist_clear (l->s.contid); +free (l->s.contid); + l->s.contid =NULL ; + }free (l->s.uuid); l->s.uuid =NULL ;free (l->s.vmname);
src/ausearch-llist.h +1 -1
@@ -56,7 +56,7 @@ typedef structint arch;// arch int syscall;// syscall uint32_t session_id;// Login session id -__u64 contid;// Container id +slist *contid;// Container id long long exit;// Syscall exit code int exit_is_set;// Syscall exit code is valid char *hostname;// remote hostname
src/ausearch-match.c +38 -2
@@ -37,6 +37,7 @@ static int strmatch(const char *needle, const char *haystack);static int user_match (llist *l);static int group_match (llist *l);static int context_match (llist *l); +static int contid_match (llist *l);static void load_interpretations (const llist *l) {
@@ -113,8 +114,7 @@ int match(llist *l)if ((event_session_id !=-2 ) && (event_session_id != l->s.session_id))return 0 ; -if ((event_contid !=-1 ) && - (event_contid != l->s.contid)) +if (contid_match (l) ==0 )return 0 ;if (event_exit_is_set) {if (l->s.exit_is_set ==0 )
@@ -417,3 +417,39 @@ static int context_match(llist *l)return 1 ; } +/* +* This function compares container ids. It returns a 0 if no match and a 1 if +* there is a match +*/ +static int contid_match (llist *l) +{ +if (event_contid) { +int found =0 ; +const snode *ecn; +slist *ecptr = event_contid; + +slist_first (ecptr); + ecn =slist_get_cur (ecptr); +if (l->s.contid) { +while (ecn && !found) { +const snode *sn; +slist *sptr = l->s.contid; + +slist_first (sptr); + sn =slist_get_cur (sptr); +while (sn && !found) { +if (!strcmp (sn->str, ecn->str)) + found++; +else + sn =slist_next (sptr); + } +if (found) +return found; + ecn =slist_next (ecptr); + } +return found; + } + } +return 0 ; +} +
src/ausearch-options.c +33 -3
@@ -60,7 +60,7 @@ int event_syscall = -1, event_machine = -1;int event_ua =0 , event_ga =0 , event_se =0 ;int just_one =0 ;uint32_t event_session_id =-2 ; -unsigned long long int event_contid =-1 ; +const char *event_contid =NULL ;long long event_exit =0 ;int event_exit_is_set =0 ;int line_buffered =0 ;
@@ -1200,22 +1200,52 @@ int check_params(int count, char *vars[]) {size_t len =strlen (optarg);if (isdigit (optarg[0 ])) { +__u64 contid; + errno =0 ; - event_contid =strtoull (optarg,NULL ,0 ); + contid =strtoull (optarg,NULL ,0 );if (errno) {fprintf (stderr,"Numeric container ID conversion error (%s) for %s\n" ,strerror (errno), optarg); retval =-1 ; + }else { +if (!event_contid) { + event_contid =malloc (sizeof (slist)); +if (!event_contid) { + retval =-1 ; +break ; + } +slist_create (event_contid); + } + sn.str =strdup (optarg); + sn.key =NULL ; + sn.hits =0 ; +slist_append (event_contid, &sn); } }else if (len >=2 && *(optarg)=='-' && (isdigit (optarg[1 ]))) { +__u64 contid; + errno =0 ; - event_contid =strtoll (optarg,NULL ,0 ); + contid =strtoll (optarg,NULL ,0 );if (errno) { retval =-1 ;fprintf (stderr,"Error converting %s\n" , optarg); + }else { +if (!event_contid) { + event_contid =malloc (sizeof (slist)); +if (!event_contid) { + retval =-1 ; +break ; + } +slist_create (event_contid); + } + sn.str =strdup (optarg); + sn.key =NULL ; + sn.hits =0 ; +slist_append (event_contid, &sn); } }else { fprintf(stderr,
src/ausearch-options.h +1 -1
@@ -40,7 +40,7 @@ extern int line_buffered;extern int event_debug;extern pid_t event_ppid;extern uint32_t event_session_id; -extern unsigned long long int event_contid; +extern const char *event_contid;extern ilist *event_type;/* Data type to govern output format */
src/ausearch-parse.c +114 -1
146 lines not on this page · raw message
src/ausearch-report.c +1 -1
@@ -293,7 +293,7 @@ no_print: }else if (str && (val ==NULL )) {// Goes all the way to the end. Done parsing // Known: MCS context in PATH rec obj=u:r:t:s0:c2,c7 -// Known: CONTAINER_ID contid can be a comma-separated list +// Known: CONTAINER_ID contid can be a comma/carrat-separated list int ftype =auparse_interp_adjust_type (n->type, name, ptr); if (ftype == AUPARSE_TYPE_MAC_LABEL
Signature · 1 line
1.8.3.1
PATCH v8 11/14 ausearch: convert contid to comma/carrat-sep cnode/clist
In reply to Richard Guy BriggsConvert the contid list from a list of strings to a list of contids for faster and more efficient processing.
--- src/Makefile.am | 6 +- src/ausearch-contid.c | 171 +++++++++++++++++++++++++++++++++++++++++++++++++ src/ausearch-contid.h | 61 ++++++++++++++++++ src/ausearch-llist.c | 2 +- src/ausearch-llist.h | 3 +- src/ausearch-match.c | 36 +++++------ src/ausearch-options.c | 26 ++++---- src/ausearch-options.h | 3 +- src/ausearch-parse.c | 127 +++++++++++++----------------------- 9 files changed, 313 insertions(+), 122 deletions(-) create mode 100644 src/ausearch-contid.c create mode 100644 src/ausearch-contid.h
src/Makefile.am +3 -3
@@ -25,7 +25,7 @@ SUBDIRS = test AM_CPPFLAGS = -I${top_srcdir} -I${top_srcdir}/lib -I${top_srcdir}/src/libev -I${top_srcdir}/auparse -I${top_srcdir}/audisp -I${top_srcdir}/common sbin_PROGRAMS = auditd auditctl aureport ausearch autrace AM_CFLAGS = -D_GNU_SOURCE -Wno-pointer-sign -noinst_HEADERS = auditd-config.h auditd-event.h auditd-listen.h ausearch-llist.h ausearch-options.h auditctl-llist.h aureport-options.h ausearch-parse.h aureport-scan.h ausearch-lookup.h ausearch-int.h auditd-dispatch.h ausearch-string.h ausearch-nvpair.h ausearch-common.h ausearch-avc.h ausearch-time.h ausearch-lol.h auditctl-listing.h ausearch-checkpt.h +noinst_HEADERS = auditd-config.h auditd-event.h auditd-listen.h ausearch-llist.h ausearch-options.h auditctl-llist.h aureport-options.h ausearch-parse.h aureport-scan.h ausearch-lookup.h ausearch-int.h auditd-dispatch.h ausearch-string.h ausearch-nvpair.h ausearch-common.h ausearch-avc.h ausearch-time.h ausearch-lol.h auditctl-listing.h ausearch-checkpt.h ausearch-contid.h auditd_SOURCES = auditd.c auditd-event.c auditd-config.c auditd-reconfig.c auditd-sendmail.c auditd-dispatch.c if ENABLE_LISTENER
@@ -41,10 +41,10 @@ auditctl_CFLAGS = -fPIE -DPIE -g -D_GNU_SOURCE auditctl_LDFLAGS = -pie -Wl,-z,relro -Wl,-z,now auditctl_LDADD = -L${top_builddir}/lib -laudit -L${top_builddir}/auparse -lauparse -L${top_builddir}/common -laucommon -aureport_SOURCES = aureport.c auditd-config.c ausearch-llist.c aureport-options.c ausearch-string.c ausearch-parse.c aureport-scan.c aureport-output.c ausearch-lookup.c ausearch-int.c ausearch-time.c ausearch-nvpair.c ausearch-avc.c ausearch-lol.c +aureport_SOURCES = aureport.c auditd-config.c ausearch-llist.c aureport-options.c ausearch-string.c ausearch-parse.c aureport-scan.c aureport-output.c ausearch-lookup.c ausearch-int.c ausearch-time.c ausearch-nvpair.c ausearch-avc.c ausearch-lol.c ausearch-contid.c aureport_LDADD = -L${top_builddir}/lib -laudit -L${top_builddir}/auparse -lauparse -L${top_builddir}/common -laucommon -ausearch_SOURCES = ausearch.c auditd-config.c ausearch-llist.c ausearch-options.c ausearch-report.c ausearch-match.c ausearch-string.c ausearch-parse.c ausearch-int.c ausearch-time.c ausearch-nvpair.c ausearch-lookup.c ausearch-avc.c ausearch-lol.c ausearch-checkpt.c +ausearch_SOURCES = ausearch.c auditd-config.c ausearch-llist.c ausearch-options.c ausearch-report.c ausearch-match.c ausearch-string.c ausearch-parse.c ausearch-int.c ausearch-time.c ausearch-nvpair.c ausearch-lookup.c ausearch-avc.c ausearch-lol.c ausearch-checkpt.c ausearch-contid.c ausearch_LDADD = -L${top_builddir}/lib -laudit -L${top_builddir}/auparse -lauparse -L${top_builddir}/common -laucommon autrace_SOURCES = autrace.c delete_all.c auditctl-llist.c
src/ausearch-contid.c new file +171 -0
171 lines not on this page · raw message
src/ausearch-contid.h new file +61 -0
61 lines not on this page · raw message
src/ausearch-llist.c +1 -1
@@ -213,7 +213,7 @@ void list_clear(llist* l) l->s.syscall =0 ; l->s.session_id =-2 ;if (l->s.contid) { -slist_clear (l->s.contid); +clist_clear (l->s.contid);free (l->s.contid); l->s.contid =NULL ; }
src/ausearch-llist.h +2 -1
@@ -31,6 +31,7 @@#include <sys/types.h> #include "ausearch-string.h" #include "ausearch-avc.h" +#include "ausearch-contid.h" #include "ausearch-common.h"
@@ -56,7 +57,7 @@ typedef structint arch;// arch int syscall;// syscall uint32_t session_id;// Login session id -slist *contid;// Container id +clist *contid;// Container id long long exit;// Syscall exit code int exit_is_set;// Syscall exit code is valid char *hostname;// remote hostname
src/ausearch-match.c +16 -20
@@ -424,32 +424,28 @@ static int context_match(llist *l)static int contid_match (llist *l) {if (event_contid) { -int found =0 ; -const snode *ecn; -slist *ecptr = event_contid; +const cnode *ecn; +clist *ecptr = event_contid; -slist_first (ecptr); - ecn =slist_get_cur (ecptr); +clist_first (ecptr); + ecn =clist_get_cur (ecptr);if (l->s.contid) { -while (ecn && !found) { -const snode *sn; -slist *sptr = l->s.contid; +while (ecn) { +const cnode *cn; +clist *cptr = l->s.contid; -slist_first (sptr); - sn =slist_get_cur (sptr); -while (sn && !found) { -if (!strcmp (sn->str, ecn->str)) - found++; -else - sn =slist_next (sptr); +clist_first (cptr); + cn =clist_get_cur (cptr); +while (cn) { +if (cn->id == ecn->id) +return 1 ; + cn =clist_next (cptr); } -if (found) -return found; - ecn =slist_next (ecptr); + ecn =clist_next (ecptr); } -return found; } +return 0 ; } -return 0 ; +return 1 ; }
src/ausearch-options.c +13 -13
@@ -60,7 +60,7 @@ int event_syscall = -1, event_machine = -1;int event_ua =0 , event_ga =0 , event_se =0 ;int just_one =0 ;uint32_t event_session_id =-2 ; -const char *event_contid =NULL ; +clist *event_contid =NULL ;long long event_exit =0 ;int event_exit_is_set =0 ;int line_buffered =0 ;
@@ -1201,6 +1201,7 @@ int check_params(int count, char *vars[])size_t len =strlen (optarg);if (isdigit (optarg[0 ])) {__u64 contid; +cnode cn; errno =0 ; contid =strtoull (optarg,NULL ,0 );
@@ -1211,21 +1212,21 @@ int check_params(int count, char *vars[]) retval =-1 ; }else {if (!event_contid) { - event_contid =malloc (sizeof (slist)); + event_contid =malloc (sizeof (clist));if (!event_contid) { retval =-1 ;break ; } -slist_create (event_contid); +clist_create (event_contid); } - sn.str =strdup (optarg); - sn.key =NULL ; - sn.hits =0 ; -slist_append (event_contid, &sn); + cn.id = contid; + cn.hits =0 ; +clist_append (event_contid, &cn); } }else if (len >=2 && *(optarg)=='-' && (isdigit (optarg[1 ]))) {__u64 contid; +cnode cn; errno =0 ; contid =strtoll (optarg,NULL ,0 );
@@ -1235,17 +1236,16 @@ int check_params(int count, char *vars[]) optarg); }else {if (!event_contid) { - event_contid =malloc (sizeof (slist)); + event_contid =malloc (sizeof (clist));if (!event_contid) { retval =-1 ;break ; } -slist_create (event_contid); +clist_create (event_contid); } - sn.str =strdup (optarg); - sn.key =NULL ; - sn.hits =0 ; -slist_append (event_contid, &sn); + cn.id = contid; + cn.hits =0 ; +clist_append (event_contid, &cn); } }else { fprintf(stderr,
src/ausearch-options.h +2 -1
@@ -29,6 +29,7 @@#include <stdint.h> #include "ausearch-common.h" #include "ausearch-int.h" +#include "ausearch-contid.h" /* Global variables that describe what search is to be performed */ extern const char *event_key;
@@ -40,7 +41,7 @@ extern int line_buffered;extern int event_debug;extern pid_t event_ppid;extern uint32_t event_session_id; -extern const char *event_contid; +extern clist *event_contid;extern ilist *event_type;/* Data type to govern output format */
src/ausearch-parse.c +44 -83
173 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v8 12/14 auditctl: add a config parameter to limit the contid nesting depth
In reply to Richard Guy BriggsThis adds the auditctl option "--contid-depth-limit" that takes one argument.
Please see kernel patch ("audit: check contid depth and add limit config param").
--- configure.ac | 1 + docs/Makefile.am | 2 +- docs/audit_set_contid_depth_limit.3 | 26 ++++++++++++++++++++++++++ docs/auditctl.8 | 3 +++ lib/libaudit.c | 21 +++++++++++++++++++++ lib/libaudit.h | 1 + src/auditctl-listing.c | 4 ++++ src/auditctl.c | 33 +++++++++++++++++++++++++++++++++ 8 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 docs/audit_set_contid_depth_limit.3
configure.ac +1 -0
@@ -67,6 +67,7 @@ AC_CHECK_DECLS([AUDIT_FEATURE_VERSION], [], [], [[#include <linux/audit.h>]]) AC_CHECK_MEMBERS([struct audit_status.feature_bitmap], [], [], [[#include <linux/audit.h>]]) AC_CHECK_DECLS([AUDIT_VERSION_BACKLOG_WAIT_TIME], [], [], [[#include <linux/audit.h>]]) AC_CHECK_DECLS([AUDIT_STATUS_BACKLOG_WAIT_TIME], [], [], [[#include <linux/audit.h>]]) +AC_CHECK_DECLS([AUDIT_STATUS_CONTID_DEPTH_LIMIT], [], [], [[#include <linux/audit.h>]]) AC_CHECK_DECLS([ADDR_NO_RANDOMIZE],,, [#include <sys/personality.h>]) dnl; posix_fallocate is used in audisp-remote AC_CHECK_FUNCS([posix_fallocate])
docs/Makefile.am +1 -1
@@ -60,6 +60,6 @@ ausearch_add_timestamp_item_ex.3 ausearch_clear.3 \ ausearch_next_event.3 ausearch_set_stop.3 \ autrace.8 get_auditfail_action.3 set_aumessage_mode.3 \ audispd-zos-remote.8 libaudit.conf.5 \ -augenrules.8 audit_set_backlog_wait_time.3 \ +augenrules.8 audit_set_backlog_wait_time.3 audit_set_contid_depth_limit.3 \ zos-remote.conf.5
docs/audit_set_contid_depth_limit.3 new file +26 -0
@@ -0,0 +1,26 @@ +.TH "AUDIT_SET_CONTID_DEPTH_LIMIT" "9" "Dec 2019" "Linux Audit API" +.SH NAME +audit_set_contid_depth_limit \- Set the audit container identifier nesting depth limit +.SH "SYNOPSIS" + +.B #include <libaudit.h> +.sp +int audit_set_contid_depth_limit (int fd, int limit); + +.SH "DESCRIPTION" + +audit_set_contid_depth_limit sets the audit container identifier nesting depth limit that the kernel will permit before preventing any further nesting. This prevents the contid field in AUDIT_CONTAINER_OP and AUDIT_CONTAINER_ID messages from overflowing and limits the netlink and disk bandwidth these messages can use. The default value is 4 in the kernel with a maximum of 20. This parameter must be balanced with the maximum number of audit container identifiers used in any network namespace. The two parameters multiplied cannot exceed 400. If set to zero, there is no limit. + + +.SH "RETURN VALUE" + +The return value is <= 0 on error, otherwise it is the netlink sequence id number. This function can have any error that sendto would encounter. + +.SH "SEE ALSO" + +.BR audit_open (3), +.BR auditd (8), +.BR auditctl (8). + +.SH AUTHOR +Richard Guy Briggs
docs/auditctl.8 +3 -0
@@ -13,6 +13,9 @@ Set max number (limit) of outstanding audit buffers allowed (Kernel Default=64) .BI \-\-backlog_wait_time \ \fIwait_time\fP Set the time for the kernel to wait (Kernel Default 60*HZ) when the backlog limit is reached before queuing more audit events to be transferred to auditd. The number must be greater than or equal to zero and less that 10 times the default value. .TP +.BI \-\-contid-depth-limit \ \fIlimit\fP +Set the limit for the kernel container nesting depth (Kernel Default 4). This prevents overflowing the contid field in CONTAINER_OP and CONTAINER_ID messages and limits netlink and disk bandwidth usage by those messages. The default value is 4 in the kernel with a maximum of 20. This parameter must be balanced with the maximum number of audit container identifiers used in any network namespace. The two parameters multiplied cannot exceed 400. If set to zero, there is no limit. +.TP .B \-c Continue loading rules in spite of an error. This summarizes the results of loading the rules. The exit code will not be success if any rule fails to load. .TP
lib/libaudit.c +21 -0
@@ -539,6 +539,27 @@ int audit_reset_lost(int fd)return rc; } +int audit_set_contid_depth_limit (int fd,uint32_t limit) +{ +int rc =-1 ; +#if HAVE_DECL_AUDIT_STATUS_CONTID_DEPTH_LIMIT ==1 +struct audit_status s; + +if ((audit_get_features () &AUDIT_FEATURE_BITMAP_CONTAINERID ) ==0 ) +return -EAU_FIELDNOSUPPORT ; + +memset (&s,0 ,sizeof (s)); + s.mask =AUDIT_STATUS_CONTID_DEPTH_LIMIT ; + s.contid_depth_limit = limit; + rc =audit_send (fd,AUDIT_SET , &s,sizeof (s)); +if (rc <0 ) +audit_msg (audit_priority (errno), +"Error sending contid depth limit request (%s)" , +strerror (-rc)); +#endif +return rc; +} +int audit_set_feature (int fd,unsigned feature,unsigned value,unsigned lock) { #if defined(HAVE_DECL_AUDIT_FEATURE_VERSION) && \
lib/libaudit.h +1 -0
@@ -652,6 +652,7 @@ extern int audit_set_rate_limit(int fd, uint32_t limit);extern int audit_set_backlog_limit (int fd,uint32_t limit);int audit_set_backlog_wait_time (int fd,uint32_t bwt);int audit_reset_lost (int fd); +extern int audit_set_contid_depth_limit (int fd,uint32_t limit);extern int audit_set_feature (int fd,unsigned feature,unsigned value,unsigned lock);extern int audit_set_loginuid_immutable (int fd);
src/auditctl-listing.c +4 -0
@@ -586,6 +586,10 @@ int audit_print_reply(struct audit_reply *rep, int fd)printf ("backlog_wait_time %u\n" , rep->status->backlog_wait_time);#endif +#if HAVE_DECL_AUDIT_STATUS_CONTID_DEPTH_LIMIT ==1 +printf ("contid_depth_limit %u\n" , + rep->status->contid_depth_limit); +#endif printed =1 ;break ; #if defined(HAVE_DECL_AUDIT_FEATURE_VERSION) && \
src/auditctl.c +33 -0
@@ -144,6 +144,9 @@ static void usage(void)#if defined(HAVE_STRUCT_AUDIT_STATUS_FEATURE_BITMAP ) " --reset-lost Reset the lost record counter\n"#endif +#if HAVE_DECL_AUDIT_STATUS_CONTID_DEPTH_LIMIT +" --contid-depth-limit Set the kernel audit container identifier depth limit\n" +#endif ); }
@@ -458,6 +461,9 @@ struct option long_opts[] =#if defined(HAVE_STRUCT_AUDIT_STATUS_FEATURE_BITMAP ) {"reset-lost", 0, NULL, 3}, #endif +#if HAVE_DECL_AUDIT_STATUS_CONTID_DEPTH_LIMIT == 1 + {"contid-depth-limit", 1, NULL, 4}, +#endif {NULL, 0, NULL, 0} };
@@ -1007,6 +1013,33 @@ process_keys: retval =-1 ; }break ; +case 4 : +#if HAVE_DECL_AUDIT_STATUS_CONTID_DEPTH_LIMIT ==1 +if (optarg &&isdigit (optarg[0 ])) { +uint32_t limit; + errno =0 ; + limit =strtoul (optarg,NULL ,0 ); +if (errno) { +audit_msg (LOG_ERR , +"Error converting contid-depth-limit" ); +return -1 ; + } +if (audit_set_contid_depth_limit (fd, limit) >0 ) +audit_request_status (fd); +else +return -1 ; + }else { +audit_msg (LOG_ERR , +"contid-depth-limit must be a numeric value was %s" , + optarg); + retval =-1 ; + } +#else +audit_msg (LOG_ERR , +"contid-depth-limit is not supported on your kernel" ); + retval =-1 ; +#endif +break ;default :usage (); retval =-1 ;
Signature · 1 line
1.8.3.1
PATCH v8 13/14 auditctl: add a config parameter to limit the contid netns count
In reply to Richard Guy BriggsThis adds the auditctl option "--contid-netns-limit" that takes one argument.
Please see kernel patch ("audit: add contid netns limit config param").
--- configure.ac | 1 + docs/Makefile.am | 1 + docs/audit_set_contid_netns_limit.3 | 25 +++++++++++++++++++++++++ docs/auditctl.8 | 5 ++++- lib/libaudit.c | 21 +++++++++++++++++++++ lib/libaudit.h | 1 + src/auditctl-listing.c | 4 ++++ src/auditctl.c | 33 +++++++++++++++++++++++++++++++++ 8 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 docs/audit_set_contid_netns_limit.3
configure.ac +1 -0
@@ -68,6 +68,7 @@ AC_CHECK_MEMBERS([struct audit_status.feature_bitmap], [], [], [[#include <linux AC_CHECK_DECLS([AUDIT_VERSION_BACKLOG_WAIT_TIME], [], [], [[#include <linux/audit.h>]]) AC_CHECK_DECLS([AUDIT_STATUS_BACKLOG_WAIT_TIME], [], [], [[#include <linux/audit.h>]]) AC_CHECK_DECLS([AUDIT_STATUS_CONTID_DEPTH_LIMIT], [], [], [[#include <linux/audit.h>]]) +AC_CHECK_DECLS([AUDIT_STATUS_CONTID_NETNS_LIMIT], [], [], [[#include <linux/audit.h>]]) AC_CHECK_DECLS([ADDR_NO_RANDOMIZE],,, [#include <sys/personality.h>]) dnl; posix_fallocate is used in audisp-remote AC_CHECK_FUNCS([posix_fallocate])
docs/Makefile.am +1 -0
@@ -61,5 +61,6 @@ ausearch_next_event.3 ausearch_set_stop.3 \ autrace.8 get_auditfail_action.3 set_aumessage_mode.3 \ audispd-zos-remote.8 libaudit.conf.5 \ augenrules.8 audit_set_backlog_wait_time.3 audit_set_contid_depth_limit.3 \ +audit_set_contid_netns_limit.3 \ zos-remote.conf.5
docs/audit_set_contid_netns_limit.3 new file +25 -0
@@ -0,0 +1,25 @@ +.TH "AUDIT_SET_CONTID_NETNS_LIMIT" "18" "Dec 2019" "Linux Audit API" +.SH NAME +audit_set_contid_netns_limit \- Set the audit container identifier network namespace limit +.SH "SYNOPSIS" + +.B #include <libaudit.h> +.sp +int audit_set_contid_netns_limit (int fd, int limit); + +.SH "DESCRIPTION" + +audit_set_contid_netns_limit sets the audit container identifier network namespace limit that the kernel will permit before preventing any further nesting. This prevents the contid field in AUDIT_CONTAINER_OP and AUDIT_CONTAINER_ID messages from overflowing and limits the netlink and disk bandwidth these messages can use. This parameter works in conjunction with contid_depth_limit. The two parameters multiplied cannot exceed 400. The default value is 100 in the kernel with a maximum of 400 when contid_depth_limit is set to 1. If set to zero, there is no limit. + +.SH "RETURN VALUE" + +The return value is <= 0 on error, otherwise it is the netlink sequence id number. This function can have any error that sendto would encounter. + +.SH "SEE ALSO" + +.BR audit_open (3), +.BR auditd (8), +.BR auditctl (8). + +.SH AUTHOR +Richard Guy Briggs
docs/auditctl.8 +4 -1
@@ -14,7 +14,10 @@ Set max number (limit) of outstanding audit buffers allowed (Kernel Default=64) Set the time for the kernel to wait (Kernel Default 60*HZ) when the backlog limit is reached before queuing more audit events to be transferred to auditd. The number must be greater than or equal to zero and less that 10 times the default value. .TP .BI \-\-contid-depth-limit \ \fIlimit\fP -Set the limit for the kernel container nesting depth (Kernel Default 4). This prevents overflowing the contid field in CONTAINER_OP and CONTAINER_ID messages and limits netlink and disk bandwidth usage by those messages. The default value is 4 in the kernel with a maximum of 20. This parameter must be balanced with the maximum number of audit container identifiers used in any network namespace. The two parameters multiplied cannot exceed 400. If set to zero, there is no limit. +Set the limit for the kernel container nesting depth (Kernel Default 4). This prevents overflowing the contid field in CONTAINER_OP and CONTAINER_ID messages and limits netlink and disk bandwidth usage by those messages. This parameter works in conjunction with contid_netns_limit. The two parameters multiplied together cannot exceed 400. The default value is 4 in the kernel with a maximum of 400 when contid_netns_limit is set to 1. If set to zero, there is no limit. +.TP +.BI \-\-contid-netns-limit \ \fIlimit\fP +Set the limit for the kernel container network namespace (Kernel Default 100). This prevents overflowing the contid field in CONTAINER_OP and CONTAINER_ID messages and limits netlink and disk bandwidth usage by those messages. This parameter works in conjunction with contid_depth_limit. The two parameters multiplied together cannot exceed 400. The default value is 100 in the kernel with a maximum of 400 when contid_depth_limit is set to 1. If set to zero, there is no limit. .TP .B \-c Continue loading rules in spite of an error. This summarizes the results of loading the rules. The exit code will not be success if any rule fails to load.
lib/libaudit.c +21 -0
@@ -560,6 +560,27 @@ int audit_set_contid_depth_limit(int fd, uint32_t limit)return rc; } +int audit_set_contid_netns_limit (int fd,uint32_t limit) +{ +int rc =-1 ; +#if HAVE_DECL_AUDIT_STATUS_CONTID_NETNS_LIMIT ==1 +struct audit_status s; + +if ((audit_get_features () &AUDIT_FEATURE_BITMAP_CONTAINERID ) ==0 ) +return -EAU_FIELDNOSUPPORT ; + +memset (&s,0 ,sizeof (s)); + s.mask =AUDIT_STATUS_CONTID_NETNS_LIMIT ; + s.contid_netns_limit = limit; + rc =audit_send (fd,AUDIT_SET , &s,sizeof (s)); +if (rc <0 ) +audit_msg (audit_priority (errno), +"Error sending contid netns limit request (%s)" , +strerror (-rc)); +#endif +return rc; +} +int audit_set_feature (int fd,unsigned feature,unsigned value,unsigned lock) { #if defined(HAVE_DECL_AUDIT_FEATURE_VERSION) && \
lib/libaudit.h +1 -0
@@ -653,6 +653,7 @@ extern int audit_set_backlog_limit(int fd, uint32_t limit);int audit_set_backlog_wait_time (int fd,uint32_t bwt);int audit_reset_lost (int fd);extern int audit_set_contid_depth_limit (int fd,uint32_t limit); +extern int audit_set_contid_netns_limit (int fd,uint32_t limit);extern int audit_set_feature (int fd,unsigned feature,unsigned value,unsigned lock);extern int audit_set_loginuid_immutable (int fd);
src/auditctl-listing.c +4 -0
@@ -590,6 +590,10 @@ int audit_print_reply(struct audit_reply *rep, int fd)printf ("contid_depth_limit %u\n" , rep->status->contid_depth_limit);#endif +#if HAVE_DECL_AUDIT_STATUS_CONTID_NETNS_LIMIT ==1 +printf ("contid_netns_limit %u\n" , + rep->status->contid_netns_limit); +#endif printed =1 ;break ; #if defined(HAVE_DECL_AUDIT_FEATURE_VERSION) && \
src/auditctl.c +33 -0
@@ -147,6 +147,9 @@ static void usage(void)#if HAVE_DECL_AUDIT_STATUS_CONTID_DEPTH_LIMIT " --contid-depth-limit Set the kernel audit container identifier depth limit\n"#endif +#if HAVE_DECL_AUDIT_STATUS_CONTID_NETNS_LIMIT +" --contid-netns-limit Set the kernel audit container identifier netns limit\n" +#endif ); }
@@ -464,6 +467,9 @@ struct option long_opts[] =#if HAVE_DECL_AUDIT_STATUS_CONTID_DEPTH_LIMIT ==1 {"contid-depth-limit", 1, NULL, 4}, #endif +#if HAVE_DECL_AUDIT_STATUS_CONTID_NETNS_LIMIT == 1 + {"contid-netns-limit", 1, NULL, 5}, +#endif {NULL, 0, NULL, 0} };
@@ -1040,6 +1046,33 @@ process_keys: retval =-1 ;#endif break ; +case 5 : +#if HAVE_DECL_AUDIT_STATUS_CONTID_NETNS_LIMIT ==1 +if (optarg &&isdigit (optarg[0 ])) { +uint32_t limit; + errno =0 ; + limit =strtoul (optarg,NULL ,0 ); +if (errno) { +audit_msg (LOG_ERR , +"Error converting contid-netns-limit" ); +return -1 ; + } +if (audit_set_contid_netns_limit (fd, limit) >0 ) +audit_request_status (fd); +else +return -1 ; + }else { +audit_msg (LOG_ERR , +"contid-netns-limit must be a numeric value was %s" , + optarg); + retval =-1 ; + } +#else +audit_msg (LOG_ERR , +"contid-netns-limit is not supported on your kernel" ); + retval =-1 ; +#endif +break ;default :usage (); retval =-1 ;
Signature · 1 line
1.8.3.1
PATCH v8 14/14 libaudit: add support to get and set capcontid on a task
In reply to Richard Guy BriggsAdd support to be able to set a capability to allow a task to set the audit container identifier of descendants.
See: https://github.com/linux-audit/audit-userspace/issues/51
See: https://github.com/linux-audit/audit-kernel/issues/90
See: https://github.com/linux-audit/audit-testsuite/issues/64
See: https://github.com/linux-audit/audit-kernel/wiki/RFE-Audit-Container-ID
Add the audit_get_capcontid() and audit_set_capcontid() calls analogous to CAP_AUDIT_CONTROL for descendant user namespaces.
--- docs/Makefile.am | 1 + docs/audit_get_capcontid.3 | 25 ++++++++++++++++ docs/audit_set_capcontid.3 | 24 +++++++++++++++ lib/libaudit.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++ lib/libaudit.h | 4 +++ lib/msg_typetab.h | 1 + 6 files changed, 129 insertions(+) create mode 100644 docs/audit_get_capcontid.3 create mode 100644 docs/audit_set_capcontid.3
docs/Makefile.am +1 -0
@@ -29,6 +29,7 @@ auditd.conf.5 auditd-plugins.5 \ audit_delete_rule_data.3 audit_detect_machine.3 \ audit_encode_nv_string.3 audit_getloginuid.3 \ audit_get_reply.3 audit_get_session.3 audit_get_containerid.3 \ +audit_get_capcontid.3 audit_set_capcontid.3 \ audit_log_acct_message.3 audit_log_user_avc_message.3 \ audit_log_user_command.3 audit_log_user_comm_message.3 \ audit_log_user_message.3 audit_log_semanage_message.3 \
docs/audit_get_capcontid.3 new file +25 -0
@@ -0,0 +1,25 @@ +.TH "AUDIT_GET_CAPCONTID" "26" "Aug 2019" "Red Hat" "Linux Audit API" +.SH NAME +audit_get_capcontid \- Get a program's capability container id value +.SH SYNOPSIS +.B #include <libaudit.h> +.sp +int audit_get_capcontid(pid_t pid); + +.SH DESCRIPTION +This function returns the pid task's audit capability container identifier attribute. + +.SH "RETURN VALUE" + +This function returns the audit capability container identifier value if it is implemented. It will return a \-1 if the audit capability container identifier is unavailable. + +.SH "ERRORS" + +This function returns \-2 on failure. Additionally, in the event of a real error, errno would be set. The function can set errno based on failures of open, read, or strtoull. + +.SH "SEE ALSO" + +.BR audit_set_capcontid (3). + +.SH AUTHOR +Richard Guy Briggs
docs/audit_set_capcontid.3 new file +24 -0
@@ -0,0 +1,24 @@ +.TH "AUDIT_SET_CAPCONTID" "26" "Aug 2019" "Red Hat" "Linux Audit API" +.SH NAME +audit_set_capcontid \- Set a program's capability container id value +.SH SYNOPSIS +.B #include <libaudit.h> +.sp +int audit_set_capcontid(pid_t pid, uint32_t capcontid); + +.SH "DESCRIPTION" + +This function sets the pid task's attribute capability container id with the value of capcontid. The capcontid value may only be set by programs with the CAP_AUDIT_CONTROL capability in the initial user namespace or with capcontid. This normally means the root account or root in a container. +.sp +The capcontid value is part of the task structure and is inheritted by child processes within a user namespace. It is used to enable the capability to set container identifier of a child task in a descendent user namespace. Container orchestrator/engines should set this value only on children it wishes to be able to set audit container identifiers. + +.SH "RETURN VALUE" + +This function returns 0 on success and non-zero otherwise. + +.SH "SEE ALSO" + +.BR audit_get_capcontid (3). + +.SH AUTHOR +Richard Guy Briggs
lib/libaudit.c +74 -0
80 lines not on this page · raw message
lib/libaudit.h +4 -0
@@ -255,6 +255,10 @@ extern "C" {#define AUDIT_SIGNAL_INFO2 1021/* auditd signal sender info */ #endif +#ifndef AUDIT_SET_CAPCONTID +#define AUDIT_SET_CAPCONTID 1022/* set capcontid of specified pid */ +#endif +#ifndef AUDIT_MMAP #define AUDIT_MMAP 1323/* Descriptor and flags in mmap */ #endif
lib/msg_typetab.h +1 -0
@@ -45,6 +45,7 @@ _S(AUDIT_LOGIN, "LOGIN" )//_S(AUDIT_SET_FEATURE, "SET_FEATURE" ) //_S(AUDIT_GET_FEATURE, "GET_FEATURE" ) //_S(AUDIT_SIGNAL_INFO2, "SIGNAL_INFO2" ) +_S(AUDIT_SET_CAPCONTID, "SET_CAPCONTID" ) _S(AUDIT_CONTAINER_OP, "CONTAINER_OP" ) _S(AUDIT_USER_AUTH, "USER_AUTH" )_S (AUDIT_USER_ACCT ,"USER_ACCT" )
Signature · 1 line
1.8.3.1