Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795883503; b=WQjIV0RB4xZS0+6cpV+/fT3ae+P6mHV6/S0R23Nm+WUKWG885JrKClchUkrn+T3KACxC By8398S+D0+T7NbM0s0zFOwd5inQKnUeGolIzOSq4bRuIpKMIUEyFdgSIUM6kY7xgAAk6 BG9RSf/DbWXt45uF4UXlSipPvkNkaw63eRg/q4hNkNmkG7TvtrAviCMBQLoMYydrAoqfy 6EDRwINlnugKxg/GwEtWafemRQzXFxQ3Yali+8xjc0zSOUqFdf9I/YFe8Me2kxJhfMyi6 JEqsvlJF3TDDfN+MiXToWGORUsbD2XXUlmwtiSRzx4oFOoBXZpUGxMoVgh8/QtkHawg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795883503; h=Received:DKIM-Signature:Received:Received:X-ME-Sender: X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID:Received:X-Mailer: MIME-Version:Date:From:To:Cc:Message-Id:In-Reply-To:References: Subject:Content-Type:Content-Transfer-Encoding; bh=tltQ4v/imjN0wEHHls/1tHC5Bg7enQWxOx3HoFH+Jfo=; b=GvydcUOWQRcioTEJ3VY11p7YdBI8+0rrmEoggF6BZrOse8UvCa6HqyfTl2fBdfGaKZKQ crxyeeXgWja2oBm/dFnJvypw3JYzD6/pc6fIGTsk4tunABlasRD9VRIDy0algi4a/CflL 8Xlc0iU1l6qo6L1o2qpNxM9W5dAKKOiuFh4tm9+nrle9/uh43z9uUHwjx3IBk/uWGAJPG gojgtjC9706P+lbnAN8onZxQr9LlIk/q2pIPMClZiohKhA++DQLy8cyHEFCUYjJ5qICff rI3xigS/2o76b/YWtaLskHKT6s+HcVctC/uombTPLzjQrAccfCmuDFTG4/6DTQjP1Og== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SQyxuIJD; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA98B606A31C for ; Sat, 28 Nov 2026 16:31:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SQyxuIJD Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF5761F00898; Sat, 28 Nov 2026 16:31:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795883503; bh=tltQ4v/imjN0wEHHls/1tHC5Bg7enQWxOx3HoFH+Jfo=; h=Date:From:To:Cc:In-Reply-To:References:Subject; b=SQyxuIJD49OVzaW5EVHat5by/LNVjKpPs8s5yK7IvNjsz52omzagjvhNDKVgBl/kc mDruJKWc4C64ovn1ZpqzHMSvXatPCLqcZUcZvkULYpMH+V2ZZMk0bbUj3QU3ruycQO xIUAUXoajDQ0CazYHzrp6xbw0wpWhmzmmoL1RZgIA3QpUOtc8GTGIrRIDFAmLw4wth lyCAFz7He8S66nJYLXPWpxgOQVmyKu39Z2DPASFEfI7C5ad7IhqvW7nCek/fIVQ8W8 +cWoFdImvDVKDdnQgkPx/yt0mLmALWbaKDzakX1QqAqXEAXpgLPO0X9kCB1RAJAXIA de9VcLDkyVUyQ== Received: from ams-compute-02.internal (ams-compute-02.internal [10.64.2.62]) by mailfauth.ams.internal (Postfix) with ESMTP id 1171E198003A; Sat, 28 Nov 2026 11:31:41 -0500 (EST) Received: from ams-imap-11 ([10.64.2.31]) by ams-compute-02.internal (MEProxy); Sat, 28 Nov 2026 11:31:41 -0500 X-ME-Sender: X-ME-Proxy-Cause: dmFkZTFdNkKeTW1vuClpUqvq2SsmRI/0cZQhh94rKtVoJRC/jr/DWc668MJthDoAe+JQG5 S3L9IeeM6PloAKvEIwz35amTceXp0Hh+0Tqefzq1O1SqY+NskN02ExQpXrXKqcRIaBBwjU i2Bq6aHbMMiTXyHgys6+Xi6KzSjWaFHkg91zoDEshO00jQPnykU5dK3JKJcTRjx0AA5hsk Cdk5SA2wild1r0QBivZd2v4ykAoTneuTzXB/MKv8H9Q/bSXVucioK2sa9UreklAnr0Di33 IBURDF8ixzoGqrqoEHExIKF/XSljQTf7/cm3ZBEYuW1XMc9IDKBzdAYCYzQlPgwAfFksAl aek+dZ6xNgJwBraevfWMcKI1bUmd8wIdlcBbf+EKKWL5DQu1NnqUNgWuM20VtNhwtkQYRm FziOFbsPmzJk50dUm6Ng34C7Br2QMDPosR2djxBHjN0FjeUuhoeTbEYxFT5T+b693AiR1s GaaQFmuFg+p8AfBK7jJo//6ITOeea4l8iljRYcqU33HfCvqCdH0SVQfUzHuoFpaJKVi558 LrpU1kTYqhspqCZ6MpGOb4pTPTtYnbUkahlt0lorXCTLi1I1vN9YXRDIQCRn0nh22HjqFp lWUK9xORzgF3r+fRcNyQ5XX9d3wXsQXsNqfHNyjlL5qRr8TRmQDldtjd/M+w X-ME-Proxy: Feedback-ID: ice86485a:Fastmail Received: by mailuser.ams.internal (Postfix, from userid 501) id 44B27F80093; Sat, 28 Nov 2026 11:31:39 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Date: Sat, 28 Nov 2026 17:31:18 +0100 From: "Ard Biesheuvel" To: "Jonggeun Park" Cc: "Jeremy Kerr" , "Kees Cook" , "Tony Luck" , "Guilherme G. Piccoli" , "Ilias Apalodimas" , linux-efi@vger.kernel.org Message-Id: In-Reply-To: References: <20260815074844.1330-1-jakejgpark@gmail.com> <20260903115516.32495-1-jakejgpark@gmail.com> <5b13119c-105a-4197-8f5c-711acc47ac0c@app.fastmail.com> <20260903222830.213089de@pumpkin> Subject: Re: [PATCH v2] efi: vars: commonize the 512-byte name buffer quirk Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Sat, 28 Nov 2026, at 02:11, Jonggeun Park wrote: > Hi Ard, > > I'd like to kindly follow up on this patch. > > Could you please let me know if anything else is needed from my side? > I don't think the patch is good. And my advice actually makes it worse. *name_size =3D 512; is not correct because efivar_get_next_variable() does not know the size of the caller's buffer, and it might be smaller, which is why I proposed *name_size =3D min(*name_size, 512); but this is even worse, because the value may be the size of the variable name returned by the previous call, not the size of the caller's buffer. And the patch actually removes the only assignment in efi-pstore, and so efivar_get_next_variable() has no way of knowing the size of the actual buffer. IOW, the callers must keep setting the buffer size before each call. That way, the min() variant is correct, and we can move the BUILD_BUG() into efivar_get_next_variable() too. But it does not remove a lot of duplication. > 2026=EB=85=84 9=EC=9B=94 4=EC=9D=BC (=EA=B8=88) =EC=98=A4=EC=A0=84 6:2= 8, David Laight =EB=8B=98=EC=9D=B4 =EC=9E=91= =EC=84=B1: >> >> On Thu, 03 Sep 2026 22:03:18 +0200 >> "Ard Biesheuvel" wrote: >> >> > Thanks for respinning this. >> > >> > Some additional thoughts below. >> > >> > On Thu, 3 Sep 2026, at 13:55, Jonggeun Park wrote: >> > > Some old UEFI implementations reject GetNextVariableName() calls = with >> > > a name buffer size larger than 512 bytes. Both efivar_init() and >> > > efi_pstore_read() open-code the same workaround of resetting the = size >> > > to 512 on every iteration. >> > > >> > > Move this workaround into efivar_get_next_variable(), which keeps= this >> > > quirk in one place, resolving the TODO in efi-pstore.c. >> > > >> > > No functional change intended. >> > > >> > > Signed-off-by: Jonggeun Park >> > > --- >> > > v2: >> > > - Move the workaround into the existing efivar_get_next_variable(= ). >> > > --- >> > > drivers/firmware/efi/efi-pstore.c | 10 ---------- >> > > drivers/firmware/efi/vars.c | 7 +++++++ >> > > fs/efivarfs/vars.c | 12 +----------- >> > > 3 files changed, 8 insertions(+), 21 deletions(-) >> > > >> > > diff --git a/drivers/firmware/efi/efi-pstore.c >> > > b/drivers/firmware/efi/efi-pstore.c >> > > index a5db3534f..4f2594d08 100644 >> > > --- a/drivers/firmware/efi/efi-pstore.c >> > > +++ b/drivers/firmware/efi/efi-pstore.c >> > > @@ -164,16 +164,6 @@ static ssize_t efi_pstore_read(struct >> > > pstore_record *record) >> > > efi_status_t status; >> > > >> > > for (;;) { >> > > - /* >> > > - * A small set of old UEFI implementations reject siz= es >> > > - * above a certain threshold, the lowest seen in the = wild >> > > - * is 512. >> > > - * >> > > - * TODO: Commonize with the iteration implementation = in >> > > - * fs/efivarfs to keep all the quirks in one pl= ace. >> > > - */ >> > > - varname_size =3D 512; >> > > - >> > > /* >> > > * If this is the first read() call in the pstore enu= meration, >> > > * varname will be the empty string, and the GetNextV= ariable() >> > > diff --git a/drivers/firmware/efi/vars.c b/drivers/firmware/efi/v= ars.c >> > > index 3700e9869..0f95fc60d 100644 >> > > --- a/drivers/firmware/efi/vars.c >> > > +++ b/drivers/firmware/efi/vars.c >> > > @@ -191,11 +191,18 @@ EXPORT_SYMBOL_NS_GPL(efivar_get_variable, >> > > "EFIVAR"); >> > > /* >> > > * efivar_get_next_variable() - enumerate the next name/vendor p= air >> > > * >> > > + * A small set of old UEFI implementations reject sizes above a = certain >> > > + * threshold, the lowest seen in the wild is 512. Set the name b= uffer >> > > size >> > > + * to 512 on each call. >> > > + * >> > > * Must be called with efivars_lock held. >> > > */ >> > > efi_status_t efivar_get_next_variable(unsigned long *name_size, >> > > efi_char16_t *name, efi_guid_t = *vendor) >> > > { >> > > + BUILD_BUG_ON(EFI_VAR_NAME_LEN < 512); >> > > + *name_size =3D 512; >> > > + >> > >> > This should really be >> > >> > *name_size =3D min(*name_size, 512UL); >> >> You don't need the UL suffix. >> >> > >> > so that a smaller buffer size provided by the caller is respected. >> > >> > That also removes the need for the BUILD_BUG_ON(). >> > >> > No need to send a v3, I can fix that up when applying. >> > >> > > return __efivars->ops->get_next_variable(name_size, name, ven= dor); >> > > } >> > > EXPORT_SYMBOL_NS_GPL(efivar_get_next_variable, "EFIVAR"); >> > > diff --git a/fs/efivarfs/vars.c b/fs/efivarfs/vars.c >> > > index 6833c3d24..5a01833a6 100644 >> > > --- a/fs/efivarfs/vars.c >> > > +++ b/fs/efivarfs/vars.c >> > > @@ -391,18 +391,8 @@ int efivar_init(int (*func)(efi_char16_t *, >> > > efi_guid_t, unsigned long, void *), >> > > if (err) >> > > goto free; >> > > >> > > - /* >> > > - * 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 =3D 512; >> > > - BUILD_BUG_ON(EFI_VAR_NAME_LEN < 512); >> > > - >> > > - status =3D efivar_get_next_variable(&variable_name_si= ze, >> > > - variable_name, >> > > + status =3D efivar_get_next_variable(&variable_name_si= ze, variable_name, >> > > &vendor_guid); >> > > switch (status) { >> > > case EFI_SUCCESS: >> > > -- >> > > 2.43.0 >> > >>