Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp125926imm; Tue, 31 Jul 2018 15:07:34 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcrf/FcDTrh4zq4FQjFmZHLqMZfUf8/+lR3vXJEBySBSDv44GQweBvkHNxtZp571R/uudWp X-Received: by 2002:a62:9849:: with SMTP id q70-v6mr23945226pfd.178.1533074854331; Tue, 31 Jul 2018 15:07:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533074854; cv=none; d=google.com; s=arc-20160816; b=JotDCEJFOiZyOM+/inSwbJftzk4UaIhOtz0E/YH6566pCjsN0desj3isuGZq0bRNMk bfMWvjhl04ZLn7JGyqvwmlagjusCropPq37Whmaf9plvLSNDjSzLUPmR1xG10DKrXH9s AVAJq5a1hWW4EWztJS0jZuIywV6GEXfJy59rz5OplIUfKoz8rI18W59GX66WNm5kOx0+ 4u5QqLNMTU0mOLySRDJ8K7QucnbtXFVUfMAW6nHkBR5pmnUuo4MgsP/t0bBmQO3RIqtR sVfy9IC4qdDUUvuUzmlrcz/S0b+apUXfnXNXiXhsdYL5JrrQYzVZNSZf4AGawzbzE1s0 fIeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=02I1lDV20N4OrFRRAZ43YLAf17Cd+2CkBk49sL6aBH4=; b=UU/3VvSHzB+awU0OrhoqCBB/IZIkOQw4saPk7Rt9Obq9bLMSPW8wL7G2q1bf7h9Yua wuB0KeAs1ZpRFQDvVEDhajrDc8ROOniZxU9rmepZ0xcVatefGkAgYCGS8ycDwf0b2jEl rgTnyyyfyCZFK4YO7CnM7a7gt99eNl25z/8wVnVpUX2IMHx9RxNvUlZNwRX/WahtL41i zLBI0du6CUia8zGjWQYWvbqDf6p9z78lUDadr1Hcup/APINj8Aaq73U0Hdn9C9dblAPa Qbk+Mf/G9z/OVeyg9soh+skSCM476Hh6W3czWNr44HsR0XeQ4+qhWhjrb3fNT4stOjkG piWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=pIGdfLzb; 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 y13-v6si13014611pgp.560.2018.07.31.15.07.14; Tue, 31 Jul 2018 15:07:34 -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=fail header.i=@infradead.org header.s=merlin.20170209 header.b=pIGdfLzb; 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 S1732602AbeGaXsg (ORCPT + 99 others); Tue, 31 Jul 2018 19:48:36 -0400 Received: from merlin.infradead.org ([205.233.59.134]:34582 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731484AbeGaXsg (ORCPT ); Tue, 31 Jul 2018 19:48:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=02I1lDV20N4OrFRRAZ43YLAf17Cd+2CkBk49sL6aBH4=; b=pIGdfLzb8qGbS2rIecmpOooaxh vSePYkdY+iD8dXDzMUg5Dttt2+1tWPVMRQVlYHATe16AOXhlmeylT4fYr8F1nPq6iGSzTxuUhFh8l fuU3Ai3I1AhM3ZAaJy/gkIMhZsbzrUDJbYomqN5H3DkAlNA5XcM29FbMSiwlRIuk4+Fq/dpaei183 mY0il007cvUtfTzsq/5U60J5Wvz1tsgMZKb4S3sdnb8iS1kjc8IoVtjJvWSD2MYXyWmxedLczjaEh B6kR+/aFIvw5gRBSFqrnHvmwzGG19jL/+0TlWTloAFTlo2NVomUIdzGcbP6Cy08vRJXJBqYk/Jr9e 5YUtOODA==; Received: from static-50-53-52-16.bvtn.or.frontiernet.net ([50.53.52.16] helo=midway.dunlab) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fkcmO-0000Tn-4n; Tue, 31 Jul 2018 22:06:08 +0000 Subject: Re: [PATCH v2] security: Add LSM fixup hooks to set*gid syscalls. To: Micah Morton , jmorris@namei.org Cc: linux-security-module@vger.kernel.org, serge@hallyn.com, Kees Cook , linux-kernel@vger.kernel.org References: From: Randy Dunlap Message-ID: Date: Tue, 31 Jul 2018 15:06:02 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/31/2018 02:47 PM, Micah Morton wrote: > The ChromiumOS LSM used by ChromeOS will provide a hook for this, in > order to enforce ChromeOS-specific policies regarding which UIDs/GIDs a > process with CAP_SET{UID/GID} can transition to. The > security_task_fix_setuid LSM hook is very helpful in enabling such a feature > for ChromeOS that governs UID transitions, but unfortunately for us it looks > like the equivalent hook that would allow us to govern GID transitions from an > LSM never got added. > > Resending with plain text mode enabled. > > --- > > The set*uid system calls all call an LSM fixup hook called > security_task_fix_setuid, which allows for altering the behavior of those > calls by a security module. Comments explaining the LSM_SETID_* constants > in /include/linux/security.h imply that the constants are to be used for > both the set*uid and set*gid syscalls, but the set*gid syscalls do not > have the relevant hooks, meaning a security module can only alter syscalls > that change user identity attributes but not ones that change group > identity attributes. This patch adds the necessary LSM hook, called > security_task_fix_setgid, and calls the hook from the appropriate places > in the set*gid syscalls.Tested by putting a print statement in the hook and > seeing it triggered from the various set*gid syscalls. > > Signed-off-by: Micah Morton > Acked-by: Kees Cook > --- > NOTE: the security_task_fix_setgid line in sys_setfsgid is over 80 > characters, but I figured I'd just follow how it was done in sys_setfsuid > rather than trying to wrap the line, since the functions are nearly > identical. > > diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h > index 8f1131c8dd54..a2166c812a97 100644 > --- a/include/linux/lsm_hooks.h > +++ b/include/linux/lsm_hooks.h > @@ -599,6 +599,15 @@ > * @old is the set of credentials that are being replaces > * @flags contains one of the LSM_SETID_* values. > * Return 0 on success. > + * @task_fix_setgid: > + * Update the module's state after setting one or more of the group > + * identity attributes of the current process. The @flags parameter > + * indicates which of the set*gid system calls invoked this hook. > + * @new is the set of credentials that will be installed. Modifications > + * should be made to this rather than to @current->cred. > + * @old is the set of credentials that are being replaced > + * @flags contains one of the LSM_SETID_* values. > + * Return 0 on success. > * @task_setpgid: > * Check permission before setting the process group identifier of the > * process @p to @pgid. > @@ -1587,6 +1596,8 @@ union security_list_options { > enum kernel_read_file_id id); > int (*task_fix_setuid)(struct cred *new, const struct cred *old, > int flags); > + int (*task_fix_setgid)(struct cred *new, const struct cred *old, > + int flags); > int (*task_setpgid)(struct task_struct *p, pid_t pgid); > int (*task_getpgid)(struct task_struct *p); > int (*task_getsid)(struct task_struct *p); > @@ -1876,6 +1887,7 @@ struct security_hook_heads { > struct hlist_head kernel_post_read_file; > struct hlist_head kernel_module_request; > struct hlist_head task_fix_setuid; > + struct hlist_head task_fix_setgid; > struct hlist_head task_setpgid; > struct hlist_head task_getpgid; > struct hlist_head task_getsid; > diff --git a/include/linux/security.h b/include/linux/security.h > index 63030c85ee19..a82d97cf13ab 100644 > --- a/include/linux/security.h > +++ b/include/linux/security.h > @@ -325,6 +325,8 @@ int security_kernel_post_read_file(struct file > *file, char *buf, loff_t size, > enum kernel_read_file_id id); > int security_task_fix_setuid(struct cred *new, const struct cred *old, > int flags); > +int security_task_fix_setgid(struct cred *new, const struct cred *old, > + int flags); > int security_task_setpgid(struct task_struct *p, pid_t pgid); > int security_task_getpgid(struct task_struct *p); > int security_task_getsid(struct task_struct *p); > @@ -929,6 +931,13 @@ static inline int security_task_fix_setuid(struct > cred *new, > return cap_task_fix_setuid(new, old, flags); > } > > +static inline int security_task_fix_setgid(struct cred *new, > + const struct cred *old, > + int flags) > +{ > + return 0; > +} > + > static inline int security_task_setpgid(struct task_struct *p, pid_t pgid) > { > return 0; > diff --git a/kernel/sys.c b/kernel/sys.c > index 38509dc1f77b..f6ef922c6815 100644 > --- a/kernel/sys.c > +++ b/kernel/sys.c > @@ -392,6 +392,10 @@ long __sys_setregid(gid_t rgid, gid_t egid) > new->sgid = new->egid; > new->fsgid = new->egid; > > + retval = security_task_fix_setgid(new, old, LSM_SETID_RE); > + if (retval < 0) > + goto error; > + > return commit_creds(new); > > error: > @@ -434,6 +438,10 @@ long __sys_setgid(gid_t gid) > else > goto error; > > + retval = security_task_fix_setgid(new, old, LSM_SETID_ID); > + if (retval < 0) > + goto error; > + > return commit_creds(new); > > error: > @@ -755,6 +763,10 @@ long __sys_setresgid(gid_t rgid, gid_t egid, gid_t sgid) > new->sgid = ksgid; > new->fsgid = new->egid; > > + retval = security_task_fix_setgid(new, old, LSM_SETID_RES); > + if (retval < 0) > + goto error; > + > return commit_creds(new); > > error: > @@ -861,7 +873,8 @@ long __sys_setfsgid(gid_t gid) > ns_capable(old->user_ns, CAP_SETGID)) { > if (!gid_eq(kgid, old->fsgid)) { > new->fsgid = kgid; > - goto change_okay; > + if (security_task_fix_setgid(new, old, LSM_SETID_FS) == 0) > + goto change_okay; > } > } > > diff --git a/security/security.c b/security/security.c > index 68f46d849abe..587786fc0aaa 100644 > --- a/security/security.c > +++ b/security/security.c > @@ -1062,6 +1062,12 @@ int security_task_fix_setuid(struct cred *new, > const struct cred *old, > return call_int_hook(task_fix_setuid, 0, new, old, flags); > } > > +int security_task_fix_setgid(struct cred *new, const struct cred *old, > + int flags) > +{ > + return call_int_hook(task_fix_setgid, 0, new, old, flags); > +} > + > int security_task_setpgid(struct task_struct *p, pid_t pgid) > { > return call_int_hook(task_setpgid, 0, p, pgid); > > -- > 4.18-rc2 > > -- > > On Tue, Jul 31, 2018 at 1:09 PM James Morris wrote: >> >> On Tue, 31 Jul 2018, Micah Morton wrote: >> >>> +static inline int security_task_fix_setgid(struct cred *new, >>> + const struct cred *old, >>> + int flags) >>> +{ >>> + return 0; >>> +} >>> + >> >> This looks whitespace-damaged. Please send patches as plain text. Still is ... -- ~Randy