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 60F823C415D; Tue, 12 May 2026 16:42:12 +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=1778604132; cv=none; b=ae9QBXNBp/1iC4yHMPfQt+nqt5eauVFmMTZVOm1P518ECUPoEXvU9t6Gt5reNOSaMiNnAJq/hlUWDUKVNOemaZi3TFeCmNbsFYZX19SoyFkp8sxYMDKM52sWKZbkE/ZEFDyqWBBBN37KcYLw6lg52aDLsxKEbOXQyrx93Uhckmc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778604132; c=relaxed/simple; bh=HoLO8a+vZpAtLOTBMM5s56bZzE6B2/xXip3V7gv1An8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pf/QgN7WAOqx8dF2L3V3uiwUpgMBC10AqdNMIgoo8vRxx1fNfRjDrVIGguM3VT2KEUAPyr/Q/Ac1O12M9Px7q7x74yyCMMYSPfMnUDMtISorsW3QjbCyEMWsWUl8oyU7LnEsp2EEjCgM2pOALqrvoSg3KEGRxGSq823VejR7TOA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TTTeSIYr; 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="TTTeSIYr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00A35C2BCC7; Tue, 12 May 2026 16:42:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778604132; bh=HoLO8a+vZpAtLOTBMM5s56bZzE6B2/xXip3V7gv1An8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=TTTeSIYr0mdy8HmJYqjqcLWEHq0y8Zlb5+Bkj0i0AArnuJ7wbNWQRMMg/+jBX4e7l DMqWrdAzfmyEdet2+8O3vETYUEeeqn+HB1x8V5oWp3B/dV8OYzwc7AiQ+4kpybNjeu oXlammqPj2J4WUGQdZx5gTME6ga/ClckN0NU0hI7bwp362zNjXaD8zqd7sk5PtrP0Q I6saHT3UM/tU5CEmUlfhbS35iXJrbw0AAOWn+6LoGkEM+4Ezqd4MYb6Z2cOe1iuf5v X0x+S5CcTFnIhFy4dpdSpOQ5IspuYVG0Zf0k0TaC3AV6LVdFF6C+DXDWZy4rOp+aAH FMfkMFkcQb+cg== Date: Tue, 12 May 2026 09:42:11 -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 04/12] swap: restrict to regular files or block devices Message-ID: <20260512164211.GE9555@frogsfrogsfrogs> References: <20260512053625.2950900-1-hch@lst.de> <20260512053625.2950900-5-hch@lst.de> Precedence: bulk X-Mailing-List: linux-doc@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-5-hch@lst.de> On Tue, May 12, 2026 at 07:35:20AM +0200, Christoph Hellwig wrote: > Various swap code assumes it runs either on a block device or on a > regular file. Make this restriction explicit using checks right > after opening the file. > > Signed-off-by: Christoph Hellwig Makes sense to me. Reviewed-by: "Darrick J. Wong" --D > --- > mm/swapfile.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/mm/swapfile.c b/mm/swapfile.c > index a183c9c95695..651c1b59ff9f 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c > @@ -3515,6 +3515,10 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) > error = -ENOENT; > goto bad_swap_unlock_inode; > } > + if (!S_ISBLK(inode->i_mode) && !S_ISREG(inode->i_mode)) { > + error = -EINVAL; > + goto bad_swap_unlock_inode; > + } > if (IS_SWAPFILE(inode)) { > error = -EBUSY; > goto bad_swap_unlock_inode; > -- > 2.53.0 > >