Re: [PATCH ghak25 v4 3/3] audit: add subj creds to NETFILTER_CFG record to cover async unregister
On Sun, May 17, 2020 at 8:40 PM Richard Guy Briggs wrote: > On 2020-05-17 17:50, Paul Moore wrote: > > On Sun, May 17, 2020 at 10:15 AM Richard Guy Briggs wrote: > > > On 2020-04-28 18:25, Paul Moore wrote: > > > > On Wed, Apr 22, 2020 at 5:40 PM Richard Guy Briggs > > > > wrote: > > > > > Some table unregister actions seem to be initiated by the kernel to > > > > > garbage collect unused tables that are not initiated by any userspace > > > > > actions. It was found to be necessary to add the subject credentials > > > > > to > > > > > cover this case to reveal the source of these actions. A sample > > > > > record: > > > > > > > > > > type=NETFILTER_CFG msg=audit(2020-03-11 21:25:21.491:269) : > > > > > table=nat family=bridge entries=0 op=unregister pid=153 uid=root > > > > > auid=unset tty=(none) ses=unset subj=system_u:system_r:kernel_t:s0 > > > > > comm=kworker/u4:2 exe=(null) > > > > > > > > [I'm going to comment up here instead of in the code because it is a > > > > bit easier for everyone to see what the actual impact might be on the > > > > records.] > > > > > > > > Steve wants subject info in this case, okay, but let's try to trim out > > > > some of the fields which simply don't make sense in this record; I'm > > > > thinking of fields that are unset/empty in the kernel case and are > > > > duplicates of other records in the userspace/syscall case. I think > > > > that means we can drop "tty", "ses", "comm", and "exe" ... yes? > > > > > > > > While "auid" is a potential target for removal based on the > > > > dup-or-unset criteria, I think it falls under Steve's request for > > > > subject info here, even if it is garbage in this case. > > > > > > Can you explain why auid falls under this criteria but ses does not if > > > both are unset? > > > > "While "auid" is a potential target for removal based on the > > dup-or-unset criteria, I think it falls under Steve's request for > > subject info here, even if it is garbage in this case." > > > > It's a concession to Steve. As I mentioned previously, I think the > > subject info is bogus in this case; either it is valid and we get it > > from the SYSCALL record or it simply isn't present in any meaningful > > way. > > Sorry for being so dense. I still don't follow your explanation. You've > repeated the same paragraph that didn't make sense to me the first time. > > What definition of "subject info" are you working with? The subject is generally the task which is causing the event to occur, "subject info" would be any such attribute which describes the subject; examples include LSM label, the various UIDs/GIDs, etc.. Think "current->cred" and you on the right track. > I had assumed > it was the set of fields that contain information that came from that > task's struct task_struct. Some of those fields contain information > that isn't helpful. Why not remove them all rather than keep one that > still contains no useful information? Once again - and I don't know how else to explain this to you - I think it is pointless to record the subject info in this record as we either have that info from other records in the event or there is no valid subject info to record. As you state in the commit description: "Some table unregister actions seem to be initiated by the kernel to garbage collect unused tables that are not initiated by any userspace actions." > Or is it a matter of keeping one > key field that contains no useful information that proves that the rest > is bogus? Steve said that daemons leave no useful information in auid > as well, so I don't see how keeping this field helps us. My > understanding is that the subj field's "...:kernel_t:..." is the key > here and that pid and comm give us a bit more of a clue that it is a > kernel thread. Is that correct? What use does including auid serve > here? As I've mentioned in the thread above, including the auid was done as a concession to Steve, I don't think it serves any useful purpose. -- paul moore www.paul-moore.com
Re: [PATCH ghak25 v4 3/3] audit: add subj creds to NETFILTER_CFG record to cover async unregister
On 2020-05-17 17:50, Paul Moore wrote: > On Sun, May 17, 2020 at 10:15 AM Richard Guy Briggs wrote: > > On 2020-04-28 18:25, Paul Moore wrote: > > > On Wed, Apr 22, 2020 at 5:40 PM Richard Guy Briggs > > > wrote: > > > > Some table unregister actions seem to be initiated by the kernel to > > > > garbage collect unused tables that are not initiated by any userspace > > > > actions. It was found to be necessary to add the subject credentials to > > > > cover this case to reveal the source of these actions. A sample record: > > > > > > > > type=NETFILTER_CFG msg=audit(2020-03-11 21:25:21.491:269) : table=nat > > > > family=bridge entries=0 op=unregister pid=153 uid=root auid=unset > > > > tty=(none) ses=unset subj=system_u:system_r:kernel_t:s0 > > > > comm=kworker/u4:2 exe=(null) > > > > > > [I'm going to comment up here instead of in the code because it is a > > > bit easier for everyone to see what the actual impact might be on the > > > records.] > > > > > > Steve wants subject info in this case, okay, but let's try to trim out > > > some of the fields which simply don't make sense in this record; I'm > > > thinking of fields that are unset/empty in the kernel case and are > > > duplicates of other records in the userspace/syscall case. I think > > > that means we can drop "tty", "ses", "comm", and "exe" ... yes? > > > > > > While "auid" is a potential target for removal based on the > > > dup-or-unset criteria, I think it falls under Steve's request for > > > subject info here, even if it is garbage in this case. > > > > Can you explain why auid falls under this criteria but ses does not if > > both are unset? > > "While "auid" is a potential target for removal based on the > dup-or-unset criteria, I think it falls under Steve's request for > subject info here, even if it is garbage in this case." > > It's a concession to Steve. As I mentioned previously, I think the > subject info is bogus in this case; either it is valid and we get it > from the SYSCALL record or it simply isn't present in any meaningful > way. Sorry for being so dense. I still don't follow your explanation. You've repeated the same paragraph that didn't make sense to me the first time. What definition of "subject info" are you working with? I had assumed it was the set of fields that contain information that came from that task's struct task_struct. Some of those fields contain information that isn't helpful. Why not remove them all rather than keep one that still contains no useful information? Or is it a matter of keeping one key field that contains no useful information that proves that the rest is bogus? Steve said that daemons leave no useful information in auid as well, so I don't see how keeping this field helps us. My understanding is that the subj field's "...:kernel_t:..." is the key here and that pid and comm give us a bit more of a clue that it is a kernel thread. Is that correct? What use does including auid serve here? I suppose that the uid field is somewhat useful, since the kernel could conceivably switch to a particular user to run a kernel thread. Is that even currently possible? > paul moore - RGB -- Richard Guy Briggs Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada IRC: rgb, SunRaycer Voice: +1.647.777.2635, Internal: (81) 32635
Re: [PATCH ghak25 v4 3/3] audit: add subj creds to NETFILTER_CFG record to cover async unregister
On Sun, May 17, 2020 at 10:15 AM Richard Guy Briggs wrote: > On 2020-04-28 18:25, Paul Moore wrote: > > On Wed, Apr 22, 2020 at 5:40 PM Richard Guy Briggs wrote: > > > Some table unregister actions seem to be initiated by the kernel to > > > garbage collect unused tables that are not initiated by any userspace > > > actions. It was found to be necessary to add the subject credentials to > > > cover this case to reveal the source of these actions. A sample record: > > > > > > type=NETFILTER_CFG msg=audit(2020-03-11 21:25:21.491:269) : table=nat > > > family=bridge entries=0 op=unregister pid=153 uid=root auid=unset > > > tty=(none) ses=unset subj=system_u:system_r:kernel_t:s0 comm=kworker/u4:2 > > > exe=(null) > > > > [I'm going to comment up here instead of in the code because it is a > > bit easier for everyone to see what the actual impact might be on the > > records.] > > > > Steve wants subject info in this case, okay, but let's try to trim out > > some of the fields which simply don't make sense in this record; I'm > > thinking of fields that are unset/empty in the kernel case and are > > duplicates of other records in the userspace/syscall case. I think > > that means we can drop "tty", "ses", "comm", and "exe" ... yes? > > > > While "auid" is a potential target for removal based on the > > dup-or-unset criteria, I think it falls under Steve's request for > > subject info here, even if it is garbage in this case. > > Can you explain why auid falls under this criteria but ses does not if > both are unset? "While "auid" is a potential target for removal based on the dup-or-unset criteria, I think it falls under Steve's request for subject info here, even if it is garbage in this case." It's a concession to Steve. As I mentioned previously, I think the subject info is bogus in this case; either it is valid and we get it from the SYSCALL record or it simply isn't present in any meaningful way. -- paul moore www.paul-moore.com
Re: [PATCH ghak25 v4 3/3] audit: add subj creds to NETFILTER_CFG record to cover async unregister
On 2020-04-28 18:25, Paul Moore wrote: > On Wed, Apr 22, 2020 at 5:40 PM Richard Guy Briggs wrote: > > Some table unregister actions seem to be initiated by the kernel to > > garbage collect unused tables that are not initiated by any userspace > > actions. It was found to be necessary to add the subject credentials to > > cover this case to reveal the source of these actions. A sample record: > > > > type=NETFILTER_CFG msg=audit(2020-03-11 21:25:21.491:269) : table=nat > > family=bridge entries=0 op=unregister pid=153 uid=root auid=unset > > tty=(none) ses=unset subj=system_u:system_r:kernel_t:s0 comm=kworker/u4:2 > > exe=(null) > > [I'm going to comment up here instead of in the code because it is a > bit easier for everyone to see what the actual impact might be on the > records.] > > Steve wants subject info in this case, okay, but let's try to trim out > some of the fields which simply don't make sense in this record; I'm > thinking of fields that are unset/empty in the kernel case and are > duplicates of other records in the userspace/syscall case. I think > that means we can drop "tty", "ses", "comm", and "exe" ... yes? > > While "auid" is a potential target for removal based on the > dup-or-unset criteria, I think it falls under Steve's request for > subject info here, even if it is garbage in this case. Can you explain why auid falls under this criteria but ses does not if both are unset? If auid is unset then we know ses is unset? If subj contains *:kernel_t:* then uid can also be dropped even though it is set, no? I figure if we are going to start dropping fields, might as well drop enough to make it worth the effort, even though this is a rare event. As for searchability, I have solved that easily in the parser. > > Signed-off-by: Richard Guy Briggs > > --- > > kernel/auditsc.c | 18 ++ > > 1 file changed, 18 insertions(+) > > > > diff --git a/kernel/auditsc.c b/kernel/auditsc.c > > index d281c18d1771..d7a45b181be0 100644 > > --- a/kernel/auditsc.c > > +++ b/kernel/auditsc.c > > @@ -2557,12 +2557,30 @@ void __audit_log_nfcfg(const char *name, u8 af, > > unsigned int nentries, > >enum audit_nfcfgop op) > > { > > struct audit_buffer *ab; > > + const struct cred *cred; > > + struct tty_struct *tty; > > + char comm[sizeof(current->comm)]; > > > > ab = audit_log_start(audit_context(), GFP_KERNEL, > > AUDIT_NETFILTER_CFG); > > if (!ab) > > return; > > audit_log_format(ab, "table=%s family=%u entries=%u op=%s", > > name, af, nentries, audit_nfcfgs[op].s); > > + > > + cred = current_cred(); > > + tty = audit_get_tty(); > > + audit_log_format(ab, " pid=%u uid=%u auid=%u tty=%s ses=%u", > > +task_pid_nr(current), > > +from_kuid(_user_ns, cred->uid), > > +from_kuid(_user_ns, > > audit_get_loginuid(current)), > > +tty ? tty_name(tty) : "(none)", > > +audit_get_sessionid(current)); > > + audit_put_tty(tty); > > + audit_log_task_context(ab); /* subj= */ > > + audit_log_format(ab, " comm="); > > + audit_log_untrustedstring(ab, get_task_comm(comm, current)); > > + audit_log_d_path_exe(ab, current->mm); /* exe= */ > > + > > audit_log_end(ab); > > } > > EXPORT_SYMBOL_GPL(__audit_log_nfcfg); > > paul moore - RGB -- Richard Guy Briggs Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada IRC: rgb, SunRaycer Voice: +1.647.777.2635, Internal: (81) 32635
Re: [PATCH ghak25 v4 3/3] audit: add subj creds to NETFILTER_CFG record to cover async unregister
On Wednesday, May 6, 2020 6:42:33 PM EDT Richard Guy Briggs wrote: > > > > We can't be adding deleting fields based on how its triggered. If > > > > they are unset, that is fine. The main issue is they have to behave > > > > the same. > > > > > > I don't think the intent was to have fields swing in and out depending > > > on trigger. The idea is to potentially permanently not include them in > > > this record type only. The justification is that where they aren't > > > needed for the kernel trigger situation it made sense to delete them > > > because if it is a user context event it will be accompanied by a > > > syscall record that already has that information and there would be no > > > sense in duplicating it. > > > > We should not be adding syscall records to anything that does not result > > from a syscall rule triggering the event. Its very wasteful. More > > wasteful than just adding the necessary fields. > > So what you are saying is you want all the fields that are being > proposed to be added to this record? Yes. > If the records are all from one event, they all should all have the same > timestamp/serial number so that the records are kept together and not > mistaken for multiple events. But NETFILTER_CFG is a simple event known to have only 1 record. > One reason for having information in seperate records is to be able to > filter them either in kernel or in userspace if you don't need certain > records. We can't filter out SYSCALL. -Steve
Re: [PATCH ghak25 v4 3/3] audit: add subj creds to NETFILTER_CFG record to cover async unregister
On Wed, May 6, 2020 at 6:43 PM Richard Guy Briggs wrote: > On 2020-05-06 17:26, Steve Grubb wrote: > > On Wednesday, April 29, 2020 5:32:47 PM EDT Richard Guy Briggs wrote: > > > On 2020-04-29 14:47, Steve Grubb wrote: > > > > On Wednesday, April 29, 2020 10:31:46 AM EDT Richard Guy Briggs wrote: > > > > > On 2020-04-28 18:25, Paul Moore wrote: > > > > > > On Wed, Apr 22, 2020 at 5:40 PM Richard Guy Briggs > > > > > > > > wrote: > > > > > > > Some table unregister actions seem to be initiated by the kernel > > > > > > > to > > > > > > > garbage collect unused tables that are not initiated by any > > > > > > > userspace > > > > > > > actions. It was found to be necessary to add the subject > > > > > > > credentials > > > > > > > to cover this case to reveal the source of these actions. A > > > > > > > sample > > > > > > > record: > > > > > > > type=NETFILTER_CFG msg=audit(2020-03-11 21:25:21.491:269) : > > > > > > > table=nat > > > > > > > family=bridge entries=0 op=unregister pid=153 uid=root auid=unset > > > > > > > tty=(none) ses=unset subj=system_u:system_r:kernel_t:s0 > > > > > > > comm=kworker/u4:2 exe=(null)> > > > > > > > > > > > > [I'm going to comment up here instead of in the code because it is a > > > > > > bit easier for everyone to see what the actual impact might be on > > > > > > the > > > > > > records.] > > > > > > > > > > > > Steve wants subject info in this case, okay, but let's try to trim > > > > > > out > > > > > > some of the fields which simply don't make sense in this record; I'm > > > > > > thinking of fields that are unset/empty in the kernel case and are > > > > > > duplicates of other records in the userspace/syscall case. I think > > > > > > that means we can drop "tty", "ses", "comm", and "exe" ... yes? > > > > > > > > > > From the ghak28 discussion, this list and order was selected due to > > > > > Steve's preference for the "kernel" record convention, so deviating > > > > > from this will create yet a new field list. I'll defer to Steve on > > > > > this. It also has to do with the searchability of fields if they are > > > > > missing. > > > > > > > > > > I do agree that some fields will be superfluous in the kernel case. > > > > > The most important field would be "subj", but then "pid" and "comm", I > > > > > would think. Based on this contents of the "subj" field, I'd think > > > > > that "uid", "auid", "tty", "ses" and "exe" are not needed. > > > > > > > > We can't be adding deleting fields based on how its triggered. If they > > > > are unset, that is fine. The main issue is they have to behave the same. > > > > > > I don't think the intent was to have fields swing in and out depending > > > on trigger. The idea is to potentially permanently not include them in > > > this record type only. The justification is that where they aren't > > > needed for the kernel trigger situation it made sense to delete them > > > because if it is a user context event it will be accompanied by a > > > syscall record that already has that information and there would be no > > > sense in duplicating it. > > > > We should not be adding syscall records to anything that does not result > > from > > a syscall rule triggering the event. Its very wasteful. More wasteful than > > just adding the necessary fields. > > So what you are saying is you want all the fields that are being > proposed to be added to this record? > > If the records are all from one event, they all should all have the same > timestamp/serial number so that the records are kept together and not > mistaken for multiple events. One reason for having information in > seperate records is to be able to filter them either in kernel or in > userspace if you don't need certain records. Yes, I'm opposed to duplicating fields across records in a single event. If there are cases where we have a standalone record, such as with "unregister", then there is an argument to be made about duplicating some fields that are important in the standalone unregister case. However, this is *only* for those fields which make sense in the standalone kernel unregister event; if the field isn't useful in this unregister corner case *and* it is duplicated in another record type which normally accompanies this record in an event there is no reason it needs to be in this record. > > I also wished we had a coding specification that put this in writing so that > > every event is not a committee decision. That anyone can look at the > > document > > and Do The Right Thing ™. > > > > If I add a section to Writing-Good-Events outlining the expected ordering of > > fields, would that be enough that we do not have long discussions about > > event > > format? I'm thinking this would also help new people that want to > > contribute. To be clear, we are not changing any existing record formats; they are part of the kernel/userspace ABI and changing them would break the ABI. In a perfect world both the audit kernel and userspace would have been
Re: [PATCH ghak25 v4 3/3] audit: add subj creds to NETFILTER_CFG record to cover async unregister
On 2020-05-06 17:26, Steve Grubb wrote: > On Wednesday, April 29, 2020 5:32:47 PM EDT Richard Guy Briggs wrote: > > On 2020-04-29 14:47, Steve Grubb wrote: > > > On Wednesday, April 29, 2020 10:31:46 AM EDT Richard Guy Briggs wrote: > > > > On 2020-04-28 18:25, Paul Moore wrote: > > > > > On Wed, Apr 22, 2020 at 5:40 PM Richard Guy Briggs > > > > > > wrote: > > > > > > Some table unregister actions seem to be initiated by the kernel to > > > > > > garbage collect unused tables that are not initiated by any > > > > > > userspace > > > > > > actions. It was found to be necessary to add the subject > > > > > > credentials > > > > > > to cover this case to reveal the source of these actions. A > > > > > > sample > > > > > > record: > > > > > > type=NETFILTER_CFG msg=audit(2020-03-11 21:25:21.491:269) : > > > > > > table=nat > > > > > > family=bridge entries=0 op=unregister pid=153 uid=root auid=unset > > > > > > tty=(none) ses=unset subj=system_u:system_r:kernel_t:s0 > > > > > > comm=kworker/u4:2 exe=(null)> > > > > > > > > > > [I'm going to comment up here instead of in the code because it is a > > > > > bit easier for everyone to see what the actual impact might be on the > > > > > records.] > > > > > > > > > > Steve wants subject info in this case, okay, but let's try to trim > > > > > out > > > > > some of the fields which simply don't make sense in this record; I'm > > > > > thinking of fields that are unset/empty in the kernel case and are > > > > > duplicates of other records in the userspace/syscall case. I think > > > > > that means we can drop "tty", "ses", "comm", and "exe" ... yes? > > > > > > > > From the ghak28 discussion, this list and order was selected due to > > > > Steve's preference for the "kernel" record convention, so deviating > > > > from this will create yet a new field list. I'll defer to Steve on > > > > this. It also has to do with the searchability of fields if they are > > > > missing. > > > > > > > > I do agree that some fields will be superfluous in the kernel case. > > > > The most important field would be "subj", but then "pid" and "comm", I > > > > would think. Based on this contents of the "subj" field, I'd think > > > > that "uid", "auid", "tty", "ses" and "exe" are not needed. > > > > > > We can't be adding deleting fields based on how its triggered. If they > > > are unset, that is fine. The main issue is they have to behave the same. > > > > I don't think the intent was to have fields swing in and out depending > > on trigger. The idea is to potentially permanently not include them in > > this record type only. The justification is that where they aren't > > needed for the kernel trigger situation it made sense to delete them > > because if it is a user context event it will be accompanied by a > > syscall record that already has that information and there would be no > > sense in duplicating it. > > We should not be adding syscall records to anything that does not result from > a syscall rule triggering the event. Its very wasteful. More wasteful than > just adding the necessary fields. So what you are saying is you want all the fields that are being proposed to be added to this record? If the records are all from one event, they all should all have the same timestamp/serial number so that the records are kept together and not mistaken for multiple events. One reason for having information in seperate records is to be able to filter them either in kernel or in userspace if you don't need certain records. > I also wished we had a coding specification that put this in writing so that > every event is not a committee decision. That anyone can look at the document > and Do The Right Thing ™. > > If I add a section to Writing-Good-Events outlining the expected ordering of > fields, would that be enough that we do not have long discussions about event > format? I'm thinking this would also help new people that want to contribute. If you add this expected ordering of fields, can we re-factor all the kernel code to use this order because the userspace parser won't care what order they are in? I realize this isn't what you are saying, but having a clear description in that document that talks about the different classes of events and what each one needs in terms of minimum to full subject attributes and object attributes would help a lot. It would also help for new records to be able to decide if it should follow the format of an existing related or similar record, or a new class with the expected standard order. > -Steve - RGB -- Richard Guy Briggs Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada IRC: rgb, SunRaycer Voice: +1.647.777.2635, Internal: (81) 32635
Re: [PATCH ghak25 v4 3/3] audit: add subj creds to NETFILTER_CFG record to cover async unregister
On Wednesday, April 29, 2020 5:32:47 PM EDT Richard Guy Briggs wrote: > On 2020-04-29 14:47, Steve Grubb wrote: > > On Wednesday, April 29, 2020 10:31:46 AM EDT Richard Guy Briggs wrote: > > > On 2020-04-28 18:25, Paul Moore wrote: > > > > On Wed, Apr 22, 2020 at 5:40 PM Richard Guy Briggs > > > > wrote: > > > > > Some table unregister actions seem to be initiated by the kernel to > > > > > garbage collect unused tables that are not initiated by any > > > > > userspace > > > > > actions. It was found to be necessary to add the subject > > > > > credentials > > > > > to cover this case to reveal the source of these actions. A > > > > > sample > > > > > record: > > > > > type=NETFILTER_CFG msg=audit(2020-03-11 21:25:21.491:269) : > > > > > table=nat > > > > > family=bridge entries=0 op=unregister pid=153 uid=root auid=unset > > > > > tty=(none) ses=unset subj=system_u:system_r:kernel_t:s0 > > > > > comm=kworker/u4:2 exe=(null)> > > > > > > > > [I'm going to comment up here instead of in the code because it is a > > > > bit easier for everyone to see what the actual impact might be on the > > > > records.] > > > > > > > > Steve wants subject info in this case, okay, but let's try to trim > > > > out > > > > some of the fields which simply don't make sense in this record; I'm > > > > thinking of fields that are unset/empty in the kernel case and are > > > > duplicates of other records in the userspace/syscall case. I think > > > > that means we can drop "tty", "ses", "comm", and "exe" ... yes? > > > > > > From the ghak28 discussion, this list and order was selected due to > > > Steve's preference for the "kernel" record convention, so deviating > > > from this will create yet a new field list. I'll defer to Steve on > > > this. It also has to do with the searchability of fields if they are > > > missing. > > > > > > I do agree that some fields will be superfluous in the kernel case. > > > The most important field would be "subj", but then "pid" and "comm", I > > > would think. Based on this contents of the "subj" field, I'd think > > > that "uid", "auid", "tty", "ses" and "exe" are not needed. > > > > We can't be adding deleting fields based on how its triggered. If they > > are unset, that is fine. The main issue is they have to behave the same. > > I don't think the intent was to have fields swing in and out depending > on trigger. The idea is to potentially permanently not include them in > this record type only. The justification is that where they aren't > needed for the kernel trigger situation it made sense to delete them > because if it is a user context event it will be accompanied by a > syscall record that already has that information and there would be no > sense in duplicating it. We should not be adding syscall records to anything that does not result from a syscall rule triggering the event. Its very wasteful. More wasteful than just adding the necessary fields. I also wished we had a coding specification that put this in writing so that every event is not a committee decision. That anyone can look at the document and Do The Right Thing ™. If I add a section to Writing-Good-Events outlining the expected ordering of fields, would that be enough that we do not have long discussions about event format? I'm thinking this would also help new people that want to contribute. -Steve
Re: [PATCH ghak25 v4 3/3] audit: add subj creds to NETFILTER_CFG record to cover async unregister
On Wed, Apr 29, 2020 at 5:33 PM Richard Guy Briggs wrote: > On 2020-04-29 14:47, Steve Grubb wrote: > > On Wednesday, April 29, 2020 10:31:46 AM EDT Richard Guy Briggs wrote: > > > On 2020-04-28 18:25, Paul Moore wrote: > > > > On Wed, Apr 22, 2020 at 5:40 PM Richard Guy Briggs > > wrote: > > > > > Some table unregister actions seem to be initiated by the kernel to > > > > > garbage collect unused tables that are not initiated by any userspace > > > > > actions. It was found to be necessary to add the subject credentials > > > > > to cover this case to reveal the source of these actions. A sample > > > > > record: > > > > > type=NETFILTER_CFG msg=audit(2020-03-11 21:25:21.491:269) : > > > > > table=nat > > > > > family=bridge entries=0 op=unregister pid=153 uid=root auid=unset > > > > > tty=(none) ses=unset subj=system_u:system_r:kernel_t:s0 > > > > > comm=kworker/u4:2 exe=(null)> > > > > [I'm going to comment up here instead of in the code because it is a > > > > bit easier for everyone to see what the actual impact might be on the > > > > records.] > > > > > > > > Steve wants subject info in this case, okay, but let's try to trim out > > > > some of the fields which simply don't make sense in this record; I'm > > > > thinking of fields that are unset/empty in the kernel case and are > > > > duplicates of other records in the userspace/syscall case. I think > > > > that means we can drop "tty", "ses", "comm", and "exe" ... yes? > > > > > > From the ghak28 discussion, this list and order was selected due to > > > Steve's preference for the "kernel" record convention, so deviating from > > > this will create yet a new field list. I'll defer to Steve on this. It > > > also has to do with the searchability of fields if they are missing. > > > > > > I do agree that some fields will be superfluous in the kernel case. > > > The most important field would be "subj", but then "pid" and "comm", I > > > would think. Based on this contents of the "subj" field, I'd think that > > > "uid", "auid", "tty", "ses" and "exe" are not needed. > > > > We can't be adding deleting fields based on how its triggered. If they are > > unset, that is fine. The main issue is they have to behave the same. > > I don't think the intent was to have fields swing in and out depending > on trigger. The idea is to potentially permanently not include them in > this record type only. The justification is that where they aren't > needed for the kernel trigger situation it made sense to delete them > because if it is a user context event it will be accompanied by a > syscall record that already has that information and there would be no > sense in duplicating it. Yes, exactly. -- paul moore www.paul-moore.com
Re: [PATCH ghak25 v4 3/3] audit: add subj creds to NETFILTER_CFG record to cover async unregister
On 2020-04-29 14:47, Steve Grubb wrote: > On Wednesday, April 29, 2020 10:31:46 AM EDT Richard Guy Briggs wrote: > > On 2020-04-28 18:25, Paul Moore wrote: > > > On Wed, Apr 22, 2020 at 5:40 PM Richard Guy Briggs > wrote: > > > > Some table unregister actions seem to be initiated by the kernel to > > > > garbage collect unused tables that are not initiated by any userspace > > > > actions. It was found to be necessary to add the subject credentials > > > > to cover this case to reveal the source of these actions. A sample > > > > record: > > > > type=NETFILTER_CFG msg=audit(2020-03-11 21:25:21.491:269) : table=nat > > > > family=bridge entries=0 op=unregister pid=153 uid=root auid=unset > > > > tty=(none) ses=unset subj=system_u:system_r:kernel_t:s0 > > > > comm=kworker/u4:2 exe=(null)> > > > [I'm going to comment up here instead of in the code because it is a > > > bit easier for everyone to see what the actual impact might be on the > > > records.] > > > > > > Steve wants subject info in this case, okay, but let's try to trim out > > > some of the fields which simply don't make sense in this record; I'm > > > thinking of fields that are unset/empty in the kernel case and are > > > duplicates of other records in the userspace/syscall case. I think > > > that means we can drop "tty", "ses", "comm", and "exe" ... yes? > > > > From the ghak28 discussion, this list and order was selected due to > > Steve's preference for the "kernel" record convention, so deviating from > > this will create yet a new field list. I'll defer to Steve on this. It > > also has to do with the searchability of fields if they are missing. > > > > I do agree that some fields will be superfluous in the kernel case. > > The most important field would be "subj", but then "pid" and "comm", I > > would think. Based on this contents of the "subj" field, I'd think that > > "uid", "auid", "tty", "ses" and "exe" are not needed. > > We can't be adding deleting fields based on how its triggered. If they are > unset, that is fine. The main issue is they have to behave the same. I don't think the intent was to have fields swing in and out depending on trigger. The idea is to potentially permanently not include them in this record type only. The justification is that where they aren't needed for the kernel trigger situation it made sense to delete them because if it is a user context event it will be accompanied by a syscall record that already has that information and there would be no sense in duplicating it. > > > While "auid" is a potential target for removal based on the > > > dup-or-unset criteria, I think it falls under Steve's request for > > > subject info here, even if it is garbage in this case. > > auid is always unset for daemons. We do not throw it away because of that. > > -Steve > > > If we keep auid, I'd say keep ses, since they usually go together, > > though they are separated by another field in this "kernel" record field > > ordering. > > > > I expect this orphan record to occur so infrequently that I don't think > > bandwidth or space are a serious concern. > > > > > > Signed-off-by: Richard Guy Briggs > > > > --- > > > > > > > > kernel/auditsc.c | 18 ++ > > > > 1 file changed, 18 insertions(+) > > > > > > > > diff --git a/kernel/auditsc.c b/kernel/auditsc.c > > > > index d281c18d1771..d7a45b181be0 100644 > > > > --- a/kernel/auditsc.c > > > > +++ b/kernel/auditsc.c > > > > @@ -2557,12 +2557,30 @@ void __audit_log_nfcfg(const char *name, u8 af, > > > > unsigned int nentries,> > > > > >enum audit_nfcfgop op) > > > > > > > > { > > > > > > > > struct audit_buffer *ab; > > > > > > > > + const struct cred *cred; > > > > + struct tty_struct *tty; > > > > + char comm[sizeof(current->comm)]; > > > > > > > > ab = audit_log_start(audit_context(), GFP_KERNEL, > > > > AUDIT_NETFILTER_CFG); > > > > if (!ab) > > > > > > > > return; > > > > > > > > audit_log_format(ab, "table=%s family=%u entries=%u op=%s", > > > > > > > > name, af, nentries, audit_nfcfgs[op].s); > > > > > > > > + > > > > + cred = current_cred(); > > > > + tty = audit_get_tty(); > > > > + audit_log_format(ab, " pid=%u uid=%u auid=%u tty=%s ses=%u", > > > > +task_pid_nr(current), > > > > +from_kuid(_user_ns, cred->uid), > > > > +from_kuid(_user_ns, > > > > audit_get_loginuid(current)), +tty ? > > > > tty_name(tty) : "(none)", > > > > +audit_get_sessionid(current)); > > > > + audit_put_tty(tty); > > > > + audit_log_task_context(ab); /* subj= */ > > > > + audit_log_format(ab, " comm="); > > > > + audit_log_untrustedstring(ab, get_task_comm(comm, current)); > > > > + audit_log_d_path_exe(ab,
Re: [PATCH ghak25 v4 3/3] audit: add subj creds to NETFILTER_CFG record to cover async unregister
On Wednesday, April 29, 2020 10:31:46 AM EDT Richard Guy Briggs wrote: > On 2020-04-28 18:25, Paul Moore wrote: > > On Wed, Apr 22, 2020 at 5:40 PM Richard Guy Briggs wrote: > > > Some table unregister actions seem to be initiated by the kernel to > > > garbage collect unused tables that are not initiated by any userspace > > > actions. It was found to be necessary to add the subject credentials > > > to cover this case to reveal the source of these actions. A sample > > > record: > > > type=NETFILTER_CFG msg=audit(2020-03-11 21:25:21.491:269) : table=nat > > > family=bridge entries=0 op=unregister pid=153 uid=root auid=unset > > > tty=(none) ses=unset subj=system_u:system_r:kernel_t:s0 > > > comm=kworker/u4:2 exe=(null)> > > [I'm going to comment up here instead of in the code because it is a > > bit easier for everyone to see what the actual impact might be on the > > records.] > > > > Steve wants subject info in this case, okay, but let's try to trim out > > some of the fields which simply don't make sense in this record; I'm > > thinking of fields that are unset/empty in the kernel case and are > > duplicates of other records in the userspace/syscall case. I think > > that means we can drop "tty", "ses", "comm", and "exe" ... yes? > > From the ghak28 discussion, this list and order was selected due to > Steve's preference for the "kernel" record convention, so deviating from > this will create yet a new field list. I'll defer to Steve on this. It > also has to do with the searchability of fields if they are missing. > > I do agree that some fields will be superfluous in the kernel case. > The most important field would be "subj", but then "pid" and "comm", I > would think. Based on this contents of the "subj" field, I'd think that > "uid", "auid", "tty", "ses" and "exe" are not needed. We can't be adding deleting fields based on how its triggered. If they are unset, that is fine. The main issue is they have to behave the same. > > While "auid" is a potential target for removal based on the > > dup-or-unset criteria, I think it falls under Steve's request for > > subject info here, even if it is garbage in this case. auid is always unset for daemons. We do not throw it away because of that. -Steve > If we keep auid, I'd say keep ses, since they usually go together, > though they are separated by another field in this "kernel" record field > ordering. > > I expect this orphan record to occur so infrequently that I don't think > bandwidth or space are a serious concern. > > > > Signed-off-by: Richard Guy Briggs > > > --- > > > > > > kernel/auditsc.c | 18 ++ > > > 1 file changed, 18 insertions(+) > > > > > > diff --git a/kernel/auditsc.c b/kernel/auditsc.c > > > index d281c18d1771..d7a45b181be0 100644 > > > --- a/kernel/auditsc.c > > > +++ b/kernel/auditsc.c > > > @@ -2557,12 +2557,30 @@ void __audit_log_nfcfg(const char *name, u8 af, > > > unsigned int nentries,> > > > >enum audit_nfcfgop op) > > > > > > { > > > > > > struct audit_buffer *ab; > > > > > > + const struct cred *cred; > > > + struct tty_struct *tty; > > > + char comm[sizeof(current->comm)]; > > > > > > ab = audit_log_start(audit_context(), GFP_KERNEL, > > > AUDIT_NETFILTER_CFG); > > > if (!ab) > > > > > > return; > > > > > > audit_log_format(ab, "table=%s family=%u entries=%u op=%s", > > > > > > name, af, nentries, audit_nfcfgs[op].s); > > > > > > + > > > + cred = current_cred(); > > > + tty = audit_get_tty(); > > > + audit_log_format(ab, " pid=%u uid=%u auid=%u tty=%s ses=%u", > > > +task_pid_nr(current), > > > +from_kuid(_user_ns, cred->uid), > > > +from_kuid(_user_ns, > > > audit_get_loginuid(current)), +tty ? > > > tty_name(tty) : "(none)", > > > +audit_get_sessionid(current)); > > > + audit_put_tty(tty); > > > + audit_log_task_context(ab); /* subj= */ > > > + audit_log_format(ab, " comm="); > > > + audit_log_untrustedstring(ab, get_task_comm(comm, current)); > > > + audit_log_d_path_exe(ab, current->mm); /* exe= */ > > > + > > > > > > audit_log_end(ab); > > > > > > } > > > EXPORT_SYMBOL_GPL(__audit_log_nfcfg); > > - RGB > > -- > Richard Guy Briggs > Sr. S/W Engineer, Kernel Security, Base Operating Systems > Remote, Ottawa, Red Hat Canada > IRC: rgb, SunRaycer > Voice: +1.647.777.2635, Internal: (81) 32635
Re: [PATCH ghak25 v4 3/3] audit: add subj creds to NETFILTER_CFG record to cover async unregister
On 2020-04-28 18:25, Paul Moore wrote: > On Wed, Apr 22, 2020 at 5:40 PM Richard Guy Briggs wrote: > > Some table unregister actions seem to be initiated by the kernel to > > garbage collect unused tables that are not initiated by any userspace > > actions. It was found to be necessary to add the subject credentials to > > cover this case to reveal the source of these actions. A sample record: > > > > type=NETFILTER_CFG msg=audit(2020-03-11 21:25:21.491:269) : table=nat > > family=bridge entries=0 op=unregister pid=153 uid=root auid=unset > > tty=(none) ses=unset subj=system_u:system_r:kernel_t:s0 comm=kworker/u4:2 > > exe=(null) > > [I'm going to comment up here instead of in the code because it is a > bit easier for everyone to see what the actual impact might be on the > records.] > > Steve wants subject info in this case, okay, but let's try to trim out > some of the fields which simply don't make sense in this record; I'm > thinking of fields that are unset/empty in the kernel case and are > duplicates of other records in the userspace/syscall case. I think > that means we can drop "tty", "ses", "comm", and "exe" ... yes? >From the ghak28 discussion, this list and order was selected due to Steve's preference for the "kernel" record convention, so deviating from this will create yet a new field list. I'll defer to Steve on this. It also has to do with the searchability of fields if they are missing. I do agree that some fields will be superfluous in the kernel case. The most important field would be "subj", but then "pid" and "comm", I would think. Based on this contents of the "subj" field, I'd think that "uid", "auid", "tty", "ses" and "exe" are not needed. > While "auid" is a potential target for removal based on the > dup-or-unset criteria, I think it falls under Steve's request for > subject info here, even if it is garbage in this case. If we keep auid, I'd say keep ses, since they usually go together, though they are separated by another field in this "kernel" record field ordering. I expect this orphan record to occur so infrequently that I don't think bandwidth or space are a serious concern. > > Signed-off-by: Richard Guy Briggs > > --- > > kernel/auditsc.c | 18 ++ > > 1 file changed, 18 insertions(+) > > > > diff --git a/kernel/auditsc.c b/kernel/auditsc.c > > index d281c18d1771..d7a45b181be0 100644 > > --- a/kernel/auditsc.c > > +++ b/kernel/auditsc.c > > @@ -2557,12 +2557,30 @@ void __audit_log_nfcfg(const char *name, u8 af, > > unsigned int nentries, > >enum audit_nfcfgop op) > > { > > struct audit_buffer *ab; > > + const struct cred *cred; > > + struct tty_struct *tty; > > + char comm[sizeof(current->comm)]; > > > > ab = audit_log_start(audit_context(), GFP_KERNEL, > > AUDIT_NETFILTER_CFG); > > if (!ab) > > return; > > audit_log_format(ab, "table=%s family=%u entries=%u op=%s", > > name, af, nentries, audit_nfcfgs[op].s); > > + > > + cred = current_cred(); > > + tty = audit_get_tty(); > > + audit_log_format(ab, " pid=%u uid=%u auid=%u tty=%s ses=%u", > > +task_pid_nr(current), > > +from_kuid(_user_ns, cred->uid), > > +from_kuid(_user_ns, > > audit_get_loginuid(current)), > > +tty ? tty_name(tty) : "(none)", > > +audit_get_sessionid(current)); > > + audit_put_tty(tty); > > + audit_log_task_context(ab); /* subj= */ > > + audit_log_format(ab, " comm="); > > + audit_log_untrustedstring(ab, get_task_comm(comm, current)); > > + audit_log_d_path_exe(ab, current->mm); /* exe= */ > > + > > audit_log_end(ab); > > } > > EXPORT_SYMBOL_GPL(__audit_log_nfcfg); > > -- > paul moore > www.paul-moore.com > - RGB -- Richard Guy Briggs Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada IRC: rgb, SunRaycer Voice: +1.647.777.2635, Internal: (81) 32635
Re: [PATCH ghak25 v4 3/3] audit: add subj creds to NETFILTER_CFG record to cover async unregister
On Wed, Apr 22, 2020 at 5:40 PM Richard Guy Briggs wrote: > Some table unregister actions seem to be initiated by the kernel to > garbage collect unused tables that are not initiated by any userspace > actions. It was found to be necessary to add the subject credentials to > cover this case to reveal the source of these actions. A sample record: > > type=NETFILTER_CFG msg=audit(2020-03-11 21:25:21.491:269) : table=nat > family=bridge entries=0 op=unregister pid=153 uid=root auid=unset tty=(none) > ses=unset subj=system_u:system_r:kernel_t:s0 comm=kworker/u4:2 exe=(null) [I'm going to comment up here instead of in the code because it is a bit easier for everyone to see what the actual impact might be on the records.] Steve wants subject info in this case, okay, but let's try to trim out some of the fields which simply don't make sense in this record; I'm thinking of fields that are unset/empty in the kernel case and are duplicates of other records in the userspace/syscall case. I think that means we can drop "tty", "ses", "comm", and "exe" ... yes? While "auid" is a potential target for removal based on the dup-or-unset criteria, I think it falls under Steve's request for subject info here, even if it is garbage in this case. > Signed-off-by: Richard Guy Briggs > --- > kernel/auditsc.c | 18 ++ > 1 file changed, 18 insertions(+) > > diff --git a/kernel/auditsc.c b/kernel/auditsc.c > index d281c18d1771..d7a45b181be0 100644 > --- a/kernel/auditsc.c > +++ b/kernel/auditsc.c > @@ -2557,12 +2557,30 @@ void __audit_log_nfcfg(const char *name, u8 af, > unsigned int nentries, >enum audit_nfcfgop op) > { > struct audit_buffer *ab; > + const struct cred *cred; > + struct tty_struct *tty; > + char comm[sizeof(current->comm)]; > > ab = audit_log_start(audit_context(), GFP_KERNEL, > AUDIT_NETFILTER_CFG); > if (!ab) > return; > audit_log_format(ab, "table=%s family=%u entries=%u op=%s", > name, af, nentries, audit_nfcfgs[op].s); > + > + cred = current_cred(); > + tty = audit_get_tty(); > + audit_log_format(ab, " pid=%u uid=%u auid=%u tty=%s ses=%u", > +task_pid_nr(current), > +from_kuid(_user_ns, cred->uid), > +from_kuid(_user_ns, > audit_get_loginuid(current)), > +tty ? tty_name(tty) : "(none)", > +audit_get_sessionid(current)); > + audit_put_tty(tty); > + audit_log_task_context(ab); /* subj= */ > + audit_log_format(ab, " comm="); > + audit_log_untrustedstring(ab, get_task_comm(comm, current)); > + audit_log_d_path_exe(ab, current->mm); /* exe= */ > + > audit_log_end(ab); > } > EXPORT_SYMBOL_GPL(__audit_log_nfcfg); -- paul moore www.paul-moore.com