From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 CDE323CA4AF; Tue, 12 May 2026 05:37:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778564259; cv=none; b=u02CtnD5hCC7QVhR5vSKzJCP1Hx0beMf34Y7s/XUBChtEdhZhjQToWr7YIwj8zursrmXOZq2q0za2jjJ/FURYzkoEfmiXsy+xvoLTe6/E4UimXErB9Se+z6i0QZ0Z7qmhqQXQnU8n31Vl7t/sQ37M/gZKwdfMIEFUhHqLP2/Rdc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778564259; c=relaxed/simple; bh=dw8grI9DSk4s/G8r9TQjH7qPDNdcXwLkbx+zXbdjH8s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mwhLy7v4EzTNYWMkXpkoeTZwFv++Ik0ZeSAg4Zi2Jk+OfFjpKdAReIBKSvRRXzgaJXFqLKfxq+Tbn0640Ukm46fz9tnZ6IURmhg7BTTM9VVeYKsqpZlNdw3w+6BaIafY+6Yerzr0j3ktm2AuoAEiI3VkmmnTGnYCqk8FSUXCFhA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=T+9tuwEe; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="T+9tuwEe" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=GNG6f/qsobCnQrMhBOENN8KDFhS7LUQniOJgelpzd6g=; b=T+9tuwEeXC5tQgcpvWKYfuq6Ar uKkEDYS0He1n12AYyubbJb1pKFwP0d0egx+o3zSlEHg33Z+uNrYMplMAd1fCjYcVjBidd1n34L8DK yofO+zJRzWIbLRHqeLst7TRdnMK1aRDpYTT0iIQ6IIOy6TBzDn6JFvcDscaBZdLTC1OsW2eOjm3YW EFb1C3k0vinDbZ33FIm1eb3PLLRF4xxvmFXprvKiBggk5QgqvmIOvXvpsL8EgCQV8IL6Xkdfigr9F zwHZAG0Q/JdYvWqG+ejmLyrFHsg1w1ZB6VSHKa4nxK61Ndh02jSbtEK//PKZzbVyiFuzG30kwk7vc Bah3mVQg==; Received: from 2a02-8389-2341-5b80-decc-1a96-daaa-a2cc.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:decc:1a96:daaa:a2cc] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.99.1 #2 (Red Hat Linux)) id 1wMfo6-0000000FfOs-3Cda; Tue, 12 May 2026 05:37:27 +0000 From: Christoph Hellwig To: Andrew Morton , Chris Li , Kairui Song Cc: Christian Brauner , "Darrick J . Wong " , Jens Axboe , David Sterba , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Trond Myklebust , Anna Schumaker , Namjae Jeon , Hyunchul Lee , Steve French , Paulo Alcantara , Carlos Maiolino , Damien Le Moal , Naohiro Aota , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org Subject: [PATCH 07/12] swap,block: limit swap file size to device size Date: Tue, 12 May 2026 07:35:23 +0200 Message-ID: <20260512053625.2950900-8-hch@lst.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260512053625.2950900-1-hch@lst.de> References: <20260512053625.2950900-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Don't blindly pass the value from the swap header to swap_add_extent, but instead the device size rounded down to page granularity. This activated the sanity checking in the core code that catches a too large value in the swap header. Signed-off-by: Christoph Hellwig --- block/fops.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/block/fops.c b/block/fops.c index 453141801684..067e46299666 100644 --- a/block/fops.c +++ b/block/fops.c @@ -951,7 +951,9 @@ static int blkdev_mmap_prepare(struct vm_area_desc *desc) static int blkdev_swap_activate(struct file *file, struct swap_info_struct *sis) { - return add_swap_extent(sis, sis->max, 0); + loff_t isize = i_size_read(bdev_file_inode(file)); + + return add_swap_extent(sis, div_u64(isize, PAGE_SIZE), 0); } const struct file_operations def_blk_fops = { -- 2.53.0