Received: by 10.192.165.148 with SMTP id m20csp31956imm; Wed, 9 May 2018 08:20:06 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr+15y4sFgDHs0ANBKPkCUYVnoLCROy0DbcTadbhxTduMlO3oEXdHdxfoss354z22u0eIfI X-Received: by 10.98.163.21 with SMTP id s21mr44674388pfe.168.1525879206636; Wed, 09 May 2018 08:20:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525879206; cv=none; d=google.com; s=arc-20160816; b=j8gGYWzCf1VmFFCkJUeXYhMxMLuQZCxnjNlTieH0Ugipct02jpxT7p1wj83BDwuxg4 ESDRQsKi2mbo/xhPooksB9SziiNR/PbuorilAwS5g5T98tL39wIVIzWy9JU1saToUGIw lMwoK43xq2ot9/2EgQpqVF4tAS44G5y8wHd5MXplzqMp8nk0QZDZaqqsocI105/96Nil CV+CMHaqFyW05P9jzaAUoHpyHPpMPknSpiOHL86vMRn7NpsoLDIz4MccLvjcl+qhMGDv Rl1ysEdNR0S+a3W7wnHQt5dXfwJm4Fu43zTQDqWDnPPhVvkBROPRs4DuPFpj103qyKsB +ZLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=IH6TBUoSqC/natqRRFn62QW3eRws/3tgzZ5fn/K4tJE=; b=QZGkWCO8QUi23CRjCFHXn4CApk4ag3AdeWJczGbmRY+PoM5TA1DLJXGh3OllTBfa7b 0w2fgikMBwKt9WdsdNCk4O1Ju7mBhSB1kXNLxxjcINMZ1CW0H1mC3Yp96H8NuDvNvpB0 XtbMS2d3ctaA/hV2A8+6MqcjePTXqEpw6HbfQii4SD6FJ6Xf97MpBWvYEez/+rfAshfG Hm8/925SYfML2JmP/IcT5pZvtQUb9lHPBtzri2v1XVAa45SedbOdwkn198UCyAk3PBj8 r1RIykw5HWz9/EveaxXm22Er7XAAlVq68n3xZHNFL2yx9vLyw4qHzgesT+EzLkxWZ6Hn bl7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=Kvced4l/; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r39-v6si26898690pld.249.2018.05.09.08.19.52; Wed, 09 May 2018 08:20:06 -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; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=Kvced4l/; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965102AbeEIPTC (ORCPT + 99 others); Wed, 9 May 2018 11:19:02 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:33506 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935389AbeEIPSx (ORCPT ); Wed, 9 May 2018 11:18:53 -0400 Received: by mail-lf0-f65.google.com with SMTP id m18-v6so51521719lfb.0 for ; Wed, 09 May 2018 08:18:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=IH6TBUoSqC/natqRRFn62QW3eRws/3tgzZ5fn/K4tJE=; b=Kvced4l/7zbUp4zad8XZbMk+cwG5lIYwyuWU/JlTwK/x/gGTtHFy4WfWbKCSYPJubO ZyiZYhEQys+QW8YLtg7Ln7ccv6mzPDauNrKNzfM3dCTBosyc1/4aafEmLTOfoexadyjz cF6ZYm+vpcW4RbDkqHrKsTGbQAMOv9nJ67FEHV6K0r8t64WjAV5AN0igvElkfqwHI+ru JK5ao+e64CdxQ8H0YmNShQ75mQCa4+zw7RjueADD5LSEex6f0ExbLcmhwqjpFTFCmmPq 5yeuQ4LYFR25/bGqcerm14LnUlXzfsP4CJXDmszrVLDCihETGtbz1R7E8HtzIQUDqKLb bv5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=IH6TBUoSqC/natqRRFn62QW3eRws/3tgzZ5fn/K4tJE=; b=S/Hlyzufy6nuv7V7LbKtv7tsTIlnwvbXgbqdOBASR3NQig7eyT3/UIyFDluuifiomK FAztwVXX5DvHd4R0amQWRGNJG/xhlLpA+W7nNHeqhBF5ssLGyLNXxucflz2zqYjx3I6g 550vRFDg3AH3KpFS7ybLi/QvpYi4SPikBYcxlS9/ciHy63x/qnvobKYd4KpAa17F7eTJ oPQccyKmR5pQCbH+kE3ruPzBqxEC0x0fOY50DkifqDIYlRi/GwvUkae+YeB3z9KQjHyC GxNdeFFzH8EF2f0pYYTmMK3/v+uWhHSMYQmSU55rxO1mF+Mo/KDhRvy36O4/zocOQ2hJ 9Rhw== X-Gm-Message-State: ALKqPwfqpzJs303qp64uRWL+IeQoVIige23ughdZj3jzjSukJTfPMG6a qP4O0lZOk6He93Ex2tkDO4LtWaZ2gyJxpvSRiX+T X-Received: by 2002:a2e:c41:: with SMTP id o1-v6mr179532ljd.87.1525879131466; Wed, 09 May 2018 08:18:51 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a19:a947:0:0:0:0:0 with HTTP; Wed, 9 May 2018 08:18:50 -0700 (PDT) X-Originating-IP: [68.177.129.184] In-Reply-To: <20180509013415.sohoc2jbofdqqw5v@madcap2.tricolour.ca> References: <91fd13c7a66718dc827d299fa101883e5d0a864f.1525466167.git.rgb@redhat.com> <20180509013415.sohoc2jbofdqqw5v@madcap2.tricolour.ca> From: Paul Moore Date: Wed, 9 May 2018 11:18:50 -0400 Message-ID: Subject: Re: [PATCH ghak81 RFC V1 2/5] audit: convert sessionid unset to a macro To: Richard Guy Briggs Cc: Linux-Audit Mailing List , LKML , Linux NetDev Upstream Mailing List , Netfilter Devel List , Linux Security Module list , Integrity Measurement Architecture , SElinux list , David Howells , Ingo Molnar Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 8, 2018 at 9:34 PM, Richard Guy Briggs wrote: > On 2018-05-04 16:54, Richard Guy Briggs wrote: >> Use a macro, "AUDIT_SID_UNSET", to replace each instance of >> initialization and comparison to an audit session ID. >> >> Signed-off-by: Richard Guy Briggs > > There's a minor issue with this patch, adding a header include to > init/init_task.c in this patch and removing it from patch 5. That'll be > in the next revision. Okay, thanks for the heads-up. FWIW, this patch looks reasonable in principle; changing magic numbers to macros/constants is almost always a step in the right direction. > I have dynamic allocation working, so that has a good chance of > appearing too. I'll comment on that in your patch 0, I just want to get through the rest of the patches first. >> --- >> include/linux/audit.h | 2 +- >> include/net/xfrm.h | 2 +- >> include/uapi/linux/audit.h | 1 + >> init/init_task.c | 2 +- >> kernel/auditsc.c | 4 ++-- >> 5 files changed, 6 insertions(+), 5 deletions(-) >> >> diff --git a/include/linux/audit.h b/include/linux/audit.h >> index 75d5b03..5f86f7c 100644 >> --- a/include/linux/audit.h >> +++ b/include/linux/audit.h >> @@ -513,7 +513,7 @@ static inline kuid_t audit_get_loginuid(struct task_struct *tsk) >> } >> static inline unsigned int audit_get_sessionid(struct task_struct *tsk) >> { >> - return -1; >> + return AUDIT_SID_UNSET; >> } >> static inline void audit_ipc_obj(struct kern_ipc_perm *ipcp) >> { } >> diff --git a/include/net/xfrm.h b/include/net/xfrm.h >> index a872379..fcce8ee 100644 >> --- a/include/net/xfrm.h >> +++ b/include/net/xfrm.h >> @@ -751,7 +751,7 @@ static inline void xfrm_audit_helper_usrinfo(bool task_valid, >> audit_get_loginuid(current) : >> INVALID_UID); >> const unsigned int ses = task_valid ? audit_get_sessionid(current) : >> - (unsigned int) -1; >> + AUDIT_SID_UNSET; >> >> audit_log_format(audit_buf, " auid=%u ses=%u", auid, ses); >> audit_log_task_context(audit_buf); >> diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h >> index 4e61a9e..04f9bd2 100644 >> --- a/include/uapi/linux/audit.h >> +++ b/include/uapi/linux/audit.h >> @@ -465,6 +465,7 @@ struct audit_tty_status { >> }; >> >> #define AUDIT_UID_UNSET (unsigned int)-1 >> +#define AUDIT_SID_UNSET ((unsigned int)-1) >> >> /* audit_rule_data supports filter rules with both integer and string >> * fields. It corresponds with AUDIT_ADD_RULE, AUDIT_DEL_RULE and >> diff --git a/init/init_task.c b/init/init_task.c >> index 3ac6e75..c788f91 100644 >> --- a/init/init_task.c >> +++ b/init/init_task.c >> @@ -119,7 +119,7 @@ struct task_struct init_task >> .thread_node = LIST_HEAD_INIT(init_signals.thread_head), >> #ifdef CONFIG_AUDITSYSCALL >> .loginuid = INVALID_UID, >> - .sessionid = (unsigned int)-1, >> + .sessionid = AUDIT_SID_UNSET, >> #endif >> #ifdef CONFIG_PERF_EVENTS >> .perf_event_mutex = __MUTEX_INITIALIZER(init_task.perf_event_mutex), >> diff --git a/kernel/auditsc.c b/kernel/auditsc.c >> index f3817d0..6e3ceb9 100644 >> --- a/kernel/auditsc.c >> +++ b/kernel/auditsc.c >> @@ -2050,7 +2050,7 @@ static void audit_log_set_loginuid(kuid_t koldloginuid, kuid_t kloginuid, >> int audit_set_loginuid(kuid_t loginuid) >> { >> struct task_struct *task = current; >> - unsigned int oldsessionid, sessionid = (unsigned int)-1; >> + unsigned int oldsessionid, sessionid = AUDIT_SID_UNSET; >> kuid_t oldloginuid; >> int rc; >> >> @@ -2064,7 +2064,7 @@ int audit_set_loginuid(kuid_t loginuid) >> /* are we setting or clearing? */ >> if (uid_valid(loginuid)) { >> sessionid = (unsigned int)atomic_inc_return(&session_id); >> - if (unlikely(sessionid == (unsigned int)-1)) >> + if (unlikely(sessionid == AUDIT_SID_UNSET)) >> sessionid = (unsigned int)atomic_inc_return(&session_id); >> } >> >> -- >> 1.8.3.1 >> >> -- >> Linux-audit mailing list >> Linux-audit@redhat.com >> https://www.redhat.com/mailman/listinfo/linux-audit > > - 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 > > -- > Linux-audit mailing list > Linux-audit@redhat.com > https://www.redhat.com/mailman/listinfo/linux-audit -- paul moore www.paul-moore.com