Does Landlock not work with eCryptfs?
Subsystems (3)
Hello!
I have a machine where the home directory is encrypted with eCryptfs, and it seems that Landlock is not working properly on eCryptfs files (but the same program works as expected on other mounts)?
## Problem description
Steps to reproduce:
* Create a directory "subdir" in the current directory
* Enable Landlock but ask for "subdir" to be readable
* os.ReadDir(dir)
Observed result:
* os.ReadDir function fails when trying to open the file (verified with strace)
Expected result:
* os.ReadDir should work, because we asked for it to work when enabling Landlock
## Reproduction code
I have uploaded a reproduction program in Go to Github, which should be understandable also if you are primarily a C user:
https://github.com/gnoack/llecryptfsrepro/blob/main/repro.go
To build and run the reproduction code, run:
git clone https://github.com/gnoack/llecryptfsrepro
cd llecryptfsrepro
go build
./llecryptfsrepro # executes the three steps as above, check source code
You can invoke this binary in different file system types to see the difference.
I have admittedly only checked it with a distribution kernel on Manjaro Linux: The Linux version is 6.2.2-1-MANJARO.
This looks like a bug to me?
Is this a known issue?
Thanks,
–Günther
Hi Günther,
Thanks for the report, I confirm there is indeed a bug. I tested with a Debian distro:
ecryptfs-setup-private --nopwcheck --noautomount ecryptfs-mount-private
# And then with the kernel's sample/landlock/sandboxer:
LL_FS_RO="/usr" LL_FS_RW="${HOME}/Private" sandboxer ls ~/Private
ls: cannot open directory '/home/user/Private': Permission denied
Actions other than listing a directory (e.g. creating files/directories, reading/writing to files) are controlled as expected. The issue might be that directories' inodes are not the same when listing the content of a directory or when creating new files/directories (which is weird). My hypothesis is that Landlock would then deny directory reading because the directory's inode doesn't match any rule. It might be related to the overlay nature of ecryptfs.
Tyler, do you have some idea?
FYI, I sent a patch fixing hostfs's inode management: https://lore.kernel.org/all/[email protected]/
Regards,
Mickaël
Quoted 49 lines · Günther Noack
Hello!
I have a machine where the home directory is encrypted with eCryptfs, and it seems that Landlock is not working properly on eCryptfs files (but the same program works as expected on other mounts)?
## Problem description
Steps to reproduce:
* Create a directory "subdir" in the current directory
* Enable Landlock but ask for "subdir" to be readable
*os.ReadDir(dir)Observed result:
* os.ReadDir function fails when trying to open the file (verified with strace)
Expected result:
* os.ReadDir should work, because we asked for it to work when enabling Landlock
## Reproduction code
I have uploaded a reproduction program in Go to Github, which should be understandable also if you are primarily a C user:
https://github.com/gnoack/llecryptfsrepro/blob/main/repro.goTo build and run the reproduction code, run:
git clone https://github.com/gnoack/llecryptfsrepro
cd llecryptfsrepro
go build
./llecryptfsrepro # executes the three steps as above, check source codeYou can invoke this binary in different file system types to see the difference.
I have admittedly only checked it with a distribution kernel on Manjaro Linux: The Linux version is 6.2.2-1-MANJARO.
This looks like a bug to me?
Is this a known issue?Thanks,
–Günther
Hello!
Quoted 19 lines · Mickaël Salaün
Hi Günther,
Thanks for the report, I confirm there is indeed a bug. I tested with a Debian distro:
ecryptfs-setup-private --nopwcheck --noautomount ecryptfs-mount-private
# And then with the kernel's sample/landlock/sandboxer:
LL_FS_RO="/usr" LL_FS_RW="${HOME}/Private" sandboxer ls ~/Private
ls: cannot open directory '/home/user/Private': Permission deniedActions other than listing a directory (e.g. creating files/directories, reading/writing to files) are controlled as expected. The issue might be that directories' inodes are not the same when listing the content of a directory or when creating new files/directories (which is weird). My hypothesis is that Landlock would then deny directory reading because the directory's inode doesn't match any rule. It might be related to the overlay nature of ecryptfs.
Quoted 1 line
Tyler, do you have some idea?
I had a hunch, and found out that the example can be made to work by granting the LANDLOCK_ACCESS_FS_READ_DIR right on the place where the *encrypted* version of that home directory lives:
err := landlock.V1.RestrictPaths(
landlock.RODirs(dir),
landlock.PathAccess(llsys.AccessFSReadDir, "/home/.ecryptfs/gnoack/.Private"),
)
It does seem a bit like eCryptfs it calling security_file_open() under the hood for the encrypted version of that file? Is that correct?
–Günther
Quoted 28 lines · Günther Noack
Hello!
Quoted 19 lines · Mickaël Salaün
Hi Günther,
Thanks for the report, I confirm there is indeed a bug. I tested with a Debian distro:
ecryptfs-setup-private --nopwcheck --noautomount ecryptfs-mount-private
# And then with the kernel's sample/landlock/sandboxer:
LL_FS_RO="/usr" LL_FS_RW="${HOME}/Private" sandboxer ls ~/Private
ls: cannot open directory '/home/user/Private': Permission deniedActions other than listing a directory (e.g. creating files/directories, reading/writing to files) are controlled as expected. The issue might be that directories' inodes are not the same when listing the content of a directory or when creating new files/directories (which is weird). My hypothesis is that Landlock would then deny directory reading because the directory's inode doesn't match any rule. It might be related to the overlay nature of ecryptfs.
Quoted 1 line
Tyler, do you have some idea?
I had a hunch, and found out that the example can be made to work by granting the
LANDLOCK_ACCESS_FS_READ_DIRright on the place where the *encrypted* version of that home directory lives:
Quoted 7 lines
err := landlock.V1.RestrictPaths( landlock.RODirs(dir), landlock.PathAccess(llsys.AccessFSReadDir, "/home/.ecryptfs/gnoack/.Private"), )It does seem a bit like eCryptfs it calling
security_file_open()under the hood for the encrypted version of that file? Is that correct?
Yes, that's right, the lower directory is used to list the content of the ecryptfs directory: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/ecryptfs/file.c#n112 iterate_dir(lower_file, …)
There is an inconsistency between ecryptfs_dir_open() and ecryptfs_open(). ecryptfs_dir_open() actually checks access right to the lower directory, which is why landlocked processes may not access the upper directory when reading its content. ecryptfs_open() uses a cache for upper files (which could be a problem on its own). The execution flow is:
ecryptfs_open() -> ecryptfs_get_lower_file() -> ecryptfs_init_lower_file() -> ecryptfs_privileged_open()
In ecryptfs_privileged_open(), the dentry_open() call failed if access to the lower file is not allowed by Landlock (or other access-control systems). Then wait_for_completion(&req.done) waits for a kernel's thread executing ecryptfs_threadfn(), which uses the kernel's credential to access the lower file.
I think there are two main solutions to fix this consistency issue:
- store the mounter credentials and uses them instead of the kernel's credentials for lower file and directory access checks (ecryptfs_dir_open and ecryptfs_threadfn changes);
- use the kernel's credentials for all lower file/dir access check, especially in ecryptfs_dir_open().
I think using the mounter credentials makes more sense, is much safer, and fits with overlayfs. It may not work in cases where the mounter doesn't have access to the lower file hierarchy though.
File creation calls vfs_*() helpers (lower directory) and there is not path nor file security hook calls for those, so it works unconditionally.
From Landlock end users point of view, it makes more sense to grants access to a file hierarchy (where access is already allowed) and be allowed to access this file hierarchy, whatever it belongs to a specific filesystem (and whatever the potential lower file hierarchy, which may be unknown to users). This is how it works for overlayfs and I'd like to have the same behavior for ecryptfs.
Quoted 42 lines · Mickaël Salaün
Quoted 28 lines · Günther Noack
Hello!
Quoted 19 lines · Mickaël Salaün
Hi Günther,
Thanks for the report, I confirm there is indeed a bug. I tested with a Debian distro:
ecryptfs-setup-private --nopwcheck --noautomount ecryptfs-mount-private
# And then with the kernel's sample/landlock/sandboxer:
LL_FS_RO="/usr" LL_FS_RW="${HOME}/Private" sandboxer ls ~/Private
ls: cannot open directory '/home/user/Private': Permission deniedActions other than listing a directory (e.g. creating files/directories, reading/writing to files) are controlled as expected. The issue might be that directories' inodes are not the same when listing the content of a directory or when creating new files/directories (which is weird). My hypothesis is that Landlock would then deny directory reading because the directory's inode doesn't match any rule. It might be related to the overlay nature of ecryptfs.
Quoted 1 line
Tyler, do you have some idea?
I had a hunch, and found out that the example can be made to work by granting the
LANDLOCK_ACCESS_FS_READ_DIRright on the place where the *encrypted* version of that home directory lives:Quoted 7 lines
err := landlock.V1.RestrictPaths( landlock.RODirs(dir), landlock.PathAccess(llsys.AccessFSReadDir, "/home/.ecryptfs/gnoack/.Private"), )It does seem a bit like eCryptfs it calling
security_file_open()under the hood for the encrypted version of that file? Is that correct?Yes, that's right, the lower directory is used to list the content of the ecryptfs directory:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/ecryptfs/file.c#n112iterate_dir(lower_file, …)
Christian Brauner
maintainerQuoted 29 lines · Mickaël Salaün
There is an inconsistency between
ecryptfs_dir_open()andecryptfs_open().ecryptfs_dir_open()actually checks access right to the lower directory, which is why landlocked processes may not access the upper directory when reading its content.ecryptfs_open()uses a cache for upper files (which could be a problem on its own). The execution flow is:
ecryptfs_open()->ecryptfs_get_lower_file()->ecryptfs_init_lower_file()->ecryptfs_privileged_open()In
ecryptfs_privileged_open(), thedentry_open()call failed if access to the lower file is not allowed by Landlock (or other access-control systems). Thenwait_for_completion(&req.done)waits for a kernel's thread executingecryptfs_threadfn(), which uses the kernel's credential to access the lower file.I think there are two main solutions to fix this consistency issue:
- store the mounter credentials and uses them instead of the kernel's credentials for lower file and directory access checks (ecryptfs_dir_openandecryptfs_threadfnchanges);
- use the kernel's credentials for all lower file/dir access check, especially inecryptfs_dir_open().I think using the mounter credentials makes more sense, is much safer, and fits with overlayfs. It may not work in cases where the mounter doesn't have access to the lower file hierarchy though.
File creation calls vfs_*() helpers (lower directory) and there is not path nor file security hook calls for those, so it works unconditionally.
Quoted 6 lines
From Landlock end users point of view, it makes more sense to grants access to a file hierarchy (where access is already allowed) and be allowed to access this file hierarchy, whatever it belongs to a specific filesystem (and whatever the potential lower file hierarchy, which may be unknown to users). This is how it works for overlayfs and I'd like to have the same behavior for ecryptfs.
So given that ecryptfs is marked as "Odd Fixes" who is realistically going to do the work of switching it to a mounter's credentials model, making sure this doesn't regress anything, and dealing with any potential bugs caused by this. It might be potentially better to just refuse to combine Landlock with ecryptfs if that's possible.
Quoted 37 lines · Christian Brauner
Quoted 29 lines · Mickaël Salaün
There is an inconsistency between
ecryptfs_dir_open()andecryptfs_open().ecryptfs_dir_open()actually checks access right to the lower directory, which is why landlocked processes may not access the upper directory when reading its content.ecryptfs_open()uses a cache for upper files (which could be a problem on its own). The execution flow is:
ecryptfs_open()->ecryptfs_get_lower_file()->ecryptfs_init_lower_file()->ecryptfs_privileged_open()In
ecryptfs_privileged_open(), thedentry_open()call failed if access to the lower file is not allowed by Landlock (or other access-control systems). Thenwait_for_completion(&req.done)waits for a kernel's thread executingecryptfs_threadfn(), which uses the kernel's credential to access the lower file.I think there are two main solutions to fix this consistency issue:
- store the mounter credentials and uses them instead of the kernel's credentials for lower file and directory access checks (ecryptfs_dir_openandecryptfs_threadfnchanges);
- use the kernel's credentials for all lower file/dir access check, especially inecryptfs_dir_open().I think using the mounter credentials makes more sense, is much safer, and fits with overlayfs. It may not work in cases where the mounter doesn't have access to the lower file hierarchy though.
File creation calls vfs_*() helpers (lower directory) and there is not path nor file security hook calls for those, so it works unconditionally.
Quoted 6 lines
From Landlock end users point of view, it makes more sense to grants access
to a file hierarchy (where access is already allowed) and be allowed to access this file hierarchy, whatever it belongs to a specific filesystem (and whatever the potential lower file hierarchy, which may be unknown to users). This is how it works for overlayfs and I'd like to have the same behavior for ecryptfs.
Quoted 5 lines
So given that ecryptfs is marked as "Odd Fixes" who is realistically going to do the work of switching it to a mounter's credentials model, making sure this doesn't regress anything, and dealing with any potential bugs caused by this. It might be potentially better to just refuse to combine Landlock with ecryptfs if that's possible.
If Tyler is OK with the proposed solutions, I'll get a closer look at it in a few months. If anyone is interested to work on that, I'd be happy to review and test (the Landlock part).
+ecryptfs mailing list FYI
Just some additional data points on the Landlock/eCryptfs issues.
Quoted 38 lines · Mickaël Salaün
Quoted 37 lines · Christian Brauner
Quoted 35 lines · Mickaël Salaün
There is an inconsistency between
ecryptfs_dir_open()andecryptfs_open().ecryptfs_dir_open()actually checks access right to the lower directory, which is why landlocked processes may not access the upper directory when reading its content.ecryptfs_open()uses a cache for upper files (which could be a problem on its own). The execution flow is:
ecryptfs_open()->ecryptfs_get_lower_file()->ecryptfs_init_lower_file()->ecryptfs_privileged_open()In
ecryptfs_privileged_open(), thedentry_open()call failed if access to the lower file is not allowed by Landlock (or other access-control systems). Thenwait_for_completion(&req.done)waits for a kernel's thread executingecryptfs_threadfn(), which uses the kernel's credential to access the lower file.I think there are two main solutions to fix this consistency issue:
- store the mounter credentials and uses them instead of the kernel's credentials for lower file and directory access checks (ecryptfs_dir_openandecryptfs_threadfnchanges);
- use the kernel's credentials for all lower file/dir access check, especially inecryptfs_dir_open().I think using the mounter credentials makes more sense, is much safer, and fits with overlayfs. It may not work in cases where the mounter doesn't have access to the lower file hierarchy though.
File creation calls vfs_*() helpers (lower directory) and there is not path nor file security hook calls for those, so it works unconditionally.
From Landlock end users point of view, it makes more sense to grants access
to a file hierarchy (where access is already allowed) and be allowed to access this file hierarchy, whatever it belongs to a specific filesystem (and whatever the potential lower file hierarchy, which may be unknown to users). This is how it works for overlayfs and I'd like to have the same behavior for ecryptfs.
Quoted 5 lines
Quoted 5 lines
So given that ecryptfs is marked as "Odd Fixes" who is realistically going to do the work of switching it to a mounter's credentials model, making sure this doesn't regress anything, and dealing with any potential bugs caused by this. It might be potentially better to just refuse to combine Landlock with ecryptfs if that's possible.
There is now a patch to mark it orphaned (independent of this thread):
https://lore.kernel.org/all/[email protected]/
Quoted 3 lines
If Tyler is OK with the proposed solutions, I'll get a closer look at it in a few months. If anyone is interested to work on that, I'd be happy to review and test (the Landlock part).
I wonder whether this problem of calling security hooks for the underlying directory might have been affecting AppArmor and SELinux as well? There seem to be reports on the web, but it's possible that I am misinterpreting some of them:
https://wiki.ubuntu.com/SecurityTeam/Roadmap
mentions this "unscheduled wishlist item":
"eCryptfs + SELinux/AppArmor integration, to protect encrypted data from root"
https://askubuntu.com/a/1195430
reports that AppArmor does not work on an eCryptfs mount for their use case "i tried adding the [eCryptfs] source folder as an alias in apparmor and it now works."
—Günther
Tyler Hicks (Microsoft)
maintainerQuoted 43 lines · Günther Noack
+ecryptfs mailing list FYI
Just some additional data points on the Landlock/eCryptfs issues.
Quoted 38 lines · Mickaël Salaün
Quoted 37 lines · Christian Brauner
Quoted 35 lines · Mickaël Salaün
There is an inconsistency between
ecryptfs_dir_open()andecryptfs_open().ecryptfs_dir_open()actually checks access right to the lower directory, which is why landlocked processes may not access the upper directory when reading its content.ecryptfs_open()uses a cache for upper files (which could be a problem on its own). The execution flow is:
ecryptfs_open()->ecryptfs_get_lower_file()->ecryptfs_init_lower_file()->ecryptfs_privileged_open()In
ecryptfs_privileged_open(), thedentry_open()call failed if access to the lower file is not allowed by Landlock (or other access-control systems). Thenwait_for_completion(&req.done)waits for a kernel's thread executingecryptfs_threadfn(), which uses the kernel's credential to access the lower file.I think there are two main solutions to fix this consistency issue:
- store the mounter credentials and uses them instead of the kernel's credentials for lower file and directory access checks (ecryptfs_dir_openandecryptfs_threadfnchanges);
- use the kernel's credentials for all lower file/dir access check, especially inecryptfs_dir_open().I think using the mounter credentials makes more sense, is much safer, and fits with overlayfs. It may not work in cases where the mounter doesn't have access to the lower file hierarchy though.
File creation calls vfs_*() helpers (lower directory) and there is not path nor file security hook calls for those, so it works unconditionally.
From Landlock end users point of view, it makes more sense to grants access
to a file hierarchy (where access is already allowed) and be allowed to access this file hierarchy, whatever it belongs to a specific filesystem (and whatever the potential lower file hierarchy, which may be unknown to users). This is how it works for overlayfs and I'd like to have the same behavior for ecryptfs.
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
So given that ecryptfs is marked as "Odd Fixes" who is realistically going to do the work of switching it to a mounter's credentials model, making sure this doesn't regress anything, and dealing with any potential bugs caused by this. It might be potentially better to just refuse to combine Landlock with ecryptfs if that's possible.
There is now a patch to mark it orphaned (independent of this thread):
https://lore.kernel.org/all/[email protected]/
I have little time to devote to eCryptfs these days. I'm not sure it needs to be fully orphaned but I think deprecation and marking for removal is the responsible thing to do.
Quoted 8 lines
Quoted 3 lines
If Tyler is OK with the proposed solutions, I'll get a closer look at it in a few months. If anyone is interested to work on that, I'd be happy to review and test (the Landlock part).
I wonder whether this problem of calling security hooks for the underlying directory might have been affecting AppArmor and SELinux as well? There seem to be reports on the web, but it's possible that I am misinterpreting some of them:
Yes, this eCryptfs design problem is common for other LSMs, as well.
Tyler
Quoted 12 lines
https://wiki.ubuntu.com/SecurityTeam/Roadmap
mentions this "unscheduled wishlist item":
"eCryptfs + SELinux/AppArmor integration, to protect encrypted data from root"https://askubuntu.com/a/1195430
reports that AppArmor does not work on an eCryptfs mount for their use case "i tried adding the [eCryptfs] source folder as an alias in apparmor and it now works."—Günther
Tyler Hicks
maintainerQuoted 45 lines · Mickaël Salaün
Quoted 37 lines · Christian Brauner
Quoted 29 lines · Mickaël Salaün
There is an inconsistency between
ecryptfs_dir_open()andecryptfs_open().ecryptfs_dir_open()actually checks access right to the lower directory, which is why landlocked processes may not access the upper directory when reading its content.ecryptfs_open()uses a cache for upper files (which could be a problem on its own). The execution flow is:
ecryptfs_open()->ecryptfs_get_lower_file()->ecryptfs_init_lower_file()->ecryptfs_privileged_open()In
ecryptfs_privileged_open(), thedentry_open()call failed if access to the lower file is not allowed by Landlock (or other access-control systems). Thenwait_for_completion(&req.done)waits for a kernel's thread executingecryptfs_threadfn(), which uses the kernel's credential to access the lower file.I think there are two main solutions to fix this consistency issue:
- store the mounter credentials and uses them instead of the kernel's credentials for lower file and directory access checks (ecryptfs_dir_openandecryptfs_threadfnchanges);
- use the kernel's credentials for all lower file/dir access check, especially inecryptfs_dir_open().I think using the mounter credentials makes more sense, is much safer, and fits with overlayfs. It may not work in cases where the mounter doesn't have access to the lower file hierarchy though.
File creation calls vfs_*() helpers (lower directory) and there is not path nor file security hook calls for those, so it works unconditionally.
Quoted 6 lines
From Landlock end users point of view, it makes more sense to grants access
to a file hierarchy (where access is already allowed) and be allowed to access this file hierarchy, whatever it belongs to a specific filesystem (and whatever the potential lower file hierarchy, which may be unknown to users). This is how it works for overlayfs and I'd like to have the same behavior for ecryptfs.Quoted 5 lines
So given that ecryptfs is marked as "Odd Fixes" who is realistically going to do the work of switching it to a mounter's credentials model, making sure this doesn't regress anything, and dealing with any potential bugs caused by this. It might be potentially better to just refuse to combine Landlock with ecryptfs if that's possible.
Quoted 3 lines
If Tyler is OK with the proposed solutions, I'll get a closer look at it in a few months. If anyone is interested to work on that, I'd be happy to review and test (the Landlock part).
I am alright with using the mounter creds but eCryptfs is typically mounted as root using a PAM module so the mounter is typically going to be more privileged than the user accessing the eCryptfs mount (in the common case of an encrypted home directory).
But, as Christian points out, I think it might be better to make Landlock refuse to work with eCryptfs. Would you be at ease with that decision if we marked eCryptfs as deprecated with a planned removal date?
Tyler
Quoted 55 lines · Tyler Hicks
Quoted 45 lines · Mickaël Salaün
Quoted 37 lines · Christian Brauner
Quoted 29 lines · Mickaël Salaün
There is an inconsistency between
ecryptfs_dir_open()andecryptfs_open().ecryptfs_dir_open()actually checks access right to the lower directory, which is why landlocked processes may not access the upper directory when reading its content.ecryptfs_open()uses a cache for upper files (which could be a problem on its own). The execution flow is:
ecryptfs_open()->ecryptfs_get_lower_file()->ecryptfs_init_lower_file()->ecryptfs_privileged_open()In
ecryptfs_privileged_open(), thedentry_open()call failed if access to the lower file is not allowed by Landlock (or other access-control systems). Thenwait_for_completion(&req.done)waits for a kernel's thread executingecryptfs_threadfn(), which uses the kernel's credential to access the lower file.I think there are two main solutions to fix this consistency issue:
- store the mounter credentials and uses them instead of the kernel's credentials for lower file and directory access checks (ecryptfs_dir_openandecryptfs_threadfnchanges);
- use the kernel's credentials for all lower file/dir access check, especially inecryptfs_dir_open().I think using the mounter credentials makes more sense, is much safer, and fits with overlayfs. It may not work in cases where the mounter doesn't have access to the lower file hierarchy though.
File creation calls vfs_*() helpers (lower directory) and there is not path nor file security hook calls for those, so it works unconditionally.
Quoted 6 lines
From Landlock end users point of view, it makes more sense to grants access
to a file hierarchy (where access is already allowed) and be allowed to access this file hierarchy, whatever it belongs to a specific filesystem (and whatever the potential lower file hierarchy, which may be unknown to users). This is how it works for overlayfs and I'd like to have the same behavior for ecryptfs.Quoted 5 lines
So given that ecryptfs is marked as "Odd Fixes" who is realistically going to do the work of switching it to a mounter's credentials model, making sure this doesn't regress anything, and dealing with any potential bugs caused by this. It might be potentially better to just refuse to combine Landlock with ecryptfs if that's possible.
Quoted 3 lines
If Tyler is OK with the proposed solutions, I'll get a closer look at it in a few months. If anyone is interested to work on that, I'd be happy to review and test (the Landlock part).
I am alright with using the mounter creds but eCryptfs is typically mounted as root using a PAM module so the mounter is typically going to be more privileged than the user accessing the eCryptfs mount (in the common case of an encrypted home directory).
Quoted 4 lines
But, as Christian points out, I think it might be better to make Landlock refuse to work with eCryptfs. Would you be at ease with that decision if we marked eCryptfs as deprecated with a planned removal date?
The only way to make Landlock "refuse" to work with eCryptfs would be to add exceptions according to the underlying filesystem when creating rules. Furthermore, to be consistent, this would need to be backported. I don't want to go in such direction to fix an eCryptfs issue.
Doing nothing would go against the principle of least astonishment because of unexpected and inconsistent behavior when using Landlock with eCryptfs. Indeed, Landlock users (e.g. app developers) may not know how, where, and on which kernel their sandboxed applications will run. This means that at best, developers will (potentially wrongly) check if eCryptfs is available/used and then disable sandboxing, and at worse the (opportunistically) sandboxed apps will break (because of denied access). In any case, it goes against user's interests.
Even if eCryptfs is marked as deprecated, it will be available for years (a lot for LTS) and (legitimate) bug reports will keep coming.
Instead, I'd like to fix the eCryptfs inconsistent behavior (highlighted by Landlock and other LSMs). I think it's worth trying the first proposed solution, which might not be too difficult to implement, and will get eCryptfs closer to the overlayfs semantic.
Hello!
Quoted 16 lines · Mickaël Salaün
Quoted 10 lines · Tyler Hicks
Quoted 3 lines · Mickaël Salaün
If Tyler is OK with the proposed solutions, I'll get a closer look at it in a few months. If anyone is interested to work on that, I'd be happy to review and test (the Landlock part).
I am alright with using the mounter creds but eCryptfs is typically mounted as root using a PAM module so the mounter is typically going to be more privileged than the user accessing the eCryptfs mount (in the common case of an encrypted home directory).
Quoted 4 lines
But, as Christian points out, I think it might be better to make Landlock refuse to work with eCryptfs. Would you be at ease with that decision if we marked eCryptfs as deprecated with a planned removal date?
Quoted 4 lines
The only way to make Landlock "refuse" to work with eCryptfs would be to add exceptions according to the underlying filesystem when creating rules. Furthermore, to be consistent, this would need to be backported. I don't want to go in such direction to fix an eCryptfs issue.
Here is an example where the Landlock LSM can't detect eCryptfs:
mkdir -p /foo/bar/baz /foo/secret landlock-restrict -ro / -rw /foo/bar -- /bin/bash
# finally, in a different terminal:
mount.ecryptfs /foo/secret /foo/bar/baz
The shell is supposed to have access to /foo/bar and everything below it, but at the time of creating the Landlock ruleset, it can't tell yet that this directory will contain an eCryptfs mount later.
Admittedly, the example is obscure, but it's strictly speaking supposed to work according to the Landlock documentation. (Only the landlocked process can't use mount(2) any more, but other processes still can.)
Note on the side: Even when mount.ecryptfs happens before the Landlock restriction, the Landlock LSM would have to traverse the existing mounts to see if there is an eCryptfs mount *below* /foo/bar.
Quoted 8 lines
Doing nothing would go against the principle of least astonishment because of unexpected and inconsistent behavior when using Landlock with eCryptfs. Indeed, Landlock users (e.g. app developers) may not know how, where, and on which kernel their sandboxed applications will run. This means that at best, developers will (potentially wrongly) check if eCryptfs is available/used and then disable sandboxing, and at worse the (opportunistically) sandboxed apps will break (because of denied access). In any case, it goes against user's interests.
I agree, I also believe that a kernel-side fix is needed.
I don't think this is feasible to do in a good way in userspace, even if we want to resort to "falling back to doing nothing" in best effort mode if eCryptfs file hierarchies are affected.
I have pondered these userspace approaches how to detect eCryptfs, but they are both lacking:
* Looking for eCryptfs in /proc/mounts might not work if we are layering multiple Landlock rulesets.
* stat(2) also does not give away whether a file is on eCryptfs (the device number is just a generic kernel internal one)
Finally, it all falls apart anyway if we want to support the case where eCryptfs is mounted after enabling the sandbox. (Obscure, but possible.)
Quoted 7 lines
Even if eCryptfs is marked as deprecated, it will be available for years (a lot for LTS) and (legitimate) bug reports will keep coming.
Instead, I'd like to fix the eCryptfs inconsistent behavior (highlighted by Landlock and other LSMs). I think it's worth trying the first proposed solution, which might not be too difficult to implement, and will get eCryptfs closer to the overlayfs semantic.
+1. As you also said: I think it's important to fix it in the LTS releases, so that we can tell people to use Landlock without having to think about these corner cases.
–Günther