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 3F242383326; Sat, 12 Sep 2026 19:40:21 +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=1789242024; cv=none; b=Ofox3z5QpcBt4kWgVjIDIQi1dvSUBkbDiMJY/XFPnFTQrZ2l9IQ0EP6OmhtIiymzgXaQtFGsp66kpuhG5A2mBEY3f6pL39EeIiStCt+QEmsc6SDdCljIWQo/L+UjysHhIRWP8CqY/hXCRUDx7B+FWHARoplQTOvEcKr2rT/v2V4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789242024; c=relaxed/simple; bh=Oiw5ww1eNVEECOR/pL3ER6z5yopPfv2aaZAd8dQ/+Mw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c2Nd7u1HN3UJ3jdbpRDt2n3wJgmGO1p5WVqDvQnKFlMA4oNqJ7Ev3ITyta7UDn1KZMZTHCfDyK/KD2OidgVMyA1oGYIW50Yh3g2+X3DprnD292ossGy5RLfsBhySdY78nL6yDlNFmjYxKRmtglbQ+5BuRUtZgInWzL+SkZdEo4s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Gx1P1C27; 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="Gx1P1C27" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2440E1F000FF; Sat, 12 Sep 2026 19:40:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789242021; bh=BimNo1qmmPFymtM/6Fc6O4NL8yV6riZ85PoQ2NIliQI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Gx1P1C27ouKwqHa55IU4nbe7iPykjw6gMrNEjtwIc8mD9+pVSYYutBS0AcCHEqTkn Fp2tHXAYiazQ/2QZdV/O8Qmlg8/cZAb2JaDiFAaw050nyA03TOBiLV3Au9icKcjPfH wli5G3zWyZ+d1nG1D4fTUj/SzGhniDffO0dc3iOY= 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 5.10 241/798] mtd: afs: validate v2 image info bounds Date: Sat, 12 Sep 2026 08:57:49 +0200 Message-ID: <20260912065522.681460441@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065516.948645775@linuxfoundation.org> References: <20260912065516.948645775@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: 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];