Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp870681iog; Mon, 13 Jun 2022 15:00:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwh5zqMfm6TuaOzp1CWVT02k3kCE8SYSPDxx7IolX5Rgm5HWhVe19EEj0l0XK5CEpJedoMv X-Received: by 2002:a63:d806:0:b0:408:9e5d:68b9 with SMTP id b6-20020a63d806000000b004089e5d68b9mr1500890pgh.22.1655157602590; Mon, 13 Jun 2022 15:00:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655157602; cv=none; d=google.com; s=arc-20160816; b=t85GQ+lxarSFdHasao1zZe/mVTfA/OnICNj7dmCfHuT1fJR389uCg8tNMI3C2Y29la oLhgeHWFWF1krLGGLT20O7YRGBqN+8Y5I+41Kdt6qKRRaCyvTLxiTIhYDljhLTTp3yzA as126GtcOukLMvQXmoUMA9lW+luiohPW7P3NM6FHfiDPVVJC51mTlttwLGc5bEHn03Sj GBJn6AP7HhTVQWC1IGgCOgW5alR8UUkNKuUQiUhfYr1BU4MMFcHQGFt+C1/EBbZDhWB/ cbAE1QgiQj8UhU3o7Ydu5eYNumPdPDR8ip9CT8Pblt8ReqCFm2o/NmRHnFw/9tIhf80C anKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=m3pP4CUDi16OPdqz61PfqfFdQ3Rj/mvHUE3nwdWy4vY=; b=XV8vWpXbgQ/Led6Byg3sbi+cbKwDwmeJ2hFIwqU0+DxzcBxVMmLeS64cSFQXhRVILS 3AwDJbBwCUyy1ScldTyrPgoj0An0lPxkJwCcMAK0DS9O50G8Kfv4yFg1Dp5/3lzAIpmR eThsCmUCkrTbd7LGV387lRpwzCMQSVkKdMjTuU9BtzLmd6NS60FKVNh7UPXExjO2Q1UW rgBPMasBcc5xC4zqJRHl2EDdI9FOexWN7PkMjmUI7/Pga+4dKpPv/246R9b81OUxe5y6 nmZPorApGzuBCudF3j+3mcF/QDvPV4+zEGAWfcQd4E5w9HgUesNy7RLSg7N8PCS6Beko m4Rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Xf8LMzKj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f6-20020a63de06000000b003c60d889162si10955130pgg.244.2022.06.13.14.59.51; Mon, 13 Jun 2022 15:00:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Xf8LMzKj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235711AbiFMVSJ (ORCPT + 99 others); Mon, 13 Jun 2022 17:18:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352076AbiFMVRz (ORCPT ); Mon, 13 Jun 2022 17:17:55 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BBE246C89 for ; Mon, 13 Jun 2022 14:00:16 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id m20so13377384ejj.10 for ; Mon, 13 Jun 2022 14:00:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=m3pP4CUDi16OPdqz61PfqfFdQ3Rj/mvHUE3nwdWy4vY=; b=Xf8LMzKjbk+b55bDO0mBuR+UF0qvlWKx5z6+YUrGHK3R9b2cJHFIXwacUxmYBlCteL ZH/mNca1asTSoeNjBu1JtIV/TllMG97497AB4ZdnnUlwfpwx5RVYAJfRlegBcaYS6H8t O/oreJ10UWSczwuf7xTac2Ci2RLQ8efz0/fXg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=m3pP4CUDi16OPdqz61PfqfFdQ3Rj/mvHUE3nwdWy4vY=; b=C3cE3Lqwy/C1nPSM1tmQN8YgsDLHAwuma08J8ZjDvmffdVUSOcSqUo2W2XzvDLSJit sI/4jP2oj9/A3AeepOVQQwZ3CFKi6fD5wAY/nLFNsmKXd856mbDabaW9aNnsu/cUAJjZ iTm4L9XyO3c6E7fI6fgLpw3lxVgpq0muBLyLnv1VufWNpPy1+ZTFurrpWH6PGmKza1bl 4dzJQQgZgEjGzCgQzE5xgwVOEwGeevsl3AJv0sCyr2S3m2R3QP4ofAy49XJkqs/6bw5m nBd0EdWxwQrf6jfoVkzWFIHLaR6pkkWSdNDxvrV46ANyzRAhOfTcoxa9QIs9FiPRfesF /OYg== X-Gm-Message-State: AOAM5336rd7H/v7f/aOu7gysNm2xSwT8InrODb4NEa8ltJdVbeXeWjBQ v0vgbcEScHo0KGE2aAJRYIZ4WQyO8PZZzm6I/7+LnA== X-Received: by 2002:a17:906:a0ce:b0:6d1:cb30:3b3b with SMTP id bh14-20020a170906a0ce00b006d1cb303b3bmr1411366ejb.582.1655154014725; Mon, 13 Jun 2022 14:00:14 -0700 (PDT) MIME-Version: 1.0 References: <20220613202852.447738-1-mortonm@chromium.org> In-Reply-To: <20220613202852.447738-1-mortonm@chromium.org> From: Micah Morton Date: Mon, 13 Jun 2022 14:00:03 -0700 Message-ID: Subject: Re: [PATCH 2/2] LSM: SafeSetID: Add setgroups() security policy handling To: linux-security-module@vger.kernel.org Cc: keescook@chromium.org, jmorris@namei.org, serge@hallyn.com, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 13, 2022 at 1:28 PM Micah Morton wrote: > > The SafeSetID LSM has functionality for restricting setuid()/setgid() > syscalls based on its configured security policies. This patch adds the > analogous functionality for the setgroups() syscall. Security policy > for the setgroups() syscall follows the same policies that are > installed on the system for setgid() syscalls. > > Signed-off-by: Micah Morton > --- > NOTE: this code does nothing to prevent a SafeSetID-restricted process > with CAP_SETGID from dropping supplementary groups. I don't anticipate > supplementary groups ever being used to restrict a process' privileges > (rather than grant privileges), so I think this is fine for the > purposes of SafeSetID. > > Developed on 5.18 > > security/safesetid/lsm.c | 39 ++++++++++++++++++++++++++++++--------- > 1 file changed, 30 insertions(+), 9 deletions(-) > > diff --git a/security/safesetid/lsm.c b/security/safesetid/lsm.c > index 963f4ad9cb66..01c355e740aa 100644 > --- a/security/safesetid/lsm.c > +++ b/security/safesetid/lsm.c > @@ -97,15 +97,9 @@ static int safesetid_security_capable(const struct cred *cred, > return 0; > > /* > - * If CAP_SET{U/G}ID is currently used for a setid() syscall, we want to > - * let it go through here; the real security check happens later, in the > - * task_fix_set{u/g}id hook. > - * > - * NOTE: > - * Until we add support for restricting setgroups() calls, GID security > - * policies offer no meaningful security since we always return 0 here > - * when called from within the setgroups() syscall and there is no > - * additional hook later on to enforce security policies for setgroups(). > + * If CAP_SET{U/G}ID is currently used for a setid or setgroups syscall, we > + * want to let it go through here; the real security check happens later, in > + * the task_fix_set{u/g}id or task_fix_setgroups hooks. > */ > if ((opts & CAP_OPT_INSETID) != 0) > return 0; > @@ -241,9 +235,36 @@ static int safesetid_task_fix_setgid(struct cred *new, > return -EACCES; > } > > +static int safesetid_task_fix_setgroups(struct cred *new, const struct cred *old) > +{ > + int i; > + > + /* Do nothing if there are no setgid restrictions for our old RGID. */ > + if (setid_policy_lookup((kid_t){.gid = old->gid}, INVALID_ID, GID) == SIDPOL_DEFAULT) > + return 0; > + > + get_group_info(new->group_info); > + for (i = 0; i < new->group_info->ngroups; i++) { > + if (!id_permitted_for_cred(old, (kid_t){.gid = group_info->gid[i]}, GID)) { Oops, should be: !id_permitted_for_cred(old, (kid_t){.gid = new->group_info->gid[i]}, GID) Guess I won't send a whole new patch just for that one line > + put_group_info(new->group_info); > + /* > + * Kill this process to avoid potential security vulnerabilities > + * that could arise from a missing allowlist entry preventing a > + * privileged process from dropping to a lesser-privileged one. > + */ > + force_sig(SIGKILL); > + return -EACCES; > + } > + } > + > + put_group_info(new->group_info); > + return 0; > +} > + > static struct security_hook_list safesetid_security_hooks[] = { > LSM_HOOK_INIT(task_fix_setuid, safesetid_task_fix_setuid), > LSM_HOOK_INIT(task_fix_setgid, safesetid_task_fix_setgid), > + LSM_HOOK_INIT(task_fix_setgroups, safesetid_task_fix_setgroups), > LSM_HOOK_INIT(capable, safesetid_security_capable) > }; > > -- > 2.36.1.476.g0c4daa206d-goog >