Skip to content

Commit 729dc34

Browse files
benh-debianmhiramat
authored andcommitted
bootconfig: Fix negative seeks on 32-bit with LFS enabled
Commit 26dda57 "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. 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. Link: https://lore.kernel.org/all/[email protected]/ Fixes: 26dda57 ("tools/bootconfig: Cleanup bootconfig footer size calculations") Signed-off-by: Ben Hutchings <[email protected]> Signed-off-by: Masami Hiramatsu (Google) <[email protected]>
1 parent c17b750 commit 729dc34

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tools/bootconfig/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ static int load_xbc_from_initrd(int fd, char **buf)
193193
if (stat.st_size < BOOTCONFIG_FOOTER_SIZE)
194194
return 0;
195195

196-
if (lseek(fd, -BOOTCONFIG_MAGIC_LEN, SEEK_END) < 0)
196+
if (lseek(fd, -(off_t)BOOTCONFIG_MAGIC_LEN, SEEK_END) < 0)
197197
return pr_errno("Failed to lseek for magic", -errno);
198198

199199
if (read(fd, magic, BOOTCONFIG_MAGIC_LEN) < 0)
@@ -203,7 +203,7 @@ static int load_xbc_from_initrd(int fd, char **buf)
203203
if (memcmp(magic, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN) != 0)
204204
return 0;
205205

206-
if (lseek(fd, -BOOTCONFIG_FOOTER_SIZE, SEEK_END) < 0)
206+
if (lseek(fd, -(off_t)BOOTCONFIG_FOOTER_SIZE, SEEK_END) < 0)
207207
return pr_errno("Failed to lseek for size", -errno);
208208

209209
if (read(fd, &size, sizeof(uint32_t)) < 0)

0 commit comments

Comments
 (0)