Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1775660pxp; Mon, 7 Mar 2022 02:02:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJwJeIKZ5A7pDyLns7KDFK+oZ/ysTqjgsHtqC04FMflt508qgaC9sFDRqY5AttTrlspBW/cD X-Received: by 2002:a05:6a00:14d4:b0:4f6:edaa:6078 with SMTP id w20-20020a056a0014d400b004f6edaa6078mr7297770pfu.62.1646647368469; Mon, 07 Mar 2022 02:02:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646647368; cv=none; d=google.com; s=arc-20160816; b=D80Bm6TfON2kUV9MQDJ7f9uCcJKT2lBhZiXcMHQ8aTzthBvXRjn6aWO5qKFYdbsYaB CJzUZQnjupgkSNElKOWzVmHa01ikBOxiLwc7YH2qac4uO6WCItc6aBNK6tIrK0Y+7pqU X/Qql843LB1acSfJl2VLgEUl+cTHYDoGQhSzmFWFuDMofSHeAdeI3ng6qvHmQxyGENs9 PnokbEKcmAdbiv9IplokjUoO4e5p99l7vaoJ4pyWlk3aRF6e/JhBZSoXckX3hajNK/Y2 WnZxr0R4I8TigTiLLQXDMx8fXXBBCMHyRBqLqMt4huyow+5QSNifm7hc8iJNZ3XeXXw0 9eHA== 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=ci2uHKITrQXB8Nj3u5E4qzrOTLlhmlQggEmRQhS7ZAc=; b=LlqLXWIWlBD9iIA+HaINn9HGIrlkBdEI4MOaE1ijLddNQeZlCmGlotppydJYcU72QH 52FFwGndeXj6IBhHVoCsKwwTO5rN/K3WLKum7HcqYlzIcUYmul0i0t7c9euDfPXbGF8Y I1bc+9YlBzeFAt+RCn8XMiVXAiqYQ1YFPXTeQTXpK/3J7ZjU6k2OV2YJuVWqidcfeg5l QobUb2u5PFSdvwglYpWEscct6u6sDqHgyMjErKjokEr9fm4tkxqfuMOkLLGBfxPjFWp7 0SFlwLKO1i5Q67/Dw8C+ymfN7uTwvQwkEKmSclSr06+l7QnfTocimNfW9ovDkSf4Kvh7 8ICg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HFGTXmPh; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i7-20020a17090a4b8700b001bd14e01fc0si7072520pjh.174.2022.03.07.02.02.33; Mon, 07 Mar 2022 02:02:48 -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=@linuxfoundation.org header.s=korg header.b=HFGTXmPh; 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 S231304AbiCGJZv (ORCPT + 99 others); Mon, 7 Mar 2022 04:25:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237311AbiCGJXm (ORCPT ); Mon, 7 Mar 2022 04:23:42 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A9B011151; Mon, 7 Mar 2022 01:22:31 -0800 (PST) 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 ams.source.kernel.org (Postfix) with ESMTPS id EF132B810BC; Mon, 7 Mar 2022 09:22:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37887C340E9; Mon, 7 Mar 2022 09:22:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646644948; bh=EWQa5r9e93SJmy+EJGlMIbPR/OtWqdd39e8vMt+MA2E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HFGTXmPhSHpI5gGzWSeKZendeYLeRXY+e1AOGKHoEo1Hj+DW0MUTHeq+jLE187p/r 8oJGiGVY3Eumlu91a29wzzcEhgX5hv38TyaP/OFwE4MoHx/kf2qIb4w0AP/rXYhwF/ Cz2ehwBklrpfaYV89bpdomz70c3d2JDgS1BqWqLE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jann Horn , Ard Biesheuvel Subject: [PATCH 4.14 32/42] efivars: Respect "block" flag in efivar_entry_set_safe() Date: Mon, 7 Mar 2022 10:19:06 +0100 Message-Id: <20220307091637.087868801@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220307091636.146155347@linuxfoundation.org> References: <20220307091636.146155347@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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,T_SCC_BODY_TEXT_LINE 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 From: Jann Horn commit 258dd902022cb10c83671176688074879517fd21 upstream. When the "block" flag is false, the old code would sometimes still call check_var_size(), which wrongly tells ->query_variable_store() that it can block. As far as I can tell, this can't really materialize as a bug at the moment, because ->query_variable_store only does something on X86 with generic EFI, and in that configuration we always take the efivar_entry_set_nonblocking() path. Fixes: ca0e30dcaa53 ("efi: Add nonblocking option to efi_query_variable_store()") Signed-off-by: Jann Horn Signed-off-by: Ard Biesheuvel Link: https://lore.kernel.org/r/20220218180559.1432559-1-jannh@google.com Signed-off-by: Greg Kroah-Hartman --- drivers/firmware/efi/vars.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/drivers/firmware/efi/vars.c +++ b/drivers/firmware/efi/vars.c @@ -763,6 +763,7 @@ int efivar_entry_set_safe(efi_char16_t * { const struct efivar_operations *ops; efi_status_t status; + unsigned long varsize; if (!__efivars) return -EINVAL; @@ -785,15 +786,17 @@ int efivar_entry_set_safe(efi_char16_t * return efivar_entry_set_nonblocking(name, vendor, attributes, size, data); + varsize = size + ucs2_strsize(name, 1024); if (!block) { if (down_trylock(&efivars_lock)) return -EBUSY; + status = check_var_size_nonblocking(attributes, varsize); } else { if (down_interruptible(&efivars_lock)) return -EINTR; + status = check_var_size(attributes, varsize); } - status = check_var_size(attributes, size + ucs2_strsize(name, 1024)); if (status != EFI_SUCCESS) { up(&efivars_lock); return -ENOSPC;