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 CBB14360ED7; Tue, 12 May 2026 16:45:53 +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=1778604353; cv=none; b=BUYSzBdyZ+SGr4HiFKfdBi9EupomzzTx32lPbaWR4idR32zG7wkBltrc5h/URLw8aMAsBR9qLBcyAzFXEy/pQqgCyw5DMlsiQxkBmVjZk8ditZTlQGcfUmV+ngMzEIiOFZ3s4zSlySCyyrOpHexmJWTP5N/Tr+6N7ex47LSR7GI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778604353; c=relaxed/simple; bh=AcAe4/elaHVR4qdaARIi+sqWloNOcTI2K7pOyCzPQJo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=j3oZA1eXTnQtBd5gaGCEdIMCW5H1K3ML9t6Bs1t7GyQtoVWBkqF97hcPQhDwRtPBnnW0AiYZeowHaspjQWL0jSw2rPgi0xcOeIyZR6OODN0B7H1FNqzviDfp8fKMxUHG3B2CjyCNYetNg8SbJAr7gf5FzbVjXutQFtAE1rHlJeY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KTl8SWVy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KTl8SWVy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50240C2BCB0; Tue, 12 May 2026 16:45:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778604353; bh=AcAe4/elaHVR4qdaARIi+sqWloNOcTI2K7pOyCzPQJo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KTl8SWVyQT9eR0KJRerRA1Am+3qK8dO9BevMUKnMoH23CRP9mM5f3Wu8yquPkjamu iDhJafpxFURM/nRV7YIcdF2vJ6mMlLYTcDMvY4jbNiIkyUsF9ww8yELMptMTkRbEh4 oMnRfp5DdCOcFHf+dy1yNxg//l2bSr3pQHtixqa4AlGaNF4Cxj1528N8RUtvReqe3h SBiA5b1rqJP4iqw7iclgX7NmxGE5ZBDhsuApEownA7rjZzSFO99rRbfwmVruqi3YO8 sRA83twil/gSQfzUvwWP5wcTf/c5w5ehJsVY7Iboby7AQBhvuZnkU7BEEXnZxHnPWb xain+gAgQ2EFA== Date: Tue, 12 May 2026 09:45:52 -0700 From: "Darrick J. Wong" To: Christoph Hellwig Cc: Andrew Morton , Chris Li , Kairui Song , Christian Brauner , 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: Re: [PATCH 07/12] swap,block: limit swap file size to device size Message-ID: <20260512164552.GH9555@frogsfrogsfrogs> References: <20260512053625.2950900-1-hch@lst.de> <20260512053625.2950900-8-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260512053625.2950900-8-hch@lst.de> On Tue, May 12, 2026 at 07:35:23AM +0200, Christoph Hellwig wrote: > 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)); Good catch! Reviewed-by: "Darrick J. Wong" --D > + > + return add_swap_extent(sis, div_u64(isize, PAGE_SIZE), 0); > } > > const struct file_operations def_blk_fops = { > -- > 2.53.0 > > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9FA8FCD343F for ; Tue, 12 May 2026 16:46:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type:Cc: Reply-To:From:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Subject:In-Reply-To:MIME-Version:References: Message-ID:To:Date:Sender:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=V6k2FGmD/QABHK8jJI2NsevNDkAkCYkX1M91biYEfPU=; b=J4+g1jdBuLP03JhuDATc0Bkno5 SBLk5xcYSUhigRz5wiSDTfAMosGn8yD5q+rcG+K/G2dBybYteTxPwfSEf6dkUi0eNf9Ku94JdQ2XA mV+KkHjrUaLfSG1FloLyEbbg/QoAfzj4GVjdrqJ9nu/LyoRN1lGdeUHlQZHU4EV8uOJs=; Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1wMqFB-0001Xv-NQ; Tue, 12 May 2026 16:46:06 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1wMqF9-0001Xp-Pz for linux-f2fs-devel@lists.sourceforge.net; Tue, 12 May 2026 16:46:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=In-Reply-To:Content-Type:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=zU7gZAkNKhb92E+S2d+2ynnLov7xXLjK9tSHVkvMHEo=; b=i7GhCx2tGzZz2OjNyk8XIqrNF+ rGXycElH58QxlKyDylpC8+NMS1+vCZsu5sDVN/hARJEtmCl8C6IGZWZFUK5zmNeK7e7Ie3e3NCu++ 7gTvNHAljnP/X0lLy/lWsUlEHCPyiEo326b0C2cwDHW2AKlFpBnWuKiVGgndD8P9wCBo=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To :From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=zU7gZAkNKhb92E+S2d+2ynnLov7xXLjK9tSHVkvMHEo=; b=BlgJi2T0s50AwhF79w6ho2awWs 5XyYcr1HV4hcxdbnkpiRnvKysWL2nNnxQJvyXyWglLyizQn+IUfue9SIifpKeGloVXFrk+RQSwN5j a7rIqAqcaLzuOjbLhHokBmfYdQMm5tfvnhUHOFcHmdw7kAyip9/uV3FWG3jciRqFXXZI=; Received: from sea.source.kernel.org ([172.234.252.31]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1wMqF9-0007My-Jt for linux-f2fs-devel@lists.sourceforge.net; Tue, 12 May 2026 16:46:04 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 81E0A43CF3; Tue, 12 May 2026 16:45:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50240C2BCB0; Tue, 12 May 2026 16:45:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778604353; bh=AcAe4/elaHVR4qdaARIi+sqWloNOcTI2K7pOyCzPQJo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KTl8SWVyQT9eR0KJRerRA1Am+3qK8dO9BevMUKnMoH23CRP9mM5f3Wu8yquPkjamu iDhJafpxFURM/nRV7YIcdF2vJ6mMlLYTcDMvY4jbNiIkyUsF9ww8yELMptMTkRbEh4 oMnRfp5DdCOcFHf+dy1yNxg//l2bSr3pQHtixqa4AlGaNF4Cxj1528N8RUtvReqe3h SBiA5b1rqJP4iqw7iclgX7NmxGE5ZBDhsuApEownA7rjZzSFO99rRbfwmVruqi3YO8 sRA83twil/gSQfzUvwWP5wcTf/c5w5ehJsVY7Iboby7AQBhvuZnkU7BEEXnZxHnPWb xain+gAgQ2EFA== Date: Tue, 12 May 2026 09:45:52 -0700 To: Christoph Hellwig Message-ID: <20260512164552.GH9555@frogsfrogsfrogs> References: <20260512053625.2950900-1-hch@lst.de> <20260512053625.2950900-8-hch@lst.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20260512053625.2950900-8-hch@lst.de> X-Headers-End: 1wMqF9-0007My-Jt Subject: Re: [f2fs-dev] [PATCH 07/12] swap, block: limit swap file size to device size X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: "Darrick J. Wong via Linux-f2fs-devel" Reply-To: "Darrick J. Wong" Cc: Paulo Alcantara , linux-doc@vger.kernel.org, Carlos Maiolino , Hyunchul Lee , linux-mm@kvack.org, Naohiro Aota , linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, Namjae Jeon , Chris Li , linux-nfs@vger.kernel.org, linux-block@vger.kernel.org, Damien Le Moal , David Sterba , Jaegeuk Kim , Jens Axboe , Christian Brauner , Kairui Song , Theodore Ts'o , linux-cifs@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, Steve French , linux-btrfs@vger.kernel.org, Anna Schumaker , linux-fsdevel@vger.kernel.org, Andrew Morton , Trond Myklebust Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net On Tue, May 12, 2026 at 07:35:23AM +0200, Christoph Hellwig wrote: > 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)); Good catch! Reviewed-by: "Darrick J. Wong" --D > + > + return add_swap_extent(sis, div_u64(isize, PAGE_SIZE), 0); > } > > const struct file_operations def_blk_fops = { > -- > 2.53.0 > > _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel