From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4C8A927B340; Mon, 3 Aug 2026 18:41:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782507; cv=none; b=CJ0lAOEvsIvzkX5QRGhAzJ++83Z0CSzAPOhBgfQuVe/YgDKQsmBLDn2x+HTI6E7HIZ3utYUuDqEqBg+2A298oEEIjyC8YQ5uCt2Ld9T37AIFfQKCOXNh+b51qroUR0OI27KmIT0Pt9A6E7XILpgNnA5/o8ZbSZF5GmmJCg4w+Dw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785782507; c=relaxed/simple; bh=uiQBz3mOQUpgseZ4BF2zQ1KUX0+aXrmMQaRmZKtIEvg=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=PfqVEQxJq27dXR8Tk0GROlcGTO2Sm+MRV8frWfDPK9+INw8CmH+/RHMkvNxCrDJDmTcZI2fdSiMZh+zbS5Or3mL+8Wl0nP0bOuyHn7o6/jBJtn566SHz9LRCrHRMJXBUjcQT7AmveXlupG+cGnWYsWYlPdtlE1rav9ceSolOmTs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=K99Ctjpq; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="K99Ctjpq" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 31A3F143D; Mon, 3 Aug 2026 11:41:39 -0700 (PDT) Received: from [10.2.198.93] (e142334-100.cambridge.arm.com [10.2.198.93]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6860C3F86F; Mon, 3 Aug 2026 11:41:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1785782503; bh=uiQBz3mOQUpgseZ4BF2zQ1KUX0+aXrmMQaRmZKtIEvg=; h=Date:Cc:Subject:To:References:From:In-Reply-To:From; b=K99Ctjpq6y2hlz37u/iCbCYcWjnzA7RxwykGj/9EpUCw2VjHCOE67FIFoBWO9wTRV jV6Nl4jQzuxB7a1/P1/uoWW0JENbjsv4wt8f0lUV/84T3HhUqwHK1BNJTLlmE8bYVF s414pYK9IjtKApzagQxNFMgK7hZ43MgCPl2cGAfM= Message-ID: Date: Mon, 3 Aug 2026 19:41:39 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: usama.anjum@arm.com, 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 , Baoquan He , Barry Song , Youngjun Park , stable@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Chris Li , Kairui Song Subject: Re: [PATCH v2] mm/swap: reject swapon() on filesystem-level encrypted files To: Eric Biggers References: <20260803180426.3123-1-ebiggers@kernel.org> Content-Language: en-US From: Usama Anjum In-Reply-To: <20260803180426.3123-1-ebiggers@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 03/08/2026 7:04 pm, 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 > Reviewed-by: Baoquan He > Signed-off-by: Eric Biggers In the past, I've certainly setup swap wrong. It'll help: Reviewed-by: Muhammad Usama Anjum > --- > > Changed in v2: > - Added a pr_warn_once > - Removed unnecessary word from fscrypt.rst > - Added Reviewed-by > > Documentation/filesystems/fscrypt.rst | 4 ++++ > mm/swapfile.c | 7 +++++++ > 2 files changed, 11 insertions(+) > > diff --git a/Documentation/filesystems/fscrypt.rst b/Documentation/filesystems/fscrypt.rst > index c0dd35f1af12..e4882b73120e 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. > + > - 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..8538659acb9e 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c > @@ -3650,6 +3650,13 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) > 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. > > base-commit: f5098b6bae761e346ebcd9da7f95622c04733cff