From patchwork Tue Mar 14 10:13:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evgeniy Baskov X-Patchwork-Id: 69510 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1695511wrd; Tue, 14 Mar 2023 04:20:38 -0700 (PDT) X-Google-Smtp-Source: AK7set+LoQJAhSdptUHvXBHqH9cvPEyqlIylPlnJ1fAGCC+KToJ1BY9Z6uSPZPGyX31YlupmAG7V X-Received: by 2002:a17:90a:5290:b0:23d:4188:ad86 with SMTP id w16-20020a17090a529000b0023d4188ad86mr881497pjh.18.1678792837947; Tue, 14 Mar 2023 04:20:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678792837; cv=none; d=google.com; s=arc-20160816; b=acDfqbaqAl7vxpgg150mL/kbavB4HEUdR1z8vzW2p+Skve1V0SulzjowesOx/pau3X m8PINKxghS/Yzu5J4sCyVHwXWD3I2etWlDjiQgWIdGD1+nrBMQEh5SFTXqCooVrpEtST JUY3Mm+rDfgVNa/8VRYtbkfHxs6/2fpXcYakQHilEOb123rwYua0akhtn/SVCDnR2z/T qqbVEzWGy+K0fpjuCSzMoWe6vppYPJTwZvhxlZz3ZSiB3CLm3DmZid28rH0qrzTeTveO z7fPkIRHwgFo5g08bNAz/hBPSOQp7ofRrkg7SyWIewt/iYpH/eILGC6S2h6sw+EDP2lc t9dA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=/4znEshL36zHB0h07IlC+ZODwPn07LA9fIruf/PmWac=; b=SkdtQA9QW9NGL9rd3bQVer6ymS1tsgMNcizWO6odI0WLCuLQC8NHpGEpddKIHGp1Ml 0Pakma2RUgO6QJa69wP95f8gR5GkMNQPCTqY+HRHR0MZpZjo7yZkmKRa+RinIqyn+iwL NIITSLHSC+1lNuhIpG6VDOiytWw9UtUNNXPV9j82KbudEmN/e1LCN+TyKA6MTcNScDYV dhVXNHQKojTvsBPWH+N/wktMrxNHAttUn/zLLbQdQzo3lUd98GsGLKInPLJ1n4S6R5vB y5RvotePJlcOgzkiBont8l/+SXVAGak/uLuE2Q5iY5ooxBp3LnVA5O19wUx8CXT2/c7V fMIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=oNiT1r+t; 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=ispras.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y8-20020a17090a86c800b0023d21d8cd42si2189716pjv.27.2023.03.14.04.20.25; Tue, 14 Mar 2023 04:20:37 -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=@ispras.ru header.s=default header.b=oNiT1r+t; 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=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229814AbjCNKxB (ORCPT + 99 others); Tue, 14 Mar 2023 06:53:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229590AbjCNKw5 (ORCPT ); Tue, 14 Mar 2023 06:52:57 -0400 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5D21974B2; Tue, 14 Mar 2023 03:52:19 -0700 (PDT) Received: from localhost.localdomain (unknown [83.149.199.65]) by mail.ispras.ru (Postfix) with ESMTPSA id 4038B4076B3E; Tue, 14 Mar 2023 10:23:26 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 4038B4076B3E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1678789406; bh=/4znEshL36zHB0h07IlC+ZODwPn07LA9fIruf/PmWac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oNiT1r+tLEAlAtfLGE/fu4wtk4UXquo6znS0SYXSk4OevG9JTnxxbA6SIVpWIbDnd yiUAHQ1O/2bH+W6RQEW42WWg2OLHTmlXgc8o+FZmW/taJUxCRo5lEcIOUeTlw22PmM xxGmYSB5eAtzt45XNoor0WNXdofGTlS7VeXcbKTo= From: Evgeniy Baskov To: Ard Biesheuvel Cc: Peter Jones , Borislav Petkov , Andy Lutomirski , Dave Hansen , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , Alexey Khoroshilov , Gerd Hoffmann , "Limonciello, Mario" , joeyli , lvc-project@linuxtesting.org, x86@kernel.org, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v5 27/27] efi/x86: don't try to set page attributes on 0-sized regions. Date: Tue, 14 Mar 2023 13:13:54 +0300 Message-Id: <465871c482bac0d996e81b5335fc6c307673517c.1678785672.git.baskov@ispras.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760341878693426095?= X-GMAIL-MSGID: =?utf-8?q?1760341878693426095?= From: Peter Jones In "efi/x86: Explicitly set sections memory attributes", the following region is defined to help compute page permissions: /* .setup [image_base, _head] */ efi_adjust_memory_range_protection(image_base, (unsigned long)_head - image_base, EFI_MEMORY_RO | EFI_MEMORY_XP); In at least some cases, that will result in a size of 0, which will produce an error and a message on the console, though no actual failure will be caused in the boot process. This patch checks that case in efi_adjust_memory_range_protection() and returns the error without logging. Signed-off-by: Peter Jones --- drivers/firmware/efi/libstub/mem.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/firmware/efi/libstub/mem.c b/drivers/firmware/efi/libstub/mem.c index d58b552739ed..f18c797785ac 100644 --- a/drivers/firmware/efi/libstub/mem.c +++ b/drivers/firmware/efi/libstub/mem.c @@ -251,6 +251,9 @@ efi_status_t efi_adjust_memory_range_protection(unsigned long start, efi_physical_addr_t rounded_start, rounded_end; unsigned long attr_clear; + if (size == 0) + return EFI_INVALID_PARAMETER; + /* * This function should not be used to modify attributes * other than writable/executable.