Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp5689imm; Thu, 10 May 2018 14:23:32 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrjF1I9PwnilU2ekn4Avdc6bzZdI8HK5FapE8sIbGiQ4PPl9dVVXpp3Zp5F/3+D5XY2LKtO X-Received: by 2002:a63:2787:: with SMTP id n129-v6mr2330298pgn.167.1525987412027; Thu, 10 May 2018 14:23:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525987411; cv=none; d=google.com; s=arc-20160816; b=pqFQBGfZM8+kSGM2e7jdfmMhxlgu1DEYz1lF92rZCYwRpBje+zHJxzm9M5Fa1ZRgHE J8kaR4YkwY5gChzNDF+C+esi2C5bWHbZFi9ml/3clYa624N0IsxLS+1ZmomYSRe3pXq1 lFjMqdzxoym8WloP5n0pi2xLxcjwIVtPB3B2RBrQQvXwIrf2imHgklaPC4yBKCbOQK0u n5TDsSBqd9XV9GAxxXebd/AU8jQpYzMS4L5QDPyI5UMVR9LMituShHeZqpRz3BCwW4CU aLTHl8D/EX7eKko8Y97xiY6T8/Zjp70pUzbZ9awWlos8zVmCapqylSwj62bH7MryUv1d K9mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=Id5+vy3ZzjGFbzik14hUI1XCa6r4Ef3XGBVj0UQr8oM=; b=vsicWu7DF1Wa9JKEoeb/dByrP8/035P5yAC+WTEZNj/t5ncQ+aWWyTkrsjLiFUdv0D GiyNnqDLePRh4nk2e5uPUF2vcp5nofEOpUn7hbmQ9G0fphMXGG1RHkP1BkeNwdatyq2Q kjKlQVVEnafXA1L92eBzZ3sjpJxTCSo5o+iJG8pToCKEF6lQmUqle7frcRLiZx8h7pvG 8gsqDj9rikeboWS8odihDYXdDQqM3dnKXAHsc03hSEjtyJrOMG40aJyBcPrkRr1w+A90 4Wa/3Wk1bgXJrbGT2tejSu89SPG9nYLEwCoOSD3dEytkMkgmDfMIUyUKLmy+WPdqhXR/ df1w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m18-v6si1371802pgv.306.2018.05.10.14.23.15; Thu, 10 May 2018 14:23:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752588AbeEJVVn (ORCPT + 99 others); Thu, 10 May 2018 17:21:43 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:56500 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752188AbeEJVVl (ORCPT ); Thu, 10 May 2018 17:21:41 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 44DC377020; Thu, 10 May 2018 21:21:40 +0000 (UTC) Received: from madcap2.tricolour.ca (ovpn-112-12.rdu2.redhat.com [10.10.112.12]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B3BBF111E406; Thu, 10 May 2018 21:21:33 +0000 (UTC) Date: Thu, 10 May 2018 17:21:14 -0400 From: Richard Guy Briggs To: Paul Moore Cc: Linux-Audit Mailing List , LKML , Linux NetDev Upstream Mailing List , Netfilter Devel List , Linux Security Module list , Integrity Measurement Architecture , SElinux list , Eric Paris , Steve Grubb , Ingo Molnar , David Howells Subject: Re: [PATCH ghak81 RFC V1 1/5] audit: normalize loginuid read access Message-ID: <20180510212114.pefeyw5cuqlmjewp@madcap2.tricolour.ca> References: <611e9c85fca8bcdb24e6fb6da412773663c007b3.1525466167.git.rgb@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20171027 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 10 May 2018 21:21:40 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 10 May 2018 21:21:40 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'rgb@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018-05-09 11:13, Paul Moore wrote: > On Fri, May 4, 2018 at 4:54 PM, Richard Guy Briggs wrote: > > Recognizing that the loginuid is an internal audit value, use an access > > function to retrieve the audit loginuid value for the task rather than > > reaching directly into the task struct to get it. > > > > Signed-off-by: Richard Guy Briggs > > --- > > kernel/auditsc.c | 16 ++++++++-------- > > 1 file changed, 8 insertions(+), 8 deletions(-) > > > > diff --git a/kernel/auditsc.c b/kernel/auditsc.c > > index 479c031..f3817d0 100644 > > --- a/kernel/auditsc.c > > +++ b/kernel/auditsc.c > > @@ -374,7 +374,7 @@ static int audit_field_compare(struct task_struct *tsk, > > case AUDIT_COMPARE_EGID_TO_OBJ_GID: > > return audit_compare_gid(cred->egid, name, f, ctx); > > case AUDIT_COMPARE_AUID_TO_OBJ_UID: > > - return audit_compare_uid(tsk->loginuid, name, f, ctx); > > + return audit_compare_uid(audit_get_loginuid(tsk), name, f, ctx); > > case AUDIT_COMPARE_SUID_TO_OBJ_UID: > > return audit_compare_uid(cred->suid, name, f, ctx); > > case AUDIT_COMPARE_SGID_TO_OBJ_GID: > > @@ -385,7 +385,7 @@ static int audit_field_compare(struct task_struct *tsk, > > return audit_compare_gid(cred->fsgid, name, f, ctx); > > /* uid comparisons */ > > case AUDIT_COMPARE_UID_TO_AUID: > > - return audit_uid_comparator(cred->uid, f->op, tsk->loginuid); > > + return audit_uid_comparator(cred->uid, f->op, audit_get_loginuid(tsk)); > > case AUDIT_COMPARE_UID_TO_EUID: > > return audit_uid_comparator(cred->uid, f->op, cred->euid); > > case AUDIT_COMPARE_UID_TO_SUID: > > @@ -394,11 +394,11 @@ static int audit_field_compare(struct task_struct *tsk, > > return audit_uid_comparator(cred->uid, f->op, cred->fsuid); > > /* auid comparisons */ > > case AUDIT_COMPARE_AUID_TO_EUID: > > - return audit_uid_comparator(tsk->loginuid, f->op, cred->euid); > > + return audit_uid_comparator(audit_get_loginuid(tsk), f->op, cred->euid); > > case AUDIT_COMPARE_AUID_TO_SUID: > > - return audit_uid_comparator(tsk->loginuid, f->op, cred->suid); > > + return audit_uid_comparator(audit_get_loginuid(tsk), f->op, cred->suid); > > case AUDIT_COMPARE_AUID_TO_FSUID: > > - return audit_uid_comparator(tsk->loginuid, f->op, cred->fsuid); > > + return audit_uid_comparator(audit_get_loginuid(tsk), f->op, cred->fsuid); > > /* euid comparisons */ > > case AUDIT_COMPARE_EUID_TO_SUID: > > return audit_uid_comparator(cred->euid, f->op, cred->suid); > > @@ -611,7 +611,7 @@ static int audit_filter_rules(struct task_struct *tsk, > > result = match_tree_refs(ctx, rule->tree); > > break; > > case AUDIT_LOGINUID: > > - result = audit_uid_comparator(tsk->loginuid, f->op, f->uid); > > + result = audit_uid_comparator(audit_get_loginuid(tsk), f->op, f->uid); > > break; > > case AUDIT_LOGINUID_SET: > > result = audit_comparator(audit_loginuid_set(tsk), f->op, f->val); > > @@ -2287,8 +2287,8 @@ int audit_signal_info(int sig, struct task_struct *t) > > (sig == SIGTERM || sig == SIGHUP || > > sig == SIGUSR1 || sig == SIGUSR2)) { > > audit_sig_pid = task_tgid_nr(tsk); > > - if (uid_valid(tsk->loginuid)) > > - audit_sig_uid = tsk->loginuid; > > + if (uid_valid(audit_get_loginuid(tsk))) > > + audit_sig_uid = audit_get_loginuid(tsk); > > I realize this comment is a little silly given the nature of loginuid, > but if we are going to abstract away loginuid accesses (which I think > is good), we should probably access it once, store it in a local > variable, perform the validity check on the local variable, then > commit the local variable to audit_sig_uid. I realize a TOCTOU > problem is unlikely here, but with this new layer of abstraction it > seems that some additional safety might be a good thing. Ok, I'll just assign it to where it is going and check it there, holding the audit_ctl_lock the whole time, since it should have been done anyways for all of audit_sig_{pid,uid,sid} anyways to get a consistent view from the AUDIT_SIGNAL_INFO fetch. > > else > > audit_sig_uid = uid; > > security_task_getsecid(tsk, &audit_sig_sid); > 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