mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Ben Hutchings <benh@debian.org>
Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH] bootconfig: Fix negative seeks on 32-bit with LFS enabled
Date: Wed, 20 Aug 2025 10:07:31 +0900	[thread overview]
Message-ID: <20250820100731.df29750fa21d864d18169d5c@kernel.org> (raw)
In-Reply-To: <aKHlevxeg6Y7UQrz@decadent.org.uk>

On Sun, 17 Aug 2025 16:21:46 +0200
Ben Hutchings <benh@debian.org> wrote:

> Commit 26dda5769509 "tools/bootconfig: Cleanup bootconfig footer size
> calculations" replaced some expressions of type int with the
> BOOTCONFIG_FOOTER_SIZE macro, which expands to an expression of type
> size_t, which is unsigned.
> 
> On 32-bit architectures with LFS enabled (i.e. off_t is 64-bit), the
> seek offset of -BOOTCONFIG_FOOTER_SIZE now turns into a positive
> value.

Oops, I thought the sign bit would be extended.

> 
> Fix this by casting the size to off_t before negating it.
> 
> Just in case someone changes BOOTCONFIG_MAGIC_LEN to have type size_t
> later, do the same thing to the seek offset of -BOOTCONFIG_MAGIC_LEN.
> 
> Fixes: 26dda5769509 ("tools/bootconfig: Cleanup bootconfig footer size calculations")
> Signed-off-by: Ben Hutchings <benh@debian.org>

Thanks for the fix!

> ---
>  tools/bootconfig/main.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c
> index 57c669d2aa90..55d59ed507d5 100644
> --- a/tools/bootconfig/main.c
> +++ b/tools/bootconfig/main.c
> @@ -193,7 +193,7 @@ static int load_xbc_from_initrd(int fd, char **buf)
>  	if (stat.st_size < BOOTCONFIG_FOOTER_SIZE)
>  		return 0;
>  
> -	if (lseek(fd, -BOOTCONFIG_MAGIC_LEN, SEEK_END) < 0)
> +	if (lseek(fd, -(off_t)BOOTCONFIG_MAGIC_LEN, SEEK_END) < 0)
>  		return pr_errno("Failed to lseek for magic", -errno);
>  
>  	if (read(fd, magic, BOOTCONFIG_MAGIC_LEN) < 0)
> @@ -203,7 +203,7 @@ static int load_xbc_from_initrd(int fd, char **buf)
>  	if (memcmp(magic, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN) != 0)
>  		return 0;
>  
> -	if (lseek(fd, -BOOTCONFIG_FOOTER_SIZE, SEEK_END) < 0)
> +	if (lseek(fd, -(off_t)BOOTCONFIG_FOOTER_SIZE, SEEK_END) < 0)
>  		return pr_errno("Failed to lseek for size", -errno);
>  
>  	if (read(fd, &size, sizeof(uint32_t)) < 0)


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

      reply	other threads:[~2025-08-20  1:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-17 14:21 Ben Hutchings
2025-08-20  1:07 ` Masami Hiramatsu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250820100731.df29750fa21d864d18169d5c@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=benh@debian.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®