From mboxrd@z Thu Jan 1 00:00:00 1970 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=1795034730; b=5ApUyMVM1JTzQjS6R2XrPrGXz8LTlrCzQPovt1fFgEupsaOuV2FEQ9XavNOj+5UxmjMC /MZXz7MbxppPDUhJ4ct/p5cA4SsTo7GLiFUuIiLpbRip6BMi6g+PDYVjbR75dziyTaoj1 aWhXEMsEyFsdF8QLo2RwxpIwLB4e8M6D88v53jzd0rl7W2gb2lFAnDdrW66hE8A9FIDZ0 eQINLhVT10Kgum4Wt373KrFBXIjW9doK4E4NWRzQfDi1bxFtRvEl9s6h6xD7oeNAA3MsU bNQEgQKVZrRKwzUCWVpvbMJqmYI5agfUm3yQ8R+tvKrcMzaR+1OKo13pChrbJ3VqtJQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795034730; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=9V6tIgvMYobTrgL1n/JFbDpGttRXW25dr7MXQo5LX1E=; b=1l0zRXEd0ov8+4ApVxdUCRkFh53j2+pVCgQwRHH5K48sqpUugAHItmCYkeRXVnx+y1UI cL+ziQY6k8hrCkvaESNfBXEe+AP9HkeqTPKuWfiLeDj1Bcr9xyEfz59keUjy25kJZ4Gap DGDtPOb0EDeOE0zwnkhHnOML5qxLUFPV9c1OQksVaVfiSWkrMjsJ+QHgtsf/ND9OX9F2i zPKt61YdNpGLVzC4coO8RlKb8W6gmIuq0nXmoxGPIXi0x/VjEjsufsUeJllOHjEhVfwtV z+NxaaRXh5If+9hoFzRyUgRiswDU7XyaKiq109dltOyYoTImrNJ3UT0P6bEBNMvB77Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b="R9WDX/iV"; 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 9B301606A32C; Wed, 18 Nov 2026 20:45:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=R9WDX/iV Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9D1A1F000C4; Wed, 18 Nov 2026 20:45:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795034730; bh=9V6tIgvMYobTrgL1n/JFbDpGttRXW25dr7MXQo5LX1E=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=R9WDX/iVHSA74PO2BRmcnjUPfzfQheki4E/odErBlBU69PBshYyNggH+V2dSXaHqB BKVJuPPyjlWTWOiMuLCNDOzRfzWHG/haykfSyxqPjTzDtK5DTD5QwXjYPbWJMtzms3 Vv1+VQDezijlgQnJLAElW+Qrjw8AmxOSp3AWvTsk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Masami Hiramatsu (Google)" , Sasha Levin Subject: [PATCH 6.6 0471/3318] tools/bootconfig: Cleanup bootconfig footer size calculations Date: Wed, 18 Nov 2026 15:18:13 +0100 Message-ID: <20261118150331.024144196@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150313.527275416@linuxfoundation.org> References: <20261118150313.527275416@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Masami Hiramatsu (Google) [ Upstream commit 26dda57695090e05c1a99c3e8f802f862d1ac474 ] There are many same pattern of 8 + BOOTCONFIG_MAGIC_LEN for calculating the size of bootconfig footer. Use BOOTCONFIG_FOOTER_SIZE macro to clean up those magic numbers. Link: https://lore.kernel.org/all/175211425693.2591046.16029516706923643510.stgit@mhiramat.tok.corp.google.com/ Signed-off-by: Masami Hiramatsu (Google) Stable-dep-of: 462d0b066b61 ("tools/bootconfig: Fix integer overflow and truncation in size checks") Signed-off-by: Sasha Levin --- tools/bootconfig/main.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c index 32cf48f2da9a1..d302235f6b974 100644 --- a/tools/bootconfig/main.c +++ b/tools/bootconfig/main.c @@ -16,6 +16,10 @@ #define pr_err(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__) +/* Bootconfig footer is [size][csum][BOOTCONFIG_MAGIC]. */ +#define BOOTCONFIG_FOOTER_SIZE \ + (sizeof(uint32_t) * 2 + BOOTCONFIG_MAGIC_LEN) + static int xbc_show_value(struct xbc_node *node, bool semicolon) { const char *val, *eol; @@ -188,7 +192,7 @@ static int load_xbc_from_initrd(int fd, char **buf) if (ret < 0) return -errno; - if (stat.st_size < 8 + BOOTCONFIG_MAGIC_LEN) + if (stat.st_size < BOOTCONFIG_FOOTER_SIZE) return 0; if (lseek(fd, -BOOTCONFIG_MAGIC_LEN, SEEK_END) < 0) @@ -201,7 +205,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, -(8 + BOOTCONFIG_MAGIC_LEN), SEEK_END) < 0) + if (lseek(fd, -BOOTCONFIG_FOOTER_SIZE, SEEK_END) < 0) return pr_errno("Failed to lseek for size", -errno); if (read(fd, &size, sizeof(uint32_t)) < 0) @@ -213,12 +217,12 @@ static int load_xbc_from_initrd(int fd, char **buf) csum = le32toh(csum); /* Wrong size error */ - if (stat.st_size < size + 8 + BOOTCONFIG_MAGIC_LEN) { + if (stat.st_size < size + BOOTCONFIG_FOOTER_SIZE) { pr_err("bootconfig size is too big\n"); return -E2BIG; } - if (lseek(fd, stat.st_size - (size + 8 + BOOTCONFIG_MAGIC_LEN), + if (lseek(fd, stat.st_size - (size + BOOTCONFIG_FOOTER_SIZE), SEEK_SET) < 0) return pr_errno("Failed to lseek", -errno); @@ -349,7 +353,7 @@ static int delete_xbc(const char *path) ret = fstat(fd, &stat); if (!ret) ret = ftruncate(fd, stat.st_size - - size - 8 - BOOTCONFIG_MAGIC_LEN); + - size - BOOTCONFIG_FOOTER_SIZE); if (ret) ret = -errno; } /* Ignore if there is no boot config in initrd */ @@ -379,8 +383,7 @@ static int apply_xbc(const char *path, const char *xbc_path) csum = xbc_calc_checksum(buf, size); /* Backup the bootconfig data */ - data = calloc(size + BOOTCONFIG_ALIGN + - sizeof(uint32_t) + sizeof(uint32_t) + BOOTCONFIG_MAGIC_LEN, 1); + data = calloc(size + BOOTCONFIG_ALIGN + BOOTCONFIG_FOOTER_SIZE, 1); if (!data) return -ENOMEM; memcpy(data, buf, size); @@ -428,7 +431,7 @@ static int apply_xbc(const char *path, const char *xbc_path) } /* To align up the total size to BOOTCONFIG_ALIGN, get padding size */ - total_size = stat.st_size + size + sizeof(uint32_t) * 2 + BOOTCONFIG_MAGIC_LEN; + total_size = stat.st_size + size + BOOTCONFIG_FOOTER_SIZE; pad = ((total_size + BOOTCONFIG_ALIGN - 1) & (~BOOTCONFIG_ALIGN_MASK)) - total_size; size += pad; -- 2.53.0