Skip to contentSkip to conversation

audit: Fix extended comparison of GID/EGID

PATCH Applied Ondrej Mosnacek 2 participants 3 messages Jun 5, 2018 – Jun 19, 2018 Audit

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 audit: Fix extended comparison of GID/EGID

The audit_filter_rules() function in auditsc.c used the in_[e]group_p() functions to check GID/EGID match, but these functions use the current task's credentials, while the comparison should use the credentials of the task given to audit_filter_rules() as a parameter (tsk).

Note that we can use group_search(cred->group_info, ...) as a replacement for both in_group_p and in_egroup_p as these functions only compare the parameter to cred->fsgid/egid and then call group_search.

In fact, the usage of in_group_p was even more incorrect: it compares to cred->fsgid (which is usually equal to cred->egid) and not cred->gid.

GitHub issue:
https://github.com/linux-audit/audit-kernel/issues/82

Fixes 37eebe39c973 ("audit: improve GID/EGID comparation logic")
---
 kernel/auditsc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/auditsc.c +4 -4
index ceb1c4596c51..518a3336a697 100644
@@ -494,20 +494,20 @@ static int audit_filter_rules(struct task_struct *tsk,
 			result = audit_gid_comparator(cred->gid, f->op, f->gid);
 			if (f->op == Audit_equal) {
 				if (!result)
-					result = in_group_p(f->gid);
+					result = groups_search(cred->group_info, f->gid);
 			} else if (f->op == Audit_not_equal) {
 				if (result)
-					result = !in_group_p(f->gid);
+					result = !groups_search(cred->group_info, f->gid);
 			}
 			break;
 		case AUDIT_EGID:
 			result = audit_gid_comparator(cred->egid, f->op, f->gid);
 			if (f->op == Audit_equal) {
 				if (!result)
-					result = in_egroup_p(f->gid);
+					result = groups_search(cred->group_info, f->gid);
 			} else if (f->op == Audit_not_equal) {
 				if (result)
-					result = !in_egroup_p(f->gid);
+					result = !groups_search(cred->group_info, f->gid);
 			}
 			break;
 		case AUDIT_SGID:
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 12 lines · Ondrej Mosnacek

The audit_filter_rules() function in auditsc.c used the in_[e]group_p() functions to check GID/EGID match, but these functions use the current task's credentials, while the comparison should use the credentials of the task given to audit_filter_rules() as a parameter (tsk).

Note that we can use group_search(cred->group_info, ...) as a replacement for both in_group_p and in_egroup_p as these functions only compare the parameter to cred->fsgid/egid and then call group_search.

In fact, the usage of in_group_p was even more incorrect: it compares to cred->fsgid (which is usually equal to cred->egid) and not cred->gid.

Quoted 8 lines

GitHub issue:
https://github.com/linux-audit/audit-kernel/issues/82

Fixes 37eebe39c973 ("audit: improve GID/EGID comparation logic")
---
 kernel/auditsc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Much better, thank you. Queued up for after the merge window.

Quoted 32 lines
kernel/auditsc.c +4 -5
index ceb1c4596c51..518a3336a697 100644
@@ -494,20 +494,20 @@ static int audit_filter_rules(struct task_struct *tsk,
                        result = audit_gid_comparator(cred->gid, f->op, f->gid);
                        if (f->op == Audit_equal) {
                                if (!result)
-                                       result = in_group_p(f->gid);
+                                       result = groups_search(cred->group_info, f->gid);
                        } else if (f->op == Audit_not_equal) {
                                if (result)
-                                       result = !in_group_p(f->gid);
+                                       result = !groups_search(cred->group_info, f->gid);
                        }
                        break;
                case AUDIT_EGID:
                        result = audit_gid_comparator(cred->egid, f->op, f->gid);
                        if (f->op == Audit_equal) {
                                if (!result)
-                                       result = in_egroup_p(f->gid);
+                                       result = groups_search(cred->group_info, f->gid);
                        } else if (f->op == Audit_not_equal) {
                                if (result)
-                                       result = !in_egroup_p(f->gid);
+                                       result = !groups_search(cred->group_info, f->gid);
                        }
                        break;
                case AUDIT_SGID:
--

2.17.1

Signature · 2 lines
paul moore
www.paul-moore.com
maintainer Applied
#2 lore raw
In reply to Ondrej Mosnacek
Quoted 12 lines · Ondrej Mosnacek

The audit_filter_rules() function in auditsc.c used the in_[e]group_p() functions to check GID/EGID match, but these functions use the current task's credentials, while the comparison should use the credentials of the task given to audit_filter_rules() as a parameter (tsk).

Note that we can use group_search(cred->group_info, ...) as a replacement for both in_group_p and in_egroup_p as these functions only compare the parameter to cred->fsgid/egid and then call group_search.

In fact, the usage of in_group_p was even more incorrect: it compares to cred->fsgid (which is usually equal to cred->egid) and not cred->gid.

Quoted 8 lines

GitHub issue:
https://github.com/linux-audit/audit-kernel/issues/82

Fixes 37eebe39c973 ("audit: improve GID/EGID comparation logic")
---
 kernel/auditsc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Merged, thanks.

Quoted 32 lines
kernel/auditsc.c +4 -5
index ceb1c4596c51..518a3336a697 100644
@@ -494,20 +494,20 @@ static int audit_filter_rules(struct task_struct *tsk,
                        result = audit_gid_comparator(cred->gid, f->op, f->gid);
                        if (f->op == Audit_equal) {
                                if (!result)
-                                       result = in_group_p(f->gid);
+                                       result = groups_search(cred->group_info, f->gid);
                        } else if (f->op == Audit_not_equal) {
                                if (result)
-                                       result = !in_group_p(f->gid);
+                                       result = !groups_search(cred->group_info, f->gid);
                        }
                        break;
                case AUDIT_EGID:
                        result = audit_gid_comparator(cred->egid, f->op, f->gid);
                        if (f->op == Audit_equal) {
                                if (!result)
-                                       result = in_egroup_p(f->gid);
+                                       result = groups_search(cred->group_info, f->gid);
                        } else if (f->op == Audit_not_equal) {
                                if (result)
-                                       result = !in_egroup_p(f->gid);
+                                       result = !groups_search(cred->group_info, f->gid);
                        }
                        break;
                case AUDIT_SGID:
--

2.17.1

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