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 93E6E32D7C7; Sat, 12 Sep 2026 13:59:29 +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=1789221573; cv=none; b=mo/LYRnfyPfuUBAlvplBk/QU4qO8HWRXK3p2oUea8mltDoHqz7PSRbOr1kXoCArUHwmgrpgNYRgXjSHVdFX09cikNwrYzFjVNlwYFGRUbJy6NOaQcBESoZifJY36IfC0JNZQwelkJqPXO87Og+pXUxS/gJZtZi/qV2R0EY8H3rs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789221573; c=relaxed/simple; bh=7QuQIUmwyOeKgR/tMv63jDuwb36DyGf1rMWLrTA5luo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B79Jkgki7emhIF8qjZh1rjDhYioolCWGHidCWCEnLJEQwMaSoyD2fJkQxfsJDXTNjgENhqtMrtf1moLRFzsatC6patl5LWcUorie+APH/I3hs5rfKacfg2WH/wxglAQRK5Nh7KvLerRLaubfkETs4ThXZLnfbVLS29ED5pMJzrE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=HTRFlNep; 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="HTRFlNep" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DCD3F1F00893; Sat, 12 Sep 2026 13:59:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789221568; bh=+paDfIKtILUIe3Xn4r78b4P9hGdF4OIaZHBuppE1fnU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=HTRFlNepI5f5kKN0rPJpLj8EuUhYxnM+bKMQ5Nqs8cW8doYYXRzbwvx6Y+wopU7vn qwbcmJBOMGcK2EVcj04M8xiS+cBdAG0e5kFaqpnJnkJCKgVOFgXbu1/5I5wljiqI/Q 52NKvkkeMC+BWJyFOw714NM6y6UnfeFpLuz9e1uM= 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 6.6 0392/1424] mtd: afs: validate v2 image info bounds Date: Sat, 12 Sep 2026 08:47:04 +0200 Message-ID: <20260912065616.067966113@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065607.279695368@linuxfoundation.org> References: <20260912065607.279695368@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 6.6-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];