U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Sriram Sriram <sriramsriram@linux.microsoft.com>
To: u-boot@lists.u-boot-project.org
Cc: Michal Simek <michal.simek@amd.com>,
	Michal Simek <monstr@monstr.eu>,
	Maarten Brock <Maarten.Brock@sttls.nl>,
	Tom Rini <trini@konsulko.com>,
	Drew Kluemke <ankluemk@microsoft.com>,
	Sriram Sriram <sriramsriram@linux.microsoft.com>
Subject: [PATCH v2 1/2] board: xilinx: Check calloc() result in board_name_decode()
Date: Wed, 16 Sep 2026 10:36:10 -0700	[thread overview]
Message-ID: <20260916173611.29425-2-sriramsriram@linux.microsoft.com> (raw)
In-Reply-To: <20260916173611.29425-1-sriramsriram@linux.microsoft.com>

The allocation of board_local_name is followed by a test on board_info
instead of on the newly allocated pointer, so an allocation failure is
never detected and the first strcat() writes through a NULL pointer.

The same test is also placed after the allocation, so returning early
because board_info is NULL leaks the buffer, while every other exit from
the function goes through the error: label and frees it.

Test board_info before allocating anything and check the calloc() result
on its own.

Fixes: 52ff1626cf4c ("xilinx: common: Enabling generic function for DT reselection")
Signed-off-by: Sriram Sriram <sriramsriram@linux.microsoft.com>
---

Changes in v2:
- New patch. Replaces v1 1/2 ("board: xilinx: Use strlcat() in
  board_name_decode()"), which is dropped in favour of Pranav Tilak's
  patch for the same heap overflow.

 board/xilinx/common/board.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/board/xilinx/common/board.c b/board/xilinx/common/board.c
index f45b879736e..9ea5f46c9a8 100644
--- a/board/xilinx/common/board.c
+++ b/board/xilinx/common/board.c
@@ -573,10 +573,13 @@ char * __maybe_unused __weak board_name_decode(void)
 	struct xilinx_board_description *desc;
 	int i, id;
 
-	board_local_name = calloc(1, MAX_NAME_LENGTH);
 	if (!board_info)
 		return NULL;
 
+	board_local_name = calloc(1, MAX_NAME_LENGTH);
+	if (!board_local_name)
+		return NULL;
+
 	for (id = 0; id <= highest_id; id++) {
 		desc = &board_info[id];
 
-- 
2.49.0


  reply	other threads:[~2026-09-16 17:36 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09 19:20 [PATCH 0/2] board: xilinx: Fix board name overflow and allow board ft_board_setup() Sriram Sriram
2026-09-09 19:20 ` [PATCH 1/2] board: xilinx: Use strlcat() in board_name_decode() Sriram Sriram
2026-09-10  7:56   ` Maarten Brock
2026-09-10  7:59     ` Michal Simek
2026-09-10  8:03   ` Michal Simek
2026-09-10  9:30     ` Maarten Brock
2026-09-10  9:43       ` Michal Simek
2026-09-15 19:24         ` Sriram Sriram
2026-09-16  8:06           ` Michal Simek
2026-09-09 19:20 ` [PATCH 2/2] board: xilinx: Make ft_board_setup() weak Sriram Sriram
2026-09-16 17:36 ` [PATCH v2 0/2] board: xilinx: board_name_decode() allocation fix and weak ft_board_setup() Sriram Sriram
2026-09-16 17:36   ` Sriram Sriram [this message]
2026-09-16 17:36   ` [PATCH v2 2/2] board: xilinx: Make ft_board_setup() weak Sriram Sriram
2026-09-25 13:51   ` [PATCH v2 0/2] board: xilinx: board_name_decode() allocation fix and weak ft_board_setup() Michal Simek
2026-09-28 22:13     ` Sriram Sriram

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=20260916173611.29425-2-sriramsriram@linux.microsoft.com \
    --to=sriramsriram@linux.microsoft.com \
    --cc=Maarten.Brock@sttls.nl \
    --cc=ankluemk@microsoft.com \
    --cc=michal.simek@amd.com \
    --cc=monstr@monstr.eu \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.u-boot-project.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