From: Ondrej Mosnacek Subject: [PATCH ghak82 v2] audit: Fix extended comparison of GID/EGID Date: Thu, 31 May 2018 09:19:54 +0200 Message-ID: <20180531071954.10998-1-omosnace@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx1.redhat.com (ext-mx11.extmail.prod.ext.phx2.redhat.com [10.5.110.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1F8EB308BDA9 for ; Thu, 31 May 2018 07:20:06 +0000 (UTC) Received: from mail-wm0-f69.google.com (mail-wm0-f69.google.com [74.125.82.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 54EE530A8E44 for ; Thu, 31 May 2018 07:20:06 +0000 (UTC) Received: by mail-wm0-f69.google.com with SMTP id f65-v6so7044859wmd.2 for ; Thu, 31 May 2018 00:20:06 -0700 (PDT) List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-audit-bounces@redhat.com Errors-To: linux-audit-bounces@redhat.com To: linux-audit@redhat.com Cc: Richard Guy Briggs List-Id: linux-audit@redhat.com 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") Signed-off-by: Ondrej Mosnacek --- kernel/auditsc.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/kernel/auditsc.c b/kernel/auditsc.c index ceb1c4596c51..3a324ca2fd20 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -492,23 +492,21 @@ static int audit_filter_rules(struct task_struct *tsk, break; case AUDIT_GID: result = audit_gid_comparator(cred->gid, f->op, f->gid); - if (f->op == Audit_equal) { - if (!result) - result = in_group_p(f->gid); - } else if (f->op == Audit_not_equal) { - if (result) - result = !in_group_p(f->gid); - } + if (f->op == Audit_equal) + result = result || + groups_search(cred->group_info, f->gid); + else if (f->op == Audit_not_equal) + result = 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); - } else if (f->op == Audit_not_equal) { - if (result) - result = !in_egroup_p(f->gid); - } + if (f->op == Audit_equal) + result = result || + groups_search(cred->group_info, f->gid); + else if (f->op == Audit_not_equal) + result = result && + !groups_search(cred->group_info, f->gid); break; case AUDIT_SGID: result = audit_gid_comparator(cred->sgid, f->op, f->gid); -- 2.17.0