audit: implement container id
Subsystems (10)
Re: [RFC PATCH ghak32 V2 09/13] audit: add containerid support for config/feature/user records
In reply to Paul MooreQuoted 25 lines · Paul Moore
Quoted 14 lines · Richard Guy Briggs
Add container ID auxiliary records to configuration change, feature set change and user generated standalone records.
Signed-off-by Richard Guy Briggs <[email protected]>--- kernel/audit.c | 50 ++++++++++++++++++++++++++++++++++++++++---------- kernel/auditfilter.c | 5 ++++- 2 files changed, 44 insertions(+), 11 deletions(-)kernel/audit.c +0
-0kernel/audit.c static int audit_log_config_change(char *function_name, u32 new, u32 old, · line 403
Quoted 4 lines
kernel/audit.c +1
-0@@ -400,8 +400,9 @@ static int audit_log_config_change(char *function_name, u32 new, u32 old, {struct audit_buffer *ab;int rc =0 ; +struct audit_context *context =audit_alloc_local ();We should be able to use
current->audit_contexthere right? If we can't for every caller, perhaps we pass anaudit_contextas an argument and only allocate a local context when the passedaudit_contextis NULL.
Quoted 2 lines
Also, if you're not comfortable always using current, just pass the
audit_contextas you do withaudit_log_common_recv_msg().
As mentioned in the tree/watch/mark patch, this is all obsoleted by making the AUDIT_CONFIG_CHANGE record a SYSCALL auxiliary record. This review would have been more helpful a month and a half ago.
Quoted 203 lines
Quoted 34 lines
kernel/audit.c +6
-3- ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_CONFIG_CHANGE ); + ab =audit_log_start (context,GFP_KERNEL ,AUDIT_CONFIG_CHANGE );if (unlikely (!ab))return rc;audit_log_format (ab,"%s=%u old=%u" , function_name, new, old);@@ -411,6 +412,8 @@ static int audit_log_config_change(char *function_name, u32 new, u32 old, allow_changes =0 ;/* Something weird, deny request */ audit_log_format (ab," res=%d" , allow_changes);audit_log_end (ab); +audit_log_container_info (context,"config" ,audit_get_containerid (current)); +audit_free_context (context);return rc; }@@ -1058,7 +1061,8 @@ static int audit_netlink_ok(struct sk_buff *skb, u16 msg_type)return err; } -static void audit_log_common_recv_msg (struct audit_buffer **ab,u16 msg_type) +static void audit_log_common_recv_msg (struct audit_context *context, +struct audit_buffer **ab,u16 msg_type) {uid_t uid =from_kuid (&init_user_ns,current_uid ());pid_t pid =task_tgid_nr (current);@@ -1068,7 +1072,7 @@ static void audit_log_common_recv_msg(struct audit_buffer **ab, u16 msg_type)return ; } - *ab =audit_log_start (NULL ,GFP_KERNEL , msg_type); + *ab =audit_log_start (context,GFP_KERNEL , msg_type);if (unlikely (!*ab))return ;audit_log_format (*ab,"pid=%d uid=%u" , pid, uid);kernel/audit.c static void audit_log_feature_change(int which, u32 old_feature, u32 new_feature · line 1104
Quoted 4 lines
kernel/audit.c +1
-0@@ -1097,11 +1101,12 @@ static void audit_log_feature_change(int which, u32 old_feature, u32 new_feature u32 old_lock, u32 new_lock, int res) { struct audit_buffer *ab; +struct audit_context *context =audit_alloc_local ();So I know based on the other patch we are currently discussing that we can use current here ...
Quoted 18 lines
kernel/audit.c +3
-1if (audit_enabled ==AUDIT_OFF )return ; - ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_FEATURE_CHANGE ); + ab =audit_log_start (context,GFP_KERNEL ,AUDIT_FEATURE_CHANGE );if (!ab)return ;audit_log_task_info (ab, current);@@ -1109,6 +1114,8 @@ static void audit_log_feature_change(int which, u32 old_feature, u32 new_feature audit_feature_names[which], !!old_feature, !!new_feature, !!old_lock, !!new_lock, res);audit_log_end (ab); +audit_log_container_info (context,"feature" ,audit_get_containerid (current)); +audit_free_context (context); }static int audit_set_feature (struct sk_buff *skb)kernel/audit.c static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) · line 1347
Quoted 4 lines
kernel/audit.c +1
-0@@ -1337,13 +1344,15 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) err =audit_filter (msg_type,AUDIT_FILTER_USER );if (err ==1 ) {/* match or error */ +struct audit_context *context =audit_alloc_local ();I'm pretty sure we can use current here.
Quoted 22 lines
kernel/audit.c +4
-1err =0 ;if (msg_type ==AUDIT_USER_TTY ) { err =tty_audit_push ();if (err)break ; } -audit_log_common_recv_msg (&ab, msg_type); +audit_log_common_recv_msg (context, &ab, msg_type);if (msg_type !=AUDIT_USER_TTY ) audit_log_format(ab, " msg='%.*s'", AUDIT_MESSAGE_TEXT_MAX,@@ -1359,6 +1368,9 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)audit_log_n_untrustedstring (ab, data, size); }audit_log_end (ab); +audit_log_container_info (context,"user" , +audit_get_containerid (current)); +audit_free_context (context); }break ;case AUDIT_ADD_RULE :kernel/audit.c static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) · line 1381
Quoted 5 lines
kernel/audit.c +1
-1@@ -1366,9 +1378,14 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)if (nlmsg_len (nlh) <sizeof (struct audit_rule_data ))return -EINVAL ;if (audit_enabled ==AUDIT_LOCKED ) { -audit_log_common_recv_msg (&ab,AUDIT_CONFIG_CHANGE ); +struct audit_context *context =audit_alloc_local ();Pretty sure current can be used here too. In fact I think everywhere where we are processing commands from netlink we can use current as I believe the entire netlink stack is processed in the context of the caller.
Quoted 10 lines
kernel/audit.c +4
-0+audit_log_common_recv_msg (context, &ab,AUDIT_CONFIG_CHANGE );audit_log_format (ab," audit_enabled=%d res=0" , audit_enabled);audit_log_end (ab); +audit_log_container_info (context,"config" , +audit_get_containerid (current)); +audit_free_context (context);return -EPERM ; } err =audit_rule_change (msg_type, seq, data,nlmsg_len (nlh));kernel/audit.c static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) · line 1397
Quoted 6 lines
kernel/audit.c +2
-1@@ -1376,17 +1393,23 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)case AUDIT_LIST_RULES : err =audit_list_rules_send (skb, seq);break ; -case AUDIT_TRIM : +case AUDIT_TRIM : { +struct audit_context *context =audit_alloc_local ();Same.
Quoted 6 lines
kernel/audit.c +2
-1audit_trim_trees (); -audit_log_common_recv_msg (&ab,AUDIT_CONFIG_CHANGE ); +audit_log_common_recv_msg (context, &ab,AUDIT_CONFIG_CHANGE );audit_log_format (ab," op=trim res=1" );audit_log_end (ab); + audit_log_container_info(context, "config",kernel/audit.c static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) · line 1412
Quoted 10 lines
kernel/audit.c +4
-0+ audit_get_containerid(current)); +audit_free_context (context);break ; + }case AUDIT_MAKE_EQUIV : {void *bufp = data;u32 sizes[2 ];size_t msglen =nlmsg_len (nlh);char *old, *new; +struct audit_context *context =audit_alloc_local ();Same.
Quoted 22 lines
kernel/audit.c +4
-1err = -EINVAL ;if (msglen <2 *sizeof (u32))@@ -1408,7 +1431,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)/* OK, here comes... */ err =audit_tag_tree (old, new); -audit_log_common_recv_msg (&ab,AUDIT_CONFIG_CHANGE ); +audit_log_common_recv_msg (context, &ab,AUDIT_CONFIG_CHANGE );audit_log_format (ab," op=make_equiv old=" );audit_log_untrustedstring (ab, old);@@ -1418,6 +1441,9 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)audit_log_end (ab);kfree (old);kfree (new); +audit_log_container_info (context,"config" , +audit_get_containerid (current)); +audit_free_context (context);break ; }case AUDIT_SIGNAL_INFO :kernel/audit.c static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) · line 1488
Quoted 4 lines
kernel/audit.c +1
-0@@ -1459,6 +1485,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)struct audit_tty_status s, old;struct audit_buffer *ab;unsigned int t; +struct audit_context *context =audit_alloc_local ();Same.
Quoted 24 lines
kernel/audit.c +4
-1memset (&s,0 ,sizeof (s));/* guard against past and future API changes */ @@ -1477,12 +1504,15 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) old.enabled = t &AUDIT_TTY_ENABLE ; old.log_passwd = !!(t &AUDIT_TTY_LOG_PASSWD ); -audit_log_common_recv_msg (&ab,AUDIT_CONFIG_CHANGE ); +audit_log_common_recv_msg (context, &ab,AUDIT_CONFIG_CHANGE );audit_log_format (ab," op=tty_set old-enabled=%d new-enabled=%d" " old-log_passwd=%d new-log_passwd=%d res=%d" , old.enabled, s.enabled, old.log_passwd, s.log_passwd, !err);audit_log_end (ab); +audit_log_container_info (context,"config" , +audit_get_containerid (current)); +audit_free_context (context);break ; }default :kernel/auditfilter.c +0
-0kernel/auditfilter.c static void audit_log_rule_change(char *action, struct audit_krule *rule, int re · line 1115
Quoted 7 lines
kernel/auditfilter.c +1
-0@@ -1109,11 +1109,12 @@ static void audit_log_rule_change(char *action, struct audit_krule *rule, int restruct audit_buffer *ab;uid_t loginuid =from_kuid (&init_user_ns,audit_get_loginuid (current));unsigned int sessionid =audit_get_sessionid (current); +struct audit_context *context =audit_alloc_local ();if (!audit_enabled)return ;Well, first I think we should be able to get rid of the local context, but if for some reason we can't use
current->audit_contextthen do the allocation after theaudit_enabledcheck.
Quoted 16 lines
Quoted 12 lines
kernel/auditfilter.c +3
-1- ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_CONFIG_CHANGE ); + ab =audit_log_start (context,GFP_KERNEL ,AUDIT_CONFIG_CHANGE );if (!ab)return ;audit_log_format (ab,"auid=%u ses=%u" ,loginuid, sessionid);@@ -1122,6 +1123,8 @@ static void audit_log_rule_change(char *action, struct audit_krule *rule, int reaudit_log_key (ab, rule->filterkey);audit_log_format (ab," list=%d res=%d" , rule->listnr, res);audit_log_end (ab); +audit_log_container_info (context,"config" ,audit_get_containerid (current)); +audit_free_context (context); }Signature · 2 lines
paul moore www.paul-moore.com
- 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 09/13] audit: add containerid support for config/feature/user records
Quoted 26 lines · Richard Guy Briggs
Quoted 25 lines · Paul Moore
Quoted 14 lines · Richard Guy Briggs
Add container ID auxiliary records to configuration change, feature set change and user generated standalone records.
Signed-off-by Richard Guy Briggs <[email protected]>--- kernel/audit.c | 50 ++++++++++++++++++++++++++++++++++++++++---------- kernel/auditfilter.c | 5 ++++- 2 files changed, 44 insertions(+), 11 deletions(-)kernel/audit.c +0
-0kernel/audit.c static int audit_log_config_change(char *function_name, u32 new, u32 old, · line 403
Quoted 4 lines
kernel/audit.c +1
-0@@ -400,8 +400,9 @@ static int audit_log_config_change(char *function_name, u32 new, u32 old, {struct audit_buffer *ab;int rc =0 ; +struct audit_context *context =audit_alloc_local ();We should be able to use
current->audit_contexthere right? If we can't for every caller, perhaps we pass anaudit_contextas an argument and only allocate a local context when the passedaudit_contextis NULL.
Quoted 5 lines
Quoted 2 lines
Also, if you're not comfortable always using current, just pass the
audit_contextas you do withaudit_log_common_recv_msg().As mentioned in the tree/watch/mark patch, this is all obsoleted by making the
AUDIT_CONFIG_CHANGErecord a SYSCALL auxiliary record.
You've known about my desire to connect records for quite some time.
Quoted 1 line
This review would have been more helpful a month and a half ago.
If you really want to sink to that level of discussion, better quality patches from you would have been helpful too, that is the one of the main reasons why it takes so long to review your code. Let's keep the commentary focused on the code, discussions like this aren't likely to be helpful to anyone.
Signature · 2 lines
paul moore www.paul-moore.com
A message that is not in the archive (sent off-list or not yet received): 20180419123109.ab7gsnwrbtog4tbf-bcJWsdo4jJjeVoXN4CMphl7TgLCtbB0G@public.gmane.org
Re: [RFC PATCH ghak32 V2 09/13] audit: add containerid support for config/feature/user records
Quoted 26 lines · Richard Guy Briggs
Quoted 25 lines · Paul Moore
Quoted 14 lines · Richard Guy Briggs
Add container ID auxiliary records to configuration change, feature set change and user generated standalone records.
Signed-off-by Richard Guy Briggs <[email protected]>--- kernel/audit.c | 50 ++++++++++++++++++++++++++++++++++++++++---------- kernel/auditfilter.c | 5 ++++- 2 files changed, 44 insertions(+), 11 deletions(-)kernel/audit.c +0
-0kernel/audit.c static int audit_log_config_change(char *function_name, u32 new, u32 old, · line 403
Quoted 4 lines
kernel/audit.c +1
-0@@ -400,8 +400,9 @@ static int audit_log_config_change(char *function_name, u32 new, u32 old, {struct audit_buffer *ab;int rc =0 ; +struct audit_context *context =audit_alloc_local ();We should be able to use
current->audit_contexthere right? If we can't for every caller, perhaps we pass anaudit_contextas an argument and only allocate a local context when the passedaudit_contextis NULL.
Quoted 5 lines
Quoted 2 lines
Also, if you're not comfortable always using current, just pass the
audit_contextas you do withaudit_log_common_recv_msg().As mentioned in the tree/watch/mark patch, this is all obsoleted by making the
AUDIT_CONFIG_CHANGErecord a SYSCALL auxiliary record.
You've known about my desire to connect records for quite some time.
Quoted 1 line
This review would have been more helpful a month and a half ago.
If you really want to sink to that level of discussion, better quality patches from you would have been helpful too, that is the one of the main reasons why it takes so long to review your code. Let's keep the commentary focused on the code, discussions like this aren't likely to be helpful to anyone.
Signature · 2 lines
paul moore www.paul-moore.com
A message that is not in the archive (sent off-list or not yet received): CAHC9VhQ-i5oA48sXXnN2fP06t5=9-NMoY0bKcGXorQw2k=CK0Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Re: [RFC PATCH ghak32 V2 09/13] audit: add containerid support for config/feature/user records
Quoted 25 lines · Paul Moore
Quoted 14 lines · Richard Guy Briggs
Add container ID auxiliary records to configuration change, feature set change and user generated standalone records.
Signed-off-by Richard Guy Briggs <[email protected]>--- kernel/audit.c | 50 ++++++++++++++++++++++++++++++++++++++++---------- kernel/auditfilter.c | 5 ++++- 2 files changed, 44 insertions(+), 11 deletions(-)kernel/audit.c +0
-0kernel/audit.c static int audit_log_config_change(char *function_name, u32 new, u32 old, · line 403
Quoted 4 lines
kernel/audit.c +1
-0@@ -400,8 +400,9 @@ static int audit_log_config_change(char *function_name, u32 new, u32 old, {struct audit_buffer *ab;int rc =0 ; +struct audit_context *context =audit_alloc_local ();We should be able to use
current->audit_contexthere right? If we can't for every caller, perhaps we pass anaudit_contextas an argument and only allocate a local context when the passedaudit_contextis NULL.
Quoted 2 lines
Also, if you're not comfortable always using current, just pass the
audit_contextas you do withaudit_log_common_recv_msg().
As mentioned in the tree/watch/mark patch, this is all obsoleted by making the AUDIT_CONFIG_CHANGE record a SYSCALL auxiliary record. This review would have been more helpful a month and a half ago.
Quoted 203 lines
Quoted 34 lines
kernel/audit.c +6
-3- ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_CONFIG_CHANGE ); + ab =audit_log_start (context,GFP_KERNEL ,AUDIT_CONFIG_CHANGE );if (unlikely (!ab))return rc;audit_log_format (ab,"%s=%u old=%u" , function_name, new, old);@@ -411,6 +412,8 @@ static int audit_log_config_change(char *function_name, u32 new, u32 old, allow_changes =0 ;/* Something weird, deny request */ audit_log_format (ab," res=%d" , allow_changes);audit_log_end (ab); +audit_log_container_info (context,"config" ,audit_get_containerid (current)); +audit_free_context (context);return rc; }@@ -1058,7 +1061,8 @@ static int audit_netlink_ok(struct sk_buff *skb, u16 msg_type)return err; } -static void audit_log_common_recv_msg (struct audit_buffer **ab,u16 msg_type) +static void audit_log_common_recv_msg (struct audit_context *context, +struct audit_buffer **ab,u16 msg_type) {uid_t uid =from_kuid (&init_user_ns,current_uid ());pid_t pid =task_tgid_nr (current);@@ -1068,7 +1072,7 @@ static void audit_log_common_recv_msg(struct audit_buffer **ab, u16 msg_type)return ; } - *ab =audit_log_start (NULL ,GFP_KERNEL , msg_type); + *ab =audit_log_start (context,GFP_KERNEL , msg_type);if (unlikely (!*ab))return ;audit_log_format (*ab,"pid=%d uid=%u" , pid, uid);kernel/audit.c static void audit_log_feature_change(int which, u32 old_feature, u32 new_feature · line 1104
Quoted 4 lines
kernel/audit.c +1
-0@@ -1097,11 +1101,12 @@ static void audit_log_feature_change(int which, u32 old_feature, u32 new_feature u32 old_lock, u32 new_lock, int res) { struct audit_buffer *ab; +struct audit_context *context =audit_alloc_local ();So I know based on the other patch we are currently discussing that we can use current here ...
Quoted 18 lines
kernel/audit.c +3
-1if (audit_enabled ==AUDIT_OFF )return ; - ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_FEATURE_CHANGE ); + ab =audit_log_start (context,GFP_KERNEL ,AUDIT_FEATURE_CHANGE );if (!ab)return ;audit_log_task_info (ab, current);@@ -1109,6 +1114,8 @@ static void audit_log_feature_change(int which, u32 old_feature, u32 new_feature audit_feature_names[which], !!old_feature, !!new_feature, !!old_lock, !!new_lock, res);audit_log_end (ab); +audit_log_container_info (context,"feature" ,audit_get_containerid (current)); +audit_free_context (context); }static int audit_set_feature (struct sk_buff *skb)kernel/audit.c static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) · line 1347
Quoted 4 lines
kernel/audit.c +1
-0@@ -1337,13 +1344,15 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) err =audit_filter (msg_type,AUDIT_FILTER_USER );if (err ==1 ) {/* match or error */ +struct audit_context *context =audit_alloc_local ();I'm pretty sure we can use current here.
Quoted 22 lines
kernel/audit.c +4
-1err =0 ;if (msg_type ==AUDIT_USER_TTY ) { err =tty_audit_push ();if (err)break ; } -audit_log_common_recv_msg (&ab, msg_type); +audit_log_common_recv_msg (context, &ab, msg_type);if (msg_type !=AUDIT_USER_TTY ) audit_log_format(ab, " msg='%.*s'", AUDIT_MESSAGE_TEXT_MAX,@@ -1359,6 +1368,9 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)audit_log_n_untrustedstring (ab, data, size); }audit_log_end (ab); +audit_log_container_info (context,"user" , +audit_get_containerid (current)); +audit_free_context (context); }break ;case AUDIT_ADD_RULE :kernel/audit.c static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) · line 1381
Quoted 5 lines
kernel/audit.c +1
-1@@ -1366,9 +1378,14 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)if (nlmsg_len (nlh) <sizeof (struct audit_rule_data ))return -EINVAL ;if (audit_enabled ==AUDIT_LOCKED ) { -audit_log_common_recv_msg (&ab,AUDIT_CONFIG_CHANGE ); +struct audit_context *context =audit_alloc_local ();Pretty sure current can be used here too. In fact I think everywhere where we are processing commands from netlink we can use current as I believe the entire netlink stack is processed in the context of the caller.
Quoted 10 lines
kernel/audit.c +4
-0+audit_log_common_recv_msg (context, &ab,AUDIT_CONFIG_CHANGE );audit_log_format (ab," audit_enabled=%d res=0" , audit_enabled);audit_log_end (ab); +audit_log_container_info (context,"config" , +audit_get_containerid (current)); +audit_free_context (context);return -EPERM ; } err =audit_rule_change (msg_type, seq, data,nlmsg_len (nlh));kernel/audit.c static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) · line 1397
Quoted 6 lines
kernel/audit.c +2
-1@@ -1376,17 +1393,23 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)case AUDIT_LIST_RULES : err =audit_list_rules_send (skb, seq);break ; -case AUDIT_TRIM : +case AUDIT_TRIM : { +struct audit_context *context =audit_alloc_local ();Same.
Quoted 6 lines
kernel/audit.c +2
-1audit_trim_trees (); -audit_log_common_recv_msg (&ab,AUDIT_CONFIG_CHANGE ); +audit_log_common_recv_msg (context, &ab,AUDIT_CONFIG_CHANGE );audit_log_format (ab," op=trim res=1" );audit_log_end (ab); + audit_log_container_info(context, "config",kernel/audit.c static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) · line 1412
Quoted 10 lines
kernel/audit.c +4
-0+ audit_get_containerid(current)); +audit_free_context (context);break ; + }case AUDIT_MAKE_EQUIV : {void *bufp = data;u32 sizes[2 ];size_t msglen =nlmsg_len (nlh);char *old, *new; +struct audit_context *context =audit_alloc_local ();Same.
Quoted 22 lines
kernel/audit.c +4
-1err = -EINVAL ;if (msglen <2 *sizeof (u32))@@ -1408,7 +1431,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)/* OK, here comes... */ err =audit_tag_tree (old, new); -audit_log_common_recv_msg (&ab,AUDIT_CONFIG_CHANGE ); +audit_log_common_recv_msg (context, &ab,AUDIT_CONFIG_CHANGE );audit_log_format (ab," op=make_equiv old=" );audit_log_untrustedstring (ab, old);@@ -1418,6 +1441,9 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)audit_log_end (ab);kfree (old);kfree (new); +audit_log_container_info (context,"config" , +audit_get_containerid (current)); +audit_free_context (context);break ; }case AUDIT_SIGNAL_INFO :kernel/audit.c static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) · line 1488
Quoted 4 lines
kernel/audit.c +1
-0@@ -1459,6 +1485,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)struct audit_tty_status s, old;struct audit_buffer *ab;unsigned int t; +struct audit_context *context =audit_alloc_local ();Same.
Quoted 24 lines
kernel/audit.c +4
-1memset (&s,0 ,sizeof (s));/* guard against past and future API changes */ @@ -1477,12 +1504,15 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) old.enabled = t &AUDIT_TTY_ENABLE ; old.log_passwd = !!(t &AUDIT_TTY_LOG_PASSWD ); -audit_log_common_recv_msg (&ab,AUDIT_CONFIG_CHANGE ); +audit_log_common_recv_msg (context, &ab,AUDIT_CONFIG_CHANGE );audit_log_format (ab," op=tty_set old-enabled=%d new-enabled=%d" " old-log_passwd=%d new-log_passwd=%d res=%d" , old.enabled, s.enabled, old.log_passwd, s.log_passwd, !err);audit_log_end (ab); +audit_log_container_info (context,"config" , +audit_get_containerid (current)); +audit_free_context (context);break ; }default :kernel/auditfilter.c +0
-0kernel/auditfilter.c static void audit_log_rule_change(char *action, struct audit_krule *rule, int re · line 1115
Quoted 7 lines
kernel/auditfilter.c +1
-0@@ -1109,11 +1109,12 @@ static void audit_log_rule_change(char *action, struct audit_krule *rule, int restruct audit_buffer *ab;uid_t loginuid =from_kuid (&init_user_ns,audit_get_loginuid (current));unsigned int sessionid =audit_get_sessionid (current); +struct audit_context *context =audit_alloc_local ();if (!audit_enabled)return ;Well, first I think we should be able to get rid of the local context, but if for some reason we can't use
current->audit_contextthen do the allocation after theaudit_enabledcheck.
Quoted 16 lines
Quoted 12 lines
kernel/auditfilter.c +3
-1- ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_CONFIG_CHANGE ); + ab =audit_log_start (context,GFP_KERNEL ,AUDIT_CONFIG_CHANGE );if (!ab)return ;audit_log_format (ab,"auid=%u ses=%u" ,loginuid, sessionid);@@ -1122,6 +1123,8 @@ static void audit_log_rule_change(char *action, struct audit_krule *rule, int reaudit_log_key (ab, rule->filterkey);audit_log_format (ab," list=%d res=%d" , rule->listnr, res);audit_log_end (ab); +audit_log_container_info (context,"config" ,audit_get_containerid (current)); +audit_free_context (context); }Signature · 2 lines
paul moore www.paul-moore.com
- 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
A message that is not in the archive (sent off-list or not yet received): c34a7a95eb045a62e2443457979db9d7afbd9aee.1521179281.git.rgb-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
Re: [RFC PATCH ghak32 V2 09/13] audit: add containerid support for config/feature/user records
Quoted 14 lines · Richard Guy Briggs
Add container ID auxiliary records to configuration change, feature set change and user generated standalone records.
Signed-off-by Richard Guy Briggs <[email protected]>--- kernel/audit.c | 50 ++++++++++++++++++++++++++++++++++++++++---------- kernel/auditfilter.c | 5 ++++- 2 files changed, 44 insertions(+), 11 deletions(-)kernel/audit.c +0
-0
kernel/audit.c static int audit_log_config_change(char *function_name, u32 new, u32 old, · line 403
Quoted 4 lines
kernel/audit.c +1
-0@@ -400,8 +400,9 @@ static int audit_log_config_change(char *function_name, u32 new, u32 old, {struct audit_buffer *ab;int rc =0 ; +struct audit_context *context =audit_alloc_local ();
We should be able to use current->audit_context here right? If we can't for every caller, perhaps we pass an audit_context as an argument and only allocate a local context when the passed audit_context is NULL.
Also, if you're not comfortable always using current, just pass the audit_context as you do with audit_log_common_recv_msg().
Quoted 34 lines
kernel/audit.c +6
-3- ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_CONFIG_CHANGE ); + ab =audit_log_start (context,GFP_KERNEL ,AUDIT_CONFIG_CHANGE );if (unlikely (!ab))return rc;audit_log_format (ab,"%s=%u old=%u" , function_name, new, old);@@ -411,6 +412,8 @@ static int audit_log_config_change(char *function_name, u32 new, u32 old, allow_changes =0 ;/* Something weird, deny request */ audit_log_format (ab," res=%d" , allow_changes);audit_log_end (ab); +audit_log_container_info (context,"config" ,audit_get_containerid (current)); +audit_free_context (context);return rc; }@@ -1058,7 +1061,8 @@ static int audit_netlink_ok(struct sk_buff *skb, u16 msg_type)return err; } -static void audit_log_common_recv_msg (struct audit_buffer **ab,u16 msg_type) +static void audit_log_common_recv_msg (struct audit_context *context, +struct audit_buffer **ab,u16 msg_type) {uid_t uid =from_kuid (&init_user_ns,current_uid ());pid_t pid =task_tgid_nr (current);@@ -1068,7 +1072,7 @@ static void audit_log_common_recv_msg(struct audit_buffer **ab, u16 msg_type)return ; } - *ab =audit_log_start (NULL ,GFP_KERNEL , msg_type); + *ab =audit_log_start (context,GFP_KERNEL , msg_type);if (unlikely (!*ab))return ;audit_log_format (*ab,"pid=%d uid=%u" , pid, uid);
kernel/audit.c static void audit_log_feature_change(int which, u32 old_feature, u32 new_feature · line 1104
Quoted 4 lines
kernel/audit.c +1
-0@@ -1097,11 +1101,12 @@ static void audit_log_feature_change(int which, u32 old_feature, u32 new_feature u32 old_lock, u32 new_lock, int res) { struct audit_buffer *ab; +struct audit_context *context =audit_alloc_local ();
So I know based on the other patch we are currently discussing that we can use current here ...
Quoted 18 lines
kernel/audit.c +3
-1if (audit_enabled ==AUDIT_OFF )return ; - ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_FEATURE_CHANGE ); + ab =audit_log_start (context,GFP_KERNEL ,AUDIT_FEATURE_CHANGE );if (!ab)return ;audit_log_task_info (ab, current);@@ -1109,6 +1114,8 @@ static void audit_log_feature_change(int which, u32 old_feature, u32 new_feature audit_feature_names[which], !!old_feature, !!new_feature, !!old_lock, !!new_lock, res);audit_log_end (ab); +audit_log_container_info (context,"feature" ,audit_get_containerid (current)); +audit_free_context (context); }static int audit_set_feature (struct sk_buff *skb)
kernel/audit.c static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) · line 1347
Quoted 4 lines
kernel/audit.c +1
-0@@ -1337,13 +1344,15 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) err =audit_filter (msg_type,AUDIT_FILTER_USER );if (err ==1 ) {/* match or error */ +struct audit_context *context =audit_alloc_local ();
I'm pretty sure we can use current here.
Quoted 22 lines
kernel/audit.c +4
-1err =0 ;if (msg_type ==AUDIT_USER_TTY ) { err =tty_audit_push ();if (err)break ; } -audit_log_common_recv_msg (&ab, msg_type); +audit_log_common_recv_msg (context, &ab, msg_type);if (msg_type !=AUDIT_USER_TTY ) audit_log_format(ab, " msg='%.*s'", AUDIT_MESSAGE_TEXT_MAX,@@ -1359,6 +1368,9 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)audit_log_n_untrustedstring (ab, data, size); }audit_log_end (ab); +audit_log_container_info (context,"user" , +audit_get_containerid (current)); +audit_free_context (context); }break ;case AUDIT_ADD_RULE :
kernel/audit.c static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) · line 1381
Quoted 5 lines
kernel/audit.c +1
-1@@ -1366,9 +1378,14 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)if (nlmsg_len (nlh) <sizeof (struct audit_rule_data ))return -EINVAL ;if (audit_enabled ==AUDIT_LOCKED ) { -audit_log_common_recv_msg (&ab,AUDIT_CONFIG_CHANGE ); +struct audit_context *context =audit_alloc_local ();
Pretty sure current can be used here too. In fact I think everywhere where we are processing commands from netlink we can use current as I believe the entire netlink stack is processed in the context of the caller.
Quoted 10 lines
kernel/audit.c +4
-0+audit_log_common_recv_msg (context, &ab,AUDIT_CONFIG_CHANGE );audit_log_format (ab," audit_enabled=%d res=0" , audit_enabled);audit_log_end (ab); +audit_log_container_info (context,"config" , +audit_get_containerid (current)); +audit_free_context (context);return -EPERM ; } err =audit_rule_change (msg_type, seq, data,nlmsg_len (nlh));
kernel/audit.c static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) · line 1397
Quoted 6 lines
kernel/audit.c +2
-1@@ -1376,17 +1393,23 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)case AUDIT_LIST_RULES : err =audit_list_rules_send (skb, seq);break ; -case AUDIT_TRIM : +case AUDIT_TRIM : { +struct audit_context *context =audit_alloc_local ();
Same.
Quoted 6 lines
kernel/audit.c +2
-1audit_trim_trees (); -audit_log_common_recv_msg (&ab,AUDIT_CONFIG_CHANGE ); +audit_log_common_recv_msg (context, &ab,AUDIT_CONFIG_CHANGE );audit_log_format (ab," op=trim res=1" );audit_log_end (ab); + audit_log_container_info(context, "config",
kernel/audit.c static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) · line 1412
Quoted 10 lines
kernel/audit.c +4
-0+ audit_get_containerid(current)); +audit_free_context (context);break ; + }case AUDIT_MAKE_EQUIV : {void *bufp = data;u32 sizes[2 ];size_t msglen =nlmsg_len (nlh);char *old, *new; +struct audit_context *context =audit_alloc_local ();
Same.
Quoted 22 lines
kernel/audit.c +4
-1err = -EINVAL ;if (msglen <2 *sizeof (u32))@@ -1408,7 +1431,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)/* OK, here comes... */ err =audit_tag_tree (old, new); -audit_log_common_recv_msg (&ab,AUDIT_CONFIG_CHANGE ); +audit_log_common_recv_msg (context, &ab,AUDIT_CONFIG_CHANGE );audit_log_format (ab," op=make_equiv old=" );audit_log_untrustedstring (ab, old);@@ -1418,6 +1441,9 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)audit_log_end (ab);kfree (old);kfree (new); +audit_log_container_info (context,"config" , +audit_get_containerid (current)); +audit_free_context (context);break ; }case AUDIT_SIGNAL_INFO :
kernel/audit.c static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) · line 1488
Quoted 4 lines
kernel/audit.c +1
-0@@ -1459,6 +1485,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)struct audit_tty_status s, old;struct audit_buffer *ab;unsigned int t; +struct audit_context *context =audit_alloc_local ();
Same.
Quoted 24 lines
kernel/audit.c +4
-1memset (&s,0 ,sizeof (s));/* guard against past and future API changes */ @@ -1477,12 +1504,15 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh) old.enabled = t &AUDIT_TTY_ENABLE ; old.log_passwd = !!(t &AUDIT_TTY_LOG_PASSWD ); -audit_log_common_recv_msg (&ab,AUDIT_CONFIG_CHANGE ); +audit_log_common_recv_msg (context, &ab,AUDIT_CONFIG_CHANGE );audit_log_format (ab," op=tty_set old-enabled=%d new-enabled=%d" " old-log_passwd=%d new-log_passwd=%d res=%d" , old.enabled, s.enabled, old.log_passwd, s.log_passwd, !err);audit_log_end (ab); +audit_log_container_info (context,"config" , +audit_get_containerid (current)); +audit_free_context (context);break ; }default :kernel/auditfilter.c +0
-0
kernel/auditfilter.c static void audit_log_rule_change(char *action, struct audit_krule *rule, int re · line 1115
Quoted 7 lines
kernel/auditfilter.c +1
-0@@ -1109,11 +1109,12 @@ static void audit_log_rule_change(char *action, struct audit_krule *rule, int restruct audit_buffer *ab;uid_t loginuid =from_kuid (&init_user_ns,audit_get_loginuid (current));unsigned int sessionid =audit_get_sessionid (current); +struct audit_context *context =audit_alloc_local ();if (!audit_enabled)return ;
Well, first I think we should be able to get rid of the local context, but if for some reason we can't use current->audit_context then do the allocation after the audit_enabled check.
Quoted 12 lines
kernel/auditfilter.c +3
-1- ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_CONFIG_CHANGE ); + ab =audit_log_start (context,GFP_KERNEL ,AUDIT_CONFIG_CHANGE );if (!ab)return ;audit_log_format (ab,"auid=%u ses=%u" ,loginuid, sessionid);@@ -1122,6 +1123,8 @@ static void audit_log_rule_change(char *action, struct audit_krule *rule, int reaudit_log_key (ab, rule->filterkey);audit_log_format (ab," list=%d res=%d" , rule->listnr, res);audit_log_end (ab); +audit_log_container_info (context,"config" ,audit_get_containerid (current)); +audit_free_context (context); }
Signature · 2 lines
paul moore www.paul-moore.com
RFC PATCH v2 10/13 audit: add containerid support for seccomp and anom_abend records
In reply to Richard Guy BriggsAdd container ID auxiliary records to secure computing and abnormal end standalone records.
--- kernel/auditsc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
kernel/auditsc.c +8 -2
@@ -2571,6 +2571,7 @@ static void audit_log_task(struct audit_buffer *ab)void audit_core_dumps (long signr) {struct audit_buffer *ab; +struct audit_context *context =audit_alloc_local ();if (!audit_enabled)return ;
@@ -2578,19 +2579,22 @@ void audit_core_dumps(long signr)if (signr ==SIGQUIT )/* don't care for those */ return ; - ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_ANOM_ABEND ); + ab =audit_log_start (context,GFP_KERNEL ,AUDIT_ANOM_ABEND );if (unlikely (!ab))return ;audit_log_task (ab);audit_log_format (ab," sig=%ld res=1" , signr);audit_log_end (ab); +audit_log_container_info (context,"abend" ,audit_get_containerid (current)); +audit_free_context (context); }void __audit_seccomp (unsigned long syscall,long signr,int code) {struct audit_buffer *ab; +struct audit_context *context =audit_alloc_local (); - ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_SECCOMP ); + ab =audit_log_start (context,GFP_KERNEL ,AUDIT_SECCOMP );if (unlikely (!ab))return ;audit_log_task (ab);
@@ -2598,6 +2602,8 @@ void __audit_seccomp(unsigned long syscall, long signr, int code) signr,syscall_get_arch (), syscall, in_compat_syscall(), KSTK_EIP(current), code);audit_log_end (ab); +audit_log_container_info (context,"seccomp" ,audit_get_containerid (current)); +audit_free_context (context); }struct list_head *audit_killed_trees (void )
Signature · 1 line
1.8.3.1
Paul Moore
maintainerRe: [RFC PATCH ghak32 V2 10/13] audit: add containerid support for seccomp and anom_abend records
Quoted 13 lines · Richard Guy Briggs
Add container ID auxiliary records to secure computing and abnormal end standalone records.
Signed-off-by Richard Guy Briggs <[email protected]>--- kernel/auditsc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)kernel/auditsc.c +0
-0
kernel/auditsc.c static void audit_log_task(struct audit_buffer *ab) · line 2574
Quoted 4 lines
kernel/auditsc.c +1
-0@@ -2571,6 +2571,7 @@ static void audit_log_task(struct audit_buffer *ab)void audit_core_dumps (long signr) {struct audit_buffer *ab; +struct audit_context *context =audit_alloc_local ();
Looking quickly at do_coredump() I *believe* we can use current here.
Quoted 11 lines
kernel/auditsc.c +1
-1if (!audit_enabled)return ;@@ -2578,19 +2579,22 @@ void audit_core_dumps(long signr)if (signr ==SIGQUIT )/* don't care for those */ return ; - ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_ANOM_ABEND ); + ab =audit_log_start (context,GFP_KERNEL ,AUDIT_ANOM_ABEND );if (unlikely (!ab))return ;audit_log_task (ab);
kernel/auditsc.c void audit_core_dumps(long signr) · line 2595
Quoted 10 lines
kernel/auditsc.c +3
-0audit_log_format (ab," sig=%ld res=1" , signr);audit_log_end (ab); +audit_log_container_info (context,"abend" ,audit_get_containerid (current)); +audit_free_context (context); }void __audit_seccomp (unsigned long syscall,long signr,int code) {struct audit_buffer *ab; +struct audit_context *context =audit_alloc_local ();
We can definitely use current here.
Quoted 14 lines
kernel/auditsc.c +3
-1- ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_SECCOMP ); + ab =audit_log_start (context,GFP_KERNEL ,AUDIT_SECCOMP );if (unlikely (!ab))return ;audit_log_task (ab);@@ -2598,6 +2602,8 @@ void __audit_seccomp(unsigned long syscall, long signr, int code) signr,syscall_get_arch (), syscall, in_compat_syscall(), KSTK_EIP(current), code);audit_log_end (ab); +audit_log_container_info (context,"seccomp" ,audit_get_containerid (current)); +audit_free_context (context); }struct list_head *audit_killed_trees (void )
Signature · 2 lines
paul moore www.paul-moore.com
Re: [RFC PATCH ghak32 V2 10/13] audit: add containerid support for seccomp and anom_abend records
Quoted 38 lines · Paul Moore
Quoted 13 lines · Richard Guy Briggs
Add container ID auxiliary records to secure computing and abnormal end standalone records.
Signed-off-by Richard Guy Briggs <[email protected]>--- kernel/auditsc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)kernel/auditsc.c +0
-0kernel/auditsc.c static void audit_log_task(struct audit_buffer *ab) · line 2574
Quoted 4 lines
kernel/auditsc.c +1
-0@@ -2571,6 +2571,7 @@ static void audit_log_task(struct audit_buffer *ab)void audit_core_dumps (long signr) {struct audit_buffer *ab; +struct audit_context *context =audit_alloc_local ();Looking quickly at
do_coredump()I *believe* we can use current here.Quoted 17 lines
kernel/auditsc.c +3
-1if (!audit_enabled)return ;@@ -2578,19 +2579,22 @@ void audit_core_dumps(long signr)if (signr ==SIGQUIT )/* don't care for those */ return ; - ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_ANOM_ABEND ); + ab =audit_log_start (context,GFP_KERNEL ,AUDIT_ANOM_ABEND );if (unlikely (!ab))return ;audit_log_task (ab);audit_log_format (ab," sig=%ld res=1" , signr);audit_log_end (ab); +audit_log_container_info (context,"abend" ,audit_get_containerid (current)); +audit_free_context (context); }
Quoted 6 lines
kernel/auditsc.c void audit_core_dumps(long signr) · line 2595
Quoted 4 lines
kernel/auditsc.c +1
-0void __audit_seccomp (unsigned long syscall,long signr,int code) {struct audit_buffer *ab; +struct audit_context *context =audit_alloc_local ();We can definitely use current here.
Ok, so both syscall aux records. That elimintes this patch from the set, can go in independently.
Quoted 13 lines
Quoted 13 lines
kernel/auditsc.c +3
-1- ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_SECCOMP ); + ab =audit_log_start (context,GFP_KERNEL ,AUDIT_SECCOMP );if (unlikely (!ab))return ;audit_log_task (ab);@@ -2598,6 +2602,8 @@ void __audit_seccomp(unsigned long syscall, long signr, int code) signr,syscall_get_arch (), syscall, in_compat_syscall(), KSTK_EIP(current), code);audit_log_end (ab); +audit_log_container_info (context,"seccomp" ,audit_get_containerid (current)); +audit_free_context (context); }
Quoted 10 lines
Quoted 1 line
kernel/auditsc.c +0
-0struct list_head *audit_killed_trees (void )Signature · 7 lines
paul moore www.paul-moore.com -- 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
Paul Moore
maintainerRe: [RFC PATCH ghak32 V2 10/13] audit: add containerid support for seccomp and anom_abend records
Quoted 46 lines · Richard Guy Briggs
Quoted 38 lines · Paul Moore
Quoted 13 lines · Richard Guy Briggs
Add container ID auxiliary records to secure computing and abnormal end standalone records.
Signed-off-by Richard Guy Briggs <[email protected]>--- kernel/auditsc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)kernel/auditsc.c +0
-0kernel/auditsc.c static void audit_log_task(struct audit_buffer *ab) · line 2574
Quoted 4 lines
kernel/auditsc.c +1
-0@@ -2571,6 +2571,7 @@ static void audit_log_task(struct audit_buffer *ab)void audit_core_dumps (long signr) {struct audit_buffer *ab; +struct audit_context *context =audit_alloc_local ();Looking quickly at
do_coredump()I *believe* we can use current here.Quoted 17 lines
kernel/auditsc.c +3
-1if (!audit_enabled)return ;@@ -2578,19 +2579,22 @@ void audit_core_dumps(long signr)if (signr ==SIGQUIT )/* don't care for those */ return ; - ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_ANOM_ABEND ); + ab =audit_log_start (context,GFP_KERNEL ,AUDIT_ANOM_ABEND );if (unlikely (!ab))return ;audit_log_task (ab);audit_log_format (ab," sig=%ld res=1" , signr);audit_log_end (ab); +audit_log_container_info (context,"abend" ,audit_get_containerid (current)); +audit_free_context (context); }Quoted 6 lines
kernel/auditsc.c void audit_core_dumps(long signr) · line 2595
Quoted 4 lines
kernel/auditsc.c +1
-0void __audit_seccomp (unsigned long syscall,long signr,int code) {struct audit_buffer *ab; +struct audit_context *context =audit_alloc_local ();We can definitely use current here.
Quoted 2 lines
Ok, so both syscall aux records. That elimintes this patch from the set, can go in independently.
Yep. It should help shrink the audit container ID patchset and perhaps more importantly it should put some distance between the connected-record debate and the audit container ID debate.
I understand we are going to need a "local" context for some things, the network packets are probably the best example, but whenever possible I would like to connect these records back to a task's context.
Signature · 2 lines
paul moore www.paul-moore.com
A message that is not in the archive (sent off-list or not yet received): 20180420004218.tgndd474wgueyjzk-bcJWsdo4jJjeVoXN4CMphl7TgLCtbB0G@public.gmane.org
Re: [RFC PATCH ghak32 V2 10/13] audit: add containerid support for seccomp and anom_abend records
Quoted 46 lines · Richard Guy Briggs
Quoted 38 lines · Paul Moore
Quoted 13 lines · Richard Guy Briggs
Add container ID auxiliary records to secure computing and abnormal end standalone records.
Signed-off-by Richard Guy Briggs <[email protected]>--- kernel/auditsc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)kernel/auditsc.c +0
-0kernel/auditsc.c static void audit_log_task(struct audit_buffer *ab) · line 2574
Quoted 4 lines
kernel/auditsc.c +1
-0@@ -2571,6 +2571,7 @@ static void audit_log_task(struct audit_buffer *ab)void audit_core_dumps (long signr) {struct audit_buffer *ab; +struct audit_context *context =audit_alloc_local ();Looking quickly at
do_coredump()I *believe* we can use current here.Quoted 17 lines
kernel/auditsc.c +3
-1if (!audit_enabled)return ;@@ -2578,19 +2579,22 @@ void audit_core_dumps(long signr)if (signr ==SIGQUIT )/* don't care for those */ return ; - ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_ANOM_ABEND ); + ab =audit_log_start (context,GFP_KERNEL ,AUDIT_ANOM_ABEND );if (unlikely (!ab))return ;audit_log_task (ab);audit_log_format (ab," sig=%ld res=1" , signr);audit_log_end (ab); +audit_log_container_info (context,"abend" ,audit_get_containerid (current)); +audit_free_context (context); }Quoted 6 lines
kernel/auditsc.c void audit_core_dumps(long signr) · line 2595
Quoted 4 lines
kernel/auditsc.c +1
-0void __audit_seccomp (unsigned long syscall,long signr,int code) {struct audit_buffer *ab; +struct audit_context *context =audit_alloc_local ();We can definitely use current here.
Quoted 2 lines
Ok, so both syscall aux records. That elimintes this patch from the set, can go in independently.
Yep. It should help shrink the audit container ID patchset and perhaps more importantly it should put some distance between the connected-record debate and the audit container ID debate.
I understand we are going to need a "local" context for some things, the network packets are probably the best example, but whenever possible I would like to connect these records back to a task's context.
Signature · 2 lines
paul moore www.paul-moore.com
A message that is not in the archive (sent off-list or not yet received): CAHC9VhS6MKoLkzpfcmYBSNnvrtbL2FOF5PX9uOfivSVEWykkQg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Re: [RFC PATCH ghak32 V2 10/13] audit: add containerid support for seccomp and anom_abend records
Quoted 38 lines · Paul Moore
Quoted 13 lines · Richard Guy Briggs
Add container ID auxiliary records to secure computing and abnormal end standalone records.
Signed-off-by Richard Guy Briggs <[email protected]>--- kernel/auditsc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)kernel/auditsc.c +0
-0kernel/auditsc.c static void audit_log_task(struct audit_buffer *ab) · line 2574
Quoted 4 lines
kernel/auditsc.c +1
-0@@ -2571,6 +2571,7 @@ static void audit_log_task(struct audit_buffer *ab)void audit_core_dumps (long signr) {struct audit_buffer *ab; +struct audit_context *context =audit_alloc_local ();Looking quickly at
do_coredump()I *believe* we can use current here.Quoted 17 lines
kernel/auditsc.c +3
-1if (!audit_enabled)return ;@@ -2578,19 +2579,22 @@ void audit_core_dumps(long signr)if (signr ==SIGQUIT )/* don't care for those */ return ; - ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_ANOM_ABEND ); + ab =audit_log_start (context,GFP_KERNEL ,AUDIT_ANOM_ABEND );if (unlikely (!ab))return ;audit_log_task (ab);audit_log_format (ab," sig=%ld res=1" , signr);audit_log_end (ab); +audit_log_container_info (context,"abend" ,audit_get_containerid (current)); +audit_free_context (context); }
Quoted 6 lines
kernel/auditsc.c void audit_core_dumps(long signr) · line 2595
Quoted 4 lines
kernel/auditsc.c +1
-0void __audit_seccomp (unsigned long syscall,long signr,int code) {struct audit_buffer *ab; +struct audit_context *context =audit_alloc_local ();We can definitely use current here.
Ok, so both syscall aux records. That elimintes this patch from the set, can go in independently.
Quoted 13 lines
Quoted 13 lines
kernel/auditsc.c +3
-1- ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_SECCOMP ); + ab =audit_log_start (context,GFP_KERNEL ,AUDIT_SECCOMP );if (unlikely (!ab))return ;audit_log_task (ab);@@ -2598,6 +2602,8 @@ void __audit_seccomp(unsigned long syscall, long signr, int code) signr,syscall_get_arch (), syscall, in_compat_syscall(), KSTK_EIP(current), code);audit_log_end (ab); +audit_log_container_info (context,"seccomp" ,audit_get_containerid (current)); +audit_free_context (context); }
Quoted 10 lines
Quoted 1 line
kernel/auditsc.c +0
-0struct list_head *audit_killed_trees (void )Signature · 7 lines
paul moore www.paul-moore.com -- 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
A message that is not in the archive (sent off-list or not yet received): 11174597083f89352f1d6491ec94e27f882625d9.1521179281.git.rgb-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
Re: [RFC PATCH ghak32 V2 10/13] audit: add containerid support for seccomp and anom_abend records
Quoted 13 lines · Richard Guy Briggs
Add container ID auxiliary records to secure computing and abnormal end standalone records.
Signed-off-by Richard Guy Briggs <[email protected]>--- kernel/auditsc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)kernel/auditsc.c +0
-0
kernel/auditsc.c static void audit_log_task(struct audit_buffer *ab) · line 2574
Quoted 4 lines
kernel/auditsc.c +1
-0@@ -2571,6 +2571,7 @@ static void audit_log_task(struct audit_buffer *ab)void audit_core_dumps (long signr) {struct audit_buffer *ab; +struct audit_context *context =audit_alloc_local ();
Looking quickly at do_coredump() I *believe* we can use current here.
Quoted 11 lines
kernel/auditsc.c +1
-1if (!audit_enabled)return ;@@ -2578,19 +2579,22 @@ void audit_core_dumps(long signr)if (signr ==SIGQUIT )/* don't care for those */ return ; - ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_ANOM_ABEND ); + ab =audit_log_start (context,GFP_KERNEL ,AUDIT_ANOM_ABEND );if (unlikely (!ab))return ;audit_log_task (ab);
kernel/auditsc.c void audit_core_dumps(long signr) · line 2595
Quoted 10 lines
kernel/auditsc.c +3
-0audit_log_format (ab," sig=%ld res=1" , signr);audit_log_end (ab); +audit_log_container_info (context,"abend" ,audit_get_containerid (current)); +audit_free_context (context); }void __audit_seccomp (unsigned long syscall,long signr,int code) {struct audit_buffer *ab; +struct audit_context *context =audit_alloc_local ();
We can definitely use current here.
Quoted 14 lines
kernel/auditsc.c +3
-1- ab =audit_log_start (NULL ,GFP_KERNEL ,AUDIT_SECCOMP ); + ab =audit_log_start (context,GFP_KERNEL ,AUDIT_SECCOMP );if (unlikely (!ab))return ;audit_log_task (ab);@@ -2598,6 +2602,8 @@ void __audit_seccomp(unsigned long syscall, long signr, int code) signr,syscall_get_arch (), syscall, in_compat_syscall(), KSTK_EIP(current), code);audit_log_end (ab); +audit_log_container_info (context,"seccomp" ,audit_get_containerid (current)); +audit_free_context (context); }struct list_head *audit_killed_trees (void )
Signature · 2 lines
paul moore www.paul-moore.com
RFC PATCH v2 11/13 audit: add support for containerid to network namespaces
In reply to Richard Guy BriggsAudit events could happen in a network namespace outside of a task context due to packets received from the net that trigger an auditing rule prior to being associated with a running task. The network namespace could in use by multiple containers by association to the tasks in that network namespace. We still want a way to attribute these events to any potential containers. Keep a list per network namespace to track these container identifiiers.
Add/increment the container identifier on:
- initial setting of the container id via /proc
- clone/fork call that inherits a container identifier
- unshare call that inherits a container identifier
- setns call that inherits a container identifier Delete/decrement the container identifier on:
- an inherited container id dropped when child set
- process exit
- unshare call that drops a net namespace
- setns call that drops a net namespace
See: https://github.com/linux-audit/audit-kernel/issues/32
See: https://github.com/linux-audit/audit-testsuite/issues/64
--- include/linux/audit.h | 7 +++++++ include/net/net_namespace.h | 12 ++++++++++++ kernel/auditsc.c | 9 ++++++--- kernel/nsproxy.c | 6 ++++++ net/core/net_namespace.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 76 insertions(+), 3 deletions(-)
include/linux/audit.h +7 -0
@@ -26,6 +26,7 @@#include <linux/sched.h> #include <linux/ptrace.h> #include <uapi/linux/audit.h> +#include <linux/refcount.h> #define AUDIT_INO_UNSET ((unsigned long)-1)#define AUDIT_DEV_UNSET ((dev_t)-1)
@@ -88,6 +89,12 @@ struct audit_field {u32 op; }; +struct audit_containerid { +struct list_head list; +u64 id; +refcount_t refcount; +}; +extern int is_audit_feature_set (int which);extern int __init audit_register_class (int class,unsigned *list);
include/net/net_namespace.h +12 -0
@@ -33,6 +33,7 @@#include <linux/ns_common.h> #include <linux/idr.h> #include <linux/skbuff.h> +#include <linux/audit.h> struct user_namespace ;struct proc_dir_entry ;
@@ -150,6 +151,7 @@ struct net {#endif struct sock *diag_nlsk;atomic_t fnhe_genid; +struct list_head audit_containerid; } __randomize_layout;#include <linux/seq_file_net.h>
@@ -301,6 +303,16 @@ static inline struct net *read_pnet(const possible_net_t *pnet)#define __net_initconst __initconst#endif +#ifdef CONFIG_NET_NS +void net_add_audit_containerid (struct net *net,u64 containerid); +void net_del_audit_containerid (struct net *net,u64 containerid); +#else +static inline void net_add_audit_containerid (struct net *,u64 ) +{ } +static inline void net_del_audit_containerid (struct net *,u64 ) +{ } +#endif +int peernet2id_alloc (struct net *net,struct net *peer);int peernet2id (struct net *net,struct net *peer);bool peernet_has_id (struct net *net,struct net *peer);
kernel/auditsc.c +6 -3
@@ -75,6 +75,7 @@#include <linux/uaccess.h> #include <linux/fsnotify_backend.h> #include <uapi/linux/limits.h> +#include <net/net_namespace.h> #include "audit.h"
@@ -2175,16 +2176,18 @@ static void audit_log_set_containerid(struct task_struct *task, u64 oldcontainer*/ int audit_set_containerid (struct task_struct *task,u64 containerid) { -u64 oldcontainerid; +u64 oldcontainerid =audit_get_containerid (task);int rc; - - oldcontainerid =audit_get_containerid (task); +struct net *net = task->nsproxy->net_ns; rc =audit_set_containerid_perm (task, containerid);if (!rc) { +if (cid_valid (oldcontainerid)) +net_del_audit_containerid (net, oldcontainerid);task_lock (task); task->containerid = containerid;task_unlock (task); +net_add_audit_containerid (net, containerid); }audit_log_set_containerid (task, oldcontainerid, containerid, rc);
kernel/nsproxy.c +6 -0
@@ -140,6 +140,7 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)struct nsproxy *old_ns = tsk->nsproxy;struct user_namespace *user_ns =task_cred_xxx (tsk, user_ns);struct nsproxy *new_ns; +u64 containerid =audit_get_containerid (tsk); if (likely(!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWPID | CLONE_NEWNET |
@@ -167,6 +168,7 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)return PTR_ERR (new_ns); tsk->nsproxy = new_ns; +net_add_audit_containerid (new_ns->net_ns, containerid);return 0 ; }
@@ -217,6 +219,7 @@ int unshare_nsproxy_namespaces(unsigned long unshare_flags,void switch_task_namespaces (struct task_struct *p,struct nsproxy *new) {struct nsproxy *ns; +u64 containerid =audit_get_containerid (p);might_sleep ();
@@ -224,6 +227,9 @@ void switch_task_namespaces(struct task_struct *p, struct nsproxy *new) ns = p->nsproxy; p->nsproxy = new;task_unlock (p); +net_del_audit_containerid (ns->net_ns, containerid); +if (new) +net_add_audit_containerid (new->net_ns, containerid);if (ns &&atomic_dec_and_test (&ns->count))free_nsproxy (ns);
net/core/net_namespace.c +45 -0
63 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Paul Moore
maintainerRe: [RFC PATCH ghak32 V2 11/13] audit: add support for containerid to network namespaces
Quoted 29 lines · Richard Guy Briggs
Audit events could happen in a network namespace outside of a task context due to packets received from the net that trigger an auditing rule prior to being associated with a running task. The network namespace could in use by multiple containers by association to the tasks in that network namespace. We still want a way to attribute these events to any potential containers. Keep a list per network namespace to track these container identifiiers.
Add/increment the container identifier on:
- initial setting of the container id via /proc
- clone/fork call that inherits a container identifier
- unshare call that inherits a container identifier
- setns call that inherits a container identifier Delete/decrement the container identifier on:
- an inherited container id dropped when child set
- process exit
- unshare call that drops a net namespace
- setns call that drops a net namespaceSee: https://github.com/linux-audit/audit-kernel/issues/32
See: https://github.com/linux-audit/audit-testsuite/issues/64Signed-off-by Richard Guy Briggs <[email protected]>--- include/linux/audit.h | 7 +++++++ include/net/net_namespace.h | 12 ++++++++++++ kernel/auditsc.c | 9 ++++++--- kernel/nsproxy.c | 6 ++++++ net/core/net_namespace.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 76 insertions(+), 3 deletions(-)
...
Quoted 13 lines
include/net/net_namespace.h +1
-0@@ -33,6 +33,7 @@#include <linux/ns_common.h> #include <linux/idr.h> #include <linux/skbuff.h> +#include <linux/audit.h> struct user_namespace ;struct proc_dir_entry ;
include/net/net_namespace.h struct net { · line 155
Quoted 5 lines
include/net/net_namespace.h +1
-0@@ -150,6 +151,7 @@ struct net {#endif struct sock *diag_nlsk;atomic_t fnhe_genid; +struct list_head audit_containerid; } __randomize_layout;
We talked about this briefly off-list, you should be using audit_net and the net_generic mechanism instead of this.
Quoted 35 lines
include/net/net_namespace.h +10
-0#include <linux/seq_file_net.h> @@ -301,6 +303,16 @@ static inline struct net *read_pnet(const possible_net_t *pnet)#define __net_initconst __initconst#endif +#ifdef CONFIG_NET_NS +void net_add_audit_containerid (struct net *net,u64 containerid); +void net_del_audit_containerid (struct net *net,u64 containerid); +#else +static inline void net_add_audit_containerid (struct net *,u64 ) +{ } +static inline void net_del_audit_containerid (struct net *,u64 ) +{ } +#endif +int peernet2id_alloc (struct net *net,struct net *peer);int peernet2id (struct net *net,struct net *peer);bool peernet_has_id (struct net *net,struct net *peer);kernel/auditsc.c +1
-1@@ -75,6 +75,7 @@#include <linux/uaccess.h> #include <linux/fsnotify_backend.h> #include <uapi/linux/limits.h> +#include <net/net_namespace.h> #include "audit.h" @@ -2175,16 +2176,18 @@ static void audit_log_set_containerid(struct task_struct *task, u64 oldcontainer*/ int audit_set_containerid (struct task_struct *task,u64 containerid) { -u64 oldcontainerid;
kernel/auditsc.c static void audit_log_set_containerid(struct task_struct *task, u64 oldcontainer · line 2186
Quoted 10 lines
kernel/auditsc.c +4
-2+u64 oldcontainerid =audit_get_containerid (task);int rc; - - oldcontainerid =audit_get_containerid (task); +struct net *net = task->nsproxy->net_ns; rc =audit_set_containerid_perm (task, containerid);if (!rc) { +if (cid_valid (oldcontainerid)) +net_del_audit_containerid (net, oldcontainerid);
Using audit_net we can handle this internal to audit, which is a Good Thing.
kernel/auditsc.c static void audit_log_set_containerid(struct task_struct *task, u64 oldcontainer · line 2190
Quoted 4 lines
kernel/auditsc.c +1
-0task_lock (task); task->containerid = containerid;task_unlock (task); +net_add_audit_containerid (net, containerid);
Same.
Quoted 16 lines
kernel/auditsc.c +0
-0}audit_log_set_containerid (task, oldcontainerid, containerid, rc);kernel/nsproxy.c +1
-0@@ -140,6 +140,7 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)struct nsproxy *old_ns = tsk->nsproxy;struct user_namespace *user_ns =task_cred_xxx (tsk, user_ns);struct nsproxy *new_ns; +u64 containerid =audit_get_containerid (tsk); if (likely(!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWPID | CLONE_NEWNET |
kernel/nsproxy.c int copy_namespaces(unsigned long flags, struct task_struct *tsk) · line 173
Quoted 6 lines
kernel/nsproxy.c +1
-0@@ -167,6 +168,7 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)return PTR_ERR (new_ns); tsk->nsproxy = new_ns; +net_add_audit_containerid (new_ns->net_ns, containerid);return 0 ; }
Hopefully we can handle this in audit_net_init(), we just need to figure out where we can get the correct task_struct for the audit container ID (some backpointer in the net struct?).
Quoted 9 lines
kernel/nsproxy.c +1
-0@@ -217,6 +219,7 @@ int unshare_nsproxy_namespaces(unsigned long unshare_flags,void switch_task_namespaces (struct task_struct *p,struct nsproxy *new) {struct nsproxy *ns; +u64 containerid =audit_get_containerid (p);might_sleep ();
kernel/nsproxy.c void switch_task_namespaces(struct task_struct *p, struct nsproxy *new) · line 232
Quoted 6 lines
kernel/nsproxy.c +3
-0@@ -224,6 +227,9 @@ void switch_task_namespaces(struct task_struct *p, struct nsproxy *new) ns = p->nsproxy; p->nsproxy = new;task_unlock (p); +net_del_audit_containerid (ns->net_ns, containerid); +if (new) +net_add_audit_containerid (new->net_ns, containerid);
Okay, we might need a hook here for switching namespaces, but I would much rather it be a generic audit hook that calls directly into audit.
Signature · 2 lines
paul moore www.paul-moore.com
Re: [RFC PATCH ghak32 V2 11/13] audit: add support for containerid to network namespaces
Quoted 96 lines · Paul Moore
Quoted 29 lines · Richard Guy Briggs
Audit events could happen in a network namespace outside of a task context due to packets received from the net that trigger an auditing rule prior to being associated with a running task. The network namespace could in use by multiple containers by association to the tasks in that network namespace. We still want a way to attribute these events to any potential containers. Keep a list per network namespace to track these container identifiiers.
Add/increment the container identifier on:
- initial setting of the container id via /proc
- clone/fork call that inherits a container identifier
- unshare call that inherits a container identifier
- setns call that inherits a container identifier Delete/decrement the container identifier on:
- an inherited container id dropped when child set
- process exit
- unshare call that drops a net namespace
- setns call that drops a net namespaceSee: https://github.com/linux-audit/audit-kernel/issues/32
See: https://github.com/linux-audit/audit-testsuite/issues/64Signed-off-by Richard Guy Briggs <[email protected]>--- include/linux/audit.h | 7 +++++++ include/net/net_namespace.h | 12 ++++++++++++ kernel/auditsc.c | 9 ++++++--- kernel/nsproxy.c | 6 ++++++ net/core/net_namespace.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 76 insertions(+), 3 deletions(-)...
Quoted 13 lines
include/net/net_namespace.h +1
-0@@ -33,6 +33,7 @@#include <linux/ns_common.h> #include <linux/idr.h> #include <linux/skbuff.h> +#include <linux/audit.h> struct user_namespace ;struct proc_dir_entry ;include/net/net_namespace.h struct net { · line 155
Quoted 5 lines
include/net/net_namespace.h +1
-0@@ -150,6 +151,7 @@ struct net {#endif struct sock *diag_nlsk;atomic_t fnhe_genid; +struct list_head audit_containerid; } __randomize_layout;We talked about this briefly off-list, you should be using
audit_netand thenet_genericmechanism instead of this.Quoted 41 lines
include/net/net_namespace.h +10
-0#include <linux/seq_file_net.h> @@ -301,6 +303,16 @@ static inline struct net *read_pnet(const possible_net_t *pnet)#define __net_initconst __initconst#endif +#ifdef CONFIG_NET_NS +void net_add_audit_containerid (struct net *net,u64 containerid); +void net_del_audit_containerid (struct net *net,u64 containerid); +#else +static inline void net_add_audit_containerid (struct net *,u64 ) +{ } +static inline void net_del_audit_containerid (struct net *,u64 ) +{ } +#endif +int peernet2id_alloc (struct net *net,struct net *peer);int peernet2id (struct net *net,struct net *peer);bool peernet_has_id (struct net *net,struct net *peer);kernel/auditsc.c +3
-3@@ -75,6 +75,7 @@#include <linux/uaccess.h> #include <linux/fsnotify_backend.h> #include <uapi/linux/limits.h> +#include <net/net_namespace.h> #include "audit.h" @@ -2175,16 +2176,18 @@ static void audit_log_set_containerid(struct task_struct *task, u64 oldcontainer*/ int audit_set_containerid (struct task_struct *task,u64 containerid) { -u64 oldcontainerid; +u64 oldcontainerid =audit_get_containerid (task);int rc; - - oldcontainerid =audit_get_containerid (task); +struct net *net = task->nsproxy->net_ns;
Quoted 6 lines
kernel/auditsc.c static void audit_log_set_containerid(struct task_struct *task, u64 oldcontainer · line 2186
Quoted 4 lines
kernel/auditsc.c +2
-0rc =audit_set_containerid_perm (task, containerid);if (!rc) { +if (cid_valid (oldcontainerid)) +net_del_audit_containerid (net, oldcontainerid);Using
audit_netwe can handle this internal to audit, which is a Good Thing.
No problem, done.
Quoted 25 lines
kernel/auditsc.c static void audit_log_set_containerid(struct task_struct *task, u64 oldcontainer · line 2190
Quoted 4 lines
kernel/auditsc.c +1
-0task_lock (task); task->containerid = containerid;task_unlock (task); +net_add_audit_containerid (net, containerid);Same.
Quoted 18 lines
kernel/auditsc.c +0
-0}audit_log_set_containerid (task, oldcontainerid, containerid, rc);kernel/nsproxy.c +1
-0@@ -140,6 +140,7 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)struct nsproxy *old_ns = tsk->nsproxy;struct user_namespace *user_ns =task_cred_xxx (tsk, user_ns);struct nsproxy *new_ns; +u64 containerid =audit_get_containerid (tsk); if (likely(!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWPID | CLONE_NEWNET |@@ -167,6 +168,7 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)return PTR_ERR (new_ns);
Quoted 8 lines
kernel/nsproxy.c int copy_namespaces(unsigned long flags, struct task_struct *tsk) · line 173
Quoted 4 lines
kernel/nsproxy.c +1
-0tsk->nsproxy = new_ns; +net_add_audit_containerid (new_ns->net_ns, containerid);return 0 ; }Hopefully we can handle this in
audit_net_init(), we just need to figure out where we can get the correcttask_structfor the audit container ID (some backpointer in the net struct?).
I don't follow. This needs to happen on every task startup. audit_net_init() is only called when a new network namespace starts up.
Quoted 8 lines
Quoted 8 lines
kernel/nsproxy.c +1
-0@@ -217,6 +219,7 @@ int unshare_nsproxy_namespaces(unsigned long unshare_flags,void switch_task_namespaces (struct task_struct *p,struct nsproxy *new) {struct nsproxy *ns; +u64 containerid =audit_get_containerid (p);might_sleep ();
Quoted 10 lines
kernel/nsproxy.c void switch_task_namespaces(struct task_struct *p, struct nsproxy *new) · line 232
Quoted 7 lines
kernel/nsproxy.c +3
-0@@ -224,6 +227,9 @@ void switch_task_namespaces(struct task_struct *p, struct nsproxy *new) ns = p->nsproxy; p->nsproxy = new;task_unlock (p); +net_del_audit_containerid (ns->net_ns, containerid); +if (new) +net_add_audit_containerid (new->net_ns, containerid);Okay, we might need a hook here for switching namespaces, but I would much rather it be a generic audit hook that calls directly into audit.
Trivial, done.
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 11/13] audit: add support for containerid to network namespaces
Quoted 31 lines · Richard Guy Briggs
Quoted 30 lines · Paul Moore
Quoted 29 lines · Richard Guy Briggs
Audit events could happen in a network namespace outside of a task context due to packets received from the net that trigger an auditing rule prior to being associated with a running task. The network namespace could in use by multiple containers by association to the tasks in that network namespace. We still want a way to attribute these events to any potential containers. Keep a list per network namespace to track these container identifiiers.
Add/increment the container identifier on:
- initial setting of the container id via /proc
- clone/fork call that inherits a container identifier
- unshare call that inherits a container identifier
- setns call that inherits a container identifier Delete/decrement the container identifier on:
- an inherited container id dropped when child set
- process exit
- unshare call that drops a net namespace
- setns call that drops a net namespaceSee: https://github.com/linux-audit/audit-kernel/issues/32
See: https://github.com/linux-audit/audit-testsuite/issues/64Signed-off-by Richard Guy Briggs <[email protected]>--- include/linux/audit.h | 7 +++++++ include/net/net_namespace.h | 12 ++++++++++++ kernel/auditsc.c | 9 ++++++--- kernel/nsproxy.c | 6 ++++++ net/core/net_namespace.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 76 insertions(+), 3 deletions(-)
...
Quoted 24 lines
Quoted 15 lines
Quoted 15 lines
kernel/nsproxy.c +1
-0@@ -140,6 +140,7 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)struct nsproxy *old_ns = tsk->nsproxy;struct user_namespace *user_ns =task_cred_xxx (tsk, user_ns);struct nsproxy *new_ns; +u64 containerid =audit_get_containerid (tsk); if (likely(!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWPID | CLONE_NEWNET |@@ -167,6 +168,7 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)return PTR_ERR (new_ns);Quoted 8 lines
kernel/nsproxy.c int copy_namespaces(unsigned long flags, struct task_struct *tsk) · line 173
Quoted 4 lines
kernel/nsproxy.c +1
-0tsk->nsproxy = new_ns; +net_add_audit_containerid (new_ns->net_ns, containerid);return 0 ; }Hopefully we can handle this in
audit_net_init(), we just need to figure out where we can get the correcttask_structfor the audit container ID (some backpointer in the net struct?).
Quoted 2 lines
I don't follow. This needs to happen on every task startup.
audit_net_init()is only called when a new network namespace starts up.
Yep, sorry, my mistake. I must have confused myself when I was looking at the code.
I'm thinking out loud here, bear with me ...
Assuming we move the netns/audit-container-ID tracking to audit_net, and considering we already have an audit hook in copy_process() (it calls audit_alloc()), would this be better handled by the copy_process() hook? This ignores naming, audit_alloc() reuse, etc.; those can be easily fixed. I'm just thinking of ways to limit our impact on the core kernel and leverage our existing interaction points.
Signature · 2 lines
paul moore www.paul-moore.com
Re: [RFC PATCH ghak32 V2 11/13] audit: add support for containerid to network namespaces
Quoted 67 lines · Paul Moore
Quoted 31 lines · Richard Guy Briggs
Quoted 30 lines · Paul Moore
Quoted 29 lines · Richard Guy Briggs
Audit events could happen in a network namespace outside of a task context due to packets received from the net that trigger an auditing rule prior to being associated with a running task. The network namespace could in use by multiple containers by association to the tasks in that network namespace. We still want a way to attribute these events to any potential containers. Keep a list per network namespace to track these container identifiiers.
Add/increment the container identifier on:
- initial setting of the container id via /proc
- clone/fork call that inherits a container identifier
- unshare call that inherits a container identifier
- setns call that inherits a container identifier Delete/decrement the container identifier on:
- an inherited container id dropped when child set
- process exit
- unshare call that drops a net namespace
- setns call that drops a net namespaceSee: https://github.com/linux-audit/audit-kernel/issues/32
See: https://github.com/linux-audit/audit-testsuite/issues/64Signed-off-by Richard Guy Briggs <[email protected]>--- include/linux/audit.h | 7 +++++++ include/net/net_namespace.h | 12 ++++++++++++ kernel/auditsc.c | 9 ++++++--- kernel/nsproxy.c | 6 ++++++ net/core/net_namespace.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 76 insertions(+), 3 deletions(-)...
Quoted 24 lines
Quoted 15 lines
Quoted 15 lines
kernel/nsproxy.c +1
-0@@ -140,6 +140,7 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)struct nsproxy *old_ns = tsk->nsproxy;struct user_namespace *user_ns =task_cred_xxx (tsk, user_ns);struct nsproxy *new_ns; +u64 containerid =audit_get_containerid (tsk); if (likely(!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWPID | CLONE_NEWNET |@@ -167,6 +168,7 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)return PTR_ERR (new_ns);Quoted 8 lines
kernel/nsproxy.c int copy_namespaces(unsigned long flags, struct task_struct *tsk) · line 173
Quoted 4 lines
kernel/nsproxy.c +1
-0tsk->nsproxy = new_ns; +net_add_audit_containerid (new_ns->net_ns, containerid);return 0 ; }Hopefully we can handle this in
audit_net_init(), we just need to figure out where we can get the correcttask_structfor the audit container ID (some backpointer in the net struct?).Quoted 2 lines
I don't follow. This needs to happen on every task startup.
audit_net_init()is only called when a new network namespace starts up.Yep, sorry, my mistake. I must have confused myself when I was looking at the code.
I'm thinking out loud here, bear with me ...
Quoted 7 lines
Assuming we move the netns/audit-container-ID tracking to
audit_net, and considering we already have an audit hook incopy_process()(it callsaudit_alloc()), would this be better handled by thecopy_process()hook? This ignores naming,audit_alloc()reuse, etc.; those can be easily fixed. I'm just thinking of ways to limit our impact on the core kernel and leverage our existing interaction points.
The new namespace hasn't been cloned yet and this is the only function where we have access to both namespaces, so I don't see how that could work...
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 11/13] audit: add support for containerid to network namespaces
On April 20, 2018 4:48:34 PM Richard Guy Briggs <[email protected]> wrote:
On 2018-04-20 16:22, Paul Moore wrote:
On Fri, Apr 20, 2018 at 4:02 PM, Richard Guy Briggs <[email protected]> wrote:
On 2018-04-18 21:46, Paul Moore wrote:
On Fri, Mar 16, 2018 at 5:00 AM, Richard Guy Briggs <[email protected]> wrote:
Audit events could happen in a network namespace outside of a task
context due to packets received from the net that trigger an auditing
rule prior to being associated with a running task. The network
namespace could in use by multiple containers by association to the
tasks in that network namespace. We still want a way to attribute
these events to any potential containers. Keep a list per network
namespace to track these container identifiiers.
Add/increment the container identifier on:
- initial setting of the container id via /proc
- clone/fork call that inherits a container identifier
- unshare call that inherits a container identifier
- setns call that inherits a container identifier Delete/decrement the container identifier on:
- an inherited container id dropped when child set
- process exit
- unshare call that drops a net namespace
- setns call that drops a net namespace
See: https://github.com/linux-audit/audit-kernel/issues/32
See: https://github.com/linux-audit/audit-testsuite/issues/64
---
include/linux/audit.h | 7 +++++++ include/net/net_namespace.h | 12 ++++++++++++ kernel/auditsc.c | 9 ++++++--- kernel/nsproxy.c | 6 ++++++ net/core/net_namespace.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 76 insertions(+), 3 deletions(-)
...
kernel/nsproxy.c +0 -0
@@ -140,6 +140,7 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)
struct nsproxy *old_ns = tsk->nsproxy;
struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns); struct nsproxy *new_ns;
+ u64 containerid = audit_get_containerid(tsk);
if (likely(!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWPID | CLONE_NEWNET |
@@ -167,6 +168,7 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk) return PTR_ERR(new_ns);
tsk->nsproxy = new_ns;
+ net_add_audit_containerid(new_ns->net_ns, containerid);
return 0;
}
Hopefully we can handle this in audit_net_init(), we just need to figure out where we can get the correct task_struct for the audit container ID (some backpointer in the net struct?).
I don't follow. This needs to happen on every task startup. audit_net_init() is only called when a new network namespace starts up.
Yep, sorry, my mistake. I must have confused myself when I was looking at the code.
I'm thinking out loud here, bear with me ...
Assuming we move the netns/audit-container-ID tracking to audit_net, and considering we already have an audit hook in copy_process() (it calls audit_alloc()), would this be better handled by the copy_process() hook? This ignores naming, audit_alloc() reuse, etc.; those can be easily fixed. I'm just thinking of ways to limit our impact on the core kernel and leverage our existing interaction points.
The new namespace hasn't been cloned yet and this is the only function where we have access to both namespaces, so I don't see how that could work...
I'll take another, closer look, with v3.
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
www.paul-moore.com
A message that is not in the archive (sent off-list or not yet received): CAHC9VhTOYUAyCJidm99som6FVmjouQUGsEHarQ4h_NhwJxQQfw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Re: [RFC PATCH ghak32 V2 11/13] audit: add support for containerid to network namespaces
Quoted 67 lines · Paul Moore
Quoted 31 lines · Richard Guy Briggs
Quoted 30 lines · Paul Moore
Quoted 29 lines · Richard Guy Briggs
Audit events could happen in a network namespace outside of a task context due to packets received from the net that trigger an auditing rule prior to being associated with a running task. The network namespace could in use by multiple containers by association to the tasks in that network namespace. We still want a way to attribute these events to any potential containers. Keep a list per network namespace to track these container identifiiers.
Add/increment the container identifier on:
- initial setting of the container id via /proc
- clone/fork call that inherits a container identifier
- unshare call that inherits a container identifier
- setns call that inherits a container identifier Delete/decrement the container identifier on:
- an inherited container id dropped when child set
- process exit
- unshare call that drops a net namespace
- setns call that drops a net namespaceSee: https://github.com/linux-audit/audit-kernel/issues/32
See: https://github.com/linux-audit/audit-testsuite/issues/64Signed-off-by Richard Guy Briggs <[email protected]>--- include/linux/audit.h | 7 +++++++ include/net/net_namespace.h | 12 ++++++++++++ kernel/auditsc.c | 9 ++++++--- kernel/nsproxy.c | 6 ++++++ net/core/net_namespace.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 76 insertions(+), 3 deletions(-)...
Quoted 24 lines
Quoted 15 lines
Quoted 15 lines
kernel/nsproxy.c +1
-0@@ -140,6 +140,7 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)struct nsproxy *old_ns = tsk->nsproxy;struct user_namespace *user_ns =task_cred_xxx (tsk, user_ns);struct nsproxy *new_ns; +u64 containerid =audit_get_containerid (tsk); if (likely(!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWPID | CLONE_NEWNET |@@ -167,6 +168,7 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)return PTR_ERR (new_ns);Quoted 8 lines
kernel/nsproxy.c int copy_namespaces(unsigned long flags, struct task_struct *tsk) · line 173
Quoted 4 lines
kernel/nsproxy.c +1
-0tsk->nsproxy = new_ns; +net_add_audit_containerid (new_ns->net_ns, containerid);return 0 ; }Hopefully we can handle this in
audit_net_init(), we just need to figure out where we can get the correcttask_structfor the audit container ID (some backpointer in the net struct?).Quoted 2 lines
I don't follow. This needs to happen on every task startup.
audit_net_init()is only called when a new network namespace starts up.Yep, sorry, my mistake. I must have confused myself when I was looking at the code.
I'm thinking out loud here, bear with me ...
Quoted 7 lines
Assuming we move the netns/audit-container-ID tracking to
audit_net, and considering we already have an audit hook incopy_process()(it callsaudit_alloc()), would this be better handled by thecopy_process()hook? This ignores naming,audit_alloc()reuse, etc.; those can be easily fixed. I'm just thinking of ways to limit our impact on the core kernel and leverage our existing interaction points.
The new namespace hasn't been cloned yet and this is the only function where we have access to both namespaces, so I don't see how that could work...
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
A message that is not in the archive (sent off-list or not yet received): 20180420200226.7tyxzuovdbgclw3m-bcJWsdo4jJjeVoXN4CMphl7TgLCtbB0G@public.gmane.org
Re: [RFC PATCH ghak32 V2 11/13] audit: add support for containerid to network namespaces
Quoted 31 lines · Richard Guy Briggs
Quoted 30 lines · Paul Moore
Quoted 29 lines · Richard Guy Briggs
Audit events could happen in a network namespace outside of a task context due to packets received from the net that trigger an auditing rule prior to being associated with a running task. The network namespace could in use by multiple containers by association to the tasks in that network namespace. We still want a way to attribute these events to any potential containers. Keep a list per network namespace to track these container identifiiers.
Add/increment the container identifier on:
- initial setting of the container id via /proc
- clone/fork call that inherits a container identifier
- unshare call that inherits a container identifier
- setns call that inherits a container identifier Delete/decrement the container identifier on:
- an inherited container id dropped when child set
- process exit
- unshare call that drops a net namespace
- setns call that drops a net namespaceSee: https://github.com/linux-audit/audit-kernel/issues/32
See: https://github.com/linux-audit/audit-testsuite/issues/64Signed-off-by Richard Guy Briggs <[email protected]>--- include/linux/audit.h | 7 +++++++ include/net/net_namespace.h | 12 ++++++++++++ kernel/auditsc.c | 9 ++++++--- kernel/nsproxy.c | 6 ++++++ net/core/net_namespace.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 76 insertions(+), 3 deletions(-)
...
Quoted 24 lines
Quoted 15 lines
Quoted 15 lines
kernel/nsproxy.c +1
-0@@ -140,6 +140,7 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)struct nsproxy *old_ns = tsk->nsproxy;struct user_namespace *user_ns =task_cred_xxx (tsk, user_ns);struct nsproxy *new_ns; +u64 containerid =audit_get_containerid (tsk); if (likely(!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWPID | CLONE_NEWNET |@@ -167,6 +168,7 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)return PTR_ERR (new_ns);Quoted 8 lines
kernel/nsproxy.c int copy_namespaces(unsigned long flags, struct task_struct *tsk) · line 173
Quoted 4 lines
kernel/nsproxy.c +1
-0tsk->nsproxy = new_ns; +net_add_audit_containerid (new_ns->net_ns, containerid);return 0 ; }Hopefully we can handle this in
audit_net_init(), we just need to figure out where we can get the correcttask_structfor the audit container ID (some backpointer in the net struct?).
Quoted 2 lines
I don't follow. This needs to happen on every task startup.
audit_net_init()is only called when a new network namespace starts up.
Yep, sorry, my mistake. I must have confused myself when I was looking at the code.
I'm thinking out loud here, bear with me ...
Assuming we move the netns/audit-container-ID tracking to audit_net, and considering we already have an audit hook in copy_process() (it calls audit_alloc()), would this be better handled by the copy_process() hook? This ignores naming, audit_alloc() reuse, etc.; those can be easily fixed. I'm just thinking of ways to limit our impact on the core kernel and leverage our existing interaction points.
Signature · 2 lines
paul moore www.paul-moore.com
A message that is not in the archive (sent off-list or not yet received): CAHC9VhRkstDMjd5T3w+iOUDjzDAs1AOm0xd3p6v_xn6fNGYQhA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Re: [RFC PATCH ghak32 V2 11/13] audit: add support for containerid to network namespaces
Quoted 96 lines · Paul Moore
Quoted 29 lines · Richard Guy Briggs
Audit events could happen in a network namespace outside of a task context due to packets received from the net that trigger an auditing rule prior to being associated with a running task. The network namespace could in use by multiple containers by association to the tasks in that network namespace. We still want a way to attribute these events to any potential containers. Keep a list per network namespace to track these container identifiiers.
Add/increment the container identifier on:
- initial setting of the container id via /proc
- clone/fork call that inherits a container identifier
- unshare call that inherits a container identifier
- setns call that inherits a container identifier Delete/decrement the container identifier on:
- an inherited container id dropped when child set
- process exit
- unshare call that drops a net namespace
- setns call that drops a net namespaceSee: https://github.com/linux-audit/audit-kernel/issues/32
See: https://github.com/linux-audit/audit-testsuite/issues/64Signed-off-by Richard Guy Briggs <[email protected]>--- include/linux/audit.h | 7 +++++++ include/net/net_namespace.h | 12 ++++++++++++ kernel/auditsc.c | 9 ++++++--- kernel/nsproxy.c | 6 ++++++ net/core/net_namespace.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 76 insertions(+), 3 deletions(-)...
Quoted 13 lines
include/net/net_namespace.h +1
-0@@ -33,6 +33,7 @@#include <linux/ns_common.h> #include <linux/idr.h> #include <linux/skbuff.h> +#include <linux/audit.h> struct user_namespace ;struct proc_dir_entry ;include/net/net_namespace.h struct net { · line 155
Quoted 5 lines
include/net/net_namespace.h +1
-0@@ -150,6 +151,7 @@ struct net {#endif struct sock *diag_nlsk;atomic_t fnhe_genid; +struct list_head audit_containerid; } __randomize_layout;We talked about this briefly off-list, you should be using
audit_netand thenet_genericmechanism instead of this.Quoted 41 lines
include/net/net_namespace.h +10
-0#include <linux/seq_file_net.h> @@ -301,6 +303,16 @@ static inline struct net *read_pnet(const possible_net_t *pnet)#define __net_initconst __initconst#endif +#ifdef CONFIG_NET_NS +void net_add_audit_containerid (struct net *net,u64 containerid); +void net_del_audit_containerid (struct net *net,u64 containerid); +#else +static inline void net_add_audit_containerid (struct net *,u64 ) +{ } +static inline void net_del_audit_containerid (struct net *,u64 ) +{ } +#endif +int peernet2id_alloc (struct net *net,struct net *peer);int peernet2id (struct net *net,struct net *peer);bool peernet_has_id (struct net *net,struct net *peer);kernel/auditsc.c +3
-3@@ -75,6 +75,7 @@#include <linux/uaccess.h> #include <linux/fsnotify_backend.h> #include <uapi/linux/limits.h> +#include <net/net_namespace.h> #include "audit.h" @@ -2175,16 +2176,18 @@ static void audit_log_set_containerid(struct task_struct *task, u64 oldcontainer*/ int audit_set_containerid (struct task_struct *task,u64 containerid) { -u64 oldcontainerid; +u64 oldcontainerid =audit_get_containerid (task);int rc; - - oldcontainerid =audit_get_containerid (task); +struct net *net = task->nsproxy->net_ns;
Quoted 6 lines
kernel/auditsc.c static void audit_log_set_containerid(struct task_struct *task, u64 oldcontainer · line 2186
Quoted 4 lines
kernel/auditsc.c +2
-0rc =audit_set_containerid_perm (task, containerid);if (!rc) { +if (cid_valid (oldcontainerid)) +net_del_audit_containerid (net, oldcontainerid);Using
audit_netwe can handle this internal to audit, which is a Good Thing.
No problem, done.
Quoted 25 lines
kernel/auditsc.c static void audit_log_set_containerid(struct task_struct *task, u64 oldcontainer · line 2190
Quoted 4 lines
kernel/auditsc.c +1
-0task_lock (task); task->containerid = containerid;task_unlock (task); +net_add_audit_containerid (net, containerid);Same.
Quoted 18 lines
kernel/auditsc.c +0
-0}audit_log_set_containerid (task, oldcontainerid, containerid, rc);kernel/nsproxy.c +1
-0@@ -140,6 +140,7 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)struct nsproxy *old_ns = tsk->nsproxy;struct user_namespace *user_ns =task_cred_xxx (tsk, user_ns);struct nsproxy *new_ns; +u64 containerid =audit_get_containerid (tsk); if (likely(!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWPID | CLONE_NEWNET |@@ -167,6 +168,7 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)return PTR_ERR (new_ns);
Quoted 8 lines
kernel/nsproxy.c int copy_namespaces(unsigned long flags, struct task_struct *tsk) · line 173
Quoted 4 lines
kernel/nsproxy.c +1
-0tsk->nsproxy = new_ns; +net_add_audit_containerid (new_ns->net_ns, containerid);return 0 ; }Hopefully we can handle this in
audit_net_init(), we just need to figure out where we can get the correcttask_structfor the audit container ID (some backpointer in the net struct?).
I don't follow. This needs to happen on every task startup. audit_net_init() is only called when a new network namespace starts up.
Quoted 8 lines
Quoted 8 lines
kernel/nsproxy.c +1
-0@@ -217,6 +219,7 @@ int unshare_nsproxy_namespaces(unsigned long unshare_flags,void switch_task_namespaces (struct task_struct *p,struct nsproxy *new) {struct nsproxy *ns; +u64 containerid =audit_get_containerid (p);might_sleep ();
Quoted 10 lines
kernel/nsproxy.c void switch_task_namespaces(struct task_struct *p, struct nsproxy *new) · line 232
Quoted 7 lines
kernel/nsproxy.c +3
-0@@ -224,6 +227,9 @@ void switch_task_namespaces(struct task_struct *p, struct nsproxy *new) ns = p->nsproxy; p->nsproxy = new;task_unlock (p); +net_del_audit_containerid (ns->net_ns, containerid); +if (new) +net_add_audit_containerid (new->net_ns, containerid);Okay, we might need a hook here for switching namespaces, but I would much rather it be a generic audit hook that calls directly into audit.
Trivial, done.
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
A message that is not in the archive (sent off-list or not yet received): 11b43a498e768a14764594c808a96b34d52be0af.1521179281.git.rgb-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
Re: [RFC PATCH ghak32 V2 11/13] audit: add support for containerid to network namespaces
Quoted 29 lines · Richard Guy Briggs
Audit events could happen in a network namespace outside of a task context due to packets received from the net that trigger an auditing rule prior to being associated with a running task. The network namespace could in use by multiple containers by association to the tasks in that network namespace. We still want a way to attribute these events to any potential containers. Keep a list per network namespace to track these container identifiiers.
Add/increment the container identifier on:
- initial setting of the container id via /proc
- clone/fork call that inherits a container identifier
- unshare call that inherits a container identifier
- setns call that inherits a container identifier Delete/decrement the container identifier on:
- an inherited container id dropped when child set
- process exit
- unshare call that drops a net namespace
- setns call that drops a net namespaceSee: https://github.com/linux-audit/audit-kernel/issues/32
See: https://github.com/linux-audit/audit-testsuite/issues/64Signed-off-by Richard Guy Briggs <[email protected]>--- include/linux/audit.h | 7 +++++++ include/net/net_namespace.h | 12 ++++++++++++ kernel/auditsc.c | 9 ++++++--- kernel/nsproxy.c | 6 ++++++ net/core/net_namespace.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 76 insertions(+), 3 deletions(-)
...
Quoted 13 lines
include/net/net_namespace.h +1
-0@@ -33,6 +33,7 @@#include <linux/ns_common.h> #include <linux/idr.h> #include <linux/skbuff.h> +#include <linux/audit.h> struct user_namespace ;struct proc_dir_entry ;
include/net/net_namespace.h struct net { · line 155
Quoted 5 lines
include/net/net_namespace.h +1
-0@@ -150,6 +151,7 @@ struct net {#endif struct sock *diag_nlsk;atomic_t fnhe_genid; +struct list_head audit_containerid; } __randomize_layout;
We talked about this briefly off-list, you should be using audit_net and the net_generic mechanism instead of this.
Quoted 35 lines
include/net/net_namespace.h +10
-0#include <linux/seq_file_net.h> @@ -301,6 +303,16 @@ static inline struct net *read_pnet(const possible_net_t *pnet)#define __net_initconst __initconst#endif +#ifdef CONFIG_NET_NS +void net_add_audit_containerid (struct net *net,u64 containerid); +void net_del_audit_containerid (struct net *net,u64 containerid); +#else +static inline void net_add_audit_containerid (struct net *,u64 ) +{ } +static inline void net_del_audit_containerid (struct net *,u64 ) +{ } +#endif +int peernet2id_alloc (struct net *net,struct net *peer);int peernet2id (struct net *net,struct net *peer);bool peernet_has_id (struct net *net,struct net *peer);kernel/auditsc.c +1
-1@@ -75,6 +75,7 @@#include <linux/uaccess.h> #include <linux/fsnotify_backend.h> #include <uapi/linux/limits.h> +#include <net/net_namespace.h> #include "audit.h" @@ -2175,16 +2176,18 @@ static void audit_log_set_containerid(struct task_struct *task, u64 oldcontainer*/ int audit_set_containerid (struct task_struct *task,u64 containerid) { -u64 oldcontainerid;
kernel/auditsc.c static void audit_log_set_containerid(struct task_struct *task, u64 oldcontainer · line 2186
Quoted 10 lines
kernel/auditsc.c +4
-2+u64 oldcontainerid =audit_get_containerid (task);int rc; - - oldcontainerid =audit_get_containerid (task); +struct net *net = task->nsproxy->net_ns; rc =audit_set_containerid_perm (task, containerid);if (!rc) { +if (cid_valid (oldcontainerid)) +net_del_audit_containerid (net, oldcontainerid);
Using audit_net we can handle this internal to audit, which is a Good Thing.
kernel/auditsc.c static void audit_log_set_containerid(struct task_struct *task, u64 oldcontainer · line 2190
Quoted 4 lines
kernel/auditsc.c +1
-0task_lock (task); task->containerid = containerid;task_unlock (task); +net_add_audit_containerid (net, containerid);
Same.
Quoted 16 lines
kernel/auditsc.c +0
-0}audit_log_set_containerid (task, oldcontainerid, containerid, rc);kernel/nsproxy.c +1
-0@@ -140,6 +140,7 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)struct nsproxy *old_ns = tsk->nsproxy;struct user_namespace *user_ns =task_cred_xxx (tsk, user_ns);struct nsproxy *new_ns; +u64 containerid =audit_get_containerid (tsk); if (likely(!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWPID | CLONE_NEWNET |
kernel/nsproxy.c int copy_namespaces(unsigned long flags, struct task_struct *tsk) · line 173
Quoted 6 lines
kernel/nsproxy.c +1
-0@@ -167,6 +168,7 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)return PTR_ERR (new_ns); tsk->nsproxy = new_ns; +net_add_audit_containerid (new_ns->net_ns, containerid);return 0 ; }
Hopefully we can handle this in audit_net_init(), we just need to figure out where we can get the correct task_struct for the audit container ID (some backpointer in the net struct?).
Quoted 9 lines
kernel/nsproxy.c +1
-0@@ -217,6 +219,7 @@ int unshare_nsproxy_namespaces(unsigned long unshare_flags,void switch_task_namespaces (struct task_struct *p,struct nsproxy *new) {struct nsproxy *ns; +u64 containerid =audit_get_containerid (p);might_sleep ();
kernel/nsproxy.c void switch_task_namespaces(struct task_struct *p, struct nsproxy *new) · line 232
Quoted 6 lines
kernel/nsproxy.c +3
-0@@ -224,6 +227,9 @@ void switch_task_namespaces(struct task_struct *p, struct nsproxy *new) ns = p->nsproxy; p->nsproxy = new;task_unlock (p); +net_del_audit_containerid (ns->net_ns, containerid); +if (new) +net_add_audit_containerid (new->net_ns, containerid);
Okay, we might need a hook here for switching namespaces, but I would much rather it be a generic audit hook that calls directly into audit.
Signature · 2 lines
paul moore www.paul-moore.com
RFC PATCH v2 12/13 audit: NETFILTER_PKT: record each container ID associated with a netNS
In reply to Richard Guy BriggsAdd container ID auxiliary record(s) to NETFILTER_PKT event standalone records. Iterate through all potential container IDs associated with a network namespace.
--- kernel/audit.c | 1 + kernel/auditsc.c | 2 ++ net/netfilter/xt_AUDIT.c | 15 ++++++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-)
kernel/audit.c +1 -0
@@ -2102,6 +2102,7 @@ int audit_log_container_info(struct audit_context *context,audit_log_end (ab);return 0 ; } +EXPORT_SYMBOL (audit_log_container_info);void audit_log_key (struct audit_buffer *ab,char *key) {
kernel/auditsc.c +2 -0
@@ -975,6 +975,7 @@ struct audit_context *audit_alloc_local(void) context->in_syscall =1 ;return context; } +EXPORT_SYMBOL (audit_alloc_local);inline void audit_free_context (struct audit_context *context) {
@@ -989,6 +990,7 @@ inline void audit_free_context(struct audit_context *context)audit_proctitle_free (context);kfree (context); } +EXPORT_SYMBOL (audit_free_context); static int audit_log_pid_context(struct audit_context *context, pid_t pid, kuid_t auid, kuid_t uid, unsigned int sessionid,
net/netfilter/xt_AUDIT.c +14 -1
@@ -71,10 +71,14 @@ static bool audit_ip6(struct audit_buffer *ab, struct sk_buff *skb) {struct audit_buffer *ab;int fam =-1 ; +struct audit_context *context =audit_alloc_local (); +struct audit_containerid *cont; +int i =0 ; +struct net *net;if (audit_enabled ==0 ) goto errout; - ab =audit_log_start (NULL ,GFP_ATOMIC ,AUDIT_NETFILTER_PKT ); + ab =audit_log_start (context,GFP_ATOMIC ,AUDIT_NETFILTER_PKT );if (ab ==NULL ) goto errout;
@@ -104,7 +108,16 @@ static bool audit_ip6(struct audit_buffer *ab, struct sk_buff *skb)audit_log_end (ab); + net =sock_net (NETLINK_CB (skb).sk); +list_for_each_entry (cont, &net->audit_containerid, list) { +char buf[14 ]; + +sprintf (buf,"net%u" , i++); +audit_log_container_info (context, buf, cont->id); + } + errout: +audit_free_context (context);return XT_CONTINUE ; }
Signature · 1 line
1.8.3.1
Paul Moore
maintainerRe: [RFC PATCH ghak32 V2 12/13] audit: NETFILTER_PKT: record each container ID associated with a netNS
Quoted 48 lines · Richard Guy Briggs
Add container ID auxiliary record(s) to
NETFILTER_PKTevent standalone records. Iterate through all potential container IDs associated with a network namespace.Signed-off-by Richard Guy Briggs <[email protected]>--- kernel/audit.c | 1 + kernel/auditsc.c | 2 ++ net/netfilter/xt_AUDIT.c | 15 ++++++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-)kernel/audit.c +1
-0@@ -2102,6 +2102,7 @@ int audit_log_container_info(struct audit_context *context,audit_log_end (ab);return 0 ; } +EXPORT_SYMBOL (audit_log_container_info);void audit_log_key (struct audit_buffer *ab,char *key) {kernel/auditsc.c +2
-0@@ -975,6 +975,7 @@ struct audit_context *audit_alloc_local(void) context->in_syscall =1 ;return context; } +EXPORT_SYMBOL (audit_alloc_local);inline void audit_free_context (struct audit_context *context) {@@ -989,6 +990,7 @@ inline void audit_free_context(struct audit_context *context)audit_proctitle_free (context);kfree (context); } +EXPORT_SYMBOL (audit_free_context); static int audit_log_pid_context(struct audit_context *context, pid_t pid, kuid_t auid, kuid_t uid, unsigned int sessionid,net/netfilter/xt_AUDIT.c +0
-0
net/netfilter/xt_AUDIT.c static bool audit_ip6(struct audit_buffer *ab, struct sk_buff *skb) · line 80
Quoted 10 lines
net/netfilter/xt_AUDIT.c +4
-0@@ -71,10 +71,14 @@ static bool audit_ip6(struct audit_buffer *ab, struct sk_buff *skb) {struct audit_buffer *ab;int fam =-1 ; +struct audit_context *context =audit_alloc_local (); +struct audit_containerid *cont; +int i =0 ; +struct net *net;if (audit_enabled ==0 ) goto errout;
Do I need to say it? I probably should ... the allocation should happen after the audit_enabled check.
Quoted 6 lines
net/netfilter/xt_AUDIT.c +1
-1- ab =audit_log_start (NULL ,GFP_ATOMIC ,AUDIT_NETFILTER_PKT ); + ab =audit_log_start (context,GFP_ATOMIC ,AUDIT_NETFILTER_PKT );if (ab ==NULL ) goto errout;
net/netfilter/xt_AUDIT.c static bool audit_ip6(struct audit_buffer *ab, struct sk_buff *skb) · line 117
Quoted 10 lines
net/netfilter/xt_AUDIT.c +7
-0@@ -104,7 +108,16 @@ static bool audit_ip6(struct audit_buffer *ab, struct sk_buff *skb)audit_log_end (ab); + net =sock_net (NETLINK_CB (skb).sk); +list_for_each_entry (cont, &net->audit_containerid, list) { +char buf[14 ]; + +sprintf (buf,"net%u" , i++); +audit_log_container_info (context, buf, cont->id); + }
It seems like this could (should?) be hidden inside an audit function, e.g. audit_log_net_containers() or something like that.
Quoted 4 lines
net/netfilter/xt_AUDIT.c +1
-0errout: +audit_free_context (context);return XT_CONTINUE ; }
Signature · 2 lines
paul moore www.paul-moore.com
Re: [RFC PATCH ghak32 V2 12/13] audit: NETFILTER_PKT: record each container ID associated with a netNS
Quoted 57 lines · Paul Moore
Quoted 56 lines · Richard Guy Briggs
Add container ID auxiliary record(s) to
NETFILTER_PKTevent standalone records. Iterate through all potential container IDs associated with a network namespace.Signed-off-by Richard Guy Briggs <[email protected]>--- kernel/audit.c | 1 + kernel/auditsc.c | 2 ++ net/netfilter/xt_AUDIT.c | 15 ++++++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-)kernel/audit.c +1
-0@@ -2102,6 +2102,7 @@ int audit_log_container_info(struct audit_context *context,audit_log_end (ab);return 0 ; } +EXPORT_SYMBOL (audit_log_container_info);void audit_log_key (struct audit_buffer *ab,char *key) {kernel/auditsc.c +2
-0@@ -975,6 +975,7 @@ struct audit_context *audit_alloc_local(void) context->in_syscall =1 ;return context; } +EXPORT_SYMBOL (audit_alloc_local);inline void audit_free_context (struct audit_context *context) {@@ -989,6 +990,7 @@ inline void audit_free_context(struct audit_context *context)audit_proctitle_free (context);kfree (context); } +EXPORT_SYMBOL (audit_free_context); static int audit_log_pid_context(struct audit_context *context, pid_t pid, kuid_t auid, kuid_t uid, unsigned int sessionid,net/netfilter/xt_AUDIT.c +4
-0@@ -71,10 +71,14 @@ static bool audit_ip6(struct audit_buffer *ab, struct sk_buff *skb) {struct audit_buffer *ab;int fam =-1 ; +struct audit_context *context =audit_alloc_local (); +struct audit_containerid *cont; +int i =0 ; +struct net *net;
Quoted 5 lines
net/netfilter/xt_AUDIT.c static bool audit_ip6(struct audit_buffer *ab, struct sk_buff *skb) · line 80
Quoted 2 lines
net/netfilter/xt_AUDIT.c +0
-0if (audit_enabled ==0 ) goto errout;Do I need to say it? I probably should ... the allocation should happen after the
audit_enabledcheck.
Already fixed in V3 in my tree a couple of weeks ago... More timely review please?
Quoted 9 lines
Quoted 9 lines
net/netfilter/xt_AUDIT.c +1
-1- ab =audit_log_start (NULL ,GFP_ATOMIC ,AUDIT_NETFILTER_PKT ); + ab =audit_log_start (context,GFP_ATOMIC ,AUDIT_NETFILTER_PKT );if (ab ==NULL ) goto errout;@@ -104,7 +108,16 @@ static bool audit_ip6(struct audit_buffer *ab, struct sk_buff *skb)audit_log_end (ab);
Quoted 10 lines
net/netfilter/xt_AUDIT.c static bool audit_ip6(struct audit_buffer *ab, struct sk_buff *skb) · line 117
Quoted 7 lines
net/netfilter/xt_AUDIT.c +7
-0+ net =sock_net (NETLINK_CB (skb).sk); +list_for_each_entry (cont, &net->audit_containerid, list) { +char buf[14 ]; + +sprintf (buf,"net%u" , i++); +audit_log_container_info (context, buf, cont->id); + }It seems like this could (should?) be hidden inside an audit function, e.g.
audit_log_net_containers()or something like that.
Perhaps... It was open-coded since at this point there are no other users. That'll make this tidier though.
Quoted 8 lines
Quoted 4 lines
net/netfilter/xt_AUDIT.c +1
-0errout: +audit_free_context (context);return XT_CONTINUE ; }Signature · 2 lines
paul moore www.paul-moore.com
- 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 12/13] audit: NETFILTER_PKT: record each container ID associated with a netNS
Quoted 58 lines · Richard Guy Briggs
Quoted 57 lines · Paul Moore
Quoted 56 lines · Richard Guy Briggs
Add container ID auxiliary record(s) to
NETFILTER_PKTevent standalone records. Iterate through all potential container IDs associated with a network namespace.Signed-off-by Richard Guy Briggs <[email protected]>--- kernel/audit.c | 1 + kernel/auditsc.c | 2 ++ net/netfilter/xt_AUDIT.c | 15 ++++++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-)kernel/audit.c +1
-0@@ -2102,6 +2102,7 @@ int audit_log_container_info(struct audit_context *context,audit_log_end (ab);return 0 ; } +EXPORT_SYMBOL (audit_log_container_info);void audit_log_key (struct audit_buffer *ab,char *key) {kernel/auditsc.c +2
-0@@ -975,6 +975,7 @@ struct audit_context *audit_alloc_local(void) context->in_syscall =1 ;return context; } +EXPORT_SYMBOL (audit_alloc_local);inline void audit_free_context (struct audit_context *context) {@@ -989,6 +990,7 @@ inline void audit_free_context(struct audit_context *context)audit_proctitle_free (context);kfree (context); } +EXPORT_SYMBOL (audit_free_context); static int audit_log_pid_context(struct audit_context *context, pid_t pid, kuid_t auid, kuid_t uid, unsigned int sessionid,net/netfilter/xt_AUDIT.c +4
-0@@ -71,10 +71,14 @@ static bool audit_ip6(struct audit_buffer *ab, struct sk_buff *skb) {struct audit_buffer *ab;int fam =-1 ; +struct audit_context *context =audit_alloc_local (); +struct audit_containerid *cont; +int i =0 ; +struct net *net;
Quoted 7 lines
Quoted 5 lines
net/netfilter/xt_AUDIT.c static bool audit_ip6(struct audit_buffer *ab, struct sk_buff *skb) · line 80
Quoted 2 lines
net/netfilter/xt_AUDIT.c +0
-0if (audit_enabled ==0 ) goto errout;Do I need to say it? I probably should ... the allocation should happen after the
audit_enabledcheck.Already fixed in V3 in my tree a couple of weeks ago...
... which you never posted, at least not anywhere I've seen. Which effectively means I wasted a good chunk of time reviewing this code late last night. Awesome.
Quoted 1 line
More timely review please?
More patience on your part?
Quoted 20 lines
Quoted 9 lines
Quoted 9 lines
net/netfilter/xt_AUDIT.c +1
-1- ab =audit_log_start (NULL ,GFP_ATOMIC ,AUDIT_NETFILTER_PKT ); + ab =audit_log_start (context,GFP_ATOMIC ,AUDIT_NETFILTER_PKT );if (ab ==NULL ) goto errout;@@ -104,7 +108,16 @@ static bool audit_ip6(struct audit_buffer *ab, struct sk_buff *skb)audit_log_end (ab);Quoted 10 lines
net/netfilter/xt_AUDIT.c static bool audit_ip6(struct audit_buffer *ab, struct sk_buff *skb) · line 117
Quoted 7 lines
net/netfilter/xt_AUDIT.c +7
-0+ net =sock_net (NETLINK_CB (skb).sk); +list_for_each_entry (cont, &net->audit_containerid, list) { +char buf[14 ]; + +sprintf (buf,"net%u" , i++); +audit_log_container_info (context, buf, cont->id); + }It seems like this could (should?) be hidden inside an audit function, e.g.
audit_log_net_containers()or something like that.
Quoted 2 lines
Perhaps... It was open-coded since at this point there are no other users. That'll make this tidier though.
If the code was all contained within a single subsystem them I would generally agree that open coding is preferable, but since we are crossing a subsystem boundary I think it would be preferable to abstract away the details into a separate function.
This will probably also be necessary once you change to using the audit_net/net_generic mechanism.
Signature · 2 lines
paul moore www.paul-moore.com
A message that is not in the archive (sent off-list or not yet received): CAHC9VhR3BNRr24BPxud0X_eyFmSxUOh9bwjWNU4Z=rnDR0fENA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Re: [RFC PATCH ghak32 V2 12/13] audit: NETFILTER_PKT: record each container ID associated with a netNS
Quoted 57 lines · Paul Moore
Quoted 56 lines · Richard Guy Briggs
Add container ID auxiliary record(s) to
NETFILTER_PKTevent standalone records. Iterate through all potential container IDs associated with a network namespace.Signed-off-by Richard Guy Briggs <[email protected]>--- kernel/audit.c | 1 + kernel/auditsc.c | 2 ++ net/netfilter/xt_AUDIT.c | 15 ++++++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-)kernel/audit.c +1
-0@@ -2102,6 +2102,7 @@ int audit_log_container_info(struct audit_context *context,audit_log_end (ab);return 0 ; } +EXPORT_SYMBOL (audit_log_container_info);void audit_log_key (struct audit_buffer *ab,char *key) {kernel/auditsc.c +2
-0@@ -975,6 +975,7 @@ struct audit_context *audit_alloc_local(void) context->in_syscall =1 ;return context; } +EXPORT_SYMBOL (audit_alloc_local);inline void audit_free_context (struct audit_context *context) {@@ -989,6 +990,7 @@ inline void audit_free_context(struct audit_context *context)audit_proctitle_free (context);kfree (context); } +EXPORT_SYMBOL (audit_free_context); static int audit_log_pid_context(struct audit_context *context, pid_t pid, kuid_t auid, kuid_t uid, unsigned int sessionid,net/netfilter/xt_AUDIT.c +4
-0@@ -71,10 +71,14 @@ static bool audit_ip6(struct audit_buffer *ab, struct sk_buff *skb) {struct audit_buffer *ab;int fam =-1 ; +struct audit_context *context =audit_alloc_local (); +struct audit_containerid *cont; +int i =0 ; +struct net *net;
Quoted 5 lines
net/netfilter/xt_AUDIT.c static bool audit_ip6(struct audit_buffer *ab, struct sk_buff *skb) · line 80
Quoted 2 lines
net/netfilter/xt_AUDIT.c +0
-0if (audit_enabled ==0 ) goto errout;Do I need to say it? I probably should ... the allocation should happen after the
audit_enabledcheck.
Already fixed in V3 in my tree a couple of weeks ago... More timely review please?
Quoted 9 lines
Quoted 9 lines
net/netfilter/xt_AUDIT.c +1
-1- ab =audit_log_start (NULL ,GFP_ATOMIC ,AUDIT_NETFILTER_PKT ); + ab =audit_log_start (context,GFP_ATOMIC ,AUDIT_NETFILTER_PKT );if (ab ==NULL ) goto errout;@@ -104,7 +108,16 @@ static bool audit_ip6(struct audit_buffer *ab, struct sk_buff *skb)audit_log_end (ab);
Quoted 10 lines
net/netfilter/xt_AUDIT.c static bool audit_ip6(struct audit_buffer *ab, struct sk_buff *skb) · line 117
Quoted 7 lines
net/netfilter/xt_AUDIT.c +7
-0+ net =sock_net (NETLINK_CB (skb).sk); +list_for_each_entry (cont, &net->audit_containerid, list) { +char buf[14 ]; + +sprintf (buf,"net%u" , i++); +audit_log_container_info (context, buf, cont->id); + }It seems like this could (should?) be hidden inside an audit function, e.g.
audit_log_net_containers()or something like that.
Perhaps... It was open-coded since at this point there are no other users. That'll make this tidier though.
Quoted 8 lines
Quoted 4 lines
net/netfilter/xt_AUDIT.c +1
-0errout: +audit_free_context (context);return XT_CONTINUE ; }Signature · 2 lines
paul moore www.paul-moore.com
- 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
A message that is not in the archive (sent off-list or not yet received): 66adde01c1dda792aff99a457eea576a0b08ca98.1521179281.git.rgb-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
Re: [RFC PATCH ghak32 V2 12/13] audit: NETFILTER_PKT: record each container ID associated with a netNS
Quoted 48 lines · Richard Guy Briggs
Add container ID auxiliary record(s) to
NETFILTER_PKTevent standalone records. Iterate through all potential container IDs associated with a network namespace.Signed-off-by Richard Guy Briggs <[email protected]>--- kernel/audit.c | 1 + kernel/auditsc.c | 2 ++ net/netfilter/xt_AUDIT.c | 15 ++++++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-)kernel/audit.c +1
-0@@ -2102,6 +2102,7 @@ int audit_log_container_info(struct audit_context *context,audit_log_end (ab);return 0 ; } +EXPORT_SYMBOL (audit_log_container_info);void audit_log_key (struct audit_buffer *ab,char *key) {kernel/auditsc.c +2
-0@@ -975,6 +975,7 @@ struct audit_context *audit_alloc_local(void) context->in_syscall =1 ;return context; } +EXPORT_SYMBOL (audit_alloc_local);inline void audit_free_context (struct audit_context *context) {@@ -989,6 +990,7 @@ inline void audit_free_context(struct audit_context *context)audit_proctitle_free (context);kfree (context); } +EXPORT_SYMBOL (audit_free_context); static int audit_log_pid_context(struct audit_context *context, pid_t pid, kuid_t auid, kuid_t uid, unsigned int sessionid,net/netfilter/xt_AUDIT.c +0
-0
net/netfilter/xt_AUDIT.c static bool audit_ip6(struct audit_buffer *ab, struct sk_buff *skb) · line 80
Quoted 10 lines
net/netfilter/xt_AUDIT.c +4
-0@@ -71,10 +71,14 @@ static bool audit_ip6(struct audit_buffer *ab, struct sk_buff *skb) {struct audit_buffer *ab;int fam =-1 ; +struct audit_context *context =audit_alloc_local (); +struct audit_containerid *cont; +int i =0 ; +struct net *net;if (audit_enabled ==0 ) goto errout;
Do I need to say it? I probably should ... the allocation should happen after the audit_enabled check.
Quoted 6 lines
net/netfilter/xt_AUDIT.c +1
-1- ab =audit_log_start (NULL ,GFP_ATOMIC ,AUDIT_NETFILTER_PKT ); + ab =audit_log_start (context,GFP_ATOMIC ,AUDIT_NETFILTER_PKT );if (ab ==NULL ) goto errout;
net/netfilter/xt_AUDIT.c static bool audit_ip6(struct audit_buffer *ab, struct sk_buff *skb) · line 117
Quoted 10 lines
net/netfilter/xt_AUDIT.c +7
-0@@ -104,7 +108,16 @@ static bool audit_ip6(struct audit_buffer *ab, struct sk_buff *skb)audit_log_end (ab); + net =sock_net (NETLINK_CB (skb).sk); +list_for_each_entry (cont, &net->audit_containerid, list) { +char buf[14 ]; + +sprintf (buf,"net%u" , i++); +audit_log_container_info (context, buf, cont->id); + }
It seems like this could (should?) be hidden inside an audit function, e.g. audit_log_net_containers() or something like that.
Quoted 4 lines
net/netfilter/xt_AUDIT.c +1
-0errout: +audit_free_context (context);return XT_CONTINUE ; }
Signature · 2 lines
paul moore www.paul-moore.com
RFC PATCH v2 13/13 debug audit: read container ID of a process
In reply to Richard Guy BriggsAdd support for reading the container ID from the proc filesystem.
This is a read from the proc entry of the form /proc/PID/containerid where PID is the process ID of the task whose container ID is sought.
The read expects up to a u64 value (unset: 18446744073709551615).
--- fs/proc/base.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
fs/proc/base.c +18 -2
@@ -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,#ifdef CONFIG_AUDITSYSCALL REG ("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_AUDITSYSCALL REG ("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),
Signature · 1 line
1.8.3.1
Re: [RFC PATCH ghak32 V2 13/13] debug audit: read container ID of a process
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.
-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
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.
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
Quoted 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
A message that is not in the archive (sent off-list or not yet received): 87muwshl4z.fsf-aS9lmoZGLiVWk0Htik3J/[email protected]
Re: [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:
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
A message that is not in the archive (sent off-list or not yet received): 1081821010c124fe4e35984ec3dac1654453bb7c.1521179281.git.rgb-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
Re: [RFC PATCH ghak32 V2 13/13] debug audit: read container ID of a process
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.
-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),
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