add support for audit container identifier
Subsystems (2)
v6 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 last is to learn the audit container identifier of the process that signals the audit daemon.
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
See: https://github.com/linux-audit/audit-kernel/wiki/RFE-Audit-Container-ID
Changelog:
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 (7):
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 add support for audit_signal_info2
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 + docs/Makefile.am | 2 +- docs/audit_get_containerid.3 | 25 +++++ docs/audit_request_signal_info.3 | 3 +- docs/auditctl.8 | 3 + lib/fieldtab.h | 1 + lib/libaudit.c | 118 ++++++++++++++++++++++- lib/libaudit.h | 31 ++++++ lib/msg_typetab.h | 3 + lib/netlink.c | 5 + src/auditctl-listing.c | 21 +++++ src/auditd-config.c | 1 + src/auditd-config.h | 1 + src/auditd-event.c | 23 +++-- src/auditd-reconfig.c | 32 ++++--- src/auditd.c | 33 +++---- 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 | 197 +++++++++++++++++++++++++++++++++++++++ 28 files changed, 530 insertions(+), 43 deletions(-) create mode 100644 docs/audit_get_containerid.3
Signature · 1 line
1.8.3.1
PATCH v6 1/7 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
@@ -243,6 +243,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 v6 2/7 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
@@ -283,6 +283,10 @@ extern "C" {#define AUDIT_FANOTIFY 1331/* Fanotify access decision */ #endif +#ifndef AUDIT_CONTAINER_ID +#define AUDIT_CONTAINER_ID 1332/* 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
@@ -124,6 +124,7 @@ _S(AUDIT_PROCTITLE, "PROCTITLE" ) _S(AUDIT_FEATURE_CHANGE, "FEATURE_CHANGE" ) _S(AUDIT_KERN_MODULE, "KERN_MODULE" ) _S(AUDIT_FANOTIFY, "FANOTIFY" ) +_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 v6 3/7 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
@@ -213,6 +213,9 @@ Parent's Process ID .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
@@ -1742,6 +1742,42 @@ int audit_rule_fieldpair_data(struct audit_rule_data **rulep, const char *pair,else if (strcmp (v,"unset" ) ==0 ) rule->values[rule->field_count] =UINT_MAX ;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
@@ -339,6 +339,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
@@ -362,6 +365,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 v6 4/7 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 | 197 +++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 251 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 +197 -0
221 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v6 5/7 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
@@ -2832,6 +2832,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;
@@ -3061,6 +3068,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 v6 6/7 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 +uin32_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 strtoul. + +.SH "SEE ALSO" + +.BR audit_getloginuid (3). + +.SH AUTHOR +Steve Grubb
lib/libaudit.c +29 -0
@@ -931,6 +931,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
@@ -575,6 +575,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);
Signature · 1 line
1.8.3.1
PATCH v6 7/7 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 | 3 ++- lib/libaudit.c | 53 +++++++++++++++++++++++++++++++++++++++- lib/libaudit.h | 15 ++++++++++++ lib/msg_typetab.h | 1 + lib/netlink.c | 4 +++ src/auditd-config.c | 1 + src/auditd-config.h | 1 + src/auditd-event.c | 23 ++++++++++++----- src/auditd-reconfig.c | 32 +++++++++++++++--------- src/auditd.c | 33 ++++++++++--------------- 11 files changed, 127 insertions(+), 40 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 +2 -1
@@ -8,12 +8,13 @@ int audit_request_signal_info(int fd); .SH "DESCRIPTION" -audit_request_signal_info requests that the kernel send information about the sender of a signal to the audit daemon. The sinal info structure is as follows: +audit_request_signal_info requests that the kernel send information about the sender of a signal to the audit daemon. The signal info structure is as follows: .nf struct audit_sig_info { uid_t uid; pid_t pid; + uint64_t cid; char ctx[0]; }; .fi
lib/libaudit.c +52 -1
71 lines not on this page · raw message
lib/libaudit.h +15 -0
@@ -34,6 +34,7 @@ extern "C" {#include <linux/netlink.h> #include <linux/audit.h> #include <stdarg.h> +#include <stdbool.h> #include <syslog.h>
@@ -247,6 +248,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
@@ -476,6 +481,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 {
@@ -501,6 +513,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;
@@ -578,6 +591,8 @@ 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_is_baremsg (struct audit_reply *rep); +extern char *audit_format_signal_info (char *buf,int len,char *op,struct audit_reply *rep,char *res);/* Translation functions */ extern int audit_name_to_field (const char *field);
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 +17 -6
@@ -1315,15 +1315,21 @@ 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 ];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); +if (cid ==-1 ) +snprintf (txt,sizeof (txt), +"config change requested by pid=%d auid=%u subj=%s" , + pid, uid, ctx); +else +snprintf (txt,sizeof (txt), +"config change requested by pid=%d auid=%u subj=%s contid=%llu" , + pid, uid, ctx, (unsigned long long )cid);audit_msg (LOG_NOTICE ,"%s" , txt);/* Do the reconfiguring. These are done in a specific
@@ -1571,9 +1577,14 @@ 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 ); +if (cid ==-1 ) + 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); +else + 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 contid=%llu" , + date, uid, pid, ctx, (unsigned long long )cid); e->reply.message = e->reply.msg.data;free ((char *)ctx); }
src/auditd-reconfig.c +20 -12
@@ -101,13 +101,24 @@ 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); -else +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_is_baremsg (&e->reply)) { new_config.sender_ctx =strdup ("?" ); + }else 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 ;
@@ -115,12 +126,9 @@ static void *config_thread_main(void *arg) }else {// need to send a failed event message char txt[MAX_AUDIT_MESSAGE_LENGTH ]; -snprintf (txt,sizeof (txt), -"op=reconfigure state=no-change auid=%u pid=%d subj=%s res=failed" , - e->reply.signal_info->uid, - e->reply.signal_info->pid, - (e->reply.len >24 ) ? - e->reply.signal_info->ctx :"?" ); +audit_format_signal_info (txt,sizeof (txt), +"reconfigure-no-change" , + &e->reply,"failed" );// FIXME: need to figure out sending this //send_audit_event(AUDIT_DAEMON_CONFIG, txt); free_config (&new_config);
src/auditd.c +13 -20
@@ -514,6 +514,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) {audit_msg (LOG_DEBUG ,"HUP detected, starting config manager" );
@@ -528,31 +529,28 @@ static void netlink_handler(struct ev_loop *loop, struct ev_io *io, hup_info_requested =0 ; }else if (usr1_info_requested) {char usr1[MAX_AUDIT_MESSAGE_LENGTH ]; -if (cur_event->reply.len ==24 ) { +if (audit_signal_info_is_baremsg (&cur_event->reply)) {snprintf (usr1,sizeof (usr1),"op=rotate-logs auid=-1 pid=-1 subj=?" ); }else { -snprintf (usr1,sizeof (usr1), -"op=rotate-logs auid=%u pid=%d subj=%s" , - cur_event->reply.signal_info->uid, - cur_event->reply.signal_info->pid, - cur_event->reply.signal_info->ctx); +audit_format_signal_info (usr1,sizeof (usr1), +"rotate-logs" , + &cur_event->reply, +"success" ); }send_audit_event (AUDIT_DAEMON_ROTATE , usr1); usr1_info_requested =0 ; }else if (usr2_info_requested) {char usr2[MAX_AUDIT_MESSAGE_LENGTH ]; -if (cur_event->reply.len ==24 ) { +if (audit_signal_info_is_baremsg (&cur_event->reply)) {snprintf (usr2,sizeof (usr2),"op=resume-logging auid=-1 " "pid=-1 subj=? res=success" ); }else { -snprintf (usr2,sizeof (usr2), -"op=resume-logging " -"auid=%u pid=%d subj=%s res=success" , - cur_event->reply.signal_info->uid, - cur_event->reply.signal_info->pid, - cur_event->reply.signal_info->ctx); +audit_format_signal_info (usr2,sizeof (usr2), +"resume-logging" , + &cur_event->reply, +"success" ); }resume_logging ();libdisp_resume ();
@@ -993,12 +991,7 @@ int main(int argc, char *argv[]) rc =get_reply (fd, &trep, rc);if (rc >0 ) {char txt[MAX_AUDIT_MESSAGE_LENGTH ]; -snprintf (txt,sizeof (txt), -"op=terminate auid=%u " -"pid=%d subj=%s res=success" , - trep.signal_info->uid, - trep.signal_info->pid, - trep.signal_info->ctx); +audit_format_signal_info (txt,sizeof (txt),"terminate" , &trep,"success" );send_audit_event (AUDIT_DAEMON_END , txt); } }
@@ -1091,7 +1084,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