From nobody Wed Dec 24 19:50:25 2025 Received: from lithops.sigma-star.at (lithops.sigma-star.at [195.201.40.130]) (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 262C9101C1; Wed, 24 Jan 2024 06:45:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.201.40.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706078757; cv=none; b=OEgA1tOh78o/DQvDlY+OUwpANOr3My9ySOvmiVxnnFGa8+TdjG3AxoBmE+E/BM94w72rjGClpRzKyaRaMiJL944zZ5LFZokr4ljW8dAT19CkfVkcaIJceT3rRr3TL1LoLzIEmSyVsw1GDtrdHbgxGpXKl0acW7nOaGFHgcyC1yg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706078757; c=relaxed/simple; bh=BqEu9DS+FXNc0fkMc3mE4R9nONdqsJpwreavQF1/W94=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=BsMqQg+NvcuMACkdSEA1vg5DQ9jo0FdaTrUqOjZhRIsONTYBUiz8n7YdWDsyQ1cBZCvSrqbnpjt2R2H7HfZ+KxglpxbjTH7YvYkqY4BTaWDYw7K4kVuXpxuXKjn0b3MbqCKzsryP9afYnp/N4Xy6ymm1dIdysWgLbN98Ek961X8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nod.at; spf=fail smtp.mailfrom=nod.at; arc=none smtp.client-ip=195.201.40.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nod.at Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nod.at Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id E830A64507DA; Wed, 24 Jan 2024 07:37:30 +0100 (CET) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id KGTPGDENNKnb; Wed, 24 Jan 2024 07:37:30 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 73AC564507DD; Wed, 24 Jan 2024 07:37:30 +0100 (CET) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id L8avlpaUQPNY; Wed, 24 Jan 2024 07:37:30 +0100 (CET) Received: from foxxylove.corp.sigma-star.at (unknown [82.150.214.1]) by lithops.sigma-star.at (Postfix) with ESMTPSA id 3541A64507DA; Wed, 24 Jan 2024 07:37:30 +0100 (CET) From: Richard Weinberger To: linux-mtd@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Richard Weinberger , Chenyuan Yang , stable@vger.kernel.org Subject: [PATCH] ubi: Check for too small LEB size in VTBL code Date: Wed, 24 Jan 2024 07:37:02 +0100 Message-Id: <20240124063702.5642-1-richard@nod.at> X-Mailer: git-send-email 2.35.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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-23BE41B26= 3B3@illinois.edu/ Signed-off-by: Richard Weinberger Reviewed-by: Zhihao Cheng --- 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 f700f0e4f2ec..6e5489e233dd 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, stru= ct 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 =3D ubi->leb_size / UBI_VTBL_RECORD_SIZE; if (ubi->vtbl_slots > UBI_MAX_VOLUMES) ubi->vtbl_slots =3D UBI_MAX_VOLUMES; --=20 2.35.3