Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp9525063rwl; Wed, 11 Jan 2023 06:50:23 -0800 (PST) X-Google-Smtp-Source: AMrXdXvG/BSjHpoEFqbZwbvvC2IvegtEfQxBkrvrcx/TDUN9GuWxKzsvpMlwrDaCazstTxKnwkk8 X-Received: by 2002:aa7:9154:0:b0:57a:7140:84ae with SMTP id 20-20020aa79154000000b0057a714084aemr64044808pfi.9.1673448622831; Wed, 11 Jan 2023 06:50:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673448622; cv=none; d=google.com; s=arc-20160816; b=MNX/fy+1hjtp+J0ysOCu7kx9033svWXk+P5PxqxyqWS4ODg1dbXH5PG1M7HGcWou+l 9sNw6gO5RmYzaXMKbQ3P3nC7klw+1JMCKoE1TyKOI0zG53YfzDiDwkkAjlDkmKAZQ10g G1iDa7nvVRu51H8NV1K2qeIYNjGHroN9JAkpM1bZFabj7nNvOe4zcZS0ax1FpwwBDot+ Oz1GFD+1OfU/7Uq0ZI4a3koi0CH4Q0y4OdOxBq1OLSt34X14LjCityl+g20EdKoyhMBD Iv845AfNRx9lLYdoIqsDtrMEf2mjrYjcOhn8wmPGOrq0pV/BH5hHjVT8DOsG3scZL0GQ Xv0g== 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=j0t2bn4nZtdh7DYNiHghgOiJ5/dQ9do1qFUNd17Ho0Q=; b=UVludd7gAF335Jy8hRnbjPfLzzP69QGeuJsrE4HC/AxN1Cf7d3xueG66C1CuDzo9/i j3IgJV850zHWYD9wNvdx1sx1uG1Fck7FP7TzStH5cxImEBFnEkO7fOzFAGa2WDybQW2v cm1rKt/CyThcm0XHJnc1ajBZlBqqPpXQDtXxdZzpwCd88EdW783LE3hBmhR77iwMrN7w VWutVoAtDOUU/QXCEcc8QUHkVKb/52xf44lI9us+EZUPBmjgwBf5zWm+fzu4Npwroy85 uy/ffpuSN9L1QwNdyVs7fyDUkkxtlCXIcNB5qeCtmI8vdw7WpP+Pwdyuc/IDiv/xt2cA I+og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore.com header.s=google header.b=Gy4Mryka; 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=paul-moore.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v10-20020a056a00148a00b00582fa10146esi15886252pfu.217.2023.01.11.06.50.15; Wed, 11 Jan 2023 06:50:22 -0800 (PST) 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=@paul-moore.com header.s=google header.b=Gy4Mryka; 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=paul-moore.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239000AbjAKO2X (ORCPT + 55 others); Wed, 11 Jan 2023 09:28:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239596AbjAKO1m (ORCPT ); Wed, 11 Jan 2023 09:27:42 -0500 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8CC61EED0 for ; Wed, 11 Jan 2023 06:26:08 -0800 (PST) Received: by mail-pl1-x62a.google.com with SMTP id y1so16952812plb.2 for ; Wed, 11 Jan 2023 06:26:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore.com; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=j0t2bn4nZtdh7DYNiHghgOiJ5/dQ9do1qFUNd17Ho0Q=; b=Gy4Mryka1zuuoKtaVN8MVkw7dRGJo1zKk8dXXcAaFhsufGRUkcyaoY9eEylCpjBRoA tc9oSd+PPBOUqYbDEv3hZKPjcdo0RESO3HlfLycCfVqINLxYWX90Pw0nnC0gLLS1Lkcr c8EEaRcUHhd+/RBgerhwWCc2y/KbqpucELD83s89s40YDId/3CuVFxAqasNQJAzY7rz/ zZJCROGm5h4+YlAL9YviW/7Oor0mkuUi8vKBd09fFQtcmcO3oAAcpRX3XABhJr5a0NdI jU4Cbvcyh3hhX0Q3f8XfLMU5lGqBjEtJ7/dRxSIgdJBHr4XdJio8fEs7VP7qh0EOLd9l g5pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=j0t2bn4nZtdh7DYNiHghgOiJ5/dQ9do1qFUNd17Ho0Q=; b=t5QC75xsogwRcdsB87Zq0tY5jBBWh30/Csvte9lcVE3vLDRmE1tOySU10sXVc4OJv8 Vq39c/ppMkPrsDQNW08ZbjB+3lBsZrFLBVarGrq5SOnDFY/paF+Ip9oXt9tF6/4Nqefu VDskMqcHPaC0yLbxoW0D2xitFz/Q4X+HAh4L+wcW1XfQMVQAO9Z5VMbbgqBekkUdSB7o os74L8FgQZ1+Sy2sl9qNsaLy4dIzKFt0ygM7c1x0tBQIVUNuj6Jlw4AON+CChlD9ydeY brJpiDFwkZFk7VeYqT6Xg2wlHR8qS2L1gA8vso/Eay5+uxyBCReQvI2ZP//ItAckjVMF vcWA== X-Gm-Message-State: AFqh2koliYPgPwJzLzFbK/jegIJNOwvX9JOat7y39EgNn9J5dzkVAFJY vO6UdOt6NcoweyCTyF9lx+Q+6atPfAeqU/W69hl8 X-Received: by 2002:a17:902:7d83:b0:193:2c1b:3371 with SMTP id a3-20020a1709027d8300b001932c1b3371mr1314817plm.56.1673447168187; Wed, 11 Jan 2023 06:26:08 -0800 (PST) MIME-Version: 1.0 References: <20221221141007.2579770-1-roberto.sassu@huaweicloud.com> <4b8688ee3d533d989196004d5f9f2c7eb4093f8b.camel@huaweicloud.com> In-Reply-To: <4b8688ee3d533d989196004d5f9f2c7eb4093f8b.camel@huaweicloud.com> From: Paul Moore Date: Wed, 11 Jan 2023 09:25:56 -0500 Message-ID: Subject: Re: [PATCH v2] security: Restore passing final prot to ima_file_mmap() To: Roberto Sassu Cc: zohar@linux.ibm.com, jmorris@namei.org, serge@hallyn.com, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk, Roberto Sassu , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS 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 Wed, Jan 11, 2023 at 4:31 AM Roberto Sassu wrote: > On Fri, 2023-01-06 at 16:14 -0500, Paul Moore wrote: > > On Wed, Dec 21, 2022 at 9:10 AM Roberto Sassu > > wrote: > > > From: Roberto Sassu > > > > > > Commit 98de59bfe4b2f ("take calculation of final prot in > > > security_mmap_file() into a helper") moved the code to update prot with the > > > actual protection flags to be granted to the requestor by the kernel to a > > > helper called mmap_prot(). However, the patch didn't update the argument > > > passed to ima_file_mmap(), making it receive the requested prot instead of > > > the final computed prot. > > > > > > A possible consequence is that files mmapped as executable might not be > > > measured/appraised if PROT_EXEC is not requested but subsequently added in > > > the final prot. > > > > > > Replace prot with mmap_prot(file, prot) as the second argument of > > > ima_file_mmap() to restore the original behavior. > > > > > > Cc: stable@vger.kernel.org > > > Fixes: 98de59bfe4b2 ("take calculation of final prot in security_mmap_file() into a helper") > > > Signed-off-by: Roberto Sassu > > > --- > > > security/security.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/security/security.c b/security/security.c > > > index d1571900a8c7..0d2359d588a1 100644 > > > --- a/security/security.c > > > +++ b/security/security.c > > > @@ -1666,7 +1666,7 @@ int security_mmap_file(struct file *file, unsigned long prot, > > > mmap_prot(file, prot), flags); > > > if (ret) > > > return ret; > > > - return ima_file_mmap(file, prot); > > > + return ima_file_mmap(file, mmap_prot(file, prot)); > > > } > > > > This seems like a reasonable fix, although as the original commit is > > ~10 years old at this point I am a little concerned about the impact > > this might have on IMA. Mimi, what do you think? > > > > Beyond that, my only other comment would be to only call mmap_prot() > > once and cache the results in a local variable. You could also fix up > > some of the ugly indentation crimes in security_mmap_file() while you > > are at it, e.g. something like this: > > Hi Paul > > thanks for the comments. With the patch set to move IMA and EVM to the > LSM infrastructure we will be back to calling mmap_prot() only once, > but I guess we could do anyway, as the patch (if accepted) would be > likely backported to stable kernels. I think there is value in fixing this now and keeping it separate from the IMA-to-LSM work as they really are disjoint. -- paul-moore.com