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 2EDE9149E1A; Thu, 11 Apr 2024 10:31:46 +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=1712831507; cv=none; b=swZdnqn/cCnnioHDy+uIUhdTZk8KdSL77M4eBHnDTSshkS5Eh4yAqmpRuFH2E4LjJhh5CPQSrThwvkSEOJNQ2UBThnNd2gWX6eQy1wB1Q6SqFhl9WmnH/T/Ca65tWags72j+s6f+1M/uLX25cnIEG61zo1kI7g6KX+ygkAZcMuc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712831507; c=relaxed/simple; bh=G2wqTvZE4RDTWLxXDkvSCm9JhZsUMkWMrPxLFhTUGdM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KkeAgzDQu0+13S/qEDtZj3Wr2xWbdzv17+/HX8TrBfco/3T7SA6yV3V6Vyw603x3fmkMdbdezhUoZCgQ0XOMyPGLZELDLaKMhc1c/qpAWgtTHVx1v8yvpC9f3wdS6mZknr9GT5cFVz+M61klNi9Y9L2g/VCKGxvh/8UGzOpZ6Ig= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=tm+vRCiW; 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="tm+vRCiW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56044C433C7; Thu, 11 Apr 2024 10:31:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1712831506; bh=G2wqTvZE4RDTWLxXDkvSCm9JhZsUMkWMrPxLFhTUGdM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tm+vRCiW7HgBw4rdqbWF0+sIUKsmIYzpi0Z+aacQDElKz/E1CQRSzy1BGW57kR5Kj Dat2N87IrSQITkK3xtXvLx6q1oPP432Iae6tdH1nfZ9jqwapZqOFsLYD0p0slvDIOE GcrqHVvLbYmPNHFQ+UUczgnR7ITDgAULpAir5u2I= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chenyuan Yang , Richard Weinberger , Zhihao Cheng , Sasha Levin Subject: [PATCH 5.10 032/294] ubi: Check for too small LEB size in VTBL code Date: Thu, 11 Apr 2024 11:53:15 +0200 Message-ID: <20240411095436.603640022@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240411095435.633465671@linuxfoundation.org> References: <20240411095435.633465671@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org 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: Richard Weinberger [ Upstream commit 68a24aba7c593eafa8fd00f2f76407b9b32b47a9 ] If the LEB size is smaller than a volume table record we cannot have volumes. In this case abort attaching. Cc: Chenyuan Yang Cc: stable@vger.kernel.org Fixes: 801c135ce73d ("UBI: Unsorted Block Images") Reported-by: Chenyuan Yang Closes: https://lore.kernel.org/linux-mtd/1433EB7A-FC89-47D6-8F47-23BE41B263B3@illinois.edu/ Signed-off-by: Richard Weinberger Reviewed-by: Zhihao Cheng Signed-off-by: Sasha Levin --- drivers/mtd/ubi/vtbl.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c index f700f0e4f2ec4..6e5489e233dd2 100644 --- a/drivers/mtd/ubi/vtbl.c +++ b/drivers/mtd/ubi/vtbl.c @@ -791,6 +791,12 @@ int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_attach_info *ai) * The number of supported volumes is limited by the eraseblock size * and by the UBI_MAX_VOLUMES constant. */ + + if (ubi->leb_size < UBI_VTBL_RECORD_SIZE) { + ubi_err(ubi, "LEB size too small for a volume record"); + return -EINVAL; + } + ubi->vtbl_slots = ubi->leb_size / UBI_VTBL_RECORD_SIZE; if (ubi->vtbl_slots > UBI_MAX_VOLUMES) ubi->vtbl_slots = UBI_MAX_VOLUMES; -- 2.43.0