From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 817DC2C08D4; Fri, 20 Mar 2026 21:55:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774043729; cv=none; b=KNSSASEK0KCH0TZ0OiP4XwPXGiNyKj6TxXGkw3uRgLCNdQHepVsx5W2rPQQo1Rzj3K5ybKuTAKF9fBpvejY8v20++U8Q1QZRr1t1hWudXCCZ2K6W453ViNPZIeDB56+PpT83MZN17Bg+71hZni8GwC+ix04uIPIP4iKmf5M/qlw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774043729; c=relaxed/simple; bh=WtVFQVLFopD61Jm7IQCGDAdAe+6bUfaFJixTM92fGmc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F9DkCVjAS/hEcEqEdb/IIR4SzSTdWT6O2ZIdO/krDuWMEAyHWQbqpZoI/AvOeZWt02QqTwRBnv0aVOGtQgHkDr8WSRfsJYcjXW4IOd9+wllPp5qgAE/y0KW/9PJw8QxGLg8aIsYHCjE09dFCx3Cw3VbjbPS4xp1ETpZyxcatlwo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qhgFQjwP; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qhgFQjwP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B74BAC2BC87; Fri, 20 Mar 2026 21:55:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774043729; bh=WtVFQVLFopD61Jm7IQCGDAdAe+6bUfaFJixTM92fGmc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qhgFQjwPxUg3a3UEF4haMMUqGZLA61ounCS3wWEp3r11TNSdDFtYU+/+3iv67sZfM rvwyFvNsz0rULDPlCwQcZAR0dk0FJqmRz0P068sya0m83JUmc5zvC9KVrNwv8uEB+g 5r4+vvZPaVcvn/Jtmi/v8k4t8RKbPQm363gnpAS+xc6Bt8PfTV3KdwOk28AwqQdS5G Dp05tq7wqJL4OyngDcgeNnwqjgO+jeB6v3HUxeX/qot2YDB5G9x/c7VuJK6RWn1ov5 HPEGeoCqJcd/TPJRRqrFCuaPZrYzoTERQRxaKdWCKXA1z/udHiQiq8XNPHkjK2Z8Pp gVjs8RXY44m7A== From: Sasha Levin To: stable@vger.kernel.org Cc: Finn Thain , Kees Cook , linux-hardening@vger.kernel.org, Miquel Raynal , Sasha Levin Subject: [PATCH 5.10.y 2/2] mtd: Avoid boot crash in RedBoot partition table parser Date: Fri, 20 Mar 2026 17:55:26 -0400 Message-ID: <20260320215526.133494-2-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260320215526.133494-1-sashal@kernel.org> References: <2026032025-scanning-frying-8ead@gregkh> <20260320215526.133494-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Finn Thain [ Upstream commit 8e2f8020270af7777d49c2e7132260983e4fc566 ] Given CONFIG_FORTIFY_SOURCE=y and a recent compiler, commit 439a1bcac648 ("fortify: Use __builtin_dynamic_object_size() when available") produces the warning below and an oops. Searching for RedBoot partition table in 50000000.flash at offset 0x7e0000 ------------[ cut here ]------------ WARNING: lib/string_helpers.c:1035 at 0xc029e04c, CPU#0: swapper/0/1 memcmp: detected buffer overflow: 15 byte read of buffer size 14 Modules linked in: CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.19.0 #1 NONE As Kees said, "'names' is pointing to the final 'namelen' many bytes of the allocation ... 'namelen' could be basically any length at all. This fortify warning looks legit to me -- this code used to be reading beyond the end of the allocation." Since the size of the dynamic allocation is calculated with strlen() we can use strcmp() instead of memcmp() and remain within bounds. Cc: Kees Cook Cc: stable@vger.kernel.org Cc: linux-hardening@vger.kernel.org Link: https://lore.kernel.org/all/202602151911.AD092DFFCD@keescook/ Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Suggested-by: Kees Cook Signed-off-by: Finn Thain Signed-off-by: Miquel Raynal Signed-off-by: Sasha Levin --- drivers/mtd/parsers/redboot.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/parsers/redboot.c b/drivers/mtd/parsers/redboot.c index 3b55b676ca6b9..c06ba7a2a34b4 100644 --- a/drivers/mtd/parsers/redboot.c +++ b/drivers/mtd/parsers/redboot.c @@ -270,9 +270,9 @@ static int parse_redboot_partitions(struct mtd_info *master, strcpy(names, fl->img->name); #ifdef CONFIG_MTD_REDBOOT_PARTS_READONLY - if (!memcmp(names, "RedBoot", 8) || - !memcmp(names, "RedBoot config", 15) || - !memcmp(names, "FIS directory", 14)) { + if (!strcmp(names, "RedBoot") || + !strcmp(names, "RedBoot config") || + !strcmp(names, "FIS directory")) { parts[i].mask_flags = MTD_WRITEABLE; } #endif -- 2.51.0