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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1CEC0C55174 for ; Fri, 31 Jul 2026 18:16:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0F96B6B00A0; Fri, 31 Jul 2026 14:16:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0D14D6B00A2; Fri, 31 Jul 2026 14:16:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F2A326B00A5; Fri, 31 Jul 2026 14:16:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C96626B00A0 for ; Fri, 31 Jul 2026 14:16:06 -0400 (EDT) Received: from smtpin06.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 5B2A8A1A5C for ; Fri, 31 Jul 2026 18:16:06 +0000 (UTC) X-FDA: 85049875932.06.01AC92F Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf15.hostedemail.com (Postfix) with ESMTP id B1E72A000E for ; Fri, 31 Jul 2026 18:16:04 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=C8mqCAa3; spf=pass (imf15.hostedemail.com: domain of ebiggers@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=ebiggers@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1785521764; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9wUJP0XuZAHVCju2vCQtbQJIE3DcNFW1LWD6svK3iD8=; b=x/IkQS3jsXRc+rlSi4sbHTJB3X29tgfRcKDpc7WlnB9iPGTrQjj4botjfcXhlrJt2PKFYy ZNw4xNbCfzW3P5eoIOGyGxxURWJrviCtc4QK26mDV3t/zd9vQ+3C896IwXx0T1rEQghev1 5BtAYBO6ShTm07C9ChoqK6fUOQq2PCs= ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1785521764; b=MperCIREIWfWmVldS5zSwF2ovg4MzqT9euzxQwcXKx3D5kdIDNxpXvGJtc+PgqG8RU6kvB /j9923qy+RHvB8dCe/m3Wi17Ym7+BHRrocbfoyJzDhPiP6wliGSOErr6oasY3gwQAEbUJN 9pdi/K39G5JQZtlIpLf/t92AMLXJY3Y= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=C8mqCAa3; spf=pass (imf15.hostedemail.com: domain of ebiggers@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=ebiggers@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 22E32600C3; Fri, 31 Jul 2026 18:16:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6998C1F00AC4; Fri, 31 Jul 2026 18:16:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785521763; bh=9wUJP0XuZAHVCju2vCQtbQJIE3DcNFW1LWD6svK3iD8=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=C8mqCAa3sOez8bYlcdk7Ex9hl1Zc3wGzNlS+gMfhYDFWo2GO6U1oOyWzlb2bPQY+x hqp45+zj52D2OrfKyI0wE6OnSs4tXIB0pDV9h5BA+FBwqNLLssYqEG2iralfKBbWze 8TnH2nZgoDMCRUVPIIfWgQ5CX2TqVmWguLZl5ry0GMyg4/zCAi/p/yVuCqOjBPDh1S 3CfPkRN86lNOdPWBsocKmexkv/xlcBg6n1fCMbp7GWE8C9TU8+qYac8CviSfGdpNx7 2tBQ+HKflUJA/Bs03oR8x3vLAb4l3YfkvzAafZcN8aqTCzekcrr22Gj5IiA+WkyfGs NrtPDLo03P3hg== Date: Fri, 31 Jul 2026 11:14:08 -0700 From: Eric Biggers To: Baoquan He Cc: linux-mm@kvack.org, Andrew Morton , Chris Li , Kairui Song , linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fscrypt@vger.kernel.org, linux-kernel@vger.kernel.org, Kemeng Shi , Nhat Pham , Barry Song , Youngjun Park , stable@vger.kernel.org Subject: Re: [PATCH] mm/swap: reject swapon() on filesystem-level encrypted files Message-ID: <20260731181408.GA12803@sol> References: <20260730184853.48347-1-ebiggers@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: os7zyqyyog98pw59x1e76onqt64fwmf3 X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: B1E72A000E X-HE-Tag: 1785521764-562880 X-HE-Meta: U2FsdGVkX19ohUEX2NhKnHIdowRYiivwQvba2+a9AI9OXPr/E/JH9X0EEvCYFbF6Asbj6TivcX8mbV392XU/GTqVGiAXKcjfFGzRbmVuIJxMpi0OEVlSFXbJiqIdwjN1qnyPmMUwTygtenijVwrb6j8ynqUTRg7fduDrCRXSl/QQiHkGw6RmafmfKa0LC2aJddFkLupSB4X1QFBjEi/MTTwl6f0xJZjPAUkVOLOPlwrjEbwLxIGMclp8WxygQJchnxDJ79aTwP+HAIAFSf37maxmguRvsC9r7x8QIfYnZL/VpqMmbsezS1KJTGgCop1V/fV8DrhyDpaegNVmlr0uFudh/hkyeVNd66799cCmq4fpSLrJ5Ek7l6ZUwbZHt/pXYh3ydGOWLzsTUuqLmVxRc7q/l6ugeAPD6wU1031UsJm6SBnk3h8J8zGaw9OFwQJCQjlYAdxLYkN3ISuon7yc5GqPfrbPZR8V3Z1cCJhs5hY8oovVAebR2maRsz0/Gf0TruabsZqRNFHnHYnmTuAp07H9BhQfn9csLbzoJGICgBXhsQmiiTvhatbQ2utFRpfzKA3c6T17tEVd/7qlFXLfIUzgsNlehGt7L00TOVsKXNOLL23BikWN4IpaMXkkMRxCKZSBgnwbGaWy8pLCPnjKIcN3RCEUxJED2qbNXWuXtk4zsKNypiHwwJJcjkt96mXeAmPhhx44IO+1zhIvojl1L2P75P0Q6h3FlF2dsTkBr4UxbRlpOvSKWpz1j8LAiiOphz6YpguEn5HyDwwiRsE+7NlIMAcOR84AY4MOfFz+eMYRpHqjOgr7sirltQpnjuyeL6HEQBRIyTxTrbr1H3uDA5fYeHADSz3+gcbWOIild7fDXWK08b253vGZ6lreAj/h9Vb2GDBRJ3lAQ1EV3QOlUmI09T+1PUzo3LITLqm/fMvVX3kai/ZquwXmjOKhRziH07UsLw2cry6z0F8xsLr jqK2aPiT FVc6pBleZyr6BOXQkgYNOypGVdueRB27CKlL/50FasHHVd8Q1em0YgTwh8Lm4eNU7p8cShBCEVkvhuw5PTQNmeFQ4D6R8Lf2PSwQv2DZsZldMlyMhdjkN2mdtYsnOahBzQxFjE6EKqdlb3fokNLJGRjMW7+jMJDdQAIiMdClGG8RirBSevIU8N2gnyAgPn7uTdUGfF2Vy+JHAGmGD/RP6B3qZUw25FRIUym9QhQ1w9B3BDe9Mnwl1tz79YK+EgAMHKS+1n0uZ33KJDyk+8y9UR5SX7g== Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Fri, Jul 31, 2026 at 11:11:02PM +0800, Baoquan He wrote: > On 07/30/26 at 11:48am, Eric Biggers wrote: > > ext4 and f2fs don't prevent filesystem-level encrypted files from being > > set up directly as swap files. In this case, encryption is bypassed. > > > > No one should be doing this, vs. the methods of encrypted swap that > > actually do work (such as swapping to a dm-crypt device, or swapping to > > a loopback device on top of a filesystem-level encrypted file). > > > > Nevertheless, to prevent user error, make swapon() explicitly reject > > this case. Document this behavior in fscrypt.rst as well. > > > > Fixes: 9bd8212f981e ("ext4 crypto: add encryption policy and password salt support") > > Fixes: f424f664f0e8 ("f2fs crypto: add encryption policy and password salt support") > > Cc: stable@vger.kernel.org > > Signed-off-by: Eric Biggers > > --- > > Documentation/filesystems/fscrypt.rst | 4 ++++ > > mm/swapfile.c | 4 ++++ > > 2 files changed, 8 insertions(+) > > > > diff --git a/Documentation/filesystems/fscrypt.rst b/Documentation/filesystems/fscrypt.rst > > index c0dd35f1af12..cba1989777da 100644 > > --- a/Documentation/filesystems/fscrypt.rst > > +++ b/Documentation/filesystems/fscrypt.rst > > @@ -1238,6 +1238,10 @@ astute users may notice some differences in behavior: > > > > - DAX (Direct Access) is not supported on encrypted files. > > > > +- Encrypted files cannot be used directly as swap files. To swap to > > + an encrypted file, set up a loopback device on top of it. > > + Alternatively, encrypted swap can use a dm-crypt device instead. > > + > > - The maximum length of an encrypted symlink is 2 bytes shorter than > > the maximum length of an unencrypted symlink. For example, on an > > EXT4 filesystem with a 4K block size, unencrypted symlinks can be up > > diff --git a/mm/swapfile.c b/mm/swapfile.c > > index 78b49b0658ad..e4991da81b5f 100644 > > --- a/mm/swapfile.c > > +++ b/mm/swapfile.c > > @@ -3650,6 +3650,10 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) > > error = -EBUSY; > > goto bad_swap_unlock_inode; > > } > > + if (IS_ENCRYPTED(inode)) { > > + error = -EINVAL; > > + goto bad_swap_unlock_inode; > > + } > > Sounds reasonable to me. > > One minor suggestion: it might be helpful to emit a pr_warn_once() > explaining *why* the swapon was rejected and pointing users to the > dm-crypt / loopback alternatives, so the -EINVAL isn't opaque. > Optional though -- the check itself is what matters. How's this? pr_warn_once("Filesystem-level encrypted swapfile '%s' is unsupported. Create a loop device over it, or use dm-crypt\n", name->name); > And this patch updates fscrypt.rst. Would it be good to also > update the swapon(8) man page to document the new -EINVAL > condition? > > Other than these, > > Reviewed-by: Baoquan He swapon(8) is for the util-linux program, not the syscall, so it doesn't document error codes specifically. It does have a NOTES section that incompletely documents filesystem-specific constraints on swap files. It's missing most of the current constraints. But sure, I'll send a patch that adds a note to there about this one. That will be a util-linux patch. - Eric 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 04F3AC55173 for ; Fri, 31 Jul 2026 18:16:14 +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=EbJgUYSy1Ib9G8SS6+mh2ieFrZ1DfsTaNS8JJVgya70=; b=ZdLEfSZPWIrOqKZf9q2M/At1uj whj/ai9O8w5IVP49appBAtw0ANYXyfBsQ6V9xGS6sJZMdwDRDP5G9gJcuWKS7IIgqHfcdmGkm9SGw PH5/Dvwhkf1L59X/+wNmFRLYStsOVPNdQcqxKFLl2XvAglYJvMbg+91M34VDoPuXyX2w=; Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1wprmF-0004y2-Jf; Fri, 31 Jul 2026 18:16:11 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1wprmE-0004xv-GD for linux-f2fs-devel@lists.sourceforge.net; Fri, 31 Jul 2026 18:16:10 +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=9wUJP0XuZAHVCju2vCQtbQJIE3DcNFW1LWD6svK3iD8=; b=WcEplRkqZ6VZeG7mwb1XDWtUHx aF07DhWZ01Y+vYsNPoUkPhVL9A3VLMNSpyMhJEs1nmlwXMs69v46XVfMVuQ7ACHxxm02g2e9QYyBg y5bJxrdqYwJS/XEfQda6hjOnGtFq3OroULcLMTWy+PvU6VJzJxEeJQFMkSzwqIMDdloo=; 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=9wUJP0XuZAHVCju2vCQtbQJIE3DcNFW1LWD6svK3iD8=; b=X+s0qeIQ7dUDRMN6bV081X9weg RUO/FluBwNJo8adAUgSjsF488WtvnqHKO+PsOvdM/CVckjNck/JJ3Y5V+xY+XUQBxl+iPt3bJofwE 6y0hogQnjAyzu4e43hkw6nh4Xi55he5CZXYBlEswf99eTWTur9MwkSWGLI+4hMRc0w3M=; Received: from tor.source.kernel.org ([172.105.4.254]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1wprmH-0007wI-Ap for linux-f2fs-devel@lists.sourceforge.net; Fri, 31 Jul 2026 18:16:10 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 22E32600C3; Fri, 31 Jul 2026 18:16:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6998C1F00AC4; Fri, 31 Jul 2026 18:16:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785521763; bh=9wUJP0XuZAHVCju2vCQtbQJIE3DcNFW1LWD6svK3iD8=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=C8mqCAa3sOez8bYlcdk7Ex9hl1Zc3wGzNlS+gMfhYDFWo2GO6U1oOyWzlb2bPQY+x hqp45+zj52D2OrfKyI0wE6OnSs4tXIB0pDV9h5BA+FBwqNLLssYqEG2iralfKBbWze 8TnH2nZgoDMCRUVPIIfWgQ5CX2TqVmWguLZl5ry0GMyg4/zCAi/p/yVuCqOjBPDh1S 3CfPkRN86lNOdPWBsocKmexkv/xlcBg6n1fCMbp7GWE8C9TU8+qYac8CviSfGdpNx7 2tBQ+HKflUJA/Bs03oR8x3vLAb4l3YfkvzAafZcN8aqTCzekcrr22Gj5IiA+WkyfGs NrtPDLo03P3hg== Date: Fri, 31 Jul 2026 11:14:08 -0700 To: Baoquan He Message-ID: <20260731181408.GA12803@sol> References: <20260730184853.48347-1-ebiggers@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Headers-End: 1wprmH-0007wI-Ap Subject: Re: [f2fs-dev] [PATCH] mm/swap: reject swapon() on filesystem-level encrypted files 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: Eric Biggers via Linux-f2fs-devel Reply-To: Eric Biggers Cc: Barry Song , Kairui Song , Nhat Pham , Chris Li , Youngjun Park , Kemeng Shi , linux-kernel@vger.kernel.org, stable@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-mm@kvack.org, linux-fscrypt@vger.kernel.org, Andrew Morton , linux-ext4@vger.kernel.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net On Fri, Jul 31, 2026 at 11:11:02PM +0800, Baoquan He wrote: > On 07/30/26 at 11:48am, Eric Biggers wrote: > > ext4 and f2fs don't prevent filesystem-level encrypted files from being > > set up directly as swap files. In this case, encryption is bypassed. > > > > No one should be doing this, vs. the methods of encrypted swap that > > actually do work (such as swapping to a dm-crypt device, or swapping to > > a loopback device on top of a filesystem-level encrypted file). > > > > Nevertheless, to prevent user error, make swapon() explicitly reject > > this case. Document this behavior in fscrypt.rst as well. > > > > Fixes: 9bd8212f981e ("ext4 crypto: add encryption policy and password salt support") > > Fixes: f424f664f0e8 ("f2fs crypto: add encryption policy and password salt support") > > Cc: stable@vger.kernel.org > > Signed-off-by: Eric Biggers > > --- > > Documentation/filesystems/fscrypt.rst | 4 ++++ > > mm/swapfile.c | 4 ++++ > > 2 files changed, 8 insertions(+) > > > > diff --git a/Documentation/filesystems/fscrypt.rst b/Documentation/filesystems/fscrypt.rst > > index c0dd35f1af12..cba1989777da 100644 > > --- a/Documentation/filesystems/fscrypt.rst > > +++ b/Documentation/filesystems/fscrypt.rst > > @@ -1238,6 +1238,10 @@ astute users may notice some differences in behavior: > > > > - DAX (Direct Access) is not supported on encrypted files. > > > > +- Encrypted files cannot be used directly as swap files. To swap to > > + an encrypted file, set up a loopback device on top of it. > > + Alternatively, encrypted swap can use a dm-crypt device instead. > > + > > - The maximum length of an encrypted symlink is 2 bytes shorter than > > the maximum length of an unencrypted symlink. For example, on an > > EXT4 filesystem with a 4K block size, unencrypted symlinks can be up > > diff --git a/mm/swapfile.c b/mm/swapfile.c > > index 78b49b0658ad..e4991da81b5f 100644 > > --- a/mm/swapfile.c > > +++ b/mm/swapfile.c > > @@ -3650,6 +3650,10 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) > > error = -EBUSY; > > goto bad_swap_unlock_inode; > > } > > + if (IS_ENCRYPTED(inode)) { > > + error = -EINVAL; > > + goto bad_swap_unlock_inode; > > + } > > Sounds reasonable to me. > > One minor suggestion: it might be helpful to emit a pr_warn_once() > explaining *why* the swapon was rejected and pointing users to the > dm-crypt / loopback alternatives, so the -EINVAL isn't opaque. > Optional though -- the check itself is what matters. How's this? pr_warn_once("Filesystem-level encrypted swapfile '%s' is unsupported. Create a loop device over it, or use dm-crypt\n", name->name); > And this patch updates fscrypt.rst. Would it be good to also > update the swapon(8) man page to document the new -EINVAL > condition? > > Other than these, > > Reviewed-by: Baoquan He swapon(8) is for the util-linux program, not the syscall, so it doesn't document error codes specifically. It does have a NOTES section that incompletely documents filesystem-specific constraints on swap files. It's missing most of the current constraints. But sure, I'll send a patch that adds a note to there about this one. That will be a util-linux patch. - Eric _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel