Skip to contentSkip to conversation

audit: Allow auditd to set pid to 0 to end auditing

PATCH In review Steve Grubb 3 participants 6 messages Oct 17, 2017 – Oct 19, 2017 Audit

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 audit: Allow auditd to set pid to 0 to end auditing

The API to end auditing has historically been for auditd to set the pid to 0. This patch restores that functionality.

See: https://github.com/linux-audit/audit-kernel/issues/69

---
 kernel/audit.c | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)
kernel/audit.c +0 -0
index 6dd556931739..f6d5fc1d8eb4 100644
@@ -1197,25 +1197,28 @@ static int audit_receive_msg(struct sk_buff *skb, 

struct nlmsghdr *nlh)
pid_t auditd_pid;
struct pid *req_pid = task_tgid(current);

- /* sanity check - PID values must match */
- if (new_pid != pid_vnr(req_pid))
+ /* Sanity check - PID values must match. Setting
+ * pid to 0 is how auditd ends auditing. */
+ if (new_pid && (new_pid != pid_vnr(req_pid)))
return -EINVAL;

/* test the auditd connection */ audit_replace(req_pid);

auditd_pid = auditd_pid_vnr();
- /* only the current auditd can unregister itself */
- if ((!new_pid) && (new_pid != auditd_pid)) {
- audit_log_config_change("audit_pid", new_pid,
- auditd_pid, 0);
- return -EACCES;
- }
- /* replacing a healthy auditd is not allowed */
- if (auditd_pid && new_pid) {
- audit_log_config_change("audit_pid", new_pid,
- auditd_pid, 0);
- return -EEXIST;
+ if (auditd_pid) {
+ /* replacing a healthy auditd is not allowed */
+ if (new_pid) {
+ audit_log_config_change("audit_pid",
+ new_pid, auditd_pid, 0);
+ return -EEXIST;
+ }
+ /* only current auditd can unregister itself */
+ if (pid_vnr(req_pid) != auditd_pid) {
+ audit_log_config_change("audit_pid",
+ new_pid, auditd_pid, 0);
+ return -EACCES;
+ }
}

if (new_pid) {

Signature · 1 line
2.13.6
maintainer
#1 lore raw
Quoted 6 lines · Steve Grubb

The API to end auditing has historically been for auditd to set the pid to 0. This patch restores that functionality.

See: https://github.com/linux-audit/audit-kernel/issues/69

A bit of kernel patch etiquette: if you make significant changes to a patch that has been previously tagged as "Acked-by", "Tested-by", or "Reviewed-by" it is considered polite to remove that tag in the new patch as the previous acks/tags/etc. really are no longer valid (at least that is my take on it). If Richard wants to re-review this new patch we can re-add the tag (I add the tags when I merge the patch).

Quoted 39 lines
---
 kernel/audit.c | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)
kernel/audit.c +6 -13
index 6dd556931739..f6d5fc1d8eb4 100644
@@ -1197,25 +1197,28 @@ static int audit_receive_msg(struct sk_buff *skb,
 struct nlmsghdr *nlh)
                        pid_t auditd_pid;
                        struct pid *req_pid = task_tgid(current);
 
-                       /* sanity check - PID values must match */
-                       if (new_pid != pid_vnr(req_pid))
+                       /* Sanity check - PID values must match. Setting
+                        * pid to 0 is how auditd ends auditing. */
+                       if (new_pid && (new_pid != pid_vnr(req_pid)))
                                return -EINVAL;
 
                        /* test the auditd connection */
                        audit_replace(req_pid);
 
                        auditd_pid = auditd_pid_vnr();
-                       /* only the current auditd can unregister itself */
-                       if ((!new_pid) && (new_pid != auditd_pid)) {
-                               audit_log_config_change("audit_pid", new_pid,
-                                                       auditd_pid, 0);
-                               return -EACCES;
-                       }
-                       /* replacing a healthy auditd is not allowed */
-                       if (auditd_pid && new_pid) {
-                               audit_log_config_change("audit_pid", new_pid,
-                                                       auditd_pid, 0);
-                               return -EEXIST;
+                       if (auditd_pid) {
+                               /* replacing a healthy auditd is not allowed */
+                               if (new_pid) {

kernel/audit.c static int audit_receive_msg(struct sk_buff *skb, · line 1222

Quoted 10 lines
kernel/audit.c +10 -0
+                                       audit_log_config_change("audit_pid",
+                                                       new_pid, auditd_pid, 0);
+                                       return -EEXIST;
+                               }
+                               /* only current auditd can unregister itself */
+                               if (pid_vnr(req_pid) != auditd_pid) {
+                                       audit_log_config_change("audit_pid",
+                                                       new_pid, auditd_pid, 0);
+                                       return -EACCES;
+                               }

I realize that you reordered the checks to simplify the conditionals, but you did reorder the checks ... I'm thinking out loud right now trying to figure out if that really matters ... probably not, especially since the checks were broken anyway ... and you need CAP_AUDIT_CONTROL to even get this far ... we're probably okay.

FWIW, this is something else that is usually best noted in the patch description. When in doubt, be very verbose in the patch description; I've never rejected a patch because the description was too lengthy, but I have rejected patches because there wasn't enough explanation.

Anyway, this looks okay to me, I'll give it another day to see if Richard wants to re-review it, otherwise I'll strip his reviewed-by tag and merge it.

Quoted 3 lines
kernel/audit.c +0 -0
                        }
 
                        if (new_pid) {
Signature · 2 lines
paul moore
www.paul-moore.com
#2 lore raw
Quoted 29 lines · EDT Paul Moore
Quoted 25 lines

auditd_pid = auditd_pid_vnr();
- /* only the current auditd can unregister itself
*/

(quoted diff) +0 -2
-                       if ((!new_pid) && (new_pid != auditd_pid)) {
-                               audit_log_config_change("audit_pid",

new_pid, -
auditd_pid, 0); - return -EACCES;

(quoted diff) +0 -4
-                       }
-                       /* replacing a healthy auditd is not allowed */
-                       if (auditd_pid && new_pid) {
-                               audit_log_config_change("audit_pid",

new_pid, -
auditd_pid, 0); - return -EEXIST;

(quoted diff) +2 -0
+                       if (auditd_pid) {
+                               /* replacing a healthy auditd is not

allowed */ + if (new_pid) {
+
audit_log_config_change("audit_pid", +

                   new_pid, auditd_pid, 0); +                            
          return -EEXIST;
(quoted diff) +2 -0
+                               }
+                               /* only current auditd can unregister

itself */ + if (pid_vnr(req_pid) !=
auditd_pid) { +
audit_log_config_change("audit_pid", +

Quoted 3 lines
                   new_pid, auditd_pid, 0); +                            
          return -EACCES;

+ }

Quoted 5 lines

I realize that you reordered the checks to simplify the conditionals, but you did reorder the checks ... I'm thinking out loud right now trying to figure out if that really matters ... probably not, especially since the checks were broken anyway ... and you need CAP_AUDIT_CONTROL to even get this far ... we're probably okay.

Yes when refactoring as you suggested I realized that we can also remove some checks for new_pid == 0 because if its not, it takes the first "if" which returns. Therefore new_pid is guaranteed to be 0 and no check for that is needed. :-)

-Steve

#3 lore raw
In reply to Paul Moore
Quoted 71 lines · Paul Moore
Quoted 6 lines · Steve Grubb

The API to end auditing has historically been for auditd to set the pid to 0. This patch restores that functionality.

See: https://github.com/linux-audit/audit-kernel/issues/69

A bit of kernel patch etiquette: if you make significant changes to a patch that has been previously tagged as "Acked-by", "Tested-by", or "Reviewed-by" it is considered polite to remove that tag in the new patch as the previous acks/tags/etc. really are no longer valid (at least that is my take on it). If Richard wants to re-review this new patch we can re-add the tag (I add the tags when I merge the patch).

Quoted 39 lines
---
 kernel/audit.c | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)
kernel/audit.c +6 -13
index 6dd556931739..f6d5fc1d8eb4 100644
@@ -1197,25 +1197,28 @@ static int audit_receive_msg(struct sk_buff *skb,
 struct nlmsghdr *nlh)
                        pid_t auditd_pid;
                        struct pid *req_pid = task_tgid(current);
 
-                       /* sanity check - PID values must match */
-                       if (new_pid != pid_vnr(req_pid))
+                       /* Sanity check - PID values must match. Setting
+                        * pid to 0 is how auditd ends auditing. */
+                       if (new_pid && (new_pid != pid_vnr(req_pid)))
                                return -EINVAL;
 
                        /* test the auditd connection */
                        audit_replace(req_pid);
 
                        auditd_pid = auditd_pid_vnr();
-                       /* only the current auditd can unregister itself */
-                       if ((!new_pid) && (new_pid != auditd_pid)) {
-                               audit_log_config_change("audit_pid", new_pid,
-                                                       auditd_pid, 0);
-                               return -EACCES;
-                       }
-                       /* replacing a healthy auditd is not allowed */
-                       if (auditd_pid && new_pid) {
-                               audit_log_config_change("audit_pid", new_pid,
-                                                       auditd_pid, 0);
-                               return -EEXIST;
+                       if (auditd_pid) {
+                               /* replacing a healthy auditd is not allowed */
+                               if (new_pid) {

kernel/audit.c static int audit_receive_msg(struct sk_buff *skb, · line 1222

Quoted 10 lines
kernel/audit.c +10 -0
+                                       audit_log_config_change("audit_pid",
+                                                       new_pid, auditd_pid, 0);
+                                       return -EEXIST;
+                               }
+                               /* only current auditd can unregister itself */
+                               if (pid_vnr(req_pid) != auditd_pid) {
+                                       audit_log_config_change("audit_pid",
+                                                       new_pid, auditd_pid, 0);
+                                       return -EACCES;
+                               }

I realize that you reordered the checks to simplify the conditionals, but you did reorder the checks ... I'm thinking out loud right now trying to figure out if that really matters ... probably not, especially since the checks were broken anyway ... and you need CAP_AUDIT_CONTROL to even get this far ... we're probably okay.

Quoted 8 lines

FWIW, this is something else that is usually best noted in the patch description. When in doubt, be very verbose in the patch description; I've never rejected a patch because the description was too lengthy, but I have rejected patches because there wasn't enough explanation.

Anyway, this looks okay to me, I'll give it another day to see if Richard wants to re-review it, otherwise I'll strip his reviewed-by tag and merge it.

Reviewing...

Quoted 7 lines
Quoted 3 lines
kernel/audit.c +0 -0
                        }
 
                        if (new_pid) {
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

#4 lore raw
Quoted 77 lines · Richard Guy Briggs
Quoted 76 lines · Paul Moore
Quoted 6 lines · Steve Grubb

The API to end auditing has historically been for auditd to set the pid to 0. This patch restores that functionality.

See: https://github.com/linux-audit/audit-kernel/issues/69

A bit of kernel patch etiquette: if you make significant changes to a patch that has been previously tagged as "Acked-by", "Tested-by", or "Reviewed-by" it is considered polite to remove that tag in the new patch as the previous acks/tags/etc. really are no longer valid (at least that is my take on it). If Richard wants to re-review this new patch we can re-add the tag (I add the tags when I merge the patch).

Quoted 39 lines
---
 kernel/audit.c | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)
kernel/audit.c +6 -13
index 6dd556931739..f6d5fc1d8eb4 100644
@@ -1197,25 +1197,28 @@ static int audit_receive_msg(struct sk_buff *skb,
 struct nlmsghdr *nlh)
                        pid_t auditd_pid;
                        struct pid *req_pid = task_tgid(current);
 
-                       /* sanity check - PID values must match */
-                       if (new_pid != pid_vnr(req_pid))
+                       /* Sanity check - PID values must match. Setting
+                        * pid to 0 is how auditd ends auditing. */
+                       if (new_pid && (new_pid != pid_vnr(req_pid)))
                                return -EINVAL;
 
                        /* test the auditd connection */
                        audit_replace(req_pid);
 
                        auditd_pid = auditd_pid_vnr();
-                       /* only the current auditd can unregister itself */
-                       if ((!new_pid) && (new_pid != auditd_pid)) {
-                               audit_log_config_change("audit_pid", new_pid,
-                                                       auditd_pid, 0);
-                               return -EACCES;
-                       }
-                       /* replacing a healthy auditd is not allowed */
-                       if (auditd_pid && new_pid) {
-                               audit_log_config_change("audit_pid", new_pid,
-                                                       auditd_pid, 0);
-                               return -EEXIST;
+                       if (auditd_pid) {
+                               /* replacing a healthy auditd is not allowed */
+                               if (new_pid) {

kernel/audit.c static int audit_receive_msg(struct sk_buff *skb, · line 1222

Quoted 10 lines
kernel/audit.c +10 -0
+                                       audit_log_config_change("audit_pid",
+                                                       new_pid, auditd_pid, 0);
+                                       return -EEXIST;
+                               }
+                               /* only current auditd can unregister itself */
+                               if (pid_vnr(req_pid) != auditd_pid) {
+                                       audit_log_config_change("audit_pid",
+                                                       new_pid, auditd_pid, 0);
+                                       return -EACCES;
+                               }

I realize that you reordered the checks to simplify the conditionals, but you did reorder the checks ... I'm thinking out loud right now trying to figure out if that really matters ... probably not, especially since the checks were broken anyway ... and you need CAP_AUDIT_CONTROL to even get this far ... we're probably okay.

FWIW, this is something else that is usually best noted in the patch description. When in doubt, be very verbose in the patch description; I've never rejected a patch because the description was too lengthy, but I have rejected patches because there wasn't enough explanation.

Quoted 5 lines
Quoted 3 lines

Anyway, this looks okay to me, I'll give it another day to see if Richard wants to re-review it, otherwise I'll strip his reviewed-by tag and merge it.

Reviewing...

Looks good to me. The re-ordering looks fine. Re-ack.

Quoted 9 lines
Quoted 7 lines
Quoted 3 lines
kernel/audit.c +0 -0
                        }
 
                        if (new_pid) {
Signature · 2 lines
paul moore
www.paul-moore.com

- RGB

- RGB

--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635

maintainer
#5 lore raw
In reply to Steve Grubb
Quoted 10 lines · Steve Grubb

The API to end auditing has historically been for auditd to set the pid to 0. This patch restores that functionality.

See: https://github.com/linux-audit/audit-kernel/issues/69

---
 kernel/audit.c | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

As a FYI, I'm not sure how you are sending patches, but however you are doing it appears to mangling the patch with word wrap. Because I'm a nice guy, I'm going to go ahead and fix this up (apply by hand), but in the future you'll need to make that the patches can be applied straight from your email.

Quoted 55 lines
kernel/audit.c +16 -13
index 6dd556931739..f6d5fc1d8eb4 100644
@@ -1197,25 +1197,28 @@ static int audit_receive_msg(struct sk_buff *skb,
 struct nlmsghdr *nlh)
                        pid_t auditd_pid;
                        struct pid *req_pid = task_tgid(current);
 
-                       /* sanity check - PID values must match */
-                       if (new_pid != pid_vnr(req_pid))
+                       /* Sanity check - PID values must match. Setting
+                        * pid to 0 is how auditd ends auditing. */
+                       if (new_pid && (new_pid != pid_vnr(req_pid)))
                                return -EINVAL;
 
                        /* test the auditd connection */
                        audit_replace(req_pid);
 
                        auditd_pid = auditd_pid_vnr();
-                       /* only the current auditd can unregister itself */
-                       if ((!new_pid) && (new_pid != auditd_pid)) {
-                               audit_log_config_change("audit_pid", new_pid,
-                                                       auditd_pid, 0);
-                               return -EACCES;
-                       }
-                       /* replacing a healthy auditd is not allowed */
-                       if (auditd_pid && new_pid) {
-                               audit_log_config_change("audit_pid", new_pid,
-                                                       auditd_pid, 0);
-                               return -EEXIST;
+                       if (auditd_pid) {
+                               /* replacing a healthy auditd is not allowed */
+                               if (new_pid) {
+                                       audit_log_config_change("audit_pid",
+                                                       new_pid, auditd_pid, 0);
+                                       return -EEXIST;
+                               }
+                               /* only current auditd can unregister itself */
+                               if (pid_vnr(req_pid) != auditd_pid) {
+                                       audit_log_config_change("audit_pid",
+                                                       new_pid, auditd_pid, 0);
+                                       return -EACCES;
+                               }
                        }
 
                        if (new_pid) {

--
2.13.6

--
Linux-audit mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/linux-audit

Signature · 2 lines
paul moore
www.paul-moore.com