From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 3D5DA5519A2; Wed, 9 Sep 2026 13:55:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788962154; cv=none; b=T16H8vW2GhFPvmdEbPJYMKb0iOcwbkgqtUyaMVKybswPDGZpOyCRq50kl9iIaNCwWqi9zb4NJsitgmDle0/pkph9bnCAInDX+XoWXUio0F68cTJc3Ucdrt7Njlh0KW8WcYMiyhpQCiHjGGs6Gmql8wdTLMhl1tAXxeq8gryedlc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788962154; c=relaxed/simple; bh=m4MReTqXlhU2GJTK/gX74fwHl9ndqk+ehrEhUDXyisI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ONmH/OaGOOKqjb4ZiKuXMLHBl8//7tugPfeopZj1qAmRmEe8C66ti8YLk72KN4Mjfu2BXqVSaf2+j6mNjrEfYQU5rsGTeR12ip1GKeJuuIIzUse7s+S6cLdQgPpZbXTPQulhrK/2DgpEoFWJCrg42HFgE7I4sJiOygmFijLqofw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ctsIFpw6; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="ctsIFpw6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F1141F00A3A; Wed, 9 Sep 2026 13:55:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788962153; bh=ebYH8nPZEgXx5hVwKhZ4y+PhwWY4X0JPNzKBOwllWuc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ctsIFpw60n/vdqMB3r9xVJOxvo4/B5KVj/eRlKKHmQcqsjvj7+iRmC9JGr1hMq2Yg KrilHb2BETu8o29Z07nnpUJKkKrBPnFN2qs9zKnqFKagpvs4vZpnmwLb+KZoBoBb+/ bwUfmwWl7+rlcLzJiqYvSf4V9ppPAkIfU+Vb5lX4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Pengpeng Hou , Linus Walleij , Miquel Raynal Subject: [PATCH 7.2 192/556] mtd: afs: validate v2 image info bounds Date: Wed, 9 Sep 2026 15:37:52 +0200 Message-ID: <20260909134237.157317425@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260909134230.441546314@linuxfoundation.org> References: <20260909134230.441546314@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 7.2-stable review patch. If anyone has any objections, please let me know. ------------------ From: Pengpeng Hou commit e9290031f736e99ad17c25c00311c92c266843b7 upstream. The AFS v2 parser uses footer[8] to locate the image information block inside the current erase block, then uses the image information region_count to walk entries from a fixed local array. The footer offset and region count come from flash contents and are not checked against the erase block or the local image-info array before use. Reject v2 entries whose image information offset would underflow the erase block calculation, and reject region counts that cannot fit in the local image-info array before walking region entries. Fixes: b7cf5e2830bb ("mtd: afs: add v2 partition parsing") Cc: stable@vger.kernel.org Signed-off-by: Pengpeng Hou Acked-by: Linus Walleij Signed-off-by: Miquel Raynal Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/parsers/afs.c | 7 +++++++ 1 file changed, 7 insertions(+) --- a/drivers/mtd/parsers/afs.c +++ b/drivers/mtd/parsers/afs.c @@ -235,6 +235,9 @@ static int afs_parse_v2_partition(struct pr_debug("Parsing v2 partition @%08x-%08x\n", off, off + mtd->erasesize); + if (mtd->erasesize < sizeof(footer)) + return -EINVAL; + /* First read the footer */ ptr = off + mtd->erasesize - sizeof(footer); ret = mtd_read(mtd, ptr, sizeof(footer), &sz, (u_char *)footer); @@ -245,6 +248,8 @@ static int afs_parse_v2_partition(struct } name = (char *) &footer[0]; version = footer[9]; + if (footer[8] > mtd->erasesize - sizeof(footer)) + return -EINVAL; ptr = off + mtd->erasesize - sizeof(footer) - footer[8]; pr_debug("found image \"%s\", version %08x, info @%08x\n", @@ -278,6 +283,8 @@ static int afs_parse_v2_partition(struct entrypoint = imginfo[pad]; attributes = imginfo[pad+1]; region_count = imginfo[pad+2]; + if (region_count > (ARRAY_SIZE(imginfo) - pad - 3) / 4) + return -EINVAL; block_start = imginfo[20]; block_end = imginfo[21];