audit: implement container id
Subsystems (10)
Re: [RFC PATCH ghak32 V2 01/13] audit: add container id
In reply to Richard Guy BriggsQuoted 8 lines · On Fri, 16 Mar 2018 05:00:28 -0400 Richard Guy Briggs…
Implement the proc fs write to set the audit container ID of a process, emitting an
AUDIT_CONTAINERrecord to document the event.This is a write from the container orchestrator task to a proc entry of the form
/proc/PID/containeridwhere PID is the process ID of the newly created task that is to become the first task in a container, or an additional task added to a container.
Quoted 7 lines
The write expects up to a u64 value (unset: 18446744073709551615).
This will produce a record such as this:
type=CONTAINER msg=audit(1519903238.968:261): op=set pid=596 uid=0 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 auid=0 tty=pts0 ses=1 opid=596 old-contid=18446744073709551615 contid=123455 res=0
The was one thing I was wondering about. Currently when we set the loginuid, the record is AUDIT_LOGINUID. The corollary is that when we set the container id, the event should be AUDIT_CONTAINERID or AUDIT_CONTAINER_ID.
During syscall events, the path info is returned in a a record simply called AUDIT_PATH, cwd info is returned in AUDIT_CWD. So, rather than calling the record that gets attached to everything AUDIT_CONTAINER_INFO, how about simply AUDIT_CONTAINER.
Quoted 256 lines
The "op" field indicates an initial set. The "pid" to "ses" fields are the orchestrator while the "opid" field is the object's PID, the process being "contained". Old and new container ID values are given in the "contid" fields, while res indicates its success.
It is not permitted to self-set, unset or re-set the container ID. A child inherits its parent's container ID, but then can be set only once after.
See: https://github.com/linux-audit/audit-kernel/issues/32
Signed-off-by Richard Guy Briggs <[email protected]>--- fs/proc/base.c | 37 ++++++++++++++++++++ include/linux/audit.h | 16 +++++++++ include/linux/init_task.h | 4 ++- include/linux/sched.h | 1 + include/uapi/linux/audit.h | 2 ++ kernel/auditsc.c | 84++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 143 insertions(+), 1 deletion(-)
fs/proc/base.c +35
-0@@ -1299,6 +1299,41 @@ static ssize_t proc_sessionid_read(struct file * file, char __user * buf, .read = proc_sessionid_read, .llseek = generic_file_llseek, }; + +static ssize_t proc_containerid_write (struct file *file,const char __user *buf, +size_t count,loff_t *ppos) +{ +struct inode *inode =file_inode (file); +u64 containerid; +int rv; +struct task_struct *task =get_proc_task (inode); + +if (!task) +return -ESRCH ; +if (*ppos !=0 ) { +/* No partial writes. */ +put_task_struct (task); +return -EINVAL ; + } + + rv =kstrtou64_from_user (buf, count,10 , &containerid); +if (rv <0 ) { +put_task_struct (task); +return rv; + } + + rv =audit_set_containerid (task, containerid); +put_task_struct (task); +if (rv <0 ) +return rv; +return count; +} + +static const struct file_operations proc_containerid_operations = { + .write = proc_containerid_write, + .llseek = generic_file_llseek, +}; +#endif #ifdef
CONFIG_FAULT_INJECTIONfs/proc/base.c +1
-0@@ -2961,6 +2996,7 @@ static int proc_pid_patch_state(struct seq_file *m, struct pid_namespace *ns, #ifdef CONFIG_AUDITSYSCALLREG ("loginuid" ,S_IWUSR |S_IRUGO , proc_loginuid_operations),REG ("sessionid" ,S_IRUGO , proc_sessionid_operations), +REG ("containerid" ,S_IWUSR , proc_containerid_operations), #endif #ifdef CONFIG_FAULT_INJECTION REG("make-it-fail", S_IRUGO|S_IWUSR,
proc_fault_inject_operations), @@ -3355,6 +3391,7 @@ static intproc_tid_comm_permission(struct inode *inode, int mask)#ifdefCONFIG_AUDITSYSCALLREG("loginuid", S_IWUSR|S_IRUGO, proc_loginuid_operations),REG("sessionid", S_IRUGO, proc_sessionid_operations),fs/proc/base.c +1
-0+ REG("containerid", S_IWUSR, proc_containerid_operations),#endif #ifdef CONFIG_FAULT_INJECTION REG("make-it-fail", S_IRUGO|S_IWUSR,
proc_fault_inject_operations), diff --gita/include/linux/audit.hb/include/linux/audit.hindex af410d9..fe4ba3f 100644include/linux/audit.h +1
-0@@ -29,6 +29,7 @@#define AUDIT_INO_UNSET ((unsigned long)-1)#define AUDIT_DEV_UNSET ((dev_t)-1) +#define INVALID_CID AUDIT_CID_UNSETstruct audit_sig_info {uid_t uid;@@ -321,6 +322,7 @@ static inline void audit_ptrace(struct
task_struct*t) extern intauditsc_get_stamp(struct audit_context *ctx, struct timespec64 *t, unsigned int *serial);
extern intaudit_set_loginuid(kuid_t loginuid);
+extern intaudit_set_containerid(struct task_struct *tsk, u64 containerid);
static inlinekuid_taudit_get_loginuid(struct task_struct *tsk){include/linux/audit.h +5
-0@@ -332,6 +334,11 @@ static inline unsigned int audit_get_sessionid(struct task_struct *tsk) return tsk->sessionid; } +static inline u64 audit_get_containerid (struct task_struct *tsk) +{ +return tsk->containerid; +} +extern void __audit_ipc_obj (struct kern_ipc_perm *ipcp); extern void __audit_ipc_set_perm(unsigned long qbytes, uid_t uid,
gid_tgid,umode_tmode); extern void__audit_bprm(struct linux_binprm *bprm); @@ -517,6 +524,10 @@ static inline unsigned intaudit_get_sessionid(struct task_struct *tsk){include/linux/audit.h +4
-0return -1 ; } +static inline kuid_t audit_get_containerid (struct task_struct *tsk) +{ +return INVALID_CID ; +}static inline void audit_ipc_obj (struct kern_ipc_perm *ipcp) { } static inline void audit_ipc_set_perm(unsigned long qbytes, uid_tuid, @@ -581,6 +592,11 @@ static inline bool
audit_loginuid_set(struct task_struct *tsk)return uid_valid(audit_get_loginuid(tsk)); }include/linux/audit.h +5
-0+static inline bool audit_containerid_set (struct task_struct *tsk) +{ +return audit_get_containerid (tsk) !=INVALID_CID ; +} + static inline void audit_log_string(struct audit_buffer *ab, constchar *buf) {
include/linux/audit.h +0
-0audit_log_n_string (ab, buf,strlen (buf));include/linux/init_task.h +3
-1@@ -18,6 +18,7 @@#include <linux/sched/rt.h> #include <linux/livepatch.h> #include <linux/mm_types.h> +#include <linux/audit.h> #include <asm/thread_info.h> @@ -120,7 +121,8 @@#ifdef CONFIG_AUDITSYSCALL #define INIT_IDS \ .loginuid = INVALID_UID, \ - .sessionid = (unsigned int)-1, + .sessionid = (unsigned int)-1, \ + .containerid = INVALID_CID,#else #define INIT_IDS #endif include/linux/sched.h +1
-0@@ -796,6 +796,7 @@ struct task_struct {#ifdef CONFIG_AUDITSYSCALL kuid_t loginuid;unsigned int sessionid; +u64 containerid;#endif struct seccomp seccomp;include/uapi/linux/audit.h +0
-0@@ -71,6 +71,7 @@#define AUDIT_TTY_SET 1017/* Set TTY auditing status */ #define
AUDIT_SET_FEATURE1018 /* Turn an
audit feature on or off */ #defineAUDIT_GET_FEATURE
1019 /* Get which features are enabled */ +#defineAUDIT_CONTAINER1020 /* Define the container id
and information */ #defineAUDIT_FIRST_USER_MSG1100 /*
Userspace messages mostly uninteresting to kernel */ #defineAUDIT_USER_AVC1107 /* We filter this
differently */ @@ -465,6 +466,7 @@ structaudit_tty_status{ };#define
AUDIT_UID_UNSET(unsigned int)-1include/uapi/linux/audit.h +1
-0+#define AUDIT_CID_UNSET ((u64)-1)/* audit_rule_data supports filter rules with both integer and string * fields. It corresponds with AUDIT_ADD_RULE, AUDIT_DEL_RULE and kernel/auditsc.c +17
-0@@ -2073,6 +2073,90 @@ int audit_set_loginuid(kuid_t loginuid)return rc; } +static int audit_set_containerid_perm (struct task_struct *task,u64 containerid) +{ +struct task_struct *parent; +u64 pcontainerid, ccontainerid; + +/* Don't allow to set our own containerid */ +if (current == task) +return -EPERM ; +/* Don't allow the containerid to be unset */ +if (!cid_valid (containerid)) +return -EINVAL ; +/* if we don't have caps, reject */ +if (!capable (CAP_AUDIT_CONTROL )) +return -EPERM ; +/* if containerid is unset, allow */ +if (!audit_containerid_set (task)) +return 0 ; +/* it is already set, and not inherited from the parent, reject */
kernel/auditsc.c +13
-0+ ccontainerid =audit_get_containerid (task); +rcu_read_lock (); + parent =rcu_dereference (task->real_parent); +rcu_read_unlock (); +task_lock (parent); + pcontainerid =audit_get_containerid (parent); +task_unlock (parent); +if (ccontainerid != pcontainerid) +return -EPERM ; +return 0 ; +} + +static void audit_log_set_containerid(struct task_struct *task, u64oldcontainerid,
kernel/auditsc.c +17
-0+ u64 containerid, int rc) +{ +struct audit_buffer *ab; +uid_t uid; +struct tty_struct *tty; + +if (!audit_enabled) +return ; + + ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_CONTAINER ); +if (!ab) +return ; + + uid =from_kuid (&init_user_ns,task_uid (current)); + tty =audit_get_tty (current); + + audit_log_format(ab, "op=set pid=%d uid=%u",
task_tgid_nr(current), uid);kernel/auditsc.c +2
-0+audit_log_task_context (ab); + audit_log_format(ab, " auid=%u tty=%s ses=%u opid=%d
Quoted 1 line
old-contid=%llu contid=%llu res=%d",
The preferred ordering would be: op, opid, old-contid, contid, pid, uid, tty, ses, subj, comm, exe, res. This groups the searchable fields together using the most common ordering so that parsing is simple.
Thanks,
-Steve
Quoted 41 lines
kernel/auditsc.c +1
-0+ from_kuid(&init_user_ns,
audit_get_loginuid(current)),kernel/auditsc.c +1
-0+ tty ? tty_name(tty) : "(none)",
audit_get_sessionid(current),kernel/auditsc.c +1
-0+ task_tgid_nr(task), oldcontainerid,containerid, !rc); +
kernel/auditsc.c +6
-0+audit_put_tty (tty); +audit_log_end (ab); +} + +/** +* audit_set_containerid - set current task's audit_context containerid
+ * @containerid: containerid value
+ *
+ * Returns 0 on success,-EPERMon permission failure.
+ *
+ * Called (set) from fs/proc/base.c::proc_containerid_write().
+ */kernel/auditsc.c +15
-0+int audit_set_containerid (struct task_struct *task,u64 containerid) +{ +u64 oldcontainerid; +int rc; + + oldcontainerid =audit_get_containerid (task); + + rc =audit_set_containerid_perm (task, containerid); +if (!rc) { +task_lock (task); + task->containerid = containerid; +task_unlock (task); + } + + audit_log_set_containerid(task, oldcontainerid, containerid,rc);
kernel/auditsc.c +3
-0+return rc; +} +/** * __audit_mq_open - record audit data for a POSIX MQ open * @oflag: open flag
Re: [RFC PATCH ghak32 V2 03/13] audit: log container info of syscalls
In reply to Richard Guy BriggsQuoted 2 lines · On Fri, 16 Mar 2018 05:00:30 -0400 Richard Guy Briggs <[email protected]> wrote:
Create a new audit record
AUDIT_CONTAINER_INFOto document the container ID of a process if it is present.
As mentioned in a previous email, I think AUDIT_CONTAINER is more suitable for the container record. One more comment below...
Quoted 104 lines
Called from
audit_log_exit(), syscalls are covered.A sample raw event:
type=SYSCALL msg=audit(1519924845.499:257): arch=c000003e syscall=257
success=yes exit=3 a0=ffffff9c a1=56374e1cef30 a2=241 a3=1b6 items=2
ppid=606 pid=635 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0
sgid=0 fsgid=0 tty=pts0 ses=3 comm="bash" exe="/usr/bin/bash" subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
key="tmpcontainerid" type=CWD msg=audit(1519924845.499:257):
cwd="/root" type=PATH msg=audit(1519924845.499:257): item=0
name="/tmp/" inode=13863 dev=00:27 mode=041777 ouid=0 ogid=0
rdev=00:00 obj=system_u:object_r:tmp_t:s0 nametype= PARENT
cap_fp=0000000000000000 cap_fi=0000000000000000 cap_fe=0 cap_fver=0
type=PATH msg=audit(1519924845.499:257): item=1
name="/tmp/tmpcontainerid" inode=17729 dev=00:27 mode=0100644 ouid=0
ogid=0 rdev=00:00 obj=unconfined_u:object_r:user_tmp_t:s0
nametype=CREATE cap_fp=0000000000000000 cap_fi=0000000000000000
cap_fe=0 cap_fver=0 type=PROCTITLE msg=audit(1519924845.499:257):
proctitle=62617368002D6300736C65657020313B206563686F2074657374203E202F746D702F746D70636F6E7461696E65726964 type=CONTAINER_INFO msg=audit(1519924845.499:257): op=task
contid=123458See: https://github.com/linux-audit/audit-kernel/issues/32
Signed-off-by Richard Guy Briggs <[email protected]>--- include/linux/audit.h | 5 +++++ include/uapi/linux/audit.h | 1 + kernel/audit.c | 20 ++++++++++++++++++++ kernel/auditsc.c | 2 ++ 4 files changed, 28 insertions(+)include/linux/audit.h +0
-0@@ -154,6 +154,8 @@ extern voidaudit_log_link_denied(const char *operation, extern int
audit_log_task_context(struct audit_buffer *ab); extern voidaudit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk);include/linux/audit.h +2
-0+extern int audit_log_container_info (struct task_struct *tsk, +struct audit_context *context);extern int audit_update_lsm_rules (void );@@ -205,6 +207,9 @@ static inline int audit_log_task_context(struct
audit_buffer*ab) static inline voidaudit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk)
{ }include/linux/audit.h +2
-0+static inline int audit_log_container_info (struct task_struct *tsk, + struct audit_context*context); +{ }
#defineaudit_enabled0
#endif /*CONFIG_AUDIT*/include/uapi/linux/audit.h +0
-0@@ -115,6 +115,7 @@#define AUDIT_REPLACE 1329/* Replace auditd if this packet unanswerd */ #define
AUDIT_KERN_MODULE
1330 /* Kernel Module events */ #defineAUDIT_FANOTIFY1331 /* Fanotify access decision
*/ +#defineAUDIT_CONTAINER_INFO1332 /* Container ID
information */ #defineAUDIT_AVC1400 /* SE
Linux avc denial or grant */ #defineAUDIT_SELINUX_ERR
1401 /* Internal SE Linux Errors */ diff --gita/kernel/audit.cb/kernel/audit.cindex 3f2f143..a12f21f 100644kernel/audit.c +19
-0@@ -2049,6 +2049,26 @@ void audit_log_session_info(struct audit_buffer *ab) audit_log_format(ab, " auid=%u ses=%u", auid, sessionid); } +/* +* audit_log_container_info - report container info +* @tsk: task to be recorded +* @context: task or local context for record +*/ +int audit_log_container_info (struct task_struct *tsk,struct audit_context *context) +{ +struct audit_buffer *ab; + +if (!audit_containerid_set (tsk)) +return 0 ; +/* Generate AUDIT_CONTAINER_INFO with container ID */ + ab =audit_log_start (context,GFP_KERNEL ,AUDIT_CONTAINER_INFO ); +if (!ab) +return -ENOMEM ; +audit_log_format (ab,"contid=%llu" ,audit_get_containerid (tsk)); +audit_log_end (ab); +return 0 ; +} +void audit_log_key (struct audit_buffer *ab,char *key) {audit_log_format (ab," key=" );kernel/auditsc.c +0
-0
kernel/auditsc.c static void audit_log_exit(struct audit_context · line 1456
Quoted 4 lines
kernel/auditsc.c +1
-0@@ -1453,6 +1453,8 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *tsaudit_log_proctitle (tsk, context); +audit_log_container_info (tsk, context);
Would there be any problem moving audit_log_container_info before audit_log_proctitle? There are some assumptions that proctitle is the last record in some situations.
Thanks,
-Steve
Quoted 3 lines
kernel/auditsc.c +0
-0/* Send end of event record to help user space know we are finished */ ab =audit_log_start (context,GFP_KERNEL ,AUDIT_EOE );if (ab)
Re: [RFC PATCH ghak32 V2 03/13] audit: log container info of syscalls
In reply to a message not in the archiveQuoted 2 lines · On Fri, 16 Mar 2018 05:00:30 -0400 Richard Guy Briggs…
Create a new audit record
AUDIT_CONTAINER_INFOto document the container ID of a process if it is present.
As mentioned in a previous email, I think AUDIT_CONTAINER is more suitable for the container record. One more comment below...
Quoted 104 lines
Called from
audit_log_exit(), syscalls are covered.A sample raw event:
type=SYSCALL msg=audit(1519924845.499:257): arch=c000003e syscall=257
success=yes exit=3 a0=ffffff9c a1=56374e1cef30 a2=241 a3=1b6 items=2
ppid=606 pid=635 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0
sgid=0 fsgid=0 tty=pts0 ses=3 comm="bash" exe="/usr/bin/bash" subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
key="tmpcontainerid" type=CWD msg=audit(1519924845.499:257):
cwd="/root" type=PATH msg=audit(1519924845.499:257): item=0
name="/tmp/" inode=13863 dev=00:27 mode=041777 ouid=0 ogid=0
rdev=00:00 obj=system_u:object_r:tmp_t:s0 nametype= PARENT
cap_fp=0000000000000000 cap_fi=0000000000000000 cap_fe=0 cap_fver=0
type=PATH msg=audit(1519924845.499:257): item=1
name="/tmp/tmpcontainerid" inode=17729 dev=00:27 mode=0100644 ouid=0
ogid=0 rdev=00:00 obj=unconfined_u:object_r:user_tmp_t:s0
nametype=CREATE cap_fp=0000000000000000 cap_fi=0000000000000000
cap_fe=0 cap_fver=0 type=PROCTITLE msg=audit(1519924845.499:257):
proctitle=62617368002D6300736C65657020313B206563686F2074657374203E202F746D702F746D70636F6E7461696E65726964 type=CONTAINER_INFO msg=audit(1519924845.499:257): op=task
contid=123458See: https://github.com/linux-audit/audit-kernel/issues/32
Signed-off-by Richard Guy Briggs <[email protected]>--- include/linux/audit.h | 5 +++++ include/uapi/linux/audit.h | 1 + kernel/audit.c | 20 ++++++++++++++++++++ kernel/auditsc.c | 2 ++ 4 files changed, 28 insertions(+)include/linux/audit.h +0
-0@@ -154,6 +154,8 @@ extern voidaudit_log_link_denied(const char *operation, extern int
audit_log_task_context(struct audit_buffer *ab); extern voidaudit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk);include/linux/audit.h +2
-0+extern int audit_log_container_info (struct task_struct *tsk, +struct audit_context *context);extern int audit_update_lsm_rules (void );@@ -205,6 +207,9 @@ static inline int audit_log_task_context(struct
audit_buffer*ab) static inline voidaudit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk)
{ }include/linux/audit.h +2
-0+static inline int audit_log_container_info (struct task_struct *tsk, + struct audit_context*context); +{ }
#defineaudit_enabled0
#endif /*CONFIG_AUDIT*/include/uapi/linux/audit.h +0
-0@@ -115,6 +115,7 @@#define AUDIT_REPLACE 1329/* Replace auditd if this packet unanswerd */ #define
AUDIT_KERN_MODULE
1330 /* Kernel Module events */ #defineAUDIT_FANOTIFY1331 /* Fanotify access decision
*/ +#defineAUDIT_CONTAINER_INFO1332 /* Container ID
information */ #defineAUDIT_AVC1400 /* SE
Linux avc denial or grant */ #defineAUDIT_SELINUX_ERR
1401 /* Internal SE Linux Errors */ diff --gita/kernel/audit.cb/kernel/audit.cindex 3f2f143..a12f21f 100644kernel/audit.c +19
-0@@ -2049,6 +2049,26 @@ void audit_log_session_info(struct audit_buffer *ab) audit_log_format(ab, " auid=%u ses=%u", auid, sessionid); } +/* +* audit_log_container_info - report container info +* @tsk: task to be recorded +* @context: task or local context for record +*/ +int audit_log_container_info (struct task_struct *tsk,struct audit_context *context) +{ +struct audit_buffer *ab; + +if (!audit_containerid_set (tsk)) +return 0 ; +/* Generate AUDIT_CONTAINER_INFO with container ID */ + ab =audit_log_start (context,GFP_KERNEL ,AUDIT_CONTAINER_INFO ); +if (!ab) +return -ENOMEM ; +audit_log_format (ab,"contid=%llu" ,audit_get_containerid (tsk)); +audit_log_end (ab); +return 0 ; +} +void audit_log_key (struct audit_buffer *ab,char *key) {audit_log_format (ab," key=" );kernel/auditsc.c +0
-0
kernel/auditsc.c static void audit_log_exit(struct audit_context · line 1456
Quoted 4 lines
kernel/auditsc.c +1
-0@@ -1453,6 +1453,8 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *tsaudit_log_proctitle (tsk, context); +audit_log_container_info (tsk, context);
Would there be any problem moving audit_log_container_info before audit_log_proctitle? There are some assumptions that proctitle is the last record in some situations.
Thanks,
-Steve
Quoted 3 lines
kernel/auditsc.c +0
-0/* Send end of event record to help user space know we are finished */ ab =audit_log_start (context,GFP_KERNEL ,AUDIT_EOE );if (ab)
Re: [RFC PATCH ghak32 V2 03/13] audit: log container info of syscalls
In reply to Steve GrubbQuoted 116 lines · Steve Grubb
Quoted 2 lines · On Fri, 16 Mar 2018 05:00:30 -0400 Richard Guy Briggs <[email protected]> wrote:
Create a new audit record
AUDIT_CONTAINER_INFOto document the container ID of a process if it is present.As mentioned in a previous email, I think
AUDIT_CONTAINERis more suitable for the container record. One more comment below...Quoted 107 lines
Called from
audit_log_exit(), syscalls are covered.A sample raw event:
type=SYSCALL msg=audit(1519924845.499:257): arch=c000003e syscall=257
success=yes exit=3 a0=ffffff9c a1=56374e1cef30 a2=241 a3=1b6 items=2
ppid=606 pid=635 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0
sgid=0 fsgid=0 tty=pts0 ses=3 comm="bash" exe="/usr/bin/bash" subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
key="tmpcontainerid" type=CWD msg=audit(1519924845.499:257):
cwd="/root" type=PATH msg=audit(1519924845.499:257): item=0
name="/tmp/" inode=13863 dev=00:27 mode=041777 ouid=0 ogid=0
rdev=00:00 obj=system_u:object_r:tmp_t:s0 nametype= PARENT
cap_fp=0000000000000000 cap_fi=0000000000000000 cap_fe=0 cap_fver=0
type=PATH msg=audit(1519924845.499:257): item=1
name="/tmp/tmpcontainerid" inode=17729 dev=00:27 mode=0100644 ouid=0
ogid=0 rdev=00:00 obj=unconfined_u:object_r:user_tmp_t:s0
nametype=CREATE cap_fp=0000000000000000 cap_fi=0000000000000000
cap_fe=0 cap_fver=0 type=PROCTITLE msg=audit(1519924845.499:257):
proctitle=62617368002D6300736C65657020313B206563686F2074657374203E202F746D702F746D70636F6E7461696E65726964 type=CONTAINER_INFO msg=audit(1519924845.499:257): op=task
contid=123458See: https://github.com/linux-audit/audit-kernel/issues/32
Signed-off-by Richard Guy Briggs <[email protected]>--- include/linux/audit.h | 5 +++++ include/uapi/linux/audit.h | 1 + kernel/audit.c | 20 ++++++++++++++++++++ kernel/auditsc.c | 2 ++ 4 files changed, 28 insertions(+)include/linux/audit.h +0
-0@@ -154,6 +154,8 @@ extern voidaudit_log_link_denied(const char *operation, extern int
audit_log_task_context(struct audit_buffer *ab); extern voidaudit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk);include/linux/audit.h +2
-0+extern int audit_log_container_info (struct task_struct *tsk, +struct audit_context *context);extern int audit_update_lsm_rules (void );@@ -205,6 +207,9 @@ static inline int audit_log_task_context(struct
audit_buffer*ab) static inline voidaudit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk)
{ }include/linux/audit.h +2
-0+static inline int audit_log_container_info (struct task_struct *tsk, + struct audit_context*context); +{ }
#defineaudit_enabled0
#endif /*CONFIG_AUDIT*/include/uapi/linux/audit.h +0
-0@@ -115,6 +115,7 @@#define AUDIT_REPLACE 1329/* Replace auditd if this packet unanswerd */ #define
AUDIT_KERN_MODULE
1330 /* Kernel Module events */ #defineAUDIT_FANOTIFY1331 /* Fanotify access decision
*/ +#defineAUDIT_CONTAINER_INFO1332 /* Container ID
information */ #defineAUDIT_AVC1400 /* SE
Linux avc denial or grant */ #defineAUDIT_SELINUX_ERR
1401 /* Internal SE Linux Errors */ diff --gita/kernel/audit.cb/kernel/audit.cindex 3f2f143..a12f21f 100644kernel/audit.c +19
-0@@ -2049,6 +2049,26 @@ void audit_log_session_info(struct audit_buffer *ab) audit_log_format(ab, " auid=%u ses=%u", auid, sessionid); } +/* +* audit_log_container_info - report container info +* @tsk: task to be recorded +* @context: task or local context for record +*/ +int audit_log_container_info (struct task_struct *tsk,struct audit_context *context) +{ +struct audit_buffer *ab; + +if (!audit_containerid_set (tsk)) +return 0 ; +/* Generate AUDIT_CONTAINER_INFO with container ID */ + ab =audit_log_start (context,GFP_KERNEL ,AUDIT_CONTAINER_INFO ); +if (!ab) +return -ENOMEM ; +audit_log_format (ab,"contid=%llu" ,audit_get_containerid (tsk)); +audit_log_end (ab); +return 0 ; +} +void audit_log_key (struct audit_buffer *ab,char *key) {audit_log_format (ab," key=" );kernel/auditsc.c +0
-0@@ -1453,6 +1453,8 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *tsaudit_log_proctitle (tsk, context);
Quoted 5 lines
kernel/auditsc.c static void audit_log_exit(struct audit_context *context, struct task_struct *ts · line 1456
Quoted 1 line
kernel/auditsc.c +1
-0+audit_log_container_info (tsk, context);Would there be any problem moving
audit_log_container_infobeforeaudit_log_proctitle? There are some assumptions that proctitle is the last record in some situations.
I see no problem doing that.
Quoted 6 lines
Thanks,
-SteveQuoted 3 lines
kernel/auditsc.c +0
-0/* Send end of event record to help user space know we are finished */ ab =audit_log_start (context,GFP_KERNEL ,AUDIT_EOE );if (ab)
- RGB
--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
Re: [RFC PATCH ghak32 V2 03/13] audit: log container info of syscalls
In reply to Steve GrubbQuoted 116 lines · Steve Grubb
Quoted 2 lines · On Fri, 16 Mar 2018 05:00:30 -0400 Richard Guy Briggs…
Create a new audit record
AUDIT_CONTAINER_INFOto document the container ID of a process if it is present.As mentioned in a previous email, I think
AUDIT_CONTAINERis more suitable for the container record. One more comment below...Quoted 107 lines
Called from
audit_log_exit(), syscalls are covered.A sample raw event:
type=SYSCALL msg=audit(1519924845.499:257): arch=c000003e syscall=257
success=yes exit=3 a0=ffffff9c a1=56374e1cef30 a2=241 a3=1b6 items=2
ppid=606 pid=635 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0
sgid=0 fsgid=0 tty=pts0 ses=3 comm="bash" exe="/usr/bin/bash" subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
key="tmpcontainerid" type=CWD msg=audit(1519924845.499:257):
cwd="/root" type=PATH msg=audit(1519924845.499:257): item=0
name="/tmp/" inode=13863 dev=00:27 mode=041777 ouid=0 ogid=0
rdev=00:00 obj=system_u:object_r:tmp_t:s0 nametype= PARENT
cap_fp=0000000000000000 cap_fi=0000000000000000 cap_fe=0 cap_fver=0
type=PATH msg=audit(1519924845.499:257): item=1
name="/tmp/tmpcontainerid" inode=17729 dev=00:27 mode=0100644 ouid=0
ogid=0 rdev=00:00 obj=unconfined_u:object_r:user_tmp_t:s0
nametype=CREATE cap_fp=0000000000000000 cap_fi=0000000000000000
cap_fe=0 cap_fver=0 type=PROCTITLE msg=audit(1519924845.499:257):
proctitle=62617368002D6300736C65657020313B206563686F2074657374203E202F746D702F746D70636F6E7461696E65726964 type=CONTAINER_INFO msg=audit(1519924845.499:257): op=task
contid=123458See: https://github.com/linux-audit/audit-kernel/issues/32
Signed-off-by Richard Guy Briggs <[email protected]>--- include/linux/audit.h | 5 +++++ include/uapi/linux/audit.h | 1 + kernel/audit.c | 20 ++++++++++++++++++++ kernel/auditsc.c | 2 ++ 4 files changed, 28 insertions(+)include/linux/audit.h +0
-0@@ -154,6 +154,8 @@ extern voidaudit_log_link_denied(const char *operation, extern int
audit_log_task_context(struct audit_buffer *ab); extern voidaudit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk);include/linux/audit.h +2
-0+extern int audit_log_container_info (struct task_struct *tsk, +struct audit_context *context);extern int audit_update_lsm_rules (void );@@ -205,6 +207,9 @@ static inline int audit_log_task_context(struct
audit_buffer*ab) static inline voidaudit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk)
{ }include/linux/audit.h +2
-0+static inline int audit_log_container_info (struct task_struct *tsk, + struct audit_context*context); +{ }
#defineaudit_enabled0
#endif /*CONFIG_AUDIT*/include/uapi/linux/audit.h +0
-0@@ -115,6 +115,7 @@#define AUDIT_REPLACE 1329/* Replace auditd if this packet unanswerd */ #define
AUDIT_KERN_MODULE
1330 /* Kernel Module events */ #defineAUDIT_FANOTIFY1331 /* Fanotify access decision
*/ +#defineAUDIT_CONTAINER_INFO1332 /* Container ID
information */ #defineAUDIT_AVC1400 /* SE
Linux avc denial or grant */ #defineAUDIT_SELINUX_ERR
1401 /* Internal SE Linux Errors */ diff --gita/kernel/audit.cb/kernel/audit.cindex 3f2f143..a12f21f 100644kernel/audit.c +19
-0@@ -2049,6 +2049,26 @@ void audit_log_session_info(struct audit_buffer *ab) audit_log_format(ab, " auid=%u ses=%u", auid, sessionid); } +/* +* audit_log_container_info - report container info +* @tsk: task to be recorded +* @context: task or local context for record +*/ +int audit_log_container_info (struct task_struct *tsk,struct audit_context *context) +{ +struct audit_buffer *ab; + +if (!audit_containerid_set (tsk)) +return 0 ; +/* Generate AUDIT_CONTAINER_INFO with container ID */ + ab =audit_log_start (context,GFP_KERNEL ,AUDIT_CONTAINER_INFO ); +if (!ab) +return -ENOMEM ; +audit_log_format (ab,"contid=%llu" ,audit_get_containerid (tsk)); +audit_log_end (ab); +return 0 ; +} +void audit_log_key (struct audit_buffer *ab,char *key) {audit_log_format (ab," key=" );kernel/auditsc.c +0
-0@@ -1453,6 +1453,8 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *tsaudit_log_proctitle (tsk, context);
Quoted 5 lines
kernel/auditsc.c static void audit_log_exit(struct audit_context *context, struct task_struct *ts · line 1456
Quoted 1 line
kernel/auditsc.c +1
-0+audit_log_container_info (tsk, context);Would there be any problem moving
audit_log_container_infobeforeaudit_log_proctitle? There are some assumptions that proctitle is the last record in some situations.
I see no problem doing that.
Quoted 6 lines
Thanks,
-SteveQuoted 3 lines
kernel/auditsc.c +0
-0/* Send end of event record to help user space know we are finished */ ab =audit_log_start (context,GFP_KERNEL ,AUDIT_EOE );if (ab)
- RGB
--
Richard Guy Briggs <[email protected]> Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
Re: [RFC PATCH ghak32 V2 01/13] audit: add container id
In reply to Steve GrubbQuoted 19 lines · Steve Grubb
Quoted 8 lines · On Fri, 16 Mar 2018 05:00:28 -0400 Richard Guy Briggs <[email protected]> wrote:
Implement the proc fs write to set the audit container ID of a process, emitting an
AUDIT_CONTAINERrecord to document the event.This is a write from the container orchestrator task to a proc entry of the form
/proc/PID/containeridwhere PID is the process ID of the newly created task that is to become the first task in a container, or an additional task added to a container.Quoted 7 lines
The write expects up to a u64 value (unset: 18446744073709551615).
This will produce a record such as this:
type=CONTAINER msg=audit(1519903238.968:261): op=set pid=596 uid=0 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 auid=0 tty=pts0 ses=1 opid=596 old-contid=18446744073709551615 contid=123455 res=0
Quoted 4 lines
The was one thing I was wondering about. Currently when we set the loginuid, the record is
AUDIT_LOGINUID. The corollary is that when we set the container id, the event should beAUDIT_CONTAINERIDorAUDIT_CONTAINER_ID.
The record type is actually AUDIT_LOGIN. The field type is AUDIT_LOGINUID. Given that correction, I think we're fine and could potentially violently agree. The existing naming is consistent.
Quoted 4 lines
During syscall events, the path info is returned in a a record simply called
AUDIT_PATH, cwd info is returned inAUDIT_CWD. So, rather than calling the record that gets attached to everythingAUDIT_CONTAINER_INFO, how about simplyAUDIT_CONTAINER.
Considering the container initiation record is different than the record to document the container involved in an otherwise normal syscall, we need two names. I don't have a strong opinion what they are.
I'd prefer AUDIT_CONTAINER and AUDIT_CONTAINER_INFO so that the two are different enough to be visually distinct while leaving AUDIT_CONTAINERID for the field type in patch 4 ("audit: add containerid filtering")
Quoted 253 lines
Quoted 253 lines
The "op" field indicates an initial set. The "pid" to "ses" fields are the orchestrator while the "opid" field is the object's PID, the process being "contained". Old and new container ID values are given in the "contid" fields, while res indicates its success.
It is not permitted to self-set, unset or re-set the container ID. A child inherits its parent's container ID, but then can be set only once after.
See: https://github.com/linux-audit/audit-kernel/issues/32
Signed-off-by Richard Guy Briggs <[email protected]>--- fs/proc/base.c | 37 ++++++++++++++++++++ include/linux/audit.h | 16 +++++++++ include/linux/init_task.h | 4 ++- include/linux/sched.h | 1 + include/uapi/linux/audit.h | 2 ++ kernel/auditsc.c | 84++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 143 insertions(+), 1 deletion(-)
fs/proc/base.c +35
-0@@ -1299,6 +1299,41 @@ static ssize_t proc_sessionid_read(struct file * file, char __user * buf, .read = proc_sessionid_read, .llseek = generic_file_llseek, }; + +static ssize_t proc_containerid_write (struct file *file,const char __user *buf, +size_t count,loff_t *ppos) +{ +struct inode *inode =file_inode (file); +u64 containerid; +int rv; +struct task_struct *task =get_proc_task (inode); + +if (!task) +return -ESRCH ; +if (*ppos !=0 ) { +/* No partial writes. */ +put_task_struct (task); +return -EINVAL ; + } + + rv =kstrtou64_from_user (buf, count,10 , &containerid); +if (rv <0 ) { +put_task_struct (task); +return rv; + } + + rv =audit_set_containerid (task, containerid); +put_task_struct (task); +if (rv <0 ) +return rv; +return count; +} + +static const struct file_operations proc_containerid_operations = { + .write = proc_containerid_write, + .llseek = generic_file_llseek, +}; +#endif #ifdef
CONFIG_FAULT_INJECTIONfs/proc/base.c +1
-0@@ -2961,6 +2996,7 @@ static int proc_pid_patch_state(struct seq_file *m, struct pid_namespace *ns, #ifdef CONFIG_AUDITSYSCALLREG ("loginuid" ,S_IWUSR |S_IRUGO , proc_loginuid_operations),REG ("sessionid" ,S_IRUGO , proc_sessionid_operations), +REG ("containerid" ,S_IWUSR , proc_containerid_operations), #endif #ifdef CONFIG_FAULT_INJECTION REG("make-it-fail", S_IRUGO|S_IWUSR,
proc_fault_inject_operations), @@ -3355,6 +3391,7 @@ static intproc_tid_comm_permission(struct inode *inode, int mask)#ifdefCONFIG_AUDITSYSCALLREG("loginuid", S_IWUSR|S_IRUGO, proc_loginuid_operations),REG("sessionid", S_IRUGO, proc_sessionid_operations),fs/proc/base.c +1
-0+ REG("containerid", S_IWUSR, proc_containerid_operations),#endif #ifdef CONFIG_FAULT_INJECTION REG("make-it-fail", S_IRUGO|S_IWUSR,
proc_fault_inject_operations), diff --gita/include/linux/audit.hb/include/linux/audit.hindex af410d9..fe4ba3f 100644include/linux/audit.h +1
-0@@ -29,6 +29,7 @@#define AUDIT_INO_UNSET ((unsigned long)-1)#define AUDIT_DEV_UNSET ((dev_t)-1) +#define INVALID_CID AUDIT_CID_UNSETstruct audit_sig_info {uid_t uid;@@ -321,6 +322,7 @@ static inline void audit_ptrace(struct
task_struct*t) extern intauditsc_get_stamp(struct audit_context *ctx, struct timespec64 *t, unsigned int *serial);
extern intaudit_set_loginuid(kuid_t loginuid);
+extern intaudit_set_containerid(struct task_struct *tsk, u64 containerid);
static inlinekuid_taudit_get_loginuid(struct task_struct *tsk){include/linux/audit.h +5
-0@@ -332,6 +334,11 @@ static inline unsigned int audit_get_sessionid(struct task_struct *tsk) return tsk->sessionid; } +static inline u64 audit_get_containerid (struct task_struct *tsk) +{ +return tsk->containerid; +} +extern void __audit_ipc_obj (struct kern_ipc_perm *ipcp); extern void __audit_ipc_set_perm(unsigned long qbytes, uid_t uid,
gid_tgid,umode_tmode); extern void__audit_bprm(struct linux_binprm *bprm); @@ -517,6 +524,10 @@ static inline unsigned intaudit_get_sessionid(struct task_struct *tsk){include/linux/audit.h +4
-0return -1 ; } +static inline kuid_t audit_get_containerid (struct task_struct *tsk) +{ +return INVALID_CID ; +}static inline void audit_ipc_obj (struct kern_ipc_perm *ipcp) { } static inline void audit_ipc_set_perm(unsigned long qbytes, uid_tuid, @@ -581,6 +592,11 @@ static inline bool
audit_loginuid_set(struct task_struct *tsk)return uid_valid(audit_get_loginuid(tsk)); }include/linux/audit.h +5
-0+static inline bool audit_containerid_set (struct task_struct *tsk) +{ +return audit_get_containerid (tsk) !=INVALID_CID ; +} + static inline void audit_log_string(struct audit_buffer *ab, constchar *buf) {
include/linux/audit.h +0
-0audit_log_n_string (ab, buf,strlen (buf));include/linux/init_task.h +3
-1@@ -18,6 +18,7 @@#include <linux/sched/rt.h> #include <linux/livepatch.h> #include <linux/mm_types.h> +#include <linux/audit.h> #include <asm/thread_info.h> @@ -120,7 +121,8 @@#ifdef CONFIG_AUDITSYSCALL #define INIT_IDS \ .loginuid = INVALID_UID, \ - .sessionid = (unsigned int)-1, + .sessionid = (unsigned int)-1, \ + .containerid = INVALID_CID,#else #define INIT_IDS #endif include/linux/sched.h +1
-0@@ -796,6 +796,7 @@ struct task_struct {#ifdef CONFIG_AUDITSYSCALL kuid_t loginuid;unsigned int sessionid; +u64 containerid;#endif struct seccomp seccomp;include/uapi/linux/audit.h +0
-0@@ -71,6 +71,7 @@#define AUDIT_TTY_SET 1017/* Set TTY auditing status */ #define
AUDIT_SET_FEATURE1018 /* Turn an
audit feature on or off */ #defineAUDIT_GET_FEATURE
1019 /* Get which features are enabled */ +#defineAUDIT_CONTAINER1020 /* Define the container id
and information */ #defineAUDIT_FIRST_USER_MSG1100 /*
Userspace messages mostly uninteresting to kernel */ #defineAUDIT_USER_AVC1107 /* We filter this
differently */ @@ -465,6 +466,7 @@ structaudit_tty_status{ };#define
AUDIT_UID_UNSET(unsigned int)-1include/uapi/linux/audit.h +1
-0+#define AUDIT_CID_UNSET ((u64)-1)/* audit_rule_data supports filter rules with both integer and string * fields. It corresponds with AUDIT_ADD_RULE, AUDIT_DEL_RULE and kernel/auditsc.c +17
-0@@ -2073,6 +2073,90 @@ int audit_set_loginuid(kuid_t loginuid)return rc; } +static int audit_set_containerid_perm (struct task_struct *task,u64 containerid) +{ +struct task_struct *parent; +u64 pcontainerid, ccontainerid; + +/* Don't allow to set our own containerid */ +if (current == task) +return -EPERM ; +/* Don't allow the containerid to be unset */ +if (!cid_valid (containerid)) +return -EINVAL ; +/* if we don't have caps, reject */ +if (!capable (CAP_AUDIT_CONTROL )) +return -EPERM ; +/* if containerid is unset, allow */ +if (!audit_containerid_set (task)) +return 0 ; +/* it is already set, and not inherited from the parent, reject */
kernel/auditsc.c +13
-0+ ccontainerid =audit_get_containerid (task); +rcu_read_lock (); + parent =rcu_dereference (task->real_parent); +rcu_read_unlock (); +task_lock (parent); + pcontainerid =audit_get_containerid (parent); +task_unlock (parent); +if (ccontainerid != pcontainerid) +return -EPERM ; +return 0 ; +} + +static void audit_log_set_containerid(struct task_struct *task, u64oldcontainerid,
kernel/auditsc.c +17
-0+ u64 containerid, int rc) +{ +struct audit_buffer *ab; +uid_t uid; +struct tty_struct *tty; + +if (!audit_enabled) +return ; + + ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_CONTAINER ); +if (!ab) +return ; + + uid =from_kuid (&init_user_ns,task_uid (current)); + tty =audit_get_tty (current); + + audit_log_format(ab, "op=set pid=%d uid=%u",
Quoted 8 lines
Quoted 4 lines
task_tgid_nr(current), uid);kernel/auditsc.c +2
-0+audit_log_task_context (ab); + audit_log_format(ab, " auid=%u tty=%s ses=%u opid=%dold-contid=%llu contid=%llu res=%d",
The preferred ordering would be: op, opid, old-contid, contid, pid, uid, tty, ses, subj, comm, exe, res. This groups the searchable fields together using the most common ordering so that parsing is simple.
There has been a suggestion to make this a syscall-connected record, and if that is the case, we'd simply drop all the fields that would be duplicated by the syscall record. Otherwise, I'll use your suggested order.
As you may recall this suggestion was also made for the AUDIT_LOGIN record.
Quoted 36 lines
Thanks,
-SteveQuoted 33 lines
kernel/auditsc.c +1
-0+ from_kuid(&init_user_ns,
audit_get_loginuid(current)),kernel/auditsc.c +1
-0+ tty ? tty_name(tty) : "(none)",
audit_get_sessionid(current),kernel/auditsc.c +1
-0+ task_tgid_nr(task), oldcontainerid,containerid, !rc); +
kernel/auditsc.c +6
-0+audit_put_tty (tty); +audit_log_end (ab); +} + +/** +* audit_set_containerid - set current task's audit_context containerid
+ * @containerid: containerid value
+ *
+ * Returns 0 on success,-EPERMon permission failure.
+ *
+ * Called (set) from fs/proc/base.c::proc_containerid_write().
+ */kernel/auditsc.c +14
-0+int audit_set_containerid (struct task_struct *task,u64 containerid) +{ +u64 oldcontainerid; +int rc; + + oldcontainerid =audit_get_containerid (task); + + rc =audit_set_containerid_perm (task, containerid); +if (!rc) { +task_lock (task); + task->containerid = containerid; +task_unlock (task); + } +
Quoted 9 lines
kernel/auditsc.c int audit_set_loginuid(kuid_t loginuid) · line 2162
Quoted 8 lines
kernel/auditsc.c +1
-0+ audit_log_set_containerid(task, oldcontainerid, containerid,rc);
kernel/auditsc.c +3
-0+return rc; +} +/** * __audit_mq_open - record audit data for a POSIX MQ open * @oflag: open flag
- RGB
--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
Re: [RFC PATCH ghak32 V2 01/13] audit: add container id
In reply to Steve GrubbQuoted 19 lines · Steve Grubb
Quoted 8 lines · On Fri, 16 Mar 2018 05:00:28 -0400 Richard Guy Briggs…
Implement the proc fs write to set the audit container ID of a process, emitting an
AUDIT_CONTAINERrecord to document the event.This is a write from the container orchestrator task to a proc entry of the form
/proc/PID/containeridwhere PID is the process ID of the newly created task that is to become the first task in a container, or an additional task added to a container.Quoted 7 lines
The write expects up to a u64 value (unset: 18446744073709551615).
This will produce a record such as this:
type=CONTAINER msg=audit(1519903238.968:261): op=set pid=596 uid=0 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 auid=0 tty=pts0 ses=1 opid=596 old-contid=18446744073709551615 contid=123455 res=0
Quoted 4 lines
The was one thing I was wondering about. Currently when we set the loginuid, the record is
AUDIT_LOGINUID. The corollary is that when we set the container id, the event should beAUDIT_CONTAINERIDorAUDIT_CONTAINER_ID.
The record type is actually AUDIT_LOGIN. The field type is AUDIT_LOGINUID. Given that correction, I think we're fine and could potentially violently agree. The existing naming is consistent.
Quoted 4 lines
During syscall events, the path info is returned in a a record simply called
AUDIT_PATH, cwd info is returned inAUDIT_CWD. So, rather than calling the record that gets attached to everythingAUDIT_CONTAINER_INFO, how about simplyAUDIT_CONTAINER.
Considering the container initiation record is different than the record to document the container involved in an otherwise normal syscall, we need two names. I don't have a strong opinion what they are.
I'd prefer AUDIT_CONTAINER and AUDIT_CONTAINER_INFO so that the two are different enough to be visually distinct while leaving AUDIT_CONTAINERID for the field type in patch 4 ("audit: add containerid filtering")
Quoted 253 lines
Quoted 253 lines
The "op" field indicates an initial set. The "pid" to "ses" fields are the orchestrator while the "opid" field is the object's PID, the process being "contained". Old and new container ID values are given in the "contid" fields, while res indicates its success.
It is not permitted to self-set, unset or re-set the container ID. A child inherits its parent's container ID, but then can be set only once after.
See: https://github.com/linux-audit/audit-kernel/issues/32
Signed-off-by Richard Guy Briggs <[email protected]>--- fs/proc/base.c | 37 ++++++++++++++++++++ include/linux/audit.h | 16 +++++++++ include/linux/init_task.h | 4 ++- include/linux/sched.h | 1 + include/uapi/linux/audit.h | 2 ++ kernel/auditsc.c | 84++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 143 insertions(+), 1 deletion(-)
fs/proc/base.c +35
-0@@ -1299,6 +1299,41 @@ static ssize_t proc_sessionid_read(struct file * file, char __user * buf, .read = proc_sessionid_read, .llseek = generic_file_llseek, }; + +static ssize_t proc_containerid_write (struct file *file,const char __user *buf, +size_t count,loff_t *ppos) +{ +struct inode *inode =file_inode (file); +u64 containerid; +int rv; +struct task_struct *task =get_proc_task (inode); + +if (!task) +return -ESRCH ; +if (*ppos !=0 ) { +/* No partial writes. */ +put_task_struct (task); +return -EINVAL ; + } + + rv =kstrtou64_from_user (buf, count,10 , &containerid); +if (rv <0 ) { +put_task_struct (task); +return rv; + } + + rv =audit_set_containerid (task, containerid); +put_task_struct (task); +if (rv <0 ) +return rv; +return count; +} + +static const struct file_operations proc_containerid_operations = { + .write = proc_containerid_write, + .llseek = generic_file_llseek, +}; +#endif #ifdef
CONFIG_FAULT_INJECTIONfs/proc/base.c +1
-0@@ -2961,6 +2996,7 @@ static int proc_pid_patch_state(struct seq_file *m, struct pid_namespace *ns, #ifdef CONFIG_AUDITSYSCALLREG ("loginuid" ,S_IWUSR |S_IRUGO , proc_loginuid_operations),REG ("sessionid" ,S_IRUGO , proc_sessionid_operations), +REG ("containerid" ,S_IWUSR , proc_containerid_operations), #endif #ifdef CONFIG_FAULT_INJECTION REG("make-it-fail", S_IRUGO|S_IWUSR,
proc_fault_inject_operations), @@ -3355,6 +3391,7 @@ static intproc_tid_comm_permission(struct inode *inode, int mask)#ifdefCONFIG_AUDITSYSCALLREG("loginuid", S_IWUSR|S_IRUGO, proc_loginuid_operations),REG("sessionid", S_IRUGO, proc_sessionid_operations),fs/proc/base.c +1
-0+ REG("containerid", S_IWUSR, proc_containerid_operations),#endif #ifdef CONFIG_FAULT_INJECTION REG("make-it-fail", S_IRUGO|S_IWUSR,
proc_fault_inject_operations), diff --gita/include/linux/audit.hb/include/linux/audit.hindex af410d9..fe4ba3f 100644include/linux/audit.h +1
-0@@ -29,6 +29,7 @@#define AUDIT_INO_UNSET ((unsigned long)-1)#define AUDIT_DEV_UNSET ((dev_t)-1) +#define INVALID_CID AUDIT_CID_UNSETstruct audit_sig_info {uid_t uid;@@ -321,6 +322,7 @@ static inline void audit_ptrace(struct
task_struct*t) extern intauditsc_get_stamp(struct audit_context *ctx, struct timespec64 *t, unsigned int *serial);
extern intaudit_set_loginuid(kuid_t loginuid);
+extern intaudit_set_containerid(struct task_struct *tsk, u64 containerid);
static inlinekuid_taudit_get_loginuid(struct task_struct *tsk){include/linux/audit.h +5
-0@@ -332,6 +334,11 @@ static inline unsigned int audit_get_sessionid(struct task_struct *tsk) return tsk->sessionid; } +static inline u64 audit_get_containerid (struct task_struct *tsk) +{ +return tsk->containerid; +} +extern void __audit_ipc_obj (struct kern_ipc_perm *ipcp); extern void __audit_ipc_set_perm(unsigned long qbytes, uid_t uid,
gid_tgid,umode_tmode); extern void__audit_bprm(struct linux_binprm *bprm); @@ -517,6 +524,10 @@ static inline unsigned intaudit_get_sessionid(struct task_struct *tsk){include/linux/audit.h +4
-0return -1 ; } +static inline kuid_t audit_get_containerid (struct task_struct *tsk) +{ +return INVALID_CID ; +}static inline void audit_ipc_obj (struct kern_ipc_perm *ipcp) { } static inline void audit_ipc_set_perm(unsigned long qbytes, uid_tuid, @@ -581,6 +592,11 @@ static inline bool
audit_loginuid_set(struct task_struct *tsk)return uid_valid(audit_get_loginuid(tsk)); }include/linux/audit.h +5
-0+static inline bool audit_containerid_set (struct task_struct *tsk) +{ +return audit_get_containerid (tsk) !=INVALID_CID ; +} + static inline void audit_log_string(struct audit_buffer *ab, constchar *buf) {
include/linux/audit.h +0
-0audit_log_n_string (ab, buf,strlen (buf));include/linux/init_task.h +3
-1@@ -18,6 +18,7 @@#include <linux/sched/rt.h> #include <linux/livepatch.h> #include <linux/mm_types.h> +#include <linux/audit.h> #include <asm/thread_info.h> @@ -120,7 +121,8 @@#ifdef CONFIG_AUDITSYSCALL #define INIT_IDS \ .loginuid = INVALID_UID, \ - .sessionid = (unsigned int)-1, + .sessionid = (unsigned int)-1, \ + .containerid = INVALID_CID,#else #define INIT_IDS #endif include/linux/sched.h +1
-0@@ -796,6 +796,7 @@ struct task_struct {#ifdef CONFIG_AUDITSYSCALL kuid_t loginuid;unsigned int sessionid; +u64 containerid;#endif struct seccomp seccomp;include/uapi/linux/audit.h +0
-0@@ -71,6 +71,7 @@#define AUDIT_TTY_SET 1017/* Set TTY auditing status */ #define
AUDIT_SET_FEATURE1018 /* Turn an
audit feature on or off */ #defineAUDIT_GET_FEATURE
1019 /* Get which features are enabled */ +#defineAUDIT_CONTAINER1020 /* Define the container id
and information */ #defineAUDIT_FIRST_USER_MSG1100 /*
Userspace messages mostly uninteresting to kernel */ #defineAUDIT_USER_AVC1107 /* We filter this
differently */ @@ -465,6 +466,7 @@ structaudit_tty_status{ };#define
AUDIT_UID_UNSET(unsigned int)-1include/uapi/linux/audit.h +1
-0+#define AUDIT_CID_UNSET ((u64)-1)/* audit_rule_data supports filter rules with both integer and string * fields. It corresponds with AUDIT_ADD_RULE, AUDIT_DEL_RULE and kernel/auditsc.c +17
-0@@ -2073,6 +2073,90 @@ int audit_set_loginuid(kuid_t loginuid)return rc; } +static int audit_set_containerid_perm (struct task_struct *task,u64 containerid) +{ +struct task_struct *parent; +u64 pcontainerid, ccontainerid; + +/* Don't allow to set our own containerid */ +if (current == task) +return -EPERM ; +/* Don't allow the containerid to be unset */ +if (!cid_valid (containerid)) +return -EINVAL ; +/* if we don't have caps, reject */ +if (!capable (CAP_AUDIT_CONTROL )) +return -EPERM ; +/* if containerid is unset, allow */ +if (!audit_containerid_set (task)) +return 0 ; +/* it is already set, and not inherited from the parent, reject */
kernel/auditsc.c +13
-0+ ccontainerid =audit_get_containerid (task); +rcu_read_lock (); + parent =rcu_dereference (task->real_parent); +rcu_read_unlock (); +task_lock (parent); + pcontainerid =audit_get_containerid (parent); +task_unlock (parent); +if (ccontainerid != pcontainerid) +return -EPERM ; +return 0 ; +} + +static void audit_log_set_containerid(struct task_struct *task, u64oldcontainerid,
kernel/auditsc.c +17
-0+ u64 containerid, int rc) +{ +struct audit_buffer *ab; +uid_t uid; +struct tty_struct *tty; + +if (!audit_enabled) +return ; + + ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_CONTAINER ); +if (!ab) +return ; + + uid =from_kuid (&init_user_ns,task_uid (current)); + tty =audit_get_tty (current); + + audit_log_format(ab, "op=set pid=%d uid=%u",
Quoted 8 lines
Quoted 4 lines
task_tgid_nr(current), uid);kernel/auditsc.c +2
-0+audit_log_task_context (ab); + audit_log_format(ab, " auid=%u tty=%s ses=%u opid=%dold-contid=%llu contid=%llu res=%d",
The preferred ordering would be: op, opid, old-contid, contid, pid, uid, tty, ses, subj, comm, exe, res. This groups the searchable fields together using the most common ordering so that parsing is simple.
There has been a suggestion to make this a syscall-connected record, and if that is the case, we'd simply drop all the fields that would be duplicated by the syscall record. Otherwise, I'll use your suggested order.
As you may recall this suggestion was also made for the AUDIT_LOGIN record.
Quoted 36 lines
Thanks,
-SteveQuoted 33 lines
kernel/auditsc.c +1
-0+ from_kuid(&init_user_ns,
audit_get_loginuid(current)),kernel/auditsc.c +1
-0+ tty ? tty_name(tty) : "(none)",
audit_get_sessionid(current),kernel/auditsc.c +1
-0+ task_tgid_nr(task), oldcontainerid,containerid, !rc); +
kernel/auditsc.c +6
-0+audit_put_tty (tty); +audit_log_end (ab); +} + +/** +* audit_set_containerid - set current task's audit_context containerid
+ * @containerid: containerid value
+ *
+ * Returns 0 on success,-EPERMon permission failure.
+ *
+ * Called (set) from fs/proc/base.c::proc_containerid_write().
+ */kernel/auditsc.c +14
-0+int audit_set_containerid (struct task_struct *task,u64 containerid) +{ +u64 oldcontainerid; +int rc; + + oldcontainerid =audit_get_containerid (task); + + rc =audit_set_containerid_perm (task, containerid); +if (!rc) { +task_lock (task); + task->containerid = containerid; +task_unlock (task); + } +
Quoted 9 lines
kernel/auditsc.c int audit_set_loginuid(kuid_t loginuid) · line 2162
Quoted 8 lines
kernel/auditsc.c +1
-0+ audit_log_set_containerid(task, oldcontainerid, containerid,rc);
kernel/auditsc.c +3
-0+return rc; +} +/** * __audit_mq_open - record audit data for a POSIX MQ open * @oflag: open flag
- RGB
--
Richard Guy Briggs <[email protected]> Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
Re: [RFC PATCH ghak32 V2 01/13] audit: add container id
In reply to Richard Guy BriggsQuoted 10 lines · On Thu, 17 May 2018 17:56:00 -0400 Richard Guy Briggs…
Quoted 4 lines
During syscall events, the path info is returned in a a record simply called
AUDIT_PATH, cwd info is returned inAUDIT_CWD. So, rather than calling the record that gets attached to everythingAUDIT_CONTAINER_INFO, how about simplyAUDIT_CONTAINER.Considering the container initiation record is different than the record to document the container involved in an otherwise normal syscall, we need two names. I don't have a strong opinion what they are.
Quoted 4 lines
I'd prefer
AUDIT_CONTAINandAUDIT_CONTAINER_INFOso that the two are different enough to be visually distinct while leavingAUDIT_CONTAINERIDfor the field type in patch 4 ("audit: add containerid filtering")
How about AUDIT_CONTAINER for the auxiliary record? The one that starts the container, I don't have a strong opinion on. Could be AUDIT_CONTAINER_INIT, AUDIT_CONTAINER_START, AUDIT_CONTAINERID, AUDIT_CONTAINER_ID, or something else. The API call that sets the ID for filtering could be AUDIT_CID or AUDIT_CONTID if that helps decide what the initial event might be. Normally, it should match the field being filtered.
Best Regards,
-Steve
Re: [RFC PATCH ghak32 V2 01/13] audit: add container id
Quoted 13 lines · Steve Grubb
Quoted 10 lines · On Thu, 17 May 2018 17:56:00 -0400 Richard Guy Briggs <[email protected]> wrote:
Quoted 4 lines
During syscall events, the path info is returned in a a record simply called
AUDIT_PATH, cwd info is returned inAUDIT_CWD. So, rather than calling the record that gets attached to everythingAUDIT_CONTAINER_INFO, how about simplyAUDIT_CONTAINER.Considering the container initiation record is different than the record to document the container involved in an otherwise normal syscall, we need two names. I don't have a strong opinion what they are.
Quoted 4 lines
Quoted 4 lines
I'd prefer
AUDIT_CONTAINandAUDIT_CONTAINER_INFOso that the two are different enough to be visually distinct while leavingAUDIT_CONTAINERIDfor the field type in patch 4 ("audit: add containerid filtering")
(Sorry, I had intended AUDIT_CONTAINER for the first in that paragraph above.)
Quoted 7 lines
How about
AUDIT_CONTAINERfor the auxiliary record? The one that starts the container, I don't have a strong opinion on. Could beAUDIT_CONTAINER_INIT,AUDIT_CONTAINER_START,AUDIT_CONTAINERID,AUDIT_CONTAINER_ID, or something else. The API call that sets the ID for filtering could beAUDIT_CIDorAUDIT_CONTIDif that helps decide what the initial event might be. Normally, it should match the field being filtered.
Ok, I had shortened the record field name to "contid=" to be unique enough while not using too much netlink bandwidth. I could have used "cid=" but that could be unobvious or ambiguous. I didn't want to use the full "containerid=" due to that. I suppose I could change the field name macro to AUDIT_CONTID.
For the one that starts the container, I'd prefer to leave the name a bit more general than "_INIT", "_START", so maybe I'll swap them around and use AUDIT_CONTAINER_INFO for the startup record, and use AUDIT_CONTAINER for the syscall auxiliary record.
Does that work?
Quoted 1 line
-Steve
- RGB
--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
Re: [RFC PATCH ghak32 V2 01/13] audit: add container id
In reply to Steve GrubbQuoted 13 lines · Steve Grubb
Quoted 10 lines · On Thu, 17 May 2018 17:56:00 -0400 Richard Guy Briggs…
Quoted 4 lines
During syscall events, the path info is returned in a a record simply called
AUDIT_PATH, cwd info is returned inAUDIT_CWD. So, rather than calling the record that gets attached to everythingAUDIT_CONTAINER_INFO, how about simplyAUDIT_CONTAINER.Considering the container initiation record is different than the record to document the container involved in an otherwise normal syscall, we need two names. I don't have a strong opinion what they are.
Quoted 4 lines
Quoted 4 lines
I'd prefer
AUDIT_CONTAINandAUDIT_CONTAINER_INFOso that the two are different enough to be visually distinct while leavingAUDIT_CONTAINERIDfor the field type in patch 4 ("audit: add containerid filtering")
(Sorry, I had intended AUDIT_CONTAINER for the first in that paragraph above.)
Quoted 7 lines
How about
AUDIT_CONTAINERfor the auxiliary record? The one that starts the container, I don't have a strong opinion on. Could beAUDIT_CONTAINER_INIT,AUDIT_CONTAINER_START,AUDIT_CONTAINERID,AUDIT_CONTAINER_ID, or something else. The API call that sets the ID for filtering could beAUDIT_CIDorAUDIT_CONTIDif that helps decide what the initial event might be. Normally, it should match the field being filtered.
Ok, I had shortened the record field name to "contid=" to be unique enough while not using too much netlink bandwidth. I could have used "cid=" but that could be unobvious or ambiguous. I didn't want to use the full "containerid=" due to that. I suppose I could change the field name macro to AUDIT_CONTID.
For the one that starts the container, I'd prefer to leave the name a bit more general than "_INIT", "_START", so maybe I'll swap them around and use AUDIT_CONTAINER_INFO for the startup record, and use AUDIT_CONTAINER for the syscall auxiliary record.
Does that work?
Quoted 1 line
-Steve
- RGB
--
Richard Guy Briggs <[email protected]> Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
Re: [RFC PATCH ghak32 V2 01/13] audit: add container id
In reply to Richard Guy BriggsQuoted 36 lines · On Fri, 18 May 2018 11:21:06 -0400 Richard Guy Briggs <[email protected]> wrote:
Quoted 13 lines · Steve Grubb
Quoted 10 lines · On Thu, 17 May 2018 17:56:00 -0400 Richard Guy Briggs <[email protected]> wrote:
Quoted 4 lines
During syscall events, the path info is returned in a a record simply called
AUDIT_PATH, cwd info is returned inAUDIT_CWD. So, rather than calling the record that gets attached to everythingAUDIT_CONTAINER_INFO, how about simplyAUDIT_CONTAINER.Considering the container initiation record is different than the record to document the container involved in an otherwise normal syscall, we need two names. I don't have a strong opinion what they are.
Quoted 4 lines
Quoted 4 lines
I'd prefer
AUDIT_CONTAINandAUDIT_CONTAINER_INFOso that the two are different enough to be visually distinct while leavingAUDIT_CONTAINERIDfor the field type in patch 4 ("audit: add containerid filtering")(Sorry, I had intended
AUDIT_CONTAINERfor the first in that paragraph above.)Quoted 7 lines
How about
AUDIT_CONTAINERfor the auxiliary record? The one that starts the container, I don't have a strong opinion on. Could beAUDIT_CONTAINER_INIT,AUDIT_CONTAINER_START,AUDIT_CONTAINERID,AUDIT_CONTAINER_ID, or something else. The API call that sets the ID for filtering could beAUDIT_CIDorAUDIT_CONTIDif that helps decide what the initial event might be. Normally, it should match the field being filtered.Ok, I had shortened the record field name to "contid=" to be unique enough while not using too much netlink bandwidth. I could have used "cid=" but that could be unobvious or ambiguous. I didn't want to use the full "containerid=" due to that. I suppose I could change the field name macro to
AUDIT_CONTID.
Quoted 6 lines
For the one that starts the container, I'd prefer to leave the name a bit more general than "
_INIT", "_START", so maybe I'll swap them around and useAUDIT_CONTAINER_INFOfor the startup record, and useAUDIT_CONTAINERfor the syscall auxiliary record.Does that work?
I'll go along with that. Thanks. But making that swap frees up AUDIT_CONTAINER_ID which could be the first event. But AUDIT_CONTAINER_INFO is also fine with me.
Best Regards,
-Steve
Re: [RFC PATCH ghak32 V2 01/13] audit: add container id
In reply to a message not in the archiveQuoted 36 lines · On Fri, 18 May 2018 11:21:06 -0400 Richard Guy Briggs…
Quoted 13 lines · Steve Grubb
Quoted 10 lines · On Thu, 17 May 2018 17:56:00 -0400 Richard Guy Briggs…
Quoted 4 lines
During syscall events, the path info is returned in a a record simply called
AUDIT_PATH, cwd info is returned inAUDIT_CWD. So, rather than calling the record that gets attached to everythingAUDIT_CONTAINER_INFO, how about simplyAUDIT_CONTAINER.Considering the container initiation record is different than the record to document the container involved in an otherwise normal syscall, we need two names. I don't have a strong opinion what they are.
Quoted 4 lines
Quoted 4 lines
I'd prefer
AUDIT_CONTAINandAUDIT_CONTAINER_INFOso that the two are different enough to be visually distinct while leavingAUDIT_CONTAINERIDfor the field type in patch 4 ("audit: add containerid filtering")(Sorry, I had intended
AUDIT_CONTAINERfor the first in that paragraph above.)Quoted 7 lines
How about
AUDIT_CONTAINERfor the auxiliary record? The one that starts the container, I don't have a strong opinion on. Could beAUDIT_CONTAINER_INIT,AUDIT_CONTAINER_START,AUDIT_CONTAINERID,AUDIT_CONTAINER_ID, or something else. The API call that sets the ID for filtering could beAUDIT_CIDorAUDIT_CONTIDif that helps decide what the initial event might be. Normally, it should match the field being filtered.Ok, I had shortened the record field name to "contid=" to be unique enough while not using too much netlink bandwidth. I could have used "cid=" but that could be unobvious or ambiguous. I didn't want to use the full "containerid=" due to that. I suppose I could change the field name macro to
AUDIT_CONTID.
Quoted 6 lines
For the one that starts the container, I'd prefer to leave the name a bit more general than "
_INIT", "_START", so maybe I'll swap them around and useAUDIT_CONTAINER_INFOfor the startup record, and useAUDIT_CONTAINERfor the syscall auxiliary record.Does that work?
I'll go along with that. Thanks. But making that swap frees up AUDIT_CONTAINER_ID which could be the first event. But AUDIT_CONTAINER_INFO is also fine with me.
Best Regards,
-Steve
Re: [RFC PATCH ghak32 V2 13/13] debug audit: read container ID of a process
In reply to Richard Guy BriggsQuoted 1 line · EDT Richard Guy Briggs
Add support for reading the container ID from the proc filesystem.
I think this could be useful in general. Please consider this to be part of the full patch set and not something merely used to debug the patches.
-Steve
Quoted 62 lines
This is a read from the proc entry of the form
/proc/PID/containeridwhere PID is the process ID of the task whose container ID is sought.The read expects up to a u64 value (unset: 18446744073709551615).
Signed-off-by Richard Guy Briggs <[email protected]>--- fs/proc/base.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)fs/proc/base.c +15
-0@@ -1300,6 +1300,21 @@ static ssize_t proc_sessionid_read(struct file * file, char __user * buf, .llseek = generic_file_llseek, }; +static ssize_t proc_containerid_read (struct file *file,char __user *buf, +size_t count,loff_t *ppos) +{ +struct inode *inode =file_inode (file); +struct task_struct *task =get_proc_task (inode); +ssize_t length; +char tmpbuf[TMPBUFLEN *2 ]; + +if (!task) +return -ESRCH ; + length =scnprintf (tmpbuf,TMPBUFLEN *2 ,"%llu" ,audit_get_containerid (task)); +put_task_struct (task); +return simple_read_from_buffer (buf, count, ppos, tmpbuf, length); +} +static ssize_t proc_containerid_write (struct file *file,const char __user *buf,size_t count,loff_t *ppos) {@@ -1330,6 +1345,7 @@ static ssize_t proc_containerid_write(struct file *file, const char __user *buf, }static const struct file_operations proc_containerid_operations = { + .read = proc_containerid_read, .write = proc_containerid_write, .llseek = generic_file_llseek, };@@ -2996,7 +3012,7 @@ static int proc_pid_patch_state(struct seq_file *m,struct
pid_namespace*ns, #ifdefCONFIG_AUDITSYSCALLfs/proc/base.c +2
-2REG ("loginuid" ,S_IWUSR |S_IRUGO , proc_loginuid_operations),REG ("sessionid" ,S_IRUGO , proc_sessionid_operations), -REG ("containerid" ,S_IWUSR , proc_containerid_operations), +REG ("containerid" ,S_IWUSR |S_IRUSR , proc_containerid_operations), #endif #ifdef CONFIG_FAULT_INJECTION REG("make-it-fail", S_IRUGO|S_IWUSR, proc_fault_inject_operations),@@ -3391,7 +3407,7 @@ static int proc_tid_comm_permission(struct inode *inode, int mask) #ifdef CONFIG_AUDITSYSCALLREG ("loginuid" ,S_IWUSR |S_IRUGO , proc_loginuid_operations),REG ("sessionid" ,S_IRUGO , proc_sessionid_operations), -REG ("containerid" ,S_IWUSR , proc_containerid_operations), +REG ("containerid" ,S_IWUSR |S_IRUSR , proc_containerid_operations), #endif #ifdef CONFIG_FAULT_INJECTION REG("make-it-fail", S_IRUGO|S_IWUSR, proc_fault_inject_operations),
Re: [RFC PATCH ghak32 V2 13/13] debug audit: read container ID of a process
In reply to a message not in the archiveQuoted 1 line · EDT Richard Guy Briggs
Add support for reading the container ID from the proc filesystem.
I think this could be useful in general. Please consider this to be part of the full patch set and not something merely used to debug the patches.
-Steve
Quoted 62 lines
This is a read from the proc entry of the form
/proc/PID/containeridwhere PID is the process ID of the task whose container ID is sought.The read expects up to a u64 value (unset: 18446744073709551615).
Signed-off-by Richard Guy Briggs <[email protected]>--- fs/proc/base.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)fs/proc/base.c +15
-0@@ -1300,6 +1300,21 @@ static ssize_t proc_sessionid_read(struct file * file, char __user * buf, .llseek = generic_file_llseek, }; +static ssize_t proc_containerid_read (struct file *file,char __user *buf, +size_t count,loff_t *ppos) +{ +struct inode *inode =file_inode (file); +struct task_struct *task =get_proc_task (inode); +ssize_t length; +char tmpbuf[TMPBUFLEN *2 ]; + +if (!task) +return -ESRCH ; + length =scnprintf (tmpbuf,TMPBUFLEN *2 ,"%llu" ,audit_get_containerid (task)); +put_task_struct (task); +return simple_read_from_buffer (buf, count, ppos, tmpbuf, length); +} +static ssize_t proc_containerid_write (struct file *file,const char __user *buf,size_t count,loff_t *ppos) {@@ -1330,6 +1345,7 @@ static ssize_t proc_containerid_write(struct file *file, const char __user *buf, }static const struct file_operations proc_containerid_operations = { + .read = proc_containerid_read, .write = proc_containerid_write, .llseek = generic_file_llseek, };@@ -2996,7 +3012,7 @@ static int proc_pid_patch_state(struct seq_file *m,struct
pid_namespace*ns, #ifdefCONFIG_AUDITSYSCALLfs/proc/base.c +2
-2REG ("loginuid" ,S_IWUSR |S_IRUGO , proc_loginuid_operations),REG ("sessionid" ,S_IRUGO , proc_sessionid_operations), -REG ("containerid" ,S_IWUSR , proc_containerid_operations), +REG ("containerid" ,S_IWUSR |S_IRUSR , proc_containerid_operations), #endif #ifdef CONFIG_FAULT_INJECTION REG("make-it-fail", S_IRUGO|S_IWUSR, proc_fault_inject_operations),@@ -3391,7 +3407,7 @@ static int proc_tid_comm_permission(struct inode *inode, int mask) #ifdef CONFIG_AUDITSYSCALLREG ("loginuid" ,S_IWUSR |S_IRUGO , proc_loginuid_operations),REG ("sessionid" ,S_IRUGO , proc_sessionid_operations), -REG ("containerid" ,S_IWUSR , proc_containerid_operations), +REG ("containerid" ,S_IWUSR |S_IRUSR , proc_containerid_operations), #endif #ifdef CONFIG_FAULT_INJECTION REG("make-it-fail", S_IRUGO|S_IWUSR, proc_fault_inject_operations),
Re: [RFC PATCH ghak32 V2 03/13] audit: log container info of syscalls
In reply to Richard Guy BriggsQuoted 128 lines · EDT Richard Guy Briggs
Quoted 127 lines · Steve Grubb
On Fri, 16 Mar 2018 05:00:30 -0400
Quoted 2 lines · Richard Guy Briggs
Create a new audit record
AUDIT_CONTAINER_INFOto document the container ID of a process if it is present.As mentioned in a previous email, I think
AUDIT_CONTAINERis more suitable for the container record. One more comment below...Quoted 118 lines
Called from
audit_log_exit(), syscalls are covered.A sample raw event:
type=SYSCALL msg=audit(1519924845.499:257): arch=c000003e syscall=257 success=yes exit=3 a0=ffffff9c a1=56374e1cef30 a2=241 a3=1b6 items=2 ppid=606 pid=635 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=3 comm="bash" exe="/usr/bin/bash" subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key="tmpcontainerid" type=CWD msg=audit(1519924845.499:257):
cwd="/root" type=PATH msg=audit(1519924845.499:257): item=0 name="/tmp/" inode=13863 dev=00:27 mode=041777 ouid=0 ogid=0 rdev=00:00 obj=system_u:object_r:tmp_t:s0 nametype= PARENT cap_fp=0000000000000000 cap_fi=0000000000000000 cap_fe=0 cap_fver=0 type=PATH msg=audit(1519924845.499:257): item=1 name="/tmp/tmpcontainerid" inode=17729 dev=00:27 mode=0100644 ouid=0 ogid=0 rdev=00:00 obj=unconfined_u:object_r:user_tmp_t:s0 nametype=CREATE cap_fp=0000000000000000 cap_fi=0000000000000000 cap_fe=0 cap_fver=0 type=PROCTITLE msg=audit(1519924845.499:257):
proctitle=62617368002D6300736C65657020313B206563686F2074657374203E202F7 46D702F746D70636F6E7461696E65726964 type=CONTAINER_INFO msg=audit(1519924845.499:257): op=task
contid=123458See: https://github.com/linux-audit/audit-kernel/issues/32
Signed-off-by Richard Guy Briggs <[email protected]>---
include/linux/audit.h | 5 +++++ include/uapi/linux/audit.h | 1 + kernel/audit.c | 20 ++++++++++++++++++++ kernel/auditsc.c | 2 ++ 4 files changed, 28 insertions(+)include/linux/audit.h +0
-0@@ -154,6 +154,8 @@ extern voidaudit_log_link_denied(const char *operation, extern int
audit_log_task_context(struct audit_buffer *ab); extern voidaudit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk);include/linux/audit.h +2
-0+extern int audit_log_container_info (struct task_struct *tsk, +struct audit_context *context);extern int audit_update_lsm_rules (void );@@ -205,6 +207,9 @@ static inline int audit_log_task_context(struct
audit_buffer*ab) static inline voidaudit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk){ }
include/linux/audit.h +2
-0+static inline int audit_log_container_info (struct task_struct *tsk, + struct audit_context*context); +{ }
#define
audit_enabled0
#endif /*CONFIG_AUDIT*/include/uapi/linux/audit.h +0
-0@@ -115,6 +115,7 @@#define AUDIT_REPLACE 1329/* Replace auditd if this packet unanswerd */ #define
AUDIT_KERN_MODULE
1330 /* Kernel Module events */ #defineAUDIT_FANOTIFY1331 /* Fanotify access decision
*/ +#defineAUDIT_CONTAINER_INFO1332 /* Container ID
information */ #defineAUDIT_AVC1400 /* SE
Linux avc denial or grant */ #defineAUDIT_SELINUX_ERR
1401 /* Internal SE Linux Errors */ diff --gita/kernel/audit.cb/kernel/audit.cindex 3f2f143..a12f21f 100644kernel/audit.c +19
-0@@ -2049,6 +2049,26 @@ void audit_log_session_info(struct audit_buffer *ab) audit_log_format(ab, " auid=%u ses=%u", auid, sessionid); } +/* +* audit_log_container_info - report container info +* @tsk: task to be recorded +* @context: task or local context for record +*/ +int audit_log_container_info (struct task_struct *tsk,struct audit_context *context) +{ +struct audit_buffer *ab; + +if (!audit_containerid_set (tsk)) +return 0 ; +/* Generate AUDIT_CONTAINER_INFO with container ID */ + ab =audit_log_start (context,GFP_KERNEL ,AUDIT_CONTAINER_INFO ); +if (!ab) +return -ENOMEM ; +audit_log_format (ab,"contid=%llu" ,audit_get_containerid (tsk)); +audit_log_end (ab); +return 0 ; +} +void audit_log_key (struct audit_buffer *ab,char *key) {audit_log_format (ab," key=" );kernel/auditsc.c +0
-0@@ -1453,6 +1453,8 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *tsaudit_log_proctitle (tsk, context);
Quoted 7 lines
Quoted 5 lines
kernel/auditsc.c static void audit_log_exit(struct audit_context *context, struct task_struct *ts · line 1456
Quoted 1 line
kernel/auditsc.c +1
-0+audit_log_container_info (tsk, context);Would there be any problem moving
audit_log_container_infobeforeaudit_log_proctitle? There are some assumptions that proctitle is the last record in some situations.I see no problem doing that.
Actually...just leave it as is. I have to fix things for simple events and they do not have a proctitle record. So, leave it as you intended and I'll work around this on my end.
Thanks,
-Steve
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
kernel/auditsc.c +0
-0/* Send end of event record to help user space know we are finished */ ab =
audit_log_start(context, GFP_KERNEL, AUDIT_EOE);if (ab)
- RGB
--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
Re: [RFC PATCH ghak32 V2 03/13] audit: log container info of syscalls
In reply to a message not in the archiveQuoted 128 lines · EDT Richard Guy Briggs
Quoted 127 lines · Steve Grubb
On Fri, 16 Mar 2018 05:00:30 -0400
Quoted 2 lines · Richard Guy Briggs
Create a new audit record
AUDIT_CONTAINER_INFOto document the container ID of a process if it is present.As mentioned in a previous email, I think
AUDIT_CONTAINERis more suitable for the container record. One more comment below...Quoted 118 lines
Called from
audit_log_exit(), syscalls are covered.A sample raw event:
type=SYSCALL msg=audit(1519924845.499:257): arch=c000003e syscall=257 success=yes exit=3 a0=ffffff9c a1=56374e1cef30 a2=241 a3=1b6 items=2 ppid=606 pid=635 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=3 comm="bash" exe="/usr/bin/bash" subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key="tmpcontainerid" type=CWD msg=audit(1519924845.499:257):
cwd="/root" type=PATH msg=audit(1519924845.499:257): item=0 name="/tmp/" inode=13863 dev=00:27 mode=041777 ouid=0 ogid=0 rdev=00:00 obj=system_u:object_r:tmp_t:s0 nametype= PARENT cap_fp=0000000000000000 cap_fi=0000000000000000 cap_fe=0 cap_fver=0 type=PATH msg=audit(1519924845.499:257): item=1 name="/tmp/tmpcontainerid" inode=17729 dev=00:27 mode=0100644 ouid=0 ogid=0 rdev=00:00 obj=unconfined_u:object_r:user_tmp_t:s0 nametype=CREATE cap_fp=0000000000000000 cap_fi=0000000000000000 cap_fe=0 cap_fver=0 type=PROCTITLE msg=audit(1519924845.499:257):
proctitle=62617368002D6300736C65657020313B206563686F2074657374203E202F7 46D702F746D70636F6E7461696E65726964 type=CONTAINER_INFO msg=audit(1519924845.499:257): op=task
contid=123458See: https://github.com/linux-audit/audit-kernel/issues/32
Signed-off-by Richard Guy Briggs <[email protected]>---
include/linux/audit.h | 5 +++++ include/uapi/linux/audit.h | 1 + kernel/audit.c | 20 ++++++++++++++++++++ kernel/auditsc.c | 2 ++ 4 files changed, 28 insertions(+)include/linux/audit.h +0
-0@@ -154,6 +154,8 @@ extern voidaudit_log_link_denied(const char *operation, extern int
audit_log_task_context(struct audit_buffer *ab); extern voidaudit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk);include/linux/audit.h +2
-0+extern int audit_log_container_info (struct task_struct *tsk, +struct audit_context *context);extern int audit_update_lsm_rules (void );@@ -205,6 +207,9 @@ static inline int audit_log_task_context(struct
audit_buffer*ab) static inline voidaudit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk){ }
include/linux/audit.h +2
-0+static inline int audit_log_container_info (struct task_struct *tsk, + struct audit_context*context); +{ }
#define
audit_enabled0
#endif /*CONFIG_AUDIT*/include/uapi/linux/audit.h +0
-0@@ -115,6 +115,7 @@#define AUDIT_REPLACE 1329/* Replace auditd if this packet unanswerd */ #define
AUDIT_KERN_MODULE
1330 /* Kernel Module events */ #defineAUDIT_FANOTIFY1331 /* Fanotify access decision
*/ +#defineAUDIT_CONTAINER_INFO1332 /* Container ID
information */ #defineAUDIT_AVC1400 /* SE
Linux avc denial or grant */ #defineAUDIT_SELINUX_ERR
1401 /* Internal SE Linux Errors */ diff --gita/kernel/audit.cb/kernel/audit.cindex 3f2f143..a12f21f 100644kernel/audit.c +19
-0@@ -2049,6 +2049,26 @@ void audit_log_session_info(struct audit_buffer *ab) audit_log_format(ab, " auid=%u ses=%u", auid, sessionid); } +/* +* audit_log_container_info - report container info +* @tsk: task to be recorded +* @context: task or local context for record +*/ +int audit_log_container_info (struct task_struct *tsk,struct audit_context *context) +{ +struct audit_buffer *ab; + +if (!audit_containerid_set (tsk)) +return 0 ; +/* Generate AUDIT_CONTAINER_INFO with container ID */ + ab =audit_log_start (context,GFP_KERNEL ,AUDIT_CONTAINER_INFO ); +if (!ab) +return -ENOMEM ; +audit_log_format (ab,"contid=%llu" ,audit_get_containerid (tsk)); +audit_log_end (ab); +return 0 ; +} +void audit_log_key (struct audit_buffer *ab,char *key) {audit_log_format (ab," key=" );kernel/auditsc.c +0
-0@@ -1453,6 +1453,8 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *tsaudit_log_proctitle (tsk, context);
Quoted 7 lines
Quoted 5 lines
kernel/auditsc.c static void audit_log_exit(struct audit_context *context, struct task_struct *ts · line 1456
Quoted 1 line
kernel/auditsc.c +1
-0+audit_log_container_info (tsk, context);Would there be any problem moving
audit_log_container_infobeforeaudit_log_proctitle? There are some assumptions that proctitle is the last record in some situations.I see no problem doing that.
Actually...just leave it as is. I have to fix things for simple events and they do not have a proctitle record. So, leave it as you intended and I'll work around this on my end.
Thanks,
-Steve
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
kernel/auditsc.c +0
-0/* Send end of event record to help user space know we are finished */ ab =
audit_log_start(context, GFP_KERNEL, AUDIT_EOE);if (ab)
- RGB
--
Richard Guy Briggs <[email protected]> Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
Re: [RFC PATCH ghak32 V2 13/13] debug audit: read container ID of a process
In reply to Steve GrubbQuoted 5 lines · Steve Grubb
Quoted 1 line · EDT Richard Guy Briggs
Add support for reading the container ID from the proc filesystem.
I think this could be useful in general. Please consider this to be part of the full patch set and not something merely used to debug the patches.
Only with an audit specific name.
As it is:
The truth is the containerid name really stinks and is quite confusing and does not imply that the label applies only to audit. And little things like this make me extremely uncofortable with it.
Eric
Paul Moore
maintainerRe: [RFC PATCH ghak32 V2 13/13] debug audit: read container ID of a process
Quoted 10 lines · Eric W. Biederman
Quoted 5 lines · Steve Grubb
Quoted 1 line · EDT Richard Guy Briggs
Add support for reading the container ID from the proc filesystem.
I think this could be useful in general. Please consider this to be part of the full patch set and not something merely used to debug the patches.
Only with an audit specific name.
Quoted 7 lines
As it is:
Nacked-by "Eric W. Biederman" <[email protected]>The truth is the containerid name really stinks and is quite confusing and does not imply that the label applies only to audit. And little things like this make me extremely uncofortable with it.
It also makes the audit container ID (notice how I *always* call it the *audit* container ID? that is not an accident) available for userspace applications to abuse. Perhaps in the future we can look at ways to make this more available to applications, but this patch is not the answer.
Signature · 2 lines
paul moore www.paul-moore.com
Re: [RFC PATCH ghak32 V2 13/13] debug audit: read container ID of a process
In reply to a message not in the archiveQuoted 10 lines · Eric W. Biederman
Quoted 5 lines · Steve Grubb
Quoted 1 line · EDT Richard Guy Briggs
Add support for reading the container ID from the proc filesystem.
I think this could be useful in general. Please consider this to be part of the full patch set and not something merely used to debug the patches.
Only with an audit specific name.
Quoted 7 lines
As it is:
The truth is the containerid name really stinks and is quite confusing and does not imply that the label applies only to audit. And little things like this make me extremely uncofortable with it.
It also makes the audit container ID (notice how I *always* call it the *audit* container ID? that is not an accident) available for userspace applications to abuse. Perhaps in the future we can look at ways to make this more available to applications, but this patch is not the answer.
Signature · 2 lines
paul moore www.paul-moore.com
Re: [RFC PATCH ghak32 V2 13/13] debug audit: read container ID of a process
In reply to Paul MooreQuoted 18 lines · Paul Moore
Quoted 9 lines · Eric W. Biederman
Quoted 5 lines · Steve Grubb
Quoted 1 line · EDT Richard Guy Briggs
Add support for reading the container ID from the proc filesystem.
I think this could be useful in general. Please consider this to be part of the full patch set and not something merely used to debug the patches.
Only with an audit specific name.
Quoted 7 lines
As it is:
The truth is the containerid name really stinks and is quite confusing and does not imply that the label applies only to audit. And little things like this make me extremely uncofortable with it.
Quoted 5 lines
It also makes the audit container ID (notice how I *always* call it the *audit* container ID? that is not an accident) available for userspace applications to abuse. Perhaps in the future we can look at ways to make this more available to applications, but this patch is not the answer.
Do you have a productive suggestion?
Quoted 1 line
paul moore
- RGB
--
Richard Guy Briggs <[email protected]> Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
Paul Moore
maintainerRe: [RFC PATCH ghak32 V2 13/13] debug audit: read container ID of a process
Quoted 19 lines · Richard Guy Briggs
Quoted 18 lines · Paul Moore
Quoted 16 lines · Eric W. Biederman
Quoted 5 lines · Steve Grubb
Quoted 1 line · EDT Richard Guy Briggs
Add support for reading the container ID from the proc filesystem.
I think this could be useful in general. Please consider this to be part of the full patch set and not something merely used to debug the patches.
Only with an audit specific name.
As it is:
The truth is the containerid name really stinks and is quite confusing and does not imply that the label applies only to audit. And little things like this make me extremely uncofortable with it.
Quoted 7 lines
Quoted 5 lines
It also makes the audit container ID (notice how I *always* call it the *audit* container ID? that is not an accident) available for userspace applications to abuse. Perhaps in the future we can look at ways to make this more available to applications, but this patch is not the answer.
Do you have a productive suggestion?
I haven't given it much thought beyond our discussions and until we get the basic audit container ID support in place (all the other parts of this patchset) I doubt I'll be giving it much thought.
Signature · 2 lines
paul moore www.paul-moore.com
Quoted 5 lines · EDT Richard Guy Briggs
Implement audit kernel container ID.
This patchset is a second RFC based on the proposal document (V3) posted:
https://www.redhat.com/archives/linux-audit/2018-January/msg00014.html
So, if you work on a container orchestrator, how exactly is this set of interfaces to be used and in what order?
Thanks,
-Steve
Quoted 122 lines
The first patch implements the proc fs write to set the audit container ID of a process, emitting an
AUDIT_CONTAINERrecord to announce the registration of that container ID on that process. This patch requires userspace support for record acceptance and proper type display.The second checks for children or co-threads and refuses to set the container ID if either are present. (This policy could be changed to set both with the same container ID provided they meet the rest of the requirements.)
The third implements the auxiliary record
AUDIT_CONTAINER_INFOif a container ID is identifiable with an event. This patch requires userspace support for proper type display.The fourth adds container ID filtering to the exit, exclude and user lists. This patch requires auditctil userspace support for the --containerid option.
The 5th adds signal and ptrace support.
The 6th creates a local audit context to be able to bind a standalone record with a locally created auxiliary record.
The 7th, 8th, 9th, 10th patches add container ID records to standalone records. Some of these may end up being syscall auxiliary records and won't need this specific support since they'll be supported via syscalls.
The 11th adds network namespace container ID labelling based on member tasks' container ID labels.
The 12th adds container ID support to standalone netfilter records that don't have a task context and lists each container to which that net namespace belongs.
The 13th implements reading the container ID from the proc filesystem for debugging. This patch isn't planned for upstream inclusion.
Feedback please!
Example: Set a container ID of 123456 to the "sleep" task:
sleep 2& child=$! echo 123456 > /proc/$child/containerid; echo $? ausearch -ts recent -m container echo child:$child contid:$( cat /proc/$child/containerid) This should produce a record such as: type=CONTAINER msg=audit(1521122590.315:222): op=set pid=689 uid=0subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 auid=0 tty=pts0 ses=3 opid=707 old-contid=18446744073709551615 contid=123456 res=1
Example: Set a filter on a container ID 123459 on
/tmp/tmpcontainerid:containerid=123459 key=tmpcontainerid auditctl -a exit,always -F dir=/tmp -F perm=wa -F containerid=$containerid-F key=$key perl -e "sleep 1;
open(my \$tmpfile, '>', \"/tmp/$key\"); close(\$tmpfile);" & child=$!
echo $containerid >/proc/$child/containerid
sleep 2
ausearch -i -ts recent -k $key
auditctl -d exit,always -F dir=/tmp -F perm=wa -F containerid=$containerid
-F key=$key rm -f/tmp/$key
This should produce an event such as:type=CONTAINER_INFO msg=audit(1521122591.614:227): op=task contid=123459 type=PROCTITLE msg=audit(1521122591.614:227):proctitle=7065726C002D6500736C65657020313B206F70656E286D792024746D7066696C 652C20273E272C20222F746D702F746D70636F6E7461696E6572696422293B20636C6F73652 824746D7066696C65293B type=PATH msg=audit(1521122591.614:227): item=1 name="/tmp/tmpcontainerid" inode=18427 dev=00:26 mode=0100644 ouid=0 ogid=0 rdev=00:00 obj=unconfined_u:object_r:user_tmp_t:s0 nametype=CREATE cap_fp=0000000000000000 cap_fi=0000000000000000 cap_fe=0 cap_fver=0 type=PATH msg=audit(1521122591.614:227): item=0 name="/tmp/" inode=13513 dev=00:26 mode=041777 ouid=0 ogid=0 rdev=00:00 obj=system_u:object_r:tmp_t:s0 nametype=PARENT cap_fp=0000000000000000 cap_fi=0000000000000000 cap_fe=0 cap_fver=0 type=CWD msg=audit(1521122591.614:227): cwd="/root"
type=SYSCALL msg=audit(1521122591.614:227): arch=c000003e syscall=257success=yes exit=3 a0=ffffffffffffff9c a1=55db90a28900 a2=241 a3=1b6 items=2 ppid=689 pid=724 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=3 comm="perl" exe="/usr/bin/perl" subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key="tmpcontainerid"
See:
https://github.com/linux-audit/audit-kernel/issues/32
https://github.com/linux-audit/audit-userspace/issues/40
https://github.com/linux-audit/audit-testsuite/issues/64Richard Guy Briggs (13):
audit: add container id
audit: check children and threading before allowing containerid
audit: log container info of syscalls
audit: add containerid filtering
audit: add containerid support for ptrace and signals
audit: add support for non-syscall auxiliary records
audit: add container aux record to watch/tree/mark
audit: add containerid support fortty_audit
audit: add containerid support for config/feature/user records
audit: add containerid support for seccomp andanom_abendrecords
audit: add support for containerid to network namespaces
audit:NETFILTER_PKT: record each container ID associated with a netNS debug audit: read container ID of a processdrivers/tty/tty_audit.c | 5 +- fs/proc/base.c | 53 ++++++++++++++++ include/linux/audit.h | 43 +++++++++++++ include/linux/init_task.h | 4 +- include/linux/sched.h | 1 + include/net/net_namespace.h | 12 ++++ include/uapi/linux/audit.h | 8 ++- kernel/audit.c | 75 ++++++++++++++++++++--- kernel/audit.h | 3 + kernel/audit_fsnotify.c | 5 +- kernel/audit_tree.c | 5 +- kernel/audit_watch.c | 33 +++++----- kernel/auditfilter.c | 52 +++++++++++++++- kernel/auditsc.c | 145 ++++++++++++++++++++++++++++++++++++++++++-- kernel/nsproxy.c | 6 ++ net/core/net_namespace.c | 45 ++++++++++++++ net/netfilter/xt_AUDIT.c | 15 ++++- 17 files changed, 473 insertions(+), 37 deletions(-)
Quoted 9 lines · Steve Grubb
Quoted 5 lines · EDT Richard Guy Briggs
Implement audit kernel container ID.
This patchset is a second RFC based on the proposal document (V3) posted:
https://www.redhat.com/archives/linux-audit/2018-January/msg00014.htmlSo, if you work on a container orchestrator, how exactly is this set of interfaces to be used and in what order?
It was designed keeping in mind the Virtuallization Manager Guest Lifecycle Events document.
https://github.com/linux-audit/audit-documentation/wiki/SPEC-Virtualization-Manager-Guest-Lifecycle-Events
The orchestrator would start setting things up and when it knows the PID of the conainer task but before that task has had a chance to thread or spawn children it registers the audit container ID via the /proc interface. After that, it consults audit for any events maching that ID.
Quoted 117 lines
Thanks,
-SteveQuoted 114 lines
The first patch implements the proc fs write to set the audit container ID of a process, emitting an
AUDIT_CONTAINERrecord to announce the registration of that container ID on that process. This patch requires userspace support for record acceptance and proper type display.The second checks for children or co-threads and refuses to set the container ID if either are present. (This policy could be changed to set both with the same container ID provided they meet the rest of the requirements.)
The third implements the auxiliary record
AUDIT_CONTAINER_INFOif a container ID is identifiable with an event. This patch requires userspace support for proper type display.The fourth adds container ID filtering to the exit, exclude and user lists. This patch requires auditctil userspace support for the --containerid option.
The 5th adds signal and ptrace support.
The 6th creates a local audit context to be able to bind a standalone record with a locally created auxiliary record.
The 7th, 8th, 9th, 10th patches add container ID records to standalone records. Some of these may end up being syscall auxiliary records and won't need this specific support since they'll be supported via syscalls.
The 11th adds network namespace container ID labelling based on member tasks' container ID labels.
The 12th adds container ID support to standalone netfilter records that don't have a task context and lists each container to which that net namespace belongs.
The 13th implements reading the container ID from the proc filesystem for debugging. This patch isn't planned for upstream inclusion.
Feedback please!
Example: Set a container ID of 123456 to the "sleep" task:
sleep 2& child=$! echo 123456 > /proc/$child/containerid; echo $? ausearch -ts recent -m container echo child:$child contid:$( cat /proc/$child/containerid) This should produce a record such as: type=CONTAINER msg=audit(1521122590.315:222): op=set pid=689 uid=0subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 auid=0 tty=pts0 ses=3 opid=707 old-contid=18446744073709551615 contid=123456 res=1
Example: Set a filter on a container ID 123459 on
/tmp/tmpcontainerid:containerid=123459 key=tmpcontainerid auditctl -a exit,always -F dir=/tmp -F perm=wa -F containerid=$containerid-F key=$key perl -e "sleep 1;
open(my \$tmpfile, '>', \"/tmp/$key\"); close(\$tmpfile);" & child=$!
echo $containerid >/proc/$child/containerid
sleep 2
ausearch -i -ts recent -k $key
auditctl -d exit,always -F dir=/tmp -F perm=wa -F containerid=$containerid
-F key=$key rm -f/tmp/$key
This should produce an event such as:type=CONTAINER_INFO msg=audit(1521122591.614:227): op=task contid=123459 type=PROCTITLE msg=audit(1521122591.614:227):proctitle=7065726C002D6500736C65657020313B206F70656E286D792024746D7066696C 652C20273E272C20222F746D702F746D70636F6E7461696E6572696422293B20636C6F73652 824746D7066696C65293B type=PATH msg=audit(1521122591.614:227): item=1 name="/tmp/tmpcontainerid" inode=18427 dev=00:26 mode=0100644 ouid=0 ogid=0 rdev=00:00 obj=unconfined_u:object_r:user_tmp_t:s0 nametype=CREATE cap_fp=0000000000000000 cap_fi=0000000000000000 cap_fe=0 cap_fver=0 type=PATH msg=audit(1521122591.614:227): item=0 name="/tmp/" inode=13513 dev=00:26 mode=041777 ouid=0 ogid=0 rdev=00:00 obj=system_u:object_r:tmp_t:s0 nametype=PARENT cap_fp=0000000000000000 cap_fi=0000000000000000 cap_fe=0 cap_fver=0 type=CWD msg=audit(1521122591.614:227): cwd="/root"
type=SYSCALL msg=audit(1521122591.614:227): arch=c000003e syscall=257success=yes exit=3 a0=ffffffffffffff9c a1=55db90a28900 a2=241 a3=1b6 items=2 ppid=689 pid=724 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=3 comm="perl" exe="/usr/bin/perl" subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key="tmpcontainerid"
See:
https://github.com/linux-audit/audit-kernel/issues/32
https://github.com/linux-audit/audit-userspace/issues/40
https://github.com/linux-audit/audit-testsuite/issues/64Richard Guy Briggs (13):
audit: add container id
audit: check children and threading before allowing containerid
audit: log container info of syscalls
audit: add containerid filtering
audit: add containerid support for ptrace and signals
audit: add support for non-syscall auxiliary records
audit: add container aux record to watch/tree/mark
audit: add containerid support fortty_audit
audit: add containerid support for config/feature/user records
audit: add containerid support for seccomp andanom_abendrecords
audit: add support for containerid to network namespaces
audit:NETFILTER_PKT: record each container ID associated with a netNS debug audit: read container ID of a processdrivers/tty/tty_audit.c | 5 +- fs/proc/base.c | 53 ++++++++++++++++ include/linux/audit.h | 43 +++++++++++++ include/linux/init_task.h | 4 +- include/linux/sched.h | 1 + include/net/net_namespace.h | 12 ++++ include/uapi/linux/audit.h | 8 ++- kernel/audit.c | 75 ++++++++++++++++++++--- kernel/audit.h | 3 + kernel/audit_fsnotify.c | 5 +- kernel/audit_tree.c | 5 +-
Quoted 12 lines
Quoted 8 lines
kernel/audit_watch.c | 33 +++++----- kernel/auditfilter.c | 52 +++++++++++++++- kernel/auditsc.c | 145 ++++++++++++++++++++++++++++++++++++++++++-- kernel/nsproxy.c | 6 ++ net/core/net_namespace.c | 45 ++++++++++++++ net/netfilter/xt_AUDIT.c | 15 ++++- 17 files changed, 473 insertions(+), 37 deletions(-)
- RGB
--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
Quoted 9 lines · Steve Grubb
Quoted 5 lines · EDT Richard Guy Briggs
Implement audit kernel container ID.
This patchset is a second RFC based on the proposal document (V3) posted:
https://www.redhat.com/archives/linux-audit/2018-January/msg00014.htmlSo, if you work on a container orchestrator, how exactly is this set of interfaces to be used and in what order?
It was designed keeping in mind the Virtuallization Manager Guest Lifecycle Events document.
https://github.com/linux-audit/audit-documentation/wiki/SPEC-Virtualization-Manager-Guest-Lifecycle-Events
The orchestrator would start setting things up and when it knows the PID of the conainer task but before that task has had a chance to thread or spawn children it registers the audit container ID via the /proc interface. After that, it consults audit for any events maching that ID.
Quoted 117 lines
Thanks,
-SteveQuoted 114 lines
The first patch implements the proc fs write to set the audit container ID of a process, emitting an
AUDIT_CONTAINERrecord to announce the registration of that container ID on that process. This patch requires userspace support for record acceptance and proper type display.The second checks for children or co-threads and refuses to set the container ID if either are present. (This policy could be changed to set both with the same container ID provided they meet the rest of the requirements.)
The third implements the auxiliary record
AUDIT_CONTAINER_INFOif a container ID is identifiable with an event. This patch requires userspace support for proper type display.The fourth adds container ID filtering to the exit, exclude and user lists. This patch requires auditctil userspace support for the --containerid option.
The 5th adds signal and ptrace support.
The 6th creates a local audit context to be able to bind a standalone record with a locally created auxiliary record.
The 7th, 8th, 9th, 10th patches add container ID records to standalone records. Some of these may end up being syscall auxiliary records and won't need this specific support since they'll be supported via syscalls.
The 11th adds network namespace container ID labelling based on member tasks' container ID labels.
The 12th adds container ID support to standalone netfilter records that don't have a task context and lists each container to which that net namespace belongs.
The 13th implements reading the container ID from the proc filesystem for debugging. This patch isn't planned for upstream inclusion.
Feedback please!
Example: Set a container ID of 123456 to the "sleep" task:
sleep 2& child=$! echo 123456 > /proc/$child/containerid; echo $? ausearch -ts recent -m container echo child:$child contid:$( cat /proc/$child/containerid) This should produce a record such as: type=CONTAINER msg=audit(1521122590.315:222): op=set pid=689 uid=0subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 auid=0 tty=pts0 ses=3 opid=707 old-contid=18446744073709551615 contid=123456 res=1
Example: Set a filter on a container ID 123459 on
/tmp/tmpcontainerid:containerid=123459 key=tmpcontainerid auditctl -a exit,always -F dir=/tmp -F perm=wa -F containerid=$containerid-F key=$key perl -e "sleep 1;
open(my \$tmpfile, '>', \"/tmp/$key\"); close(\$tmpfile);" & child=$!
echo $containerid >/proc/$child/containerid
sleep 2
ausearch -i -ts recent -k $key
auditctl -d exit,always -F dir=/tmp -F perm=wa -F containerid=$containerid
-F key=$key rm -f/tmp/$key
This should produce an event such as:type=CONTAINER_INFO msg=audit(1521122591.614:227): op=task contid=123459 type=PROCTITLE msg=audit(1521122591.614:227):proctitle=7065726C002D6500736C65657020313B206F70656E286D792024746D7066696C 652C20273E272C20222F746D702F746D70636F6E7461696E6572696422293B20636C6F73652 824746D7066696C65293B type=PATH msg=audit(1521122591.614:227): item=1 name="/tmp/tmpcontainerid" inode=18427 dev=00:26 mode=0100644 ouid=0 ogid=0 rdev=00:00 obj=unconfined_u:object_r:user_tmp_t:s0 nametype=CREATE cap_fp=0000000000000000 cap_fi=0000000000000000 cap_fe=0 cap_fver=0 type=PATH msg=audit(1521122591.614:227): item=0 name="/tmp/" inode=13513 dev=00:26 mode=041777 ouid=0 ogid=0 rdev=00:00 obj=system_u:object_r:tmp_t:s0 nametype=PARENT cap_fp=0000000000000000 cap_fi=0000000000000000 cap_fe=0 cap_fver=0 type=CWD msg=audit(1521122591.614:227): cwd="/root"
type=SYSCALL msg=audit(1521122591.614:227): arch=c000003e syscall=257success=yes exit=3 a0=ffffffffffffff9c a1=55db90a28900 a2=241 a3=1b6 items=2 ppid=689 pid=724 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=3 comm="perl" exe="/usr/bin/perl" subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key="tmpcontainerid"
See:
https://github.com/linux-audit/audit-kernel/issues/32
https://github.com/linux-audit/audit-userspace/issues/40
https://github.com/linux-audit/audit-testsuite/issues/64Richard Guy Briggs (13):
audit: add container id
audit: check children and threading before allowing containerid
audit: log container info of syscalls
audit: add containerid filtering
audit: add containerid support for ptrace and signals
audit: add support for non-syscall auxiliary records
audit: add container aux record to watch/tree/mark
audit: add containerid support fortty_audit
audit: add containerid support for config/feature/user records
audit: add containerid support for seccomp andanom_abendrecords
audit: add support for containerid to network namespaces
audit:NETFILTER_PKT: record each container ID associated with a netNS debug audit: read container ID of a processdrivers/tty/tty_audit.c | 5 +- fs/proc/base.c | 53 ++++++++++++++++ include/linux/audit.h | 43 +++++++++++++ include/linux/init_task.h | 4 +- include/linux/sched.h | 1 + include/net/net_namespace.h | 12 ++++ include/uapi/linux/audit.h | 8 ++- kernel/audit.c | 75 ++++++++++++++++++++--- kernel/audit.h | 3 + kernel/audit_fsnotify.c | 5 +- kernel/audit_tree.c | 5 +-
Quoted 12 lines
Quoted 8 lines
kernel/audit_watch.c | 33 +++++----- kernel/auditfilter.c | 52 +++++++++++++++- kernel/auditsc.c | 145 ++++++++++++++++++++++++++++++++++++++++++-- kernel/nsproxy.c | 6 ++ net/core/net_namespace.c | 45 ++++++++++++++ net/netfilter/xt_AUDIT.c | 15 ++++- 17 files changed, 473 insertions(+), 37 deletions(-)
- RGB
--
Richard Guy Briggs <[email protected]> Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
Re: [RFC PATCH ghak32 V2 01/13] audit: add container id
In reply to Steve GrubbQuoted 283 lines · Steve Grubb
Quoted 8 lines · On Fri, 16 Mar 2018 05:00:28 -0400 Richard Guy Briggs <[email protected]> wrote:
Implement the proc fs write to set the audit container ID of a process, emitting an
AUDIT_CONTAINERrecord to document the event.This is a write from the container orchestrator task to a proc entry of the form
/proc/PID/containeridwhere PID is the process ID of the newly created task that is to become the first task in a container, or an additional task added to a container.Quoted 7 lines
The write expects up to a u64 value (unset: 18446744073709551615).
This will produce a record such as this:
type=CONTAINER msg=audit(1519903238.968:261): op=set pid=596 uid=0 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 auid=0 tty=pts0 ses=1 opid=596 old-contid=18446744073709551615 contid=123455 res=0The was one thing I was wondering about. Currently when we set the loginuid, the record is
AUDIT_LOGINUID. The corollary is that when we set the container id, the event should beAUDIT_CONTAINERIDorAUDIT_CONTAINER_ID.During syscall events, the path info is returned in a a record simply called
AUDIT_PATH, cwd info is returned inAUDIT_CWD. So, rather than calling the record that gets attached to everythingAUDIT_CONTAINER_INFO, how about simplyAUDIT_CONTAINER.Quoted 253 lines
The "op" field indicates an initial set. The "pid" to "ses" fields are the orchestrator while the "opid" field is the object's PID, the process being "contained". Old and new container ID values are given in the "contid" fields, while res indicates its success.
It is not permitted to self-set, unset or re-set the container ID. A child inherits its parent's container ID, but then can be set only once after.
See: https://github.com/linux-audit/audit-kernel/issues/32
Signed-off-by Richard Guy Briggs <[email protected]>--- fs/proc/base.c | 37 ++++++++++++++++++++ include/linux/audit.h | 16 +++++++++ include/linux/init_task.h | 4 ++- include/linux/sched.h | 1 + include/uapi/linux/audit.h | 2 ++ kernel/auditsc.c | 84++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 143 insertions(+), 1 deletion(-)
fs/proc/base.c +35
-0@@ -1299,6 +1299,41 @@ static ssize_t proc_sessionid_read(struct file * file, char __user * buf, .read = proc_sessionid_read, .llseek = generic_file_llseek, }; + +static ssize_t proc_containerid_write (struct file *file,const char __user *buf, +size_t count,loff_t *ppos) +{ +struct inode *inode =file_inode (file); +u64 containerid; +int rv; +struct task_struct *task =get_proc_task (inode); + +if (!task) +return -ESRCH ; +if (*ppos !=0 ) { +/* No partial writes. */ +put_task_struct (task); +return -EINVAL ; + } + + rv =kstrtou64_from_user (buf, count,10 , &containerid); +if (rv <0 ) { +put_task_struct (task); +return rv; + } + + rv =audit_set_containerid (task, containerid); +put_task_struct (task); +if (rv <0 ) +return rv; +return count; +} + +static const struct file_operations proc_containerid_operations = { + .write = proc_containerid_write, + .llseek = generic_file_llseek, +}; +#endif #ifdef
CONFIG_FAULT_INJECTIONfs/proc/base.c +1
-0@@ -2961,6 +2996,7 @@ static int proc_pid_patch_state(struct seq_file *m, struct pid_namespace *ns, #ifdef CONFIG_AUDITSYSCALLREG ("loginuid" ,S_IWUSR |S_IRUGO , proc_loginuid_operations),REG ("sessionid" ,S_IRUGO , proc_sessionid_operations), +REG ("containerid" ,S_IWUSR , proc_containerid_operations), #endif #ifdef CONFIG_FAULT_INJECTION REG("make-it-fail", S_IRUGO|S_IWUSR,
proc_fault_inject_operations), @@ -3355,6 +3391,7 @@ static intproc_tid_comm_permission(struct inode *inode, int mask)#ifdefCONFIG_AUDITSYSCALLREG("loginuid", S_IWUSR|S_IRUGO, proc_loginuid_operations),REG("sessionid", S_IRUGO, proc_sessionid_operations),fs/proc/base.c +1
-0+ REG("containerid", S_IWUSR, proc_containerid_operations),#endif #ifdef CONFIG_FAULT_INJECTION REG("make-it-fail", S_IRUGO|S_IWUSR,
proc_fault_inject_operations), diff --gita/include/linux/audit.hb/include/linux/audit.hindex af410d9..fe4ba3f 100644include/linux/audit.h +1
-0@@ -29,6 +29,7 @@#define AUDIT_INO_UNSET ((unsigned long)-1)#define AUDIT_DEV_UNSET ((dev_t)-1) +#define INVALID_CID AUDIT_CID_UNSETstruct audit_sig_info {uid_t uid;@@ -321,6 +322,7 @@ static inline void audit_ptrace(struct
task_struct*t) extern intauditsc_get_stamp(struct audit_context *ctx, struct timespec64 *t, unsigned int *serial);
extern intaudit_set_loginuid(kuid_t loginuid);
+extern intaudit_set_containerid(struct task_struct *tsk, u64 containerid);
static inlinekuid_taudit_get_loginuid(struct task_struct *tsk){include/linux/audit.h +5
-0@@ -332,6 +334,11 @@ static inline unsigned int audit_get_sessionid(struct task_struct *tsk) return tsk->sessionid; } +static inline u64 audit_get_containerid (struct task_struct *tsk) +{ +return tsk->containerid; +} +extern void __audit_ipc_obj (struct kern_ipc_perm *ipcp); extern void __audit_ipc_set_perm(unsigned long qbytes, uid_t uid,
gid_tgid,umode_tmode); extern void__audit_bprm(struct linux_binprm *bprm); @@ -517,6 +524,10 @@ static inline unsigned intaudit_get_sessionid(struct task_struct *tsk){include/linux/audit.h +4
-0return -1 ; } +static inline kuid_t audit_get_containerid (struct task_struct *tsk) +{ +return INVALID_CID ; +}static inline void audit_ipc_obj (struct kern_ipc_perm *ipcp) { } static inline void audit_ipc_set_perm(unsigned long qbytes, uid_tuid, @@ -581,6 +592,11 @@ static inline bool
audit_loginuid_set(struct task_struct *tsk)return uid_valid(audit_get_loginuid(tsk)); }include/linux/audit.h +5
-0+static inline bool audit_containerid_set (struct task_struct *tsk) +{ +return audit_get_containerid (tsk) !=INVALID_CID ; +} + static inline void audit_log_string(struct audit_buffer *ab, constchar *buf) {
include/linux/audit.h +0
-0audit_log_n_string (ab, buf,strlen (buf));include/linux/init_task.h +3
-1@@ -18,6 +18,7 @@#include <linux/sched/rt.h> #include <linux/livepatch.h> #include <linux/mm_types.h> +#include <linux/audit.h> #include <asm/thread_info.h> @@ -120,7 +121,8 @@#ifdef CONFIG_AUDITSYSCALL #define INIT_IDS \ .loginuid = INVALID_UID, \ - .sessionid = (unsigned int)-1, + .sessionid = (unsigned int)-1, \ + .containerid = INVALID_CID,#else #define INIT_IDS #endif include/linux/sched.h +1
-0@@ -796,6 +796,7 @@ struct task_struct {#ifdef CONFIG_AUDITSYSCALL kuid_t loginuid;unsigned int sessionid; +u64 containerid;#endif struct seccomp seccomp;include/uapi/linux/audit.h +0
-0@@ -71,6 +71,7 @@#define AUDIT_TTY_SET 1017/* Set TTY auditing status */ #define
AUDIT_SET_FEATURE1018 /* Turn an
audit feature on or off */ #defineAUDIT_GET_FEATURE
1019 /* Get which features are enabled */ +#defineAUDIT_CONTAINER1020 /* Define the container id
and information */ #defineAUDIT_FIRST_USER_MSG1100 /*
Userspace messages mostly uninteresting to kernel */ #defineAUDIT_USER_AVC1107 /* We filter this
differently */ @@ -465,6 +466,7 @@ structaudit_tty_status{ };#define
AUDIT_UID_UNSET(unsigned int)-1include/uapi/linux/audit.h +1
-0+#define AUDIT_CID_UNSET ((u64)-1)/* audit_rule_data supports filter rules with both integer and string * fields. It corresponds with AUDIT_ADD_RULE, AUDIT_DEL_RULE and kernel/auditsc.c +17
-0@@ -2073,6 +2073,90 @@ int audit_set_loginuid(kuid_t loginuid)return rc; } +static int audit_set_containerid_perm (struct task_struct *task,u64 containerid) +{ +struct task_struct *parent; +u64 pcontainerid, ccontainerid; + +/* Don't allow to set our own containerid */ +if (current == task) +return -EPERM ; +/* Don't allow the containerid to be unset */ +if (!cid_valid (containerid)) +return -EINVAL ; +/* if we don't have caps, reject */ +if (!capable (CAP_AUDIT_CONTROL )) +return -EPERM ; +/* if containerid is unset, allow */ +if (!audit_containerid_set (task)) +return 0 ; +/* it is already set, and not inherited from the parent, reject */
kernel/auditsc.c +13
-0+ ccontainerid =audit_get_containerid (task); +rcu_read_lock (); + parent =rcu_dereference (task->real_parent); +rcu_read_unlock (); +task_lock (parent); + pcontainerid =audit_get_containerid (parent); +task_unlock (parent); +if (ccontainerid != pcontainerid) +return -EPERM ; +return 0 ; +} + +static void audit_log_set_containerid(struct task_struct *task, u64oldcontainerid,
kernel/auditsc.c +17
-0+ u64 containerid, int rc) +{ +struct audit_buffer *ab; +uid_t uid; +struct tty_struct *tty; + +if (!audit_enabled) +return ; + + ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_CONTAINER ); +if (!ab) +return ; + + uid =from_kuid (&init_user_ns,task_uid (current)); + tty =audit_get_tty (current); + + audit_log_format(ab, "op=set pid=%d uid=%u",
Quoted 8 lines
Quoted 4 lines
task_tgid_nr(current), uid);kernel/auditsc.c +2
-0+audit_log_task_context (ab); + audit_log_format(ab, " auid=%u tty=%s ses=%u opid=%dold-contid=%llu contid=%llu res=%d",
The preferred ordering would be: op, opid, old-contid, contid, pid, uid, tty, ses, subj, comm, exe, res. This groups the searchable fields together using the most common ordering so that parsing is simple.
Where would you like auid? It appears that just before uid would be the right place, if not in place of uid, but this is just a guess since it isn't consistent.
Quoted 40 lines
-Steve
Quoted 38 lines
kernel/auditsc.c +1
-0+ from_kuid(&init_user_ns,
audit_get_loginuid(current)),kernel/auditsc.c +1
-0+ tty ? tty_name(tty) : "(none)",
audit_get_sessionid(current),kernel/auditsc.c +1
-0+ task_tgid_nr(task), oldcontainerid,containerid, !rc); +
kernel/auditsc.c +6
-0+audit_put_tty (tty); +audit_log_end (ab); +} + +/** +* audit_set_containerid - set current task's audit_context containerid
+ * @containerid: containerid value
+ *
+ * Returns 0 on success,-EPERMon permission failure.
+ *
+ * Called (set) from fs/proc/base.c::proc_containerid_write().
+ */kernel/auditsc.c +15
-0+int audit_set_containerid (struct task_struct *task,u64 containerid) +{ +u64 oldcontainerid; +int rc; + + oldcontainerid =audit_get_containerid (task); + + rc =audit_set_containerid_perm (task, containerid); +if (!rc) { +task_lock (task); + task->containerid = containerid; +task_unlock (task); + } + + audit_log_set_containerid(task, oldcontainerid, containerid,rc);
kernel/auditsc.c +3
-0+return rc; +} +
Quoted 8 lines
Quoted 3 lines
/**
*__audit_mq_open- record audit data for a POSIX MQ open
* @oflag: open flag--
Linux-audit mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/linux-audit
- RGB
--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
Re: [RFC PATCH ghak32 V2 01/13] audit: add container id
Quoted 300 lines · EDT Richard Guy Briggs
Re: [RFC PATCH ghak32 V2 01/13] audit: add container id
From: Richard Guy Briggs <[email protected]>
To: Me
CC: [email protected], [email protected], LKML
<[email protected]>, [email protected], ... Date: 6/1/18
5:04 PMQuoted 282 lines · Steve Grubb
On Fri, 16 Mar 2018 05:00:28 -0400
Quoted 8 lines · Richard Guy Briggs
Implement the proc fs write to set the audit container ID of a process, emitting an
AUDIT_CONTAINERrecord to document the event.This is a write from the container orchestrator task to a proc entry of the form
/proc/PID/containeridwhere PID is the process ID of the newly created task that is to become the first task in a container, or an additional task added to a container.Quoted 7 lines
The write expects up to a u64 value (unset: 18446744073709551615).
This will produce a record such as this:
type=CONTAINER msg=audit(1519903238.968:261): op=set pid=596 uid=0 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 auid=0 tty=pts0 ses=1 opid=596 old-contid=18446744073709551615 contid=123455 res=0The was one thing I was wondering about. Currently when we set the loginuid, the record is
AUDIT_LOGINUID. The corollary is that when we set the container id, the event should beAUDIT_CONTAINERIDorAUDIT_CONTAINER_ID.During syscall events, the path info is returned in a a record simply called
AUDIT_PATH, cwd info is returned inAUDIT_CWD. So, rather than calling the record that gets attached to everythingAUDIT_CONTAINER_INFO, how about simplyAUDIT_CONTAINER.Quoted 253 lines
The "op" field indicates an initial set. The "pid" to "ses" fields are the orchestrator while the "opid" field is the object's PID, the process being "contained". Old and new container ID values are given in the "contid" fields, while res indicates its success.
It is not permitted to self-set, unset or re-set the container ID. A child inherits its parent's container ID, but then can be set only once after.
See: https://github.com/linux-audit/audit-kernel/issues/32
Signed-off-by Richard Guy Briggs <[email protected]>---
fs/proc/base.c | 37 ++++++++++++++++++++ include/linux/audit.h | 16 +++++++++ include/linux/init_task.h | 4 ++- include/linux/sched.h | 1 + include/uapi/linux/audit.h | 2 ++ kernel/auditsc.c | 84++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 143 insertions(+), 1 deletion(-)
fs/proc/base.c +35
-0@@ -1299,6 +1299,41 @@ static ssize_t proc_sessionid_read(struct file * file, char __user * buf, .read = proc_sessionid_read, .llseek = generic_file_llseek, }; + +static ssize_t proc_containerid_write (struct file *file,const char __user *buf, +size_t count,loff_t *ppos) +{ +struct inode *inode =file_inode (file); +u64 containerid; +int rv; +struct task_struct *task =get_proc_task (inode); + +if (!task) +return -ESRCH ; +if (*ppos !=0 ) { +/* No partial writes. */ +put_task_struct (task); +return -EINVAL ; + } + + rv =kstrtou64_from_user (buf, count,10 , &containerid); +if (rv <0 ) { +put_task_struct (task); +return rv; + } + + rv =audit_set_containerid (task, containerid); +put_task_struct (task); +if (rv <0 ) +return rv; +return count; +} + +static const struct file_operations proc_containerid_operations = { + .write = proc_containerid_write, + .llseek = generic_file_llseek, +}; +#endif #ifdef
CONFIG_FAULT_INJECTIONfs/proc/base.c +1
-0@@ -2961,6 +2996,7 @@ static int proc_pid_patch_state(struct seq_file *m, struct pid_namespace *ns, #ifdef CONFIG_AUDITSYSCALLREG ("loginuid" ,S_IWUSR |S_IRUGO , proc_loginuid_operations),REG ("sessionid" ,S_IRUGO , proc_sessionid_operations), +REG ("containerid" ,S_IWUSR , proc_containerid_operations), #endif #ifdef CONFIG_FAULT_INJECTION REG("make-it-fail", S_IRUGO|S_IWUSR,
proc_fault_inject_operations), @@ -3355,6 +3391,7 @@ static intproc_tid_comm_permission(struct inode *inode, int mask)#ifdefCONFIG_AUDITSYSCALLREG("loginuid", S_IWUSR|S_IRUGO, proc_loginuid_operations),REG("sessionid", S_IRUGO, proc_sessionid_operations),
+REG("containerid", S_IWUSR, proc_containerid_operations),
#endif
#ifdefCONFIG_FAULT_INJECTIONREG("make-it-fail", S_IRUGO|S_IWUSR, proc_fault_inject_operations), diff --gita/include/linux/audit.hb/include/linux/audit.hindex af410d9..fe4ba3f 100644include/linux/audit.h +1
-0@@ -29,6 +29,7 @@#define AUDIT_INO_UNSET ((unsigned long)-1)#define AUDIT_DEV_UNSET ((dev_t)-1) +#define INVALID_CID AUDIT_CID_UNSETstruct audit_sig_info {uid_t uid;@@ -321,6 +322,7 @@ static inline void audit_ptrace(struct
task_struct*t) extern intauditsc_get_stamp(struct audit_context *ctx, struct timespec64 *t, unsigned int *serial); extern intaudit_set_loginuid(kuid_t loginuid);
+extern intaudit_set_containerid(struct task_struct *tsk, u64 containerid);
static inlinekuid_taudit_get_loginuid(struct task_struct *tsk){include/linux/audit.h +5
-0@@ -332,6 +334,11 @@ static inline unsigned int audit_get_sessionid(struct task_struct *tsk) return tsk->sessionid; } +static inline u64 audit_get_containerid (struct task_struct *tsk) +{ +return tsk->containerid; +} +extern void __audit_ipc_obj (struct kern_ipc_perm *ipcp); extern void __audit_ipc_set_perm(unsigned long qbytes, uid_t uid,
gid_tgid,umode_tmode); extern void__audit_bprm(struct linux_binprm *bprm); @@ -517,6 +524,10 @@ static inline unsigned intaudit_get_sessionid(struct task_struct *tsk){
return -1;
}include/linux/audit.h +4
-0+static inline kuid_t audit_get_containerid (struct task_struct *tsk) +{ +return INVALID_CID ; +}static inline void
audit_ipc_obj(struct kern_ipc_perm *ipcp){ }
static inline void audit_ipc_set_perm(unsigned long qbytes,uid_tuid, @@ -581,6 +592,11 @@ static inline boolaudit_loginuid_set(struct task_struct *tsk)return uid_valid(audit_get_loginuid(tsk)); }include/linux/audit.h +5
-0+static inline bool audit_containerid_set (struct task_struct *tsk) +{ +return audit_get_containerid (tsk) !=INVALID_CID ; +} +static inline void
audit_log_string(struct audit_buffer *ab, const char *buf){audit_log_n_string(ab, buf, strlen(buf));include/linux/init_task.h +3
-1@@ -18,6 +18,7 @@#include <linux/sched/rt.h> #include <linux/livepatch.h> #include <linux/mm_types.h> +#include <linux/audit.h> #include <asm/thread_info.h> @@ -120,7 +121,8 @@#ifdef CONFIG_AUDITSYSCALL #define INIT_IDS \ .loginuid = INVALID_UID, \ - .sessionid = (unsigned int)-1, + .sessionid = (unsigned int)-1, \ + .containerid = INVALID_CID,#else #define INIT_IDS #endif include/linux/sched.h +1
-0@@ -796,6 +796,7 @@ struct task_struct {#ifdef CONFIG_AUDITSYSCALL kuid_t loginuid;unsigned int sessionid; +u64 containerid;#endif struct seccomp seccomp;include/uapi/linux/audit.h +0
-0@@ -71,6 +71,7 @@#define AUDIT_TTY_SET 1017/* Set TTY auditing status */ #define
AUDIT_SET_FEATURE1018 /* Turn an
audit feature on or off */ #defineAUDIT_GET_FEATURE
1019 /* Get which features are enabled */ +#defineAUDIT_CONTAINER1020 /* Define the container id
and information */ #defineAUDIT_FIRST_USER_MSG1100 /*
Userspace messages mostly uninteresting to kernel */ #defineAUDIT_USER_AVC1107 /* We filter this
differently */ @@ -465,6 +466,7 @@ structaudit_tty_status{ };#define
AUDIT_UID_UNSET(unsigned int)-1
+#defineAUDIT_CID_UNSET((u64)-1)/*
audit_rule_datasupports filter rules with both integer and string
* fields. It corresponds withAUDIT_ADD_RULE,AUDIT_DEL_RULEandkernel/auditsc.c +17
-0@@ -2073,6 +2073,90 @@ int audit_set_loginuid(kuid_t loginuid)return rc; } +static int audit_set_containerid_perm (struct task_struct *task,u64 containerid) +{ +struct task_struct *parent; +u64 pcontainerid, ccontainerid; + +/* Don't allow to set our own containerid */ +if (current == task) +return -EPERM ; +/* Don't allow the containerid to be unset */ +if (!cid_valid (containerid)) +return -EINVAL ; +/* if we don't have caps, reject */ +if (!capable (CAP_AUDIT_CONTROL )) +return -EPERM ; +/* if containerid is unset, allow */ +if (!audit_containerid_set (task)) +return 0 ; +/* it is already set, and not inherited from the parent, reject */
kernel/auditsc.c +13
-0+ ccontainerid =audit_get_containerid (task); +rcu_read_lock (); + parent =rcu_dereference (task->real_parent); +rcu_read_unlock (); +task_lock (parent); + pcontainerid =audit_get_containerid (parent); +task_unlock (parent); +if (ccontainerid != pcontainerid) +return -EPERM ; +return 0 ; +} + +static void audit_log_set_containerid(struct task_struct *task, u64oldcontainerid,
kernel/auditsc.c +17
-0+ u64 containerid, int rc) +{ +struct audit_buffer *ab; +uid_t uid; +struct tty_struct *tty; + +if (!audit_enabled) +return ; + + ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_CONTAINER ); +if (!ab) +return ; + + uid =from_kuid (&init_user_ns,task_uid (current)); + tty =audit_get_tty (current); + + audit_log_format(ab, "op=set pid=%d uid=%u",Quoted 8 lines
Quoted 4 lines
task_tgid_nr(current), uid);kernel/auditsc.c +2
-0+audit_log_task_context (ab); + audit_log_format(ab, " auid=%u tty=%s ses=%u opid=%dold-contid=%llu contid=%llu res=%d",
The preferred ordering would be: op, opid, old-contid, contid, pid, uid, tty, ses, subj, comm, exe, res. This groups the searchable fields together using the most common ordering so that parsing is simple.
Quoted 3 lines
Where would you like auid? It appears that just before uid would be the right place, if not in place of uid, but this is just a guess since it isn't consistent.
Just after the uid is the proper place. The most common sequence is:
pid, uid, auid, tty, session, subject context, comm, exe.
Thanks,
-Steve
Re: [RFC PATCH ghak32 V2 01/13] audit: add container id
Quoted 301 lines · Steve Grubb
Quoted 300 lines · EDT Richard Guy Briggs
Re: [RFC PATCH ghak32 V2 01/13] audit: add container id
From: Richard Guy Briggs <[email protected]>
To: Me
CC: [email protected], [email protected], LKML
<[email protected]>, [email protected], ... Date: 6/1/18
5:04 PMQuoted 290 lines · Steve Grubb
On Fri, 16 Mar 2018 05:00:28 -0400
Quoted 8 lines · Richard Guy Briggs
Implement the proc fs write to set the audit container ID of a process, emitting an
AUDIT_CONTAINERrecord to document the event.This is a write from the container orchestrator task to a proc entry of the form
/proc/PID/containeridwhere PID is the process ID of the newly created task that is to become the first task in a container, or an additional task added to a container.Quoted 7 lines
The write expects up to a u64 value (unset: 18446744073709551615).
This will produce a record such as this:
type=CONTAINER msg=audit(1519903238.968:261): op=set pid=596 uid=0 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 auid=0 tty=pts0 ses=1 opid=596 old-contid=18446744073709551615 contid=123455 res=0The was one thing I was wondering about. Currently when we set the loginuid, the record is
AUDIT_LOGINUID. The corollary is that when we set the container id, the event should beAUDIT_CONTAINERIDorAUDIT_CONTAINER_ID.During syscall events, the path info is returned in a a record simply called
AUDIT_PATH, cwd info is returned inAUDIT_CWD. So, rather than calling the record that gets attached to everythingAUDIT_CONTAINER_INFO, how about simplyAUDIT_CONTAINER.Quoted 256 lines
The "op" field indicates an initial set. The "pid" to "ses" fields are the orchestrator while the "opid" field is the object's PID, the process being "contained". Old and new container ID values are given in the "contid" fields, while res indicates its success.
It is not permitted to self-set, unset or re-set the container ID. A child inherits its parent's container ID, but then can be set only once after.
See: https://github.com/linux-audit/audit-kernel/issues/32
Signed-off-by Richard Guy Briggs <[email protected]>---
fs/proc/base.c | 37 ++++++++++++++++++++ include/linux/audit.h | 16 +++++++++ include/linux/init_task.h | 4 ++- include/linux/sched.h | 1 + include/uapi/linux/audit.h | 2 ++ kernel/auditsc.c | 84++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 143 insertions(+), 1 deletion(-)
fs/proc/base.c +35
-0@@ -1299,6 +1299,41 @@ static ssize_t proc_sessionid_read(struct file * file, char __user * buf, .read = proc_sessionid_read, .llseek = generic_file_llseek, }; + +static ssize_t proc_containerid_write (struct file *file,const char __user *buf, +size_t count,loff_t *ppos) +{ +struct inode *inode =file_inode (file); +u64 containerid; +int rv; +struct task_struct *task =get_proc_task (inode); + +if (!task) +return -ESRCH ; +if (*ppos !=0 ) { +/* No partial writes. */ +put_task_struct (task); +return -EINVAL ; + } + + rv =kstrtou64_from_user (buf, count,10 , &containerid); +if (rv <0 ) { +put_task_struct (task); +return rv; + } + + rv =audit_set_containerid (task, containerid); +put_task_struct (task); +if (rv <0 ) +return rv; +return count; +} + +static const struct file_operations proc_containerid_operations = { + .write = proc_containerid_write, + .llseek = generic_file_llseek, +}; +#endif #ifdef
CONFIG_FAULT_INJECTIONfs/proc/base.c +1
-0@@ -2961,6 +2996,7 @@ static int proc_pid_patch_state(struct seq_file *m, struct pid_namespace *ns, #ifdef CONFIG_AUDITSYSCALLREG ("loginuid" ,S_IWUSR |S_IRUGO , proc_loginuid_operations),REG ("sessionid" ,S_IRUGO , proc_sessionid_operations), +REG ("containerid" ,S_IWUSR , proc_containerid_operations), #endif #ifdef CONFIG_FAULT_INJECTION REG("make-it-fail", S_IRUGO|S_IWUSR,
proc_fault_inject_operations), @@ -3355,6 +3391,7 @@ static intproc_tid_comm_permission(struct inode *inode, int mask)#ifdefCONFIG_AUDITSYSCALLREG("loginuid", S_IWUSR|S_IRUGO, proc_loginuid_operations),REG("sessionid", S_IRUGO, proc_sessionid_operations),
+REG("containerid", S_IWUSR, proc_containerid_operations),
#endif
#ifdefCONFIG_FAULT_INJECTIONREG("make-it-fail", S_IRUGO|S_IWUSR, proc_fault_inject_operations), diff --gita/include/linux/audit.hb/include/linux/audit.hindex af410d9..fe4ba3f 100644include/linux/audit.h +1
-0@@ -29,6 +29,7 @@#define AUDIT_INO_UNSET ((unsigned long)-1)#define AUDIT_DEV_UNSET ((dev_t)-1) +#define INVALID_CID AUDIT_CID_UNSETstruct audit_sig_info {uid_t uid;@@ -321,6 +322,7 @@ static inline void audit_ptrace(struct
task_struct*t) extern intauditsc_get_stamp(struct audit_context *ctx, struct timespec64 *t, unsigned int *serial); extern intaudit_set_loginuid(kuid_t loginuid);
+extern intaudit_set_containerid(struct task_struct *tsk, u64 containerid);
static inlinekuid_taudit_get_loginuid(struct task_struct *tsk){include/linux/audit.h +5
-0@@ -332,6 +334,11 @@ static inline unsigned int audit_get_sessionid(struct task_struct *tsk) return tsk->sessionid; } +static inline u64 audit_get_containerid (struct task_struct *tsk) +{ +return tsk->containerid; +} +extern void __audit_ipc_obj (struct kern_ipc_perm *ipcp); extern void __audit_ipc_set_perm(unsigned long qbytes, uid_t uid,
gid_tgid,umode_tmode); extern void__audit_bprm(struct linux_binprm *bprm); @@ -517,6 +524,10 @@ static inline unsigned intaudit_get_sessionid(struct task_struct *tsk){
return -1;
}include/linux/audit.h +4
-0+static inline kuid_t audit_get_containerid (struct task_struct *tsk) +{ +return INVALID_CID ; +}static inline void
audit_ipc_obj(struct kern_ipc_perm *ipcp){ }
static inline void audit_ipc_set_perm(unsigned long qbytes,uid_tuid, @@ -581,6 +592,11 @@ static inline boolaudit_loginuid_set(struct task_struct *tsk)return uid_valid(audit_get_loginuid(tsk)); }include/linux/audit.h +5
-0+static inline bool audit_containerid_set (struct task_struct *tsk) +{ +return audit_get_containerid (tsk) !=INVALID_CID ; +} +static inline void
audit_log_string(struct audit_buffer *ab, const char *buf){audit_log_n_string(ab, buf, strlen(buf));include/linux/init_task.h +3
-1@@ -18,6 +18,7 @@#include <linux/sched/rt.h> #include <linux/livepatch.h> #include <linux/mm_types.h> +#include <linux/audit.h> #include <asm/thread_info.h> @@ -120,7 +121,8 @@#ifdef CONFIG_AUDITSYSCALL #define INIT_IDS \ .loginuid = INVALID_UID, \ - .sessionid = (unsigned int)-1, + .sessionid = (unsigned int)-1, \ + .containerid = INVALID_CID,#else #define INIT_IDS #endif include/linux/sched.h +1
-0@@ -796,6 +796,7 @@ struct task_struct {#ifdef CONFIG_AUDITSYSCALL kuid_t loginuid;unsigned int sessionid; +u64 containerid;#endif struct seccomp seccomp;include/uapi/linux/audit.h +0
-0@@ -71,6 +71,7 @@#define AUDIT_TTY_SET 1017/* Set TTY auditing status */ #define
AUDIT_SET_FEATURE1018 /* Turn an
audit feature on or off */ #defineAUDIT_GET_FEATURE
1019 /* Get which features are enabled */ +#defineAUDIT_CONTAINER1020 /* Define the container id
and information */ #defineAUDIT_FIRST_USER_MSG1100 /*
Userspace messages mostly uninteresting to kernel */ #defineAUDIT_USER_AVC1107 /* We filter this
differently */ @@ -465,6 +466,7 @@ structaudit_tty_status{ };#define
AUDIT_UID_UNSET(unsigned int)-1
+#defineAUDIT_CID_UNSET((u64)-1)/*
audit_rule_datasupports filter rules with both integer and string
* fields. It corresponds withAUDIT_ADD_RULE,AUDIT_DEL_RULEandkernel/auditsc.c +17
-0@@ -2073,6 +2073,90 @@ int audit_set_loginuid(kuid_t loginuid)return rc; } +static int audit_set_containerid_perm (struct task_struct *task,u64 containerid) +{ +struct task_struct *parent; +u64 pcontainerid, ccontainerid; + +/* Don't allow to set our own containerid */ +if (current == task) +return -EPERM ; +/* Don't allow the containerid to be unset */ +if (!cid_valid (containerid)) +return -EINVAL ; +/* if we don't have caps, reject */ +if (!capable (CAP_AUDIT_CONTROL )) +return -EPERM ; +/* if containerid is unset, allow */ +if (!audit_containerid_set (task)) +return 0 ; +/* it is already set, and not inherited from the parent, reject */
kernel/auditsc.c +13
-0+ ccontainerid =audit_get_containerid (task); +rcu_read_lock (); + parent =rcu_dereference (task->real_parent); +rcu_read_unlock (); +task_lock (parent); + pcontainerid =audit_get_containerid (parent); +task_unlock (parent); +if (ccontainerid != pcontainerid) +return -EPERM ; +return 0 ; +} + +static void audit_log_set_containerid(struct task_struct *task, u64oldcontainerid,
kernel/auditsc.c +17
-0+ u64 containerid, int rc) +{ +struct audit_buffer *ab; +uid_t uid; +struct tty_struct *tty; + +if (!audit_enabled) +return ; + + ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_CONTAINER ); +if (!ab) +return ; + + uid =from_kuid (&init_user_ns,task_uid (current)); + tty =audit_get_tty (current); + + audit_log_format(ab, "op=set pid=%d uid=%u",
task_tgid_nr(current), uid);kernel/auditsc.c +2
-0+audit_log_task_context (ab); + audit_log_format(ab, " auid=%u tty=%s ses=%u opid=%dQuoted 1 line
old-contid=%llu contid=%llu res=%d",
The preferred ordering would be: op, opid, old-contid, contid, pid, uid, tty, ses, subj, comm, exe, res. This groups the searchable fields together using the most common ordering so that parsing is simple.
Quoted 7 lines
Quoted 3 lines
Where would you like auid? It appears that just before uid would be the right place, if not in place of uid, but this is just a guess since it isn't consistent.
Just after the uid is the proper place. The most common sequence is:
pid, uid, auid, tty, session, subject context, comm, exe.
Not according to:
http://people.redhat.com/sgrubb/audit/record-fields.html
Quoted 1 line
-Steve
- RGB
--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635
Re: [RFC PATCH ghak32 V2 01/13] audit: add container id
Quoted 307 lines · Richard Guy Briggs
Quoted 306 lines · Steve Grubb
Quoted 303 lines · EDT Richard Guy Briggs
Re: [RFC PATCH ghak32 V2 01/13] audit: add container id
From: Richard Guy Briggs <[email protected]>
To: Me
CC: [email protected], [email protected], LKML
<[email protected]>, [email protected], ... Date: 6/1/18
5:04 PMQuoted 282 lines · Steve Grubb
On Fri, 16 Mar 2018 05:00:28 -0400
Quoted 8 lines · Richard Guy Briggs
Implement the proc fs write to set the audit container ID of a process, emitting an
AUDIT_CONTAINERrecord to document the event.This is a write from the container orchestrator task to a proc entry of the form
/proc/PID/containeridwhere PID is the process ID of the newly created task that is to become the first task in a container, or an additional task added to a container.Quoted 7 lines
The write expects up to a u64 value (unset: 18446744073709551615).
This will produce a record such as this:
type=CONTAINER msg=audit(1519903238.968:261): op=set pid=596 uid=0 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 auid=0 tty=pts0 ses=1 opid=596 old-contid=18446744073709551615 contid=123455 res=0The was one thing I was wondering about. Currently when we set the loginuid, the record is
AUDIT_LOGINUID. The corollary is that when we set the container id, the event should beAUDIT_CONTAINERIDorAUDIT_CONTAINER_ID.During syscall events, the path info is returned in a a record simply called
AUDIT_PATH, cwd info is returned inAUDIT_CWD. So, rather than calling the record that gets attached to everythingAUDIT_CONTAINER_INFO, how about simplyAUDIT_CONTAINER.Quoted 253 lines
The "op" field indicates an initial set. The "pid" to "ses" fields are the orchestrator while the "opid" field is the object's PID, the process being "contained". Old and new container ID values are given in the "contid" fields, while res indicates its success.
It is not permitted to self-set, unset or re-set the container ID. A child inherits its parent's container ID, but then can be set only once after.
See: https://github.com/linux-audit/audit-kernel/issues/32
Signed-off-by Richard Guy Briggs <[email protected]>---
fs/proc/base.c | 37 ++++++++++++++++++++ include/linux/audit.h | 16 +++++++++ include/linux/init_task.h | 4 ++- include/linux/sched.h | 1 + include/uapi/linux/audit.h | 2 ++ kernel/auditsc.c | 84++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 143 insertions(+), 1 deletion(-)
fs/proc/base.c +35
-0@@ -1299,6 +1299,41 @@ static ssize_t proc_sessionid_read(struct file * file, char __user * buf, .read = proc_sessionid_read, .llseek = generic_file_llseek, }; + +static ssize_t proc_containerid_write (struct file *file,const char __user *buf, +size_t count,loff_t *ppos) +{ +struct inode *inode =file_inode (file); +u64 containerid; +int rv; +struct task_struct *task =get_proc_task (inode); + +if (!task) +return -ESRCH ; +if (*ppos !=0 ) { +/* No partial writes. */ +put_task_struct (task); +return -EINVAL ; + } + + rv =kstrtou64_from_user (buf, count,10 , &containerid); +if (rv <0 ) { +put_task_struct (task); +return rv; + } + + rv =audit_set_containerid (task, containerid); +put_task_struct (task); +if (rv <0 ) +return rv; +return count; +} + +static const struct file_operations proc_containerid_operations = { + .write = proc_containerid_write, + .llseek = generic_file_llseek, +}; +#endif #ifdef
CONFIG_FAULT_INJECTIONfs/proc/base.c +1
-0@@ -2961,6 +2996,7 @@ static int proc_pid_patch_state(struct seq_file *m, struct pid_namespace *ns, #ifdef CONFIG_AUDITSYSCALLREG ("loginuid" ,S_IWUSR |S_IRUGO , proc_loginuid_operations),REG ("sessionid" ,S_IRUGO , proc_sessionid_operations), +REG ("containerid" ,S_IWUSR , proc_containerid_operations), #endif #ifdef CONFIG_FAULT_INJECTION REG("make-it-fail", S_IRUGO|S_IWUSR,
proc_fault_inject_operations), @@ -3355,6 +3391,7 @@ static intproc_tid_comm_permission(struct inode *inode, int mask)#ifdefCONFIG_AUDITSYSCALLREG("loginuid", S_IWUSR|S_IRUGO, proc_loginuid_operations),REG("sessionid", S_IRUGO, proc_sessionid_operations),
+REG("containerid", S_IWUSR, proc_containerid_operations),
#endif
#ifdefCONFIG_FAULT_INJECTIONREG("make-it-fail", S_IRUGO|S_IWUSR, proc_fault_inject_operations), diff --gita/include/linux/audit.hb/include/linux/audit.hindex af410d9..fe4ba3f 100644include/linux/audit.h +1
-0@@ -29,6 +29,7 @@#define AUDIT_INO_UNSET ((unsigned long)-1)#define AUDIT_DEV_UNSET ((dev_t)-1) +#define INVALID_CID AUDIT_CID_UNSETstruct audit_sig_info {uid_t uid;@@ -321,6 +322,7 @@ static inline void audit_ptrace(struct
task_struct*t) extern intauditsc_get_stamp(struct audit_context *ctx, struct timespec64 *t, unsigned int *serial); extern intaudit_set_loginuid(kuid_t loginuid);
+extern intaudit_set_containerid(struct task_struct *tsk, u64 containerid);
static inlinekuid_taudit_get_loginuid(struct task_struct *tsk){include/linux/audit.h +5
-0@@ -332,6 +334,11 @@ static inline unsigned int audit_get_sessionid(struct task_struct *tsk) return tsk->sessionid; } +static inline u64 audit_get_containerid (struct task_struct *tsk) +{ +return tsk->containerid; +} +extern void __audit_ipc_obj (struct kern_ipc_perm *ipcp); extern void __audit_ipc_set_perm(unsigned long qbytes, uid_t uid,
gid_tgid,umode_tmode); extern void__audit_bprm(struct linux_binprm *bprm); @@ -517,6 +524,10 @@ static inline unsigned intaudit_get_sessionid(struct task_struct *tsk){
return -1;
}include/linux/audit.h +4
-0+static inline kuid_t audit_get_containerid (struct task_struct *tsk) +{ +return INVALID_CID ; +}static inline void
audit_ipc_obj(struct kern_ipc_perm *ipcp){ }
static inline void audit_ipc_set_perm(unsigned long qbytes,uid_tuid, @@ -581,6 +592,11 @@ static inline boolaudit_loginuid_set(struct task_struct *tsk)return uid_valid(audit_get_loginuid(tsk)); }include/linux/audit.h +5
-0+static inline bool audit_containerid_set (struct task_struct *tsk) +{ +return audit_get_containerid (tsk) !=INVALID_CID ; +} +static inline void
audit_log_string(struct audit_buffer *ab, const char *buf){audit_log_n_string(ab, buf, strlen(buf));include/linux/init_task.h +3
-1@@ -18,6 +18,7 @@#include <linux/sched/rt.h> #include <linux/livepatch.h> #include <linux/mm_types.h> +#include <linux/audit.h> #include <asm/thread_info.h> @@ -120,7 +121,8 @@#ifdef CONFIG_AUDITSYSCALL #define INIT_IDS \ .loginuid = INVALID_UID, \ - .sessionid = (unsigned int)-1, + .sessionid = (unsigned int)-1, \ + .containerid = INVALID_CID,#else #define INIT_IDS #endif include/linux/sched.h +1
-0@@ -796,6 +796,7 @@ struct task_struct {#ifdef CONFIG_AUDITSYSCALL kuid_t loginuid;unsigned int sessionid; +u64 containerid;#endif struct seccomp seccomp;include/uapi/linux/audit.h +0
-0@@ -71,6 +71,7 @@#define AUDIT_TTY_SET 1017/* Set TTY auditing status */ #define
AUDIT_SET_FEATURE1018 /* Turn an
audit feature on or off */ #defineAUDIT_GET_FEATURE
1019 /* Get which features are enabled */ +#defineAUDIT_CONTAINER1020 /* Define the container id
and information */ #defineAUDIT_FIRST_USER_MSG1100 /*
Userspace messages mostly uninteresting to kernel */ #defineAUDIT_USER_AVC1107 /* We filter this
differently */ @@ -465,6 +466,7 @@ structaudit_tty_status{ };#define
AUDIT_UID_UNSET(unsigned int)-1
+#defineAUDIT_CID_UNSET((u64)-1)/*
audit_rule_datasupports filter rules with both integer and string
* fields. It corresponds withAUDIT_ADD_RULE,AUDIT_DEL_RULEandkernel/auditsc.c +17
-0@@ -2073,6 +2073,90 @@ int audit_set_loginuid(kuid_t loginuid)return rc; } +static int audit_set_containerid_perm (struct task_struct *task,u64 containerid) +{ +struct task_struct *parent; +u64 pcontainerid, ccontainerid; + +/* Don't allow to set our own containerid */ +if (current == task) +return -EPERM ; +/* Don't allow the containerid to be unset */ +if (!cid_valid (containerid)) +return -EINVAL ; +/* if we don't have caps, reject */ +if (!capable (CAP_AUDIT_CONTROL )) +return -EPERM ; +/* if containerid is unset, allow */ +if (!audit_containerid_set (task)) +return 0 ; +/* it is already set, and not inherited from the parent, reject */
kernel/auditsc.c +13
-0+ ccontainerid =audit_get_containerid (task); +rcu_read_lock (); + parent =rcu_dereference (task->real_parent); +rcu_read_unlock (); +task_lock (parent); + pcontainerid =audit_get_containerid (parent); +task_unlock (parent); +if (ccontainerid != pcontainerid) +return -EPERM ; +return 0 ; +} + +static void audit_log_set_containerid(struct task_struct *task, u64oldcontainerid,
kernel/auditsc.c +17
-0+ u64 containerid, int rc) +{ +struct audit_buffer *ab; +uid_t uid; +struct tty_struct *tty; + +if (!audit_enabled) +return ; + + ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_CONTAINER ); +if (!ab) +return ; + + uid =from_kuid (&init_user_ns,task_uid (current)); + tty =audit_get_tty (current); + + audit_log_format(ab, "op=set pid=%d uid=%u",Quoted 8 lines
Quoted 4 lines
task_tgid_nr(current), uid);kernel/auditsc.c +2
-0+audit_log_task_context (ab); + audit_log_format(ab, " auid=%u tty=%s ses=%u opid=%dold-contid=%llu contid=%llu res=%d",
The preferred ordering would be: op, opid, old-contid, contid, pid, uid, tty, ses, subj, comm, exe, res. This groups the searchable fields together using the most common ordering so that parsing is simple.
Where would you like auid? It appears that just before uid would be the right place, if not in place of uid, but this is just a guess since it isn't consistent.
Quoted 5 lines
Quoted 2 lines
Just after the uid is the proper place. The most common sequence is:
pid, uid, auid, tty, session, subject context, comm, exe.Not according to:
http://people.redhat.com/sgrubb/audit/record-fields.html
Ok, maybe I spoke a bit quickly... Most of the inital ones I saw were in the reverse order, but there is a clump about 3/4 of the way down which includes VIRT and USER events.
Quoted 3 lines
Quoted 1 line
-Steve
- RGB
- RGB
--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635