Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1361949imm; Fri, 11 May 2018 15:18:44 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr/BlvGIWEsGPgZgGihY8NNT2VqmoAVPTYe5tK4R0nVB0mnxYRpQkHhXn41PN3bjRoaVC+7 X-Received: by 2002:a63:8f5e:: with SMTP id r30-v6mr629614pgn.397.1526077124546; Fri, 11 May 2018 15:18:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526077124; cv=none; d=google.com; s=arc-20160816; b=knNAbWzc4/9oKRvvprHACT5R3XTT8Mkylo8FqAz8XUcnRoNBjG6PqXsl3lT2yc9kfn 4Y/KmOsTr/hZfG6u6eJ7R6hwR5T9JQuYXX9jbFJ7Aef3Lx47AovEcIUnqdlCFPiP8eEg 5VyNQ6w0F3DVpj8bprsxxoF9yVHZ79/m/2f9rDBaxotVtOAX1xxl4HsdHtOgspWj3EKB 8S3ona2vbjfJk3a6HDC/gNUPI8+isyZd8suSHt/XXlgi90NKJ0aNwBGsIREGJTqC7cPV +OKHXUbVoRRHaZ+LK9SQ4McnwI6R5mDpPFkQLcjj+6tj2a+SH1DJSWwOSF7iOFpzPPDw DuKw== 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=6+FeHT2aD5Ova3X39VSoqnKSP2fxg99r3kekfXVpoF4=; b=ZmY4QSnK7amKbqAfNvXOViVuTfJRSI0S1PnN/ukWC9KVCj9cv7fhPC5lVZB3fHyow3 KfT6400yVkkmNg3qZdJSiIvVeBQ+nwPbq72nl8Ls4KtqBGebtMzHQHTuLIriGgISlDy/ L3Dc8TPE+Rkfqo3g62M+RonWndGxGjnVs7ItUUxc5IrWRUTxMe64gzUoWhoa8AysKRa2 9Qof9l94JAb/JrBkIHMzElU64JvxBpcbLI97xJrmH8xVyRB0Nl2icwbaE9vBh1lGW88H tMfZlIPk98zStHRBImcJWuDAFNKW2HOjfHfbfQ7PNeIGoJp4OaXppqNZ5fXMkVtF1gfb kWQQ== 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 w9-v6si4157771plk.28.2018.05.11.15.18.30; Fri, 11 May 2018 15:18:44 -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 S1751774AbeEKWST (ORCPT + 99 others); Fri, 11 May 2018 18:18:19 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45864 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750972AbeEKWSR (ORCPT ); Fri, 11 May 2018 18:18:17 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 92DB240006EC; Fri, 11 May 2018 22:18:16 +0000 (UTC) Received: from madcap2.tricolour.ca (ovpn-112-35.rdu2.redhat.com [10.10.112.35]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 58E122026DEF; Fri, 11 May 2018 22:18:14 +0000 (UTC) Date: Fri, 11 May 2018 18:17:52 -0400 From: Richard Guy Briggs To: Paul Moore Cc: Linux NetDev Upstream Mailing List , LKML , David Howells , Linux Security Module list , Linux-Audit Mailing List , Netfilter Devel List , SElinux list , Integrity Measurement Architecture , Ingo Molnar Subject: Re: [PATCH ghak81 RFC V1 1/5] audit: normalize loginuid read access Message-ID: <20180511221752.6xtcf2r4rkumrp4u@madcap2.tricolour.ca> References: <611e9c85fca8bcdb24e6fb6da412773663c007b3.1525466167.git.rgb@redhat.com> <20180510212114.pefeyw5cuqlmjewp@madcap2.tricolour.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180510212114.pefeyw5cuqlmjewp@madcap2.tricolour.ca> User-Agent: NeoMutt/20171027 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 11 May 2018 22:18:16 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 11 May 2018 22:18:16 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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-10 17:21, Richard Guy Briggs wrote: > 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. Hmmm, holding audit_ctl_lock won't work because it could sleep trying to get the lock and the signal info is set in a context where sleeping isn't permitted. I'll just use a local var... > > > else > > > audit_sig_uid = uid; > > > security_task_getsecid(tsk, &audit_sig_sid); > > > paul moore > > - RGB - 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