Skip to contentSkip to conversation

security: lsm_audit: print pid and tid

PATCH In review Jeff Vander Stoep 5 participants 8 messages Jul 26, 2016 – Aug 30, 2016 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 security: lsm_audit: print pid and tid

dump_common_audit_data() currently contains a field for pid, but the value printed is actually the thread ID, tid. Update this value to return the task group ID. Add a new field for tid. With this change the values printed by audit now match the values returned by the getpid() and gettid() syscalls.

---
 security/lsm_audit.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
security/lsm_audit.c +5 -2
index cccbf30..57f26c1 100644
@@ -220,7 +220,8 @@ static void dump_common_audit_data(struct audit_buffer *ab,
 	 */
 	BUILD_BUG_ON(sizeof(a->u) > sizeof(void *)*2);
 
-	audit_log_format(ab, " pid=%d comm=", task_pid_nr(current));
+	audit_log_format(ab, " pid=%d tid=%d comm=", task_tgid_vnr(tsk),
+			task_pid_vnr(tsk));
 	audit_log_untrustedstring(ab, memcpy(comm, current->comm, sizeof(comm)));
 
 	switch (a->type) {
@@ -294,10 +295,12 @@ static void dump_common_audit_data(struct audit_buffer *ab,
 	case LSM_AUDIT_DATA_TASK: {
 		struct task_struct *tsk = a->u.tsk;
 		if (tsk) {
-			pid_t pid = task_pid_nr(tsk);
+			pid_t pid = task_tgid_vnr(tsk);
 			if (pid) {
 				char comm[sizeof(tsk->comm)];
 				audit_log_format(ab, " opid=%d ocomm=", pid);
+				audit_log_format(ab, " opid=%d otid=%d ocomm=",
+						pid, task_pid_vnr(tsk));
 				audit_log_untrustedstring(ab,
 				    memcpy(comm, tsk->comm, sizeof(comm)));
 			}
Signature · 1 line
2.8.0.rc3.226.g39d4020
maintainer
#1 lore raw
Quoted 10 lines · Jeff Vander Stoep

dump_common_audit_data() currently contains a field for pid, but the value printed is actually the thread ID, tid. Update this value to return the task group ID. Add a new field for tid. With this change the values printed by audit now match the values returned by the getpid() and gettid() syscalls.

---
 security/lsm_audit.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Hi Jeff,

Have you tested this against the audit-testsuite[1]? We don't have an explicit PID test yet, but at least two of the tests do test it as a side effect.

Steve, I don't see the thread ID listed in the field dictionary, are you okay with using "tid" for this?

However, as far as I can see, the biggest problem with this patch is that it adds a field in the middle of a record which will likely cause the audit userspace tools to explode (or so I've been warned in the past). Steve, what say you about the userspace?

[1] https://github.com/linux-audit/audit-testsuite
[2] https://github.com/linux-audit/audit-documentation/blob/master/specs/fields/field-dictionary.csv

Quoted 28 lines
security/lsm_audit.c +5 -2
index cccbf30..57f26c1 100644
@@ -220,7 +220,8 @@ static void dump_common_audit_data(struct audit_buffer *ab,
         */
        BUILD_BUG_ON(sizeof(a->u) > sizeof(void *)*2);
 
-       audit_log_format(ab, " pid=%d comm=", task_pid_nr(current));
+       audit_log_format(ab, " pid=%d tid=%d comm=", task_tgid_vnr(tsk),
+                       task_pid_vnr(tsk));
        audit_log_untrustedstring(ab, memcpy(comm, current->comm, sizeof(comm)));
 
        switch (a->type) {
@@ -294,10 +295,12 @@ static void dump_common_audit_data(struct audit_buffer *ab,
        case LSM_AUDIT_DATA_TASK: {
                struct task_struct *tsk = a->u.tsk;
                if (tsk) {
-                       pid_t pid = task_pid_nr(tsk);
+                       pid_t pid = task_tgid_vnr(tsk);
                        if (pid) {
                                char comm[sizeof(tsk->comm)];
                                audit_log_format(ab, " opid=%d ocomm=", pid);
+                               audit_log_format(ab, " opid=%d otid=%d ocomm=",
+                                               pid, task_pid_vnr(tsk));
                                audit_log_untrustedstring(ab,
                                    memcpy(comm, tsk->comm, sizeof(comm)));
                        }
Signature · 2 lines
paul moore
www.paul-moore.com
#2 lore raw
Quoted 12 lines · Paul Moore
Quoted 10 lines · Jeff Vander Stoep

dump_common_audit_data() currently contains a field for pid, but the value printed is actually the thread ID, tid. Update this value to return the task group ID. Add a new field for tid. With this change the values printed by audit now match the values returned by the getpid() and gettid() syscalls.

---
 security/lsm_audit.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
Quoted 8 lines

Hi Jeff,

Have you tested this against the audit-testsuite[1]? We don't have an explicit PID test yet, but at least two of the tests do test it as a side effect.

Steve, I don't see the thread ID listed in the field dictionary, are you okay with using "tid" for this?

There is some naming confusion between userspace and kernel space with pid vs. tid vs. tgid...

Quoted 4 lines

However, as far as I can see, the biggest problem with this patch is that it adds a field in the middle of a record which will likely cause the audit userspace tools to explode (or so I've been warned in the past). Steve, what say you about the userspace?

Adding fields in the middle isn't necessarily a problem if it doesn't confuse the existing scanner, which can skip over fields about which it does not care. I've carefully added fields in the middle in the past, trying my best to group it logically with the rest of the information as has been requested, I think: subject, action, object, result.

Quoted 16 lines

[1] https://github.com/linux-audit/audit-testsuite
[2] https://github.com/linux-audit/audit-documentation/blob/master/specs/fields/field-dictionary.csv

Quoted 13 lines
security/lsm_audit.c +2 -1
index cccbf30..57f26c1 100644
@@ -220,7 +220,8 @@ static void dump_common_audit_data(struct audit_buffer *ab,
         */
        BUILD_BUG_ON(sizeof(a->u) > sizeof(void *)*2);
 
-       audit_log_format(ab, " pid=%d comm=", task_pid_nr(current));
+       audit_log_format(ab, " pid=%d tid=%d comm=", task_tgid_vnr(tsk),
+                       task_pid_vnr(tsk));
        audit_log_untrustedstring(ab, memcpy(comm, current->comm, sizeof(comm)));
 
Quoted 24 lines
Quoted 15 lines
security/lsm_audit.c +3 -1
        switch (a->type) {
@@ -294,10 +295,12 @@ static void dump_common_audit_data(struct audit_buffer *ab,
        case LSM_AUDIT_DATA_TASK: {
                struct task_struct *tsk = a->u.tsk;
                if (tsk) {
-                       pid_t pid = task_pid_nr(tsk);
+                       pid_t pid = task_tgid_vnr(tsk);
                        if (pid) {
                                char comm[sizeof(tsk->comm)];
                                audit_log_format(ab, " opid=%d ocomm=", pid);
+                               audit_log_format(ab, " opid=%d otid=%d ocomm=",
+                                               pid, task_pid_vnr(tsk));
                                audit_log_untrustedstring(ab,
                                    memcpy(comm, tsk->comm, sizeof(comm)));
                        }
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]>
Kernel Security Engineering, Base Operating Systems, Red Hat Remote, Ottawa, Canada
Voice: +1.647.777.2635, Internal: (81) 32635

maintainer
#3 lore raw
Quoted 11 lines · Richard Guy Briggs
Quoted 4 lines · Paul Moore

However, as far as I can see, the biggest problem with this patch is that it adds a field in the middle of a record which will likely cause the audit userspace tools to explode (or so I've been warned in the past). Steve, what say you about the userspace?

Adding fields in the middle isn't necessarily a problem if it doesn't confuse the existing scanner, which can skip over fields about which it does not care. I've carefully added fields in the middle in the past, trying my best to group it logically with the rest of the information as has been requested, I think: subject, action, object, result.

I've ranted about this before so I won't do it again here, but ultimately the problem is that the guidance for userspace applications/libraries has been that you can expect certain fields in specific locations.

Signature · 2 lines
paul moore
www.paul-moore.com
maintainer
#4 lore raw
In reply to Paul Moore
Quoted 21 lines · Paul Moore
Quoted 10 lines · Jeff Vander Stoep

dump_common_audit_data() currently contains a field for pid, but the value printed is actually the thread ID, tid. Update this value to return the task group ID. Add a new field for tid. With this change the values printed by audit now match the values returned by the getpid() and gettid() syscalls.

---
 security/lsm_audit.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Hi Jeff,

Have you tested this against the audit-testsuite[1]? We don't have an explicit PID test yet, but at least two of the tests do test it as a side effect.

Steve, I don't see the thread ID listed in the field dictionary, are you okay with using "tid" for this?

Quoted 7 lines

However, as far as I can see, the biggest problem with this patch is that it adds a field in the middle of a record which will likely cause the audit userspace tools to explode (or so I've been warned in the past). Steve, what say you about the userspace?

[1] https://github.com/linux-audit/audit-testsuite
[2] https://github.com/linux-audit/audit-documentation/blob/master/specs/fields/field-dictionary.csv

Steve?

Quoted 32 lines
Quoted 18 lines
security/lsm_audit.c +2 -1
index cccbf30..57f26c1 100644
@@ -220,7 +220,8 @@ static void dump_common_audit_data(struct audit_buffer *ab,
         */
        BUILD_BUG_ON(sizeof(a->u) > sizeof(void *)*2);
 
-       audit_log_format(ab, " pid=%d comm=", task_pid_nr(current));
+       audit_log_format(ab, " pid=%d tid=%d comm=", task_tgid_vnr(tsk),
+                       task_pid_vnr(tsk));
        audit_log_untrustedstring(ab, memcpy(comm, current->comm, sizeof(comm)));
 
        switch (a->type) {
@@ -294,10 +295,12 @@ static void dump_common_audit_data(struct audit_buffer *ab,
        case LSM_AUDIT_DATA_TASK: {
                struct task_struct *tsk = a->u.tsk;
                if (tsk) {

security/lsm_audit.c static void dump_common_audit_data(struct audit_buffer *ab, · line 306

Quoted 10 lines
security/lsm_audit.c +3 -1
-                       pid_t pid = task_pid_nr(tsk);
+                       pid_t pid = task_tgid_vnr(tsk);
                        if (pid) {
                                char comm[sizeof(tsk->comm)];
                                audit_log_format(ab, " opid=%d ocomm=", pid);
+                               audit_log_format(ab, " opid=%d otid=%d ocomm=",
+                                               pid, task_pid_vnr(tsk));
                                audit_log_untrustedstring(ab,
                                    memcpy(comm, tsk->comm, sizeof(comm)));
                        }

--
paul moore
www.paul-moore.com

Signature · 2 lines
paul moore
www.paul-moore.com
#5 lore raw
In reply to Paul Moore
Quoted 13 lines · EDT Paul Moore
Quoted 11 lines · Jeff Vander Stoep

dump_common_audit_data() currently contains a field for pid, but the value printed is actually the thread ID, tid. Update this value to return the task group ID. Add a new field for tid. With this change the values printed by audit now match the values returned by the getpid() and gettid() syscalls.

---

 security/lsm_audit.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
Quoted 8 lines

Hi Jeff,

Have you tested this against the audit-testsuite[1]? We don't have an explicit PID test yet, but at least two of the tests do test it as a side effect.

Steve, I don't see the thread ID listed in the field dictionary, are you okay with using "tid" for this?

Yes. Can someone add both?

Quoted 4 lines

However, as far as I can see, the biggest problem with this patch is that it adds a field in the middle of a record which will likely cause the audit userspace tools to explode (or so I've been warned in the past). Steve, what say you about the userspace?

This is OK. After picking out pid, search utiliies scan for comm. They will just skip over the new field. If fields that we normally search change order, then we have a problem.

So, ACK on my end.

-Steve

Quoted 48 lines

[1] https://github.com/linux-audit/audit-testsuite
[2]
https://github.com/linux-audit/audit-documentation/blob/master/specs/fields
/field-dictionary.csv

Quoted 44 lines
security/lsm_audit.c +2 -1
index cccbf30..57f26c1 100644
@@ -220,7 +220,8 @@ static void dump_common_audit_data(struct audit_buffer
 *ab,> 
         */
 
        BUILD_BUG_ON(sizeof(a->u) > sizeof(void *)*2);
 
-       audit_log_format(ab, " pid=%d comm=", task_pid_nr(current));
+       audit_log_format(ab, " pid=%d tid=%d comm=", task_tgid_vnr(tsk),
+                       task_pid_vnr(tsk));
 
        audit_log_untrustedstring(ab, memcpy(comm, current->comm,
        sizeof(comm)));
        
        switch (a->type) {
security/lsm_audit.c +0 -0
@@ -294,10 +295,12 @@ static void dump_common_audit_data(struct

audit_buffer *ab,>

        case LSM_AUDIT_DATA_TASK: {
        
                struct task_struct *tsk = a->u.tsk;
                if (tsk) {
security/lsm_audit.c +2 -1
-                       pid_t pid = task_pid_nr(tsk);
+                       pid_t pid = task_tgid_vnr(tsk);
 
                        if (pid) {
 
                                char comm[sizeof(tsk->comm)];
                                audit_log_format(ab, " opid=%d ocomm=",
                                pid);
 
+                               audit_log_format(ab, " opid=%d otid=%d

ocomm=", + pid,
task_pid_vnr(tsk));>

                                audit_log_untrustedstring(ab,
                                
                                    memcpy(comm, tsk->comm,
                                    sizeof(comm)));
                        
                        }
maintainer
#6 lore raw
Quoted 16 lines · Steve Grubb
Quoted 15 lines · EDT Paul Moore
Quoted 11 lines · Jeff Vander Stoep

dump_common_audit_data() currently contains a field for pid, but the value printed is actually the thread ID, tid. Update this value to return the task group ID. Add a new field for tid. With this change the values printed by audit now match the values returned by the getpid() and gettid() syscalls.

---

 security/lsm_audit.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Hi Jeff,

Quoted 8 lines
Quoted 6 lines

Have you tested this against the audit-testsuite[1]? We don't have an explicit PID test yet, but at least two of the tests do test it as a side effect.

Steve, I don't see the thread ID listed in the field dictionary, are you okay with using "tid" for this?

Yes. Can someone add both?

Yes, I'll add "tid" to the field DB once we commit the kernel patch.

Quoted 10 lines
Quoted 4 lines

However, as far as I can see, the biggest problem with this patch is that it adds a field in the middle of a record which will likely cause the audit userspace tools to explode (or so I've been warned in the past). Steve, what say you about the userspace?

This is OK. After picking out pid, search utiliies scan for comm. They will just skip over the new field. If fields that we normally search change order, then we have a problem.

So, ACK on my end.

Okay, thanks. If we blow up your userspace I'll remind you of this conversation ;)

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

A message that is not in the archive (sent off-list or not yet received): 1469544870-11574-1-git-send-email-jeffv-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org

#8 lore raw
Quoted 10 lines · Jeff Vander Stoep

dump_common_audit_data() currently contains a field for pid, but the value printed is actually the thread ID, tid. Update this value to return the task group ID. Add a new field for tid. With this change the values printed by audit now match the values returned by the getpid() and gettid() syscalls.

---
 security/lsm_audit.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Unfortunately while reviewing this code I realized that the problem extends far beyond just lsm_audit.c, kernel/audit*.c is affected as well. It's actually much worse in kernel/audit*.c as it is very inconsistent.

I was going to ask you to fix the other code too while you were at it, but I realized what it was easy enough to fix it while I was going through the code anyway ... expect a patch shortly.

Quoted 30 lines
security/lsm_audit.c +5 -3
index cccbf30..57f26c1 100644
@@ -220,7 +220,8 @@ static void dump_common_audit_data(struct audit_buffer *ab,
         */
        BUILD_BUG_ON(sizeof(a->u) > sizeof(void *)*2);
 
-       audit_log_format(ab, " pid=%d comm=", task_pid_nr(current));
+       audit_log_format(ab, " pid=%d tid=%d comm=", task_tgid_vnr(tsk),
+                       task_pid_vnr(tsk));
        audit_log_untrustedstring(ab, memcpy(comm, current->comm, sizeof(comm)));
 
        switch (a->type) {
@@ -294,10 +295,12 @@ static void dump_common_audit_data(struct audit_buffer *ab,
        case LSM_AUDIT_DATA_TASK: {
                struct task_struct *tsk = a->u.tsk;
                if (tsk) {
-                       pid_t pid = task_pid_nr(tsk);
+                       pid_t pid = task_tgid_vnr(tsk);
                        if (pid) {
                                char comm[sizeof(tsk->comm)];
                                audit_log_format(ab, " opid=%d ocomm=", pid);
+                               audit_log_format(ab, " opid=%d otid=%d ocomm=",
+                                               pid, task_pid_vnr(tsk));
                                audit_log_untrustedstring(ab,
                                    memcpy(comm, tsk->comm, sizeof(comm)));
                        }
--

2.8.0.rc3.226.g39d4020

Signature · 7 lines
paul moore
www.paul-moore.com
_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected]
To get help, send an email containing "help" to [email protected]