Message ID | 20210409111254.271800-1-omosnace@redhat.com (mailing list archive) |
---|---|
Headers | show |
Series | vfs/security/NFS/btrfs: clean up and fix LSM option handling | expand |
On Fri, Apr 09, 2021 at 01:12:52PM +0200, Ondrej Mosnacek wrote: > This series attempts to clean up part of the mess that has grown around > the LSM mount option handling across different subsystems. I would not describe growing another FS_... flag *AND* spreading the FS_BINARY_MOUNTDATA further, with rather weird semantics at that, as a cleanup of any sort. I still very much dislike that approach.
On 4/9/2021 4:12 AM, Ondrej Mosnacek wrote: > This series attempts to clean up part of the mess that has grown around > the LSM mount option handling across different subsystems. > > The original motivation was to fix a NFS+SELinux bug that I found while > trying to get the NFS part of the selinux-testsuite [1] to work, which > is fixed by patch 2. > > The first patch paves the way for the second one by eliminating the > special case workaround in selinux_set_mnt_opts(), while also > simplifying BTRFS's LSM mount option handling. > > I tested the patches by running the NFS part of the SELinux testsuite > (which is now fully passing). I also added the pending patch for > broken BTRFS LSM options support with fsconfig(2) [2] and ran the > proposed BTRFS SELinux tests for selinux-testsuite [3] (still passing > with all patches). The Smack testsuite can be found at: https://github.com/smack-team/smack-testsuite.git It might provide another layer of confidence. > > [1] https://github.com/SELinuxProject/selinux-testsuite/ > [2] https://lore.kernel.org/selinux/20210401065403.GA1363493@infradead.org/T/ > [3] https://lore.kernel.org/selinux/20201103110121.53919-2-richard_c_haines@btinternet.com/ > ^^ the original patch no longer applies - a rebased version is here: > https://github.com/WOnder93/selinux-testsuite/commit/212e76b5bd0775c7507c1996bd172de3bcbff139.patch > > Ondrej Mosnacek (2): > vfs,LSM: introduce the FS_HANDLES_LSM_OPTS flag > selinux: fix SECURITY_LSM_NATIVE_LABELS flag handling on double mount > > fs/btrfs/super.c | 35 ++++++----------------------------- > fs/nfs/fs_context.c | 6 ++++-- > fs/super.c | 10 ++++++---- > include/linux/fs.h | 3 ++- > security/selinux/hooks.c | 32 +++++++++++++++++--------------- > 5 files changed, 35 insertions(+), 51 deletions(-) >
On Fri, Apr 9, 2021 at 2:28 PM Al Viro <viro@zeniv.linux.org.uk> wrote: > On Fri, Apr 09, 2021 at 01:12:52PM +0200, Ondrej Mosnacek wrote: > > This series attempts to clean up part of the mess that has grown around > > the LSM mount option handling across different subsystems. > > I would not describe growing another FS_... flag Why is that necessarily a bad thing? > *AND* spreading the > FS_BINARY_MOUNTDATA further, with rather weird semantics at that, > as a cleanup of any sort. How is this spreading it further? The patches remove one (rather bad) use of it in SELinux and somewhat reduce its use in btrfs. Hold on... actually I just realized that with FS_HANDLES_LSM_OPTS it is possible to do btrfs without FS_BINARY_MOUNTDATA and also eliminate the need for the workaround in vfs_parse_fs_param() (i.e. [2]). Basically instead of setting FS_BINARY_MOUNTDATA | FS_HANDLES_LSM_OPTS in btrfs_fs_type and neither in btrfs_root_fs_type, it is enough to set neither in btrfs_fs_type and only FS_HANDLES_LSM_OPTS in btrfs_root_fs_type. The security opts are then applied in the outer vfs_get_tree() call instead of the inner one, but the net effect is the same. That should pretty much do away with both the non-legit users of FS_BINARY_MOUNTDATA (selinux_set_mnt_opts() and btrfs). All the rest seem to be in line with the semantic. Would [something like] the above stand any chance of getting your approval? [2] https://lore.kernel.org/selinux/20210401065403.GA1363493@infradead.org/T/ -- Ondrej Mosnacek Software Engineer, Linux Security - SELinux kernel Red Hat, Inc.
On Fri, Apr 9, 2021 at 7:00 PM Casey Schaufler <casey@schaufler-ca.com> wrote: > On 4/9/2021 4:12 AM, Ondrej Mosnacek wrote: > > This series attempts to clean up part of the mess that has grown around > > the LSM mount option handling across different subsystems. > > > > The original motivation was to fix a NFS+SELinux bug that I found while > > trying to get the NFS part of the selinux-testsuite [1] to work, which > > is fixed by patch 2. > > > > The first patch paves the way for the second one by eliminating the > > special case workaround in selinux_set_mnt_opts(), while also > > simplifying BTRFS's LSM mount option handling. > > > > I tested the patches by running the NFS part of the SELinux testsuite > > (which is now fully passing). I also added the pending patch for > > broken BTRFS LSM options support with fsconfig(2) [2] and ran the > > proposed BTRFS SELinux tests for selinux-testsuite [3] (still passing > > with all patches). > > The Smack testsuite can be found at: > https://github.com/smack-team/smack-testsuite.git > > It might provide another layer of confidence. Thanks, but that doesn't seem to exercise mounting/remounting btrfs nor nfs with security options. Anything else should be unaffected. > > > > > [1] https://github.com/SELinuxProject/selinux-testsuite/ > > [2] https://lore.kernel.org/selinux/20210401065403.GA1363493@infradead.org/T/ > > [3] https://lore.kernel.org/selinux/20201103110121.53919-2-richard_c_haines@btinternet.com/ > > ^^ the original patch no longer applies - a rebased version is here: > > https://github.com/WOnder93/selinux-testsuite/commit/212e76b5bd0775c7507c1996bd172de3bcbff139.patch > > > > Ondrej Mosnacek (2): > > vfs,LSM: introduce the FS_HANDLES_LSM_OPTS flag > > selinux: fix SECURITY_LSM_NATIVE_LABELS flag handling on double mount > > > > fs/btrfs/super.c | 35 ++++++----------------------------- > > fs/nfs/fs_context.c | 6 ++++-- > > fs/super.c | 10 ++++++---- > > include/linux/fs.h | 3 ++- > > security/selinux/hooks.c | 32 +++++++++++++++++--------------- > > 5 files changed, 35 insertions(+), 51 deletions(-) > > >
On Fri, Apr 9, 2021 at 7:39 PM Ondrej Mosnacek <omosnace@redhat.com> wrote: > On Fri, Apr 9, 2021 at 2:28 PM Al Viro <viro@zeniv.linux.org.uk> wrote: > > On Fri, Apr 09, 2021 at 01:12:52PM +0200, Ondrej Mosnacek wrote: > > > This series attempts to clean up part of the mess that has grown around > > > the LSM mount option handling across different subsystems. > > > > I would not describe growing another FS_... flag > > Why is that necessarily a bad thing? > > > *AND* spreading the > > FS_BINARY_MOUNTDATA further, with rather weird semantics at that, > > as a cleanup of any sort. > > How is this spreading it further? The patches remove one (rather bad) > use of it in SELinux and somewhat reduce its use in btrfs. > > Hold on... actually I just realized that with FS_HANDLES_LSM_OPTS it > is possible to do btrfs without FS_BINARY_MOUNTDATA and also eliminate > the need for the workaround in vfs_parse_fs_param() (i.e. [2]). > > Basically instead of setting FS_BINARY_MOUNTDATA | FS_HANDLES_LSM_OPTS > in btrfs_fs_type and neither in btrfs_root_fs_type, it is enough to > set neither in btrfs_fs_type and only FS_HANDLES_LSM_OPTS in > btrfs_root_fs_type. The security opts are then applied in the outer > vfs_get_tree() call instead of the inner one, but the net effect is > the same. > > That should pretty much do away with both the non-legit users of > FS_BINARY_MOUNTDATA (selinux_set_mnt_opts() and btrfs). All the rest > seem to be in line with the semantic. > > Would [something like] the above stand any chance of getting your approval? So I posted this variant as v2 now: https://lore.kernel.org/selinux/20210517134201.29271-1-omosnace@redhat.com/T/ > > [2] https://lore.kernel.org/selinux/20210401065403.GA1363493@infradead.org/T/