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 553C843C7AE; Tue, 21 Jul 2026 22:24:47 +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=1784672688; cv=none; b=liww44VIr/C9hnnYTA0XNPGuFGPBjlV0Gzp3T8Ll1t4xaWsX0hANOY6OX8vyE5EC4B/s33HHR3oBiXcnybdyvyxHnmTPi8Ns1ZU6oXAwV7gFUGG1HJjEhjIYyQpua3tEi0M7L5g8gVlBTprl+HN6vQmE0r9po5cQGr90IVUsiPc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784672688; c=relaxed/simple; bh=2pq0PitGNnIbEP9omaKma4kFVUv+YQ2sQRczWEPG9Nc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h9cn03dGlNlMA05Z/MvMGhCo4b19KU6VyYHhQ2R9jLUZwpyzQXTvNotjIsVRcIvXx+Vw+gXnxVGehJDAbb224xjmTO6EsZf1XDjY9zpVKjLneZQJ4eiDy2vwlksRGC7dqF6+igRrZlZLXeMhWAIicTA5eeElWn1tc5RgGcvP5J8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=M1PYb4Gz; 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="M1PYb4Gz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2F831F000E9; Tue, 21 Jul 2026 22:24:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784672687; bh=aR/YlwFr3y0ydXe0f8/eaJ9ekLnuAYEjdAAlmI54TC0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=M1PYb4GzDJiEd6DjW6Y7Ykx4kpuA0NCzzP8VPnqtQhU9dTZXxeXqdwGgL+p8J/A9O 8HZ/P1jSwRwvRB+zXbXSnR2B6o/il5chozro1UVM5QUstw3iglWgY6YkWdSCQCkQVF 3r2pXCasF9gHTiPY+5kwc6N/wmqx1Nk8b8JwfP7k= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Maoyi Xie , Ulf Hansson Subject: [PATCH 5.15 717/843] memstick: ms_block: reject a card that reports too many blocks Date: Tue, 21 Jul 2026 17:25:52 +0200 Message-ID: <20260721152422.176544632@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152405.946368001@linuxfoundation.org> References: <20260721152405.946368001@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.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Maoyi Xie commit 718178f524b98bc920d74bc771aed823c8b81425 upstream. msb_ftl_initialize() computes the zone count from the card block count with no bound: msb->zone_count = msb->block_count / MS_BLOCKS_IN_ZONE; ... for (i = 0; i < msb->zone_count; i++) msb->free_block_count[i] = MS_BLOCKS_IN_ZONE; msb->block_count is a card value. msb_read_boot_blocks() reads number_of_blocks from the card boot page and byte swaps it. free_block_count is a fixed int[MS_MAX_ZONES]. MS_MAX_ZONES is 16, so the valid indices are 0 to 15. The init loop above indexes it by zone_count. msb_mark_block_used() and msb_mark_block_unused() index it by pba / MS_BLOCKS_IN_ZONE, for pba up to block_count - 1. A card may report up to 65535 blocks. A block_count above 8192 (MS_MAX_ZONES * MS_BLOCKS_IN_ZONE) lets the pba index reach 16. That writes past free_block_count[] and corrupts struct msb_data. A larger count runs the init loop past the end too. A real Memory Stick has at most 16 zones. So it has at most 8192 blocks. msb_ftl_initialize() now rejects a card that reports more than MS_MAX_ZONES * MS_BLOCKS_IN_ZONE blocks. Fixes: 0ab30494bc4f ("memstick: add support for legacy memorysticks") Cc: stable@vger.kernel.org Signed-off-by: Maoyi Xie Signed-off-by: Ulf Hansson Signed-off-by: Greg Kroah-Hartman --- drivers/memstick/core/ms_block.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/drivers/memstick/core/ms_block.c +++ b/drivers/memstick/core/ms_block.c @@ -1339,6 +1339,10 @@ static int msb_ftl_initialize(struct msb return 0; msb->zone_count = msb->block_count / MS_BLOCKS_IN_ZONE; + if (msb->block_count > MS_MAX_ZONES * MS_BLOCKS_IN_ZONE) { + pr_err("Too many blocks: %d\n", msb->block_count); + return -EINVAL; + } msb->logical_block_count = msb->zone_count * 496 - 2; msb->used_blocks_bitmap = bitmap_zalloc(msb->block_count, GFP_KERNEL);