From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 235982C689; Mon, 4 Mar 2024 21:30:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709587850; cv=none; b=d6LUyr1aQmah55GM0UCeC9E1nuhUig5o8go8JJl9O1Q4R6ZpSET4cMiUNK94hoMnTr/5UmfuQfoT8N1M6Uq638fex8KTkhX9MxaGnh8rK4NsegiX2PtibRNFWpXWWkMNstK/tF6Pw3BNfSF3zJmd00SQ/a+SwgMlRKVld7bn+4Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709587850; c=relaxed/simple; bh=xjxSSIbESFa5LgeDFWCwewUHd8SLBJhbVPJW/aF8HSM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cg0TTuZmTElHaOZ7U7hrhen55/Ju2BH0hW/X55nKn+ygD87Qmp+V7KUY47XGzYR2l5RA+7CH/iFZTY2RuZLjgZd1NwoLrdJzNzA1dUev8iOBp3u5DHSXKxtMDZ+PfaSul0qEKIDgsW5+2rddSZLEGcP+OBRhRcE2YUE+GAi5MeY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=mYepjdnv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="mYepjdnv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2A87C433F1; Mon, 4 Mar 2024 21:30:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1709587850; bh=xjxSSIbESFa5LgeDFWCwewUHd8SLBJhbVPJW/aF8HSM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mYepjdnvxJjsyrpCE8rnwR4JZ3uqnVSYBet609Q8wsuxIGdp1o9pqPgjIjnRdVc5N lNfUk9y12OiUIPrIbB7a4mqQxAqiB9D56KKFOkh9/UzWhxKBKujnxRfcFlUz1mXCz7 4qfQJH0kR7jgrYctjr6UOPY+aNvOcqoRhgjZSqF0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Tim Schumacher , Ard Biesheuvel Subject: [PATCH 6.7 113/162] efivarfs: Request at most 512 bytes for variable names Date: Mon, 4 Mar 2024 21:22:58 +0000 Message-ID: <20240304211555.395376674@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240304211551.833500257@linuxfoundation.org> References: <20240304211551.833500257@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.7-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tim Schumacher commit f45812cc23fb74bef62d4eb8a69fe7218f4b9f2a upstream. Work around a quirk in a few old (2011-ish) UEFI implementations, where a call to `GetNextVariableName` with a buffer size larger than 512 bytes will always return EFI_INVALID_PARAMETER. There is some lore around EFI variable names being up to 1024 bytes in size, but this has no basis in the UEFI specification, and the upper bounds are typically platform specific, and apply to the entire variable (name plus payload). Given that Linux does not permit creating files with names longer than NAME_MAX (255) bytes, 512 bytes (== 256 UTF-16 characters) is a reasonable limit. Cc: # 6.1+ Signed-off-by: Tim Schumacher Signed-off-by: Ard Biesheuvel Signed-off-by: Greg Kroah-Hartman --- fs/efivarfs/vars.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) --- a/fs/efivarfs/vars.c +++ b/fs/efivarfs/vars.c @@ -372,7 +372,7 @@ static void dup_variable_bug(efi_char16_ int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *), void *data, bool duplicates, struct list_head *head) { - unsigned long variable_name_size = 1024; + unsigned long variable_name_size = 512; efi_char16_t *variable_name; efi_status_t status; efi_guid_t vendor_guid; @@ -389,12 +389,13 @@ int efivar_init(int (*func)(efi_char16_t goto free; /* - * Per EFI spec, the maximum storage allocated for both - * the variable name and variable data is 1024 bytes. + * A small set of old UEFI implementations reject sizes + * above a certain threshold, the lowest seen in the wild + * is 512. */ do { - variable_name_size = 1024; + variable_name_size = 512; status = efivar_get_next_variable(&variable_name_size, variable_name, @@ -431,9 +432,13 @@ int efivar_init(int (*func)(efi_char16_t break; case EFI_NOT_FOUND: break; + case EFI_BUFFER_TOO_SMALL: + pr_warn("efivars: Variable name size exceeds maximum (%lu > 512)\n", + variable_name_size); + status = EFI_NOT_FOUND; + break; default: - printk(KERN_WARNING "efivars: get_next_variable: status=%lx\n", - status); + pr_warn("efivars: get_next_variable: status=%lx\n", status); status = EFI_NOT_FOUND; break; }