From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 407FB51D51E; Mon, 31 Aug 2026 13:43:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788183828; cv=none; b=aJgpf0GPijhf6wAoQBUPv/eM15HX8fwPc1sAA/hAmE2flG/iNOxE8TMi/2Mi41l6RXTMg6SMlpUIxhbmxYWMBi+YhlNe/ABuqPnKa4hBZdhiUNtQGmsKLD/BElooHi1UXdgl0l4ucEEbKFBdf7xwOty2DHbe3SNCLoEcELI51HU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788183828; c=relaxed/simple; bh=dPT8heg57gsCwj1MfHCUgkmUbrdCMe7Hjkxj7ORt0yU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hw3OWydrIWjr4Fw6xmRmmvyIzlNEJmBhm4ZA4zAcaYPnw/VOO0WmSU9Lk+pIO2kLKo5iMxouB7tv6gxWvrR/wwCW9BcgwffQpGqMk41QHJPHYF9N+BD1WkIwnygCed4Uay+aA2etjx83QGklGAkEfoxV4mSVj+8qDkm/d+LfBBw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=jigtJEy3; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="jigtJEy3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8AC461F00A3D; Mon, 31 Aug 2026 13:43:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788183825; bh=DxXFEY1+7aI6P+Ek33P38GM91EVKaon/kCONjB9uoK8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jigtJEy3xYk4MY+FvCKzXdcDnA8Lz1EVOAiI5e3j2yzA2nD+dVN3rHzA/mOUgUlXW lNTL7DBZ/dK0ksYK/ey3qiLTyp9S68xmmwxlPVVEB0EtJBdVSrRaryfzu3muHHDeI6 SiIHtT5EXmx1BduElIq2MyspvAThq+s0B5kkVU3c= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Eric Biggers , Baoquan He , Muhammad Usama Anjum , "Darrick J. Wong" , Barry Song , Chris Li , Kairui Song , Kemeng Shi , Nhat Pham , Andrew Morton Subject: [PATCH 7.1 54/76] mm/swap: reject swapon() on filesystem-level encrypted files Date: Mon, 31 Aug 2026 15:34:26 +0200 Message-ID: <20260831133402.231937790@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260831133359.185608553@linuxfoundation.org> References: <20260831133359.185608553@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Biggers commit c310a8932a3107c9bc8f01d473e9d085f8aa9c98 upstream. 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. Link: https://lore.kernel.org/20260803180426.3123-1-ebiggers@kernel.org Fixes: 9bd8212f981e ("ext4 crypto: add encryption policy and password salt support") Fixes: f424f664f0e8 ("f2fs crypto: add encryption policy and password salt support") Signed-off-by: Eric Biggers Reviewed-by: Baoquan He Reviewed-by: Muhammad Usama Anjum Reviewed-by: "Darrick J. Wong" Cc: Barry Song Cc: Chris Li Cc: Kairui Song Cc: Kemeng Shi Cc: Nhat Pham Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- Documentation/filesystems/fscrypt.rst | 4 ++++ mm/swapfile.c | 7 +++++++ 2 files changed, 11 insertions(+) --- a/Documentation/filesystems/fscrypt.rst +++ b/Documentation/filesystems/fscrypt.rst @@ -1238,6 +1238,10 @@ astute users may notice some differences - 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. + - 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 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3489,6 +3489,13 @@ SYSCALL_DEFINE2(swapon, const char __use error = -EBUSY; goto bad_swap_unlock_inode; } + if (IS_ENCRYPTED(inode)) { + pr_warn_once( + "Filesystem-level encrypted swapfile '%s' is unsupported. Create a loop device over it, or use dm-crypt\n", + name->name); + error = -EINVAL; + goto bad_swap_unlock_inode; + } /* * The swap subsystem needs a major overhaul to support this.