From patchwork Mon Oct 24 11:31:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8364 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp392327wru; Mon, 24 Oct 2022 04:35:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7lpDUofrGR3Ie0vptAv+l0ZaBKZmU+k3Gi8tSuCkRsgb+xMBB2DLNj/dwV48DOLmIfwfLb X-Received: by 2002:a17:906:58c5:b0:7a1:8e13:c071 with SMTP id e5-20020a17090658c500b007a18e13c071mr9000922ejs.671.1666611305923; Mon, 24 Oct 2022 04:35:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666611305; cv=none; d=google.com; s=arc-20160816; b=BB5TGWJtx1T5BrfjKMlGPPzp0oVYfpA4gENS3UAKpzTh4iMmvpDCadNR4418kJXb+e eAtt7qbKWDhIh5nEqrrOOUpQOJG+2qQIkOubqYcesnfyGAnlqCJA02mG/zddF+tpgEy3 L8z0KYMGlEqteSIY8ANXWDwf8ed/ngGt+kVjUL4uSBQOEoqr/W0c4bEiW69q4OdSLFH3 4k+wjhTg4kFx7alxY+aRtQx1BNdZR5lUo7la3Moq0YKI1ycOQfz+LSybMUco098aOEB0 gP2rbYY9wjZ7Whhnth+6S/hEC37X2WOOpEFYUeayTa6NpXI+cOKzoG3imSzGwlAxKNBK VzCg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=o9f8B++Adm86ht1yOEFCn3xfiIyQtroYdJ8MyE3n7Aw=; b=ttn9ry56FC4eRbJ5jTxZL8j9gyyQ8OJZVnOMa72qI4Hu029tLQSraI6/uDDkaSMl3+ acvQmMKAAPAeQatcKehgKmavFkrujI7WRk9vOsvwmFfGG+8wf8sKyAtEqNsDKC2h43cZ /DkrYZE26+AARTslxUpl0BBktvpYwkHA6kW/FkL9gb6ZAukZ/U8oWMpuYCBgQ1Rr0xi6 n6R+SZMib7XSZewrY1DxcHsxFqIDc7TcCymz22SFBzmWuLhwZDGM0VqQ3advNK9KW8Jk K7WmtxYsUdANQJMkBrFkYid00JOYFbo8CzB+hzTgakfRzmoE+tgyXKC21nc1DLvJ8Awk jG4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OQKeGs3L; 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=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e11-20020a17090658cb00b0078e9ca562d8si24130377ejs.879.2022.10.24.04.34.41; Mon, 24 Oct 2022 04:35:05 -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=@linuxfoundation.org header.s=korg header.b=OQKeGs3L; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229781AbiJXLcZ (ORCPT + 99 others); Mon, 24 Oct 2022 07:32:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230175AbiJXLcK (ORCPT ); Mon, 24 Oct 2022 07:32:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3B605E55C; Mon, 24 Oct 2022 04:31:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BD2A061251; Mon, 24 Oct 2022 11:31:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD99EC433C1; Mon, 24 Oct 2022 11:31:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666611116; bh=eLrnmTlnmMdpbACYZc3GPWxthCIJh0Mjw7MbfVQmRL8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OQKeGs3LVhowZ+EgQ5dagqKnxJ8B7g7N0yrgZUFG6xXAKr9TPWkmlxpf5gpwXxO+j ZM0f3ZU4nYoCE2gsbGKHzBI+EEOGfZZrFLzkQf/7M9rVMXlnXJsNno2bQ42oHM81QL wJFaKE/tvg+wq81hWzER1kmGzy7lG/+0i1mXi+L8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ard Biesheuvel Subject: [PATCH 6.0 15/20] efi: efivars: Fix variable writes without query_variable_store() Date: Mon, 24 Oct 2022 13:31:17 +0200 Message-Id: <20221024112935.030619098@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112934.415391158@linuxfoundation.org> References: <20221024112934.415391158@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747568616341788627?= X-GMAIL-MSGID: =?utf-8?q?1747568616341788627?= From: Ard Biesheuvel commit 8a254d90a77580244ec57e82bca7eb65656cc167 upstream. Commit bbc6d2c6ef22 ("efi: vars: Switch to new wrapper layer") refactored the efivars layer so that the 'business logic' related to which UEFI variables affect the boot flow in which way could be moved out of it, and into the efivarfs driver. This inadvertently broke setting variables on firmware implementations that lack the QueryVariableInfo() boot service, because we no longer tolerate a EFI_UNSUPPORTED result from check_var_size() when calling efivar_entry_set_get_size(), which now ends up calling check_var_size() a second time inadvertently. If QueryVariableInfo() is missing, we support writes of up to 64k - let's move that logic into check_var_size(), and drop the redundant call. Cc: # v6.0 Fixes: bbc6d2c6ef22 ("efi: vars: Switch to new wrapper layer") Signed-off-by: Ard Biesheuvel Signed-off-by: Greg Kroah-Hartman --- drivers/firmware/efi/vars.c | 10 +++++----- fs/efivarfs/vars.c | 16 ---------------- include/linux/efi.h | 3 --- 3 files changed, 5 insertions(+), 24 deletions(-) --- a/drivers/firmware/efi/vars.c +++ b/drivers/firmware/efi/vars.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -20,19 +21,19 @@ static struct efivars *__efivars; static DEFINE_SEMAPHORE(efivars_lock); -efi_status_t check_var_size(u32 attributes, unsigned long size) +static efi_status_t check_var_size(u32 attributes, unsigned long size) { const struct efivar_operations *fops; fops = __efivars->ops; if (!fops->query_variable_store) - return EFI_UNSUPPORTED; + return (size <= SZ_64K) ? EFI_SUCCESS : EFI_OUT_OF_RESOURCES; return fops->query_variable_store(attributes, size, false); } -EXPORT_SYMBOL_NS_GPL(check_var_size, EFIVAR); +static efi_status_t check_var_size_nonblocking(u32 attributes, unsigned long size) { const struct efivar_operations *fops; @@ -40,11 +41,10 @@ efi_status_t check_var_size_nonblocking( fops = __efivars->ops; if (!fops->query_variable_store) - return EFI_UNSUPPORTED; + return (size <= SZ_64K) ? EFI_SUCCESS : EFI_OUT_OF_RESOURCES; return fops->query_variable_store(attributes, size, true); } -EXPORT_SYMBOL_NS_GPL(check_var_size_nonblocking, EFIVAR); /** * efivars_kobject - get the kobject for the registered efivars --- a/fs/efivarfs/vars.c +++ b/fs/efivarfs/vars.c @@ -651,22 +651,6 @@ int efivar_entry_set_get_size(struct efi if (err) return err; - /* - * Ensure that the available space hasn't shrunk below the safe level - */ - status = check_var_size(attributes, *size + ucs2_strsize(name, 1024)); - if (status != EFI_SUCCESS) { - if (status != EFI_UNSUPPORTED) { - err = efi_status_to_err(status); - goto out; - } - - if (*size > 65536) { - err = -ENOSPC; - goto out; - } - } - status = efivar_set_variable_locked(name, vendor, attributes, *size, data, false); if (status != EFI_SUCCESS) { --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1055,9 +1055,6 @@ efi_status_t efivar_set_variable_locked( efi_status_t efivar_set_variable(efi_char16_t *name, efi_guid_t *vendor, u32 attr, unsigned long data_size, void *data); -efi_status_t check_var_size(u32 attributes, unsigned long size); -efi_status_t check_var_size_nonblocking(u32 attributes, unsigned long size); - #if IS_ENABLED(CONFIG_EFI_CAPSULE_LOADER) extern bool efi_capsule_pending(int *reset_type);