Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7338676rwb; Mon, 12 Dec 2022 13:20:25 -0800 (PST) X-Google-Smtp-Source: AA0mqf7cg0FUFtRFsLyJznGseLdNUXqeJOwRnKtIC7NQjfqqwTSdgL5FrWpZH5UyJCLKzCKUztBq X-Received: by 2002:a17:906:850d:b0:7c0:d886:b9ff with SMTP id i13-20020a170906850d00b007c0d886b9ffmr20001316ejx.16.1670880024828; Mon, 12 Dec 2022 13:20:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670880024; cv=none; d=google.com; s=arc-20160816; b=ql5iXlZlorwu+r6VplhSleidWoEc8OZbhSwpv1d+bR/lz80aqwTEFIwUKLgV3e8Tvo na0oLq4sZ5gynUQjXAg6rVhkIK4yhqezDbXERY5OI3kc/T8ZanDGSArkqygkkI3ys8zj XYIqkYp7oqqgZMlBLoEMNxig9OnLOcBlZoxRR9kRmRdXI9mOk7L3t2oTrK2pRPwhRoUG chSGB3GP0FmIrxCBPmERdRdjQgOoK9hXvnFlArrbYsdVTLPv+wiCL2aKBo9eajostYF7 Mlv6DrU0NKWYNeBbzNXMBbWF/6xkuUuM1kYjO8FzEJrbyg27ejDTZ3q0h7QdZFwvUXi1 u4BA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=gd0uj7D3HXOB3a60Cor08DiqmGyidIQkY6rq/3OxFaA=; b=t2re0jK/3AyVAmwW3hNhodsmBHCGCb692Gio3QPnXYhPw/P1NpgiBkYSt1ejhVq0ab nxFCTbqliEwMiE/D8PhfyAR3vAPndewogPDYkGh99Bc9rZT5zuakfcmA6/WsF1JhQsaU rjUvSMGM9ow2Tocp6ACYdw16fT4Cfw13tqy1wFzt5zClCaSonSvvOO1/37UDGyspITQ2 nx21ZbaFmWsOgFgG+ALZi20UgvXuSI6O5If6VnEuBWaarfkG+Pt6sa9fr1dIDl7cA/gD MfM8JL9qaVt1ZyTFal4eZ+omswO3VrAsfR2bla8UtrHjmhMrduDMQ94AIiIFury4I106 4Y+w== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mp36-20020a1709071b2400b007c0b9466effsi7404159ejc.656.2022.12.12.13.20.05; Mon, 12 Dec 2022 13:20:24 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229497AbiLLVPv (ORCPT + 75 others); Mon, 12 Dec 2022 16:15:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233443AbiLLVPV (ORCPT ); Mon, 12 Dec 2022 16:15:21 -0500 Received: from mail.hallyn.com (mail.hallyn.com [178.63.66.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B81AE1B1CB; Mon, 12 Dec 2022 13:13:30 -0800 (PST) Received: by mail.hallyn.com (Postfix, from userid 1001) id EB248403; Mon, 12 Dec 2022 15:13:19 -0600 (CST) Date: Mon, 12 Dec 2022 15:13:19 -0600 From: "Serge E. Hallyn" To: Kees Cook Cc: Paul Moore , James Morris , "Serge E. Hallyn" , linux-security-module@vger.kernel.org, Mimi Zohar , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] LoadPin: Ignore the "contents" argument of the LSM hooks Message-ID: <20221212211319.GA15511@mail.hallyn.com> References: <20221209195453.never.494-kees@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221209195453.never.494-kees@kernel.org> User-Agent: Mutt/1.9.4 (2018-02-28) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, 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 Fri, Dec 09, 2022 at 11:54:57AM -0800, Kees Cook wrote: > LoadPin only enforces the read-only origin of kernel file reads. Whether > or not it was a partial read isn't important. Remove the overly > conservative checks so that things like partial firmware reads will > succeed (i.e. reading a firmware header). > > Fixes: 2039bda1fa8d ("LSM: Add "contents" flag to kernel_read_file hook") > Cc: Paul Moore > Cc: James Morris > Cc: "Serge E. Hallyn" Acked-by: Serge Hallyn Seems reasonable. So the patch which introduced this was 2039bda1f: LSM: Add "contents" flag to kernel_read_file hook It sounds like the usage of @contents which it added to ima still makes sense. But what about the selinux_kernel_read_file() one? > Cc: linux-security-module@vger.kernel.org > Signed-off-by: Kees Cook > --- > security/loadpin/loadpin.c | 30 ++++++++++++++++++------------ > 1 file changed, 18 insertions(+), 12 deletions(-) > > diff --git a/security/loadpin/loadpin.c b/security/loadpin/loadpin.c > index de41621f4998..110a5ab2b46b 100644 > --- a/security/loadpin/loadpin.c > +++ b/security/loadpin/loadpin.c > @@ -122,21 +122,11 @@ static void loadpin_sb_free_security(struct super_block *mnt_sb) > } > } > > -static int loadpin_read_file(struct file *file, enum kernel_read_file_id id, > - bool contents) > +static int loadpin_check(struct file *file, enum kernel_read_file_id id) > { > struct super_block *load_root; > const char *origin = kernel_read_file_id_str(id); > > - /* > - * If we will not know that we'll be seeing the full contents > - * then we cannot trust a load will be complete and unchanged > - * off disk. Treat all contents=false hooks as if there were > - * no associated file struct. > - */ > - if (!contents) > - file = NULL; > - > /* If the file id is excluded, ignore the pinning. */ > if ((unsigned int)id < ARRAY_SIZE(ignore_read_file_id) && > ignore_read_file_id[id]) { > @@ -192,9 +182,25 @@ static int loadpin_read_file(struct file *file, enum kernel_read_file_id id, > return 0; > } > > +static int loadpin_read_file(struct file *file, enum kernel_read_file_id id, > + bool contents) > +{ > + /* > + * LoadPin only cares about the _origin_ of a file, not its > + * contents, so we can ignore the "are full contents available" > + * argument here. > + */ > + return loadpin_check(file, id); > +} > + > static int loadpin_load_data(enum kernel_load_data_id id, bool contents) > { > - return loadpin_read_file(NULL, (enum kernel_read_file_id) id, contents); > + /* > + * LoadPin only cares about the _origin_ of a file, not its > + * contents, so a NULL file is passed, and we can ignore the > + * state of "contents". > + */ > + return loadpin_check(NULL, (enum kernel_read_file_id) id); > } > > static struct security_hook_list loadpin_hooks[] __lsm_ro_after_init = { > -- > 2.34.1