From patchwork Tue Dec 13 18:04:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Jones X-Patchwork-Id: 32909 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp279439wrn; Tue, 13 Dec 2022 10:07:58 -0800 (PST) X-Google-Smtp-Source: AA0mqf7JxfnSJ8AAnA9BsId0M42CK4TTaU1K7FVmCc31maNlnEOwHwW9Ydjp5RUguxw8JBpMZ828 X-Received: by 2002:a05:6a20:9f87:b0:9d:efbe:e5f4 with SMTP id mm7-20020a056a209f8700b0009defbee5f4mr22712872pzb.16.1670954878577; Tue, 13 Dec 2022 10:07:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670954878; cv=none; d=google.com; s=arc-20160816; b=U5p9lf0BjRn9kPgOahWf33GIRsOofwEV1JBc/JEKa6O8zeaoqviihCZU3hWMpvEMMu /pZDbWAEmA0Vx5GpQUPM43nczdcyJ7GcYmY0HtDi9KZULYXEuRTKhiJaorr1B1bgJloy DaBZ643R5lh0D5zj3RimLEjj3lEVxNb9Y3qtJrzp1Xn2puMAMk+zaONgldopRQ03evnq MDOpntLYhdU3sJrKTRfubiJLv0s6ySZysvanJI827ItHCfUIzftkRNg3/UNpzFE/MAGF SJ0d/yImppRxzzSHmaIoS4JG4Xj5VXx1T+8+9pvX2oCT5UM60vPiOeb+TRW3bBcgJ3Iy s9CQ== 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; bh=9442XwFq1UOnuBhQolOjrgRBVO4GjmHmhrVClvO1uGo=; b=CK4hviqgz9PcBqeOesXgZd4nHmZgbw2MnPHKxtFihuCsD3vgFTXUsc6KU1fH7HmN8x vuGhN5dLg0kzvT4tl1VZE6P+yJMpJSJ2/H1t1j9bZadcjJiw7cvRhohcnBiy8oCox92d wP4sOYwR23MP+ikNsV+S5bmpOy/aEuHnznKiMqVe/efmtsw0SNA2TpPfw4rGI1azwu52 w7mGXQLWhVpgpYzTfm/m7a2bHoqvFPrZpCe8znPQu5TQSpRoYHuaPURNMSp4t35iWKt9 VoFQwTtSnGgZQv8Dh0OobZDWceE7G2G/IeDhbuyFSCyt95isrP/d0rxsbVMdzCyMqVLn lPXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EFlB+4Y8; 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=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l25-20020a635719000000b004790794f1fasi12630646pgb.428.2022.12.13.10.07.45; Tue, 13 Dec 2022 10:07:58 -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=@redhat.com header.s=mimecast20190719 header.b=EFlB+4Y8; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236405AbiLMSFS (ORCPT + 99 others); Tue, 13 Dec 2022 13:05:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235762AbiLMSFO (ORCPT ); Tue, 13 Dec 2022 13:05:14 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0446E23EAF for ; Tue, 13 Dec 2022 10:04:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670954669; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9442XwFq1UOnuBhQolOjrgRBVO4GjmHmhrVClvO1uGo=; b=EFlB+4Y8/kZgUtX/dL0FgJSMmoiJ02c2CzPlOe/pZz++TaFqFZrASG/W7rp7obYcXpxTQV /cIryL0rHMGhP/yrjyMyRf6NTkshishsdym1WhwErC13gnaVNiE5+EQZkGenZG20jHGARA lmmJCcwtu58MCnLSbdyxmZD3bqXs4Dc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-326--myBm3lRMLecQIMerV2KPw-1; Tue, 13 Dec 2022 13:04:22 -0500 X-MC-Unique: -myBm3lRMLecQIMerV2KPw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1F3508032E6; Tue, 13 Dec 2022 18:04:21 +0000 (UTC) Received: from random.internal.datastacks.com (unknown [10.2.17.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 82EE3492B00; Tue, 13 Dec 2022 18:04:20 +0000 (UTC) From: Peter Jones To: Evgeniy Baskov Cc: Ard Biesheuvel , Borislav Petkov , Andy Lutomirski , Dave Hansen , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , Alexey Khoroshilov , Peter Jones , Mario Limonciello , 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 2/2] efi/x86: don't try to set page attributes on 0-sized regions. Date: Tue, 13 Dec 2022 13:04:03 -0500 Message-Id: <20221213180403.1308507-2-pjones@redhat.com> In-Reply-To: <20221213180403.1308507-1-pjones@redhat.com> References: <20221213180317.qoy2l3mcpjparocq@redhat.com> <20221213180403.1308507-1-pjones@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752123183039796612?= X-GMAIL-MSGID: =?utf-8?q?1752123183039796612?= 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 d52841adcc2..d20b1986c9e 100644 --- a/drivers/firmware/efi/libstub/mem.c +++ b/drivers/firmware/efi/libstub/mem.c @@ -247,6 +247,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.