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 C10F713BC0C; Mon, 23 Dec 2024 16:06:24 +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=1734969984; cv=none; b=fUfJJk8Hi5CR9xTOX1n0RXOOt6y0F6TLg4o3W+8szE3C4ulB9rh+eF4kLxAINnUqJ2MiNVh35K7q/BtZzcHHD8cy1zrvzZ+ZOQZQppgDjIYKZF7FDXWVupzj61WXs/1925yU1nJUNcWWq8JJxVSjFqeUqncGHUIiraM8r7mkzNo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734969984; c=relaxed/simple; bh=/lM58sDIjCyGGpigyWk8t0IQ8UWVyq7M2g4uxZixp/s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ii/9qIjIn2TpYKBDnF5IDDVj6ZTbaoIwLIZoqVFo83dFanPEg8a2VuTRRs+InE9YKwAj8SC09rPM7zPjk6LYdWHj4uKQJFfTT4eglwN5smfjNBLgH9jDYtN7D46hq47BtJ4Vj57Z4SpEwy5bW6TzVKWL1oGS1ZSUUPBbvAWjTEM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=uaYExrwM; 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="uaYExrwM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30FD6C4CED3; Mon, 23 Dec 2024 16:06:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1734969984; bh=/lM58sDIjCyGGpigyWk8t0IQ8UWVyq7M2g4uxZixp/s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uaYExrwMaZ2cD+6Wt4gH5FZhGtaFu3oVvLDoK2DP3TI/vBnmFq+WsWIGgWP+PkDCJ VwGyoK8VxhzWwLgnVffa3ulZNrZh+vjdRT4NkEUz6LCO0dgnw1gJTPmaNBZrNmhAd7 tCnKZxCCQYpUVnpePy1P//e+w0qzjVbHQEXuMDlQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Kairui Song , Desheng Wu , Sergey Senozhatsky , Andrew Morton Subject: [PATCH 6.12 109/160] zram: refuse to use zero sized block device as backing device Date: Mon, 23 Dec 2024 16:58:40 +0100 Message-ID: <20241223155412.889415988@linuxfoundation.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241223155408.598780301@linuxfoundation.org> References: <20241223155408.598780301@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 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kairui Song commit be48c412f6ebf38849213c19547bc6d5b692b5e5 upstream. Patch series "zram: fix backing device setup issue", v2. This series fixes two bugs of backing device setting: - ZRAM should reject using a zero sized (or the uninitialized ZRAM device itself) as the backing device. - Fix backing device leaking when removing a uninitialized ZRAM device. This patch (of 2): Setting a zero sized block device as backing device is pointless, and one can easily create a recursive loop by setting the uninitialized ZRAM device itself as its own backing device by (zram0 is uninitialized): echo /dev/zram0 > /sys/block/zram0/backing_dev It's definitely a wrong config, and the module will pin itself, kernel should refuse doing so in the first place. By refusing to use zero sized device we avoided misuse cases including this one above. Link: https://lkml.kernel.org/r/20241209165717.94215-1-ryncsn@gmail.com Link: https://lkml.kernel.org/r/20241209165717.94215-2-ryncsn@gmail.com Fixes: 013bf95a83ec ("zram: add interface to specif backing device") Signed-off-by: Kairui Song Reported-by: Desheng Wu Reviewed-by: Sergey Senozhatsky Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- drivers/block/zram/zram_drv.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -524,6 +524,12 @@ static ssize_t backing_dev_store(struct } nr_pages = i_size_read(inode) >> PAGE_SHIFT; + /* Refuse to use zero sized device (also prevents self reference) */ + if (!nr_pages) { + err = -EINVAL; + goto out; + } + bitmap_sz = BITS_TO_LONGS(nr_pages) * sizeof(long); bitmap = kvzalloc(bitmap_sz, GFP_KERNEL); if (!bitmap) {