mm/swap: reject swapon() on filesystem-level encrypted files
Subsystems (5)
Eric Biggers
maintainerPATCH v2 1/1 mm/swap: reject swapon() on filesystem-level encrypted files
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.
---
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(+)
Documentation/filesystems/fscrypt.rst +4 -0
@@ -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
mm/swapfile.c +7 -0
@@ -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
Signature · 1 line
2.55.0
Quoted 7 lines · Eric Biggers
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).
Quoted 8 lines
Nevertheless, to prevent user error, make
swapon()explicitly reject this case. Document this behavior infscrypt.rstas well.Fixes 9bd8212f981e ("ext4 crypto: add encryption policy and password salt support")Fixes f424f664f0e8 ("f2fs crypto: add encryption policy and password salt support")Reviewed-by Baoquan He <[email protected]>Signed-off-by Eric Biggers <[email protected]>
In the past, I've certainly setup swap wrong. It'll help:
Quoted 46 lines
---
Changed in v2:
- Added apr_warn_once
- Removed unnecessary word fromfscrypt.rst
- Added Reviewed-byDocumentation/filesystems/fscrypt.rst | 4 ++++ mm/swapfile.c | 7 +++++++ 2 files changed, 11 insertions(+)Documentation/filesystems/fscrypt.rst +4
-0@@ -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 upmm/swapfile.c +7
-0@@ -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
Quoted 7 lines · Eric Biggers
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).
Quoted 8 lines
Nevertheless, to prevent user error, make
swapon()explicitly reject this case. Document this behavior infscrypt.rstas well.Fixes 9bd8212f981e ("ext4 crypto: add encryption policy and password salt support")Fixes f424f664f0e8 ("f2fs crypto: add encryption policy and password salt support")Reviewed-by Baoquan He <[email protected]>Signed-off-by Eric Biggers <[email protected]>
Looks good to me!
--D
Quoted 50 lines
---
Changed in v2:
- Added apr_warn_once
- Removed unnecessary word fromfscrypt.rst
- Added Reviewed-byDocumentation/filesystems/fscrypt.rst | 4 ++++ mm/swapfile.c | 7 +++++++ 2 files changed, 11 insertions(+)Documentation/filesystems/fscrypt.rst +4
-0@@ -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 upmm/swapfile.c +7
-0@@ -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:
f5098b6bae761e346ebcd9da7f95622c04733cffSignature · 1 line
2.55.0