Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp939681iog; Mon, 13 Jun 2022 16:48:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXc66QvTKaEpG+dlle3xJ9N1wGB3mL6AjxQbv1ZXprD2b2aDusThVQwgdHmpLHJsBVurCJ X-Received: by 2002:a17:907:7b92:b0:6db:71f1:fc20 with SMTP id ne18-20020a1709077b9200b006db71f1fc20mr1799358ejc.343.1655164096222; Mon, 13 Jun 2022 16:48:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655164096; cv=none; d=google.com; s=arc-20160816; b=gjzZBndTlZGvNkPUij9N26vBouNHHwUvAeyO0oXgIHA1uj3QNMC2LLbBdEzFwxkbvI 3Qb7VTfx+cAcjV2bpmehsj0mJ/je5T+cXztlE9uMVSj9C9sd4ikTyrJHvRxtqK4d5GuR u9BJc22/VAAvsNG0yT1fzG0SMj215WNdyoThK6niy9Kf2nIWRogR7WRkTmJ9Ew44I6Qc FqKj9Ng2Q1Dwu3nRtyiBaP5UPog+ICbCRKvlpAUl/hHK/hvi9tLqQrw3SfmFd9YPuzer rN6UZCC4cpTltAYZPLJ13/+PZXsZVcVxiHKWqEYc3nFpdEx0lEl2TvM1GUA5Z8XgNleO 423g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=LMZMQK49gc47drd6Jd36STmC+qlFEdOKEq0ulnkEkFs=; b=ohkXgX7g8kZxBc/ZgMTRJHGtopcjFhR/pdJkNb+omlSzwMjqGbYkI8+OPKmfPp+FDk lDE+3CJd+YGIAuxJBySkkyT2aGqdZ4uICZj/aD6/OdgAvvGuR6jAjZGu7HRkbdf858nd 8lShY1TPvD7Jd5pH1W2x/wt17Oska2m3iV+12PuybzXFnf8cxwwwXd5IQY22suaaCvfR eVCJrbOFhXFLHjmM1n0ClkLrz2+LmkM2jlS2pQniOE8xTWQy29BMbC/gyg2OFIeHS+NG xtcOwtSBubicWF5kFzzFzX4JuA6Rhzyu4Xhe+c1emzFMkVAEugQlr5yAQZ+e9k0dg7r8 +8zA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KpQN3HSa; 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 z14-20020a05640240ce00b0042dd7c5d240si10875261edb.277.2022.06.13.16.47.50; Mon, 13 Jun 2022 16:48:16 -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=KpQN3HSa; 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 S232525AbiFMXqc (ORCPT + 99 others); Mon, 13 Jun 2022 19:46:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229848AbiFMXqb (ORCPT ); Mon, 13 Jun 2022 19:46:31 -0400 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0892632EFF for ; Mon, 13 Jun 2022 16:46:31 -0700 (PDT) Received: by mail-pg1-x536.google.com with SMTP id r5so274607pgr.3 for ; Mon, 13 Jun 2022 16:46:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=LMZMQK49gc47drd6Jd36STmC+qlFEdOKEq0ulnkEkFs=; b=KpQN3HSapyv/qKjWcCGtXvRNrg5pQGiNxmt8TNqgb1TKcG5DJbt9XHcO+8jhBvRA8r sSdkkSHdkmtN/7q7JB00iwiatLreKrwfpIv/rCQy0oTRWjxDK7urmoWJMjMKJPa4we2V VG34MAF0/wvkUIH61Lad0EWacF1Mz+tqeZXvQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=LMZMQK49gc47drd6Jd36STmC+qlFEdOKEq0ulnkEkFs=; b=IrT9brqP+D75k1Gl0rOht2StYNPgdL4rWZbs9OPKACUp8iNfEBYe8qNVpttl3GT28a 2DoMIA8Q6zVPizL4YfoXzBgqJJ92yH4MVNHK+0TQSZF74kOFGlIFKI4zZjfxbC0BhnSy gFaKnZuHA7EQI4JTzpoh/x2ppoo6o6WUQCb8v9Q7jFZINZ8FSs68Q290u7es/4SQhsLX a1c6/s8sIrnBlC8wNocGLUmGoqkYlRkpmlmQ7eQKt9eIf84Vza3BHynsoEULWt+KUQan hPuXmAWjg1/KZfJYnl12+co/nwFvUArILBjs/QHp+KvgK31e1M7PPZRaZsOuTGViNoE/ UwBQ== X-Gm-Message-State: AOAM5328TEwthO7zOs/lgPrgXpTIyAQcLn3PTG+CiLFMoRlMWGHL3L0g pMjjRq45QOp1/VvAaMqGMHc2Vw== X-Received: by 2002:a63:5248:0:b0:402:de14:ab74 with SMTP id s8-20020a635248000000b00402de14ab74mr1882926pgl.18.1655163990389; Mon, 13 Jun 2022 16:46:30 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id cp15-20020a170902e78f00b00168c5230332sm5672252plb.148.2022.06.13.16.46.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jun 2022 16:46:30 -0700 (PDT) Date: Mon, 13 Jun 2022 16:46:29 -0700 From: Kees Cook To: Micah Morton Cc: linux-security-module@vger.kernel.org, jmorris@namei.org, serge@hallyn.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] LSM: SafeSetID: Add setgroups() security policy handling Message-ID: <202206131643.4FB2340C43@keescook> References: <20220613202852.447738-1-mortonm@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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=unavailable 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 02:00:03PM -0700, Micah Morton wrote: > On Mon, Jun 13, 2022 at 1:28 PM Micah Morton wrote: > [...] > > +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 This begs the question: are there self-tests for this LSM somewhere? It'd be really nice to add them to tool/testing/selftests ... -- Kees Cook