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 250F831619A; Mon, 13 Apr 2026 16:50:37 +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=1776099037; cv=none; b=ae+x+D7GKNvTmz0H/4s3ZQA9nS3bduDQ+mdhumvOmX4gDxJlw/zD76EnMNKruHWEZLl654eP6zG2stApZwzodryCHu4N3MDV8F/j7QMx+GDWPxHSuSI6197PWSNCC+zqu9StIzYxVXnUzWKk54N2B7jg5iDRofVUWWDPCZGbuIg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776099037; c=relaxed/simple; bh=2vGt8B9yvo7iD211sqI5qf1UzUmJFjxcqLH79avhmBg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oJQuH3D7ICDm8CvfPWFoVYRHOs19SAChDI2BGDquNGP97qMZaUQoSjKIpnO/M2cSMIaIcykenNLpnrj/k7GhMLlzEb6H+NGQosfUTpE42uDCXCPJN/WnDrDyu80Pb3gY50YzHUppznlzKRbFUhWMESzvFLjofFMB7Q9RXvV9qTc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Y8eyX/Xc; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Y8eyX/Xc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0028C2BCAF; Mon, 13 Apr 2026 16:50:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1776099037; bh=2vGt8B9yvo7iD211sqI5qf1UzUmJFjxcqLH79avhmBg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y8eyX/XceBJSegwXQwG5f82FkMvkonzWddBgNGQsoQv5y/3JIRrAcnXnbaZSAcW0L eh4TQc16c1UIgo+r/JVdJX3lnbvE0mr7NwXIvalQPNjNroYdeWvervHoToJNm/QOCo GmF/YhqQW+FKuaJSXCAhqjfZdelXJmE7pkNse1ng= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Kees Cook , linux-hardening@vger.kernel.org, Finn Thain , Miquel Raynal , Sasha Levin Subject: [PATCH 5.10 186/491] mtd: Avoid boot crash in RedBoot partition table parser Date: Mon, 13 Apr 2026 17:57:11 +0200 Message-ID: <20260413155826.028841014@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260413155819.042779211@linuxfoundation.org> References: <20260413155819.042779211@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ 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 Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/parsers/redboot.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/mtd/parsers/redboot.c +++ b/drivers/mtd/parsers/redboot.c @@ -270,9 +270,9 @@ nogood: 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