2023-08-08 17:08:34

by Christian Brauner

[permalink] [raw]
Subject: Re: [PATCH v9] vfs, security: Fix automount superblock LSM init problem, preventing NFS sb sharing

On Tue, Aug 08, 2023 at 07:34:20AM -0400, Jeff Layton wrote:
> From: David Howells <[email protected]>
>
> When NFS superblocks are created by automounting, their LSM parameters
> aren't set in the fs_context struct prior to sget_fc() being called,
> leading to failure to match existing superblocks.
>
> This bug leads to messages like the following appearing in dmesg when
> fscache is enabled:
>
> NFS: Cache volume key already in use (nfs,4.2,2,108,106a8c0,1,,,,100000,100000,2ee,3a98,1d4c,3a98,1)
>
> Fix this by adding a new LSM hook to load fc->security for submount
> creation.
>
> Signed-off-by: David Howells <[email protected]>
> Signed-off-by: Jeff Layton <[email protected]>
> Fixes: 9bc61ab18b1d ("vfs: Introduce fs_context, switch vfs_kern_mount() to it.")
> Fixes: 779df6a5480f ("NFS: Ensure security label is set for root inode)
> Tested-by: Jeff Layton <[email protected]>
> Reviewed-by: Jeff Layton <[email protected]>
> Acked-by: Casey Schaufler <[email protected]>
> Acked-by: "Christian Brauner (Microsoft)" <[email protected]>
> Link: https://lore.kernel.org/r/165962680944.3334508.6610023900349142034.stgit@warthog.procyon.org.uk/ # v1
> Link: https://lore.kernel.org/r/165962729225.3357250.14350728846471527137.stgit@warthog.procyon.org.uk/ # v2
> Link: https://lore.kernel.org/r/165970659095.2812394.6868894171102318796.stgit@warthog.procyon.org.uk/ # v3
> Link: https://lore.kernel.org/r/166133579016.3678898.6283195019480567275.stgit@warthog.procyon.org.uk/ # v4
> Link: https://lore.kernel.org/r/[email protected]/ # v5
> ---
> ver #2)
> - Added Smack support
> - Made LSM parameter extraction dependent on reference != NULL.
>
> ver #3)
> - Made LSM parameter extraction dependent on fc->purpose ==
> FS_CONTEXT_FOR_SUBMOUNT. Shouldn't happen on FOR_RECONFIGURE.
>
> ver #4)
> - When doing a FOR_SUBMOUNT mount, don't set the root label in SELinux or Smack.
>
> ver #5)
> - Removed unused variable.
> - Only allocate smack_mnt_opts if we're dealing with a submount.
>
> ver #6)
> - Rebase onto v6.5.0-rc4
> - Link to v6: https://lore.kernel.org/r/[email protected]
>
> ver #7)
> - Drop lsm_set boolean
> - Link to v7: https://lore.kernel.org/r/[email protected]
>
> ver #8)
> - Remove spurious semicolon in smack_fs_context_init
> - Make fs_context_init take a superblock as reference instead of dentry
> - WARN_ON_ONCE's when fc->purpose != FS_CONTEXT_FOR_SUBMOUNT
> - Call the security hook from fs_context_for_submount instead of alloc_fs_context
> - Link to v8: https://lore.kernel.org/r/[email protected]
>
> ver #9)
> - rename *_fs_context_init to *_fs_context_submount
> - remove checks for FS_CONTEXT_FOR_SUBMOUNT and NULL reference pointers
> - fix prototype on smack_fs_context_submount

Thanks, this looks good from my perspective. If it looks fine to LSM
folks as well I can put it with the rest of the super work for this
cycle or it can go through the LSM tree.


2023-08-10 14:25:15

by Jeffrey Layton

[permalink] [raw]
Subject: Re: [PATCH v9] vfs, security: Fix automount superblock LSM init problem, preventing NFS sb sharing

On Tue, 2023-08-08 at 15:31 +0200, Christian Brauner wrote:
> On Tue, Aug 08, 2023 at 07:34:20AM -0400, Jeff Layton wrote:
> > From: David Howells <[email protected]>
> >
> > When NFS superblocks are created by automounting, their LSM parameters
> > aren't set in the fs_context struct prior to sget_fc() being called,
> > leading to failure to match existing superblocks.
> >
> > This bug leads to messages like the following appearing in dmesg when
> > fscache is enabled:
> >
> > NFS: Cache volume key already in use (nfs,4.2,2,108,106a8c0,1,,,,100000,100000,2ee,3a98,1d4c,3a98,1)
> >
> > Fix this by adding a new LSM hook to load fc->security for submount
> > creation.
> >
> > Signed-off-by: David Howells <[email protected]>
> > Signed-off-by: Jeff Layton <[email protected]>
> > Fixes: 9bc61ab18b1d ("vfs: Introduce fs_context, switch vfs_kern_mount() to it.")
> > Fixes: 779df6a5480f ("NFS: Ensure security label is set for root inode)
> > Tested-by: Jeff Layton <[email protected]>
> > Reviewed-by: Jeff Layton <[email protected]>
> > Acked-by: Casey Schaufler <[email protected]>

I've made a significant number of changes since Casey acked this. It
might be a good idea to drop his Acked-by (unless he wants to chime in
and ask us to keep it).

Thanks,
Jeff

> > Acked-by: "Christian Brauner (Microsoft)" <[email protected]>
> > Link: https://lore.kernel.org/r/165962680944.3334508.6610023900349142034.stgit@warthog.procyon.org.uk/ # v1
> > Link: https://lore.kernel.org/r/165962729225.3357250.14350728846471527137.stgit@warthog.procyon.org.uk/ # v2
> > Link: https://lore.kernel.org/r/165970659095.2812394.6868894171102318796.stgit@warthog.procyon.org.uk/ # v3
> > Link: https://lore.kernel.org/r/166133579016.3678898.6283195019480567275.stgit@warthog.procyon.org.uk/ # v4
> > Link: https://lore.kernel.org/r/[email protected]/ # v5
> > ---
> > ver #2)
> > - Added Smack support
> > - Made LSM parameter extraction dependent on reference != NULL.
> >
> > ver #3)
> > - Made LSM parameter extraction dependent on fc->purpose ==
> > FS_CONTEXT_FOR_SUBMOUNT. Shouldn't happen on FOR_RECONFIGURE.
> >
> > ver #4)
> > - When doing a FOR_SUBMOUNT mount, don't set the root label in SELinux or Smack.
> >
> > ver #5)
> > - Removed unused variable.
> > - Only allocate smack_mnt_opts if we're dealing with a submount.
> >
> > ver #6)
> > - Rebase onto v6.5.0-rc4
> > - Link to v6: https://lore.kernel.org/r/[email protected]
> >
> > ver #7)
> > - Drop lsm_set boolean
> > - Link to v7: https://lore.kernel.org/r/[email protected]
> >
> > ver #8)
> > - Remove spurious semicolon in smack_fs_context_init
> > - Make fs_context_init take a superblock as reference instead of dentry
> > - WARN_ON_ONCE's when fc->purpose != FS_CONTEXT_FOR_SUBMOUNT
> > - Call the security hook from fs_context_for_submount instead of alloc_fs_context
> > - Link to v8: https://lore.kernel.org/r/[email protected]
> >
> > ver #9)
> > - rename *_fs_context_init to *_fs_context_submount
> > - remove checks for FS_CONTEXT_FOR_SUBMOUNT and NULL reference pointers
> > - fix prototype on smack_fs_context_submount
>
> Thanks, this looks good from my perspective. If it looks fine to LSM
> folks as well I can put it with the rest of the super work for this
> cycle or it can go through the LSM tree.

--
Jeff Layton <[email protected]>

2023-08-10 15:37:14

by Casey Schaufler

[permalink] [raw]
Subject: Re: [PATCH v9] vfs, security: Fix automount superblock LSM init problem, preventing NFS sb sharing

On 8/10/2023 6:57 AM, Jeff Layton wrote:
> On Tue, 2023-08-08 at 15:31 +0200, Christian Brauner wrote:
>> On Tue, Aug 08, 2023 at 07:34:20AM -0400, Jeff Layton wrote:
>>> From: David Howells <[email protected]>
>>>
>>> When NFS superblocks are created by automounting, their LSM parameters
>>> aren't set in the fs_context struct prior to sget_fc() being called,
>>> leading to failure to match existing superblocks.
>>>
>>> This bug leads to messages like the following appearing in dmesg when
>>> fscache is enabled:
>>>
>>> NFS: Cache volume key already in use (nfs,4.2,2,108,106a8c0,1,,,,100000,100000,2ee,3a98,1d4c,3a98,1)
>>>
>>> Fix this by adding a new LSM hook to load fc->security for submount
>>> creation.
>>>
>>> Signed-off-by: David Howells <[email protected]>
>>> Signed-off-by: Jeff Layton <[email protected]>
>>> Fixes: 9bc61ab18b1d ("vfs: Introduce fs_context, switch vfs_kern_mount() to it.")
>>> Fixes: 779df6a5480f ("NFS: Ensure security label is set for root inode)
>>> Tested-by: Jeff Layton <[email protected]>
>>> Reviewed-by: Jeff Layton <[email protected]>
>>> Acked-by: Casey Schaufler <[email protected]>
> I've made a significant number of changes since Casey acked this. It
> might be a good idea to drop his Acked-by (unless he wants to chime in
> and ask us to keep it).

You can keep the Acked-by.

>
> Thanks,
> Jeff
>
>>> Acked-by: "Christian Brauner (Microsoft)" <[email protected]>
>>> Link: https://lore.kernel.org/r/165962680944.3334508.6610023900349142034.stgit@warthog.procyon.org.uk/ # v1
>>> Link: https://lore.kernel.org/r/165962729225.3357250.14350728846471527137.stgit@warthog.procyon.org.uk/ # v2
>>> Link: https://lore.kernel.org/r/165970659095.2812394.6868894171102318796.stgit@warthog.procyon.org.uk/ # v3
>>> Link: https://lore.kernel.org/r/166133579016.3678898.6283195019480567275.stgit@warthog.procyon.org.uk/ # v4
>>> Link: https://lore.kernel.org/r/[email protected]/ # v5
>>> ---
>>> ver #2)
>>> - Added Smack support
>>> - Made LSM parameter extraction dependent on reference != NULL.
>>>
>>> ver #3)
>>> - Made LSM parameter extraction dependent on fc->purpose ==
>>> FS_CONTEXT_FOR_SUBMOUNT. Shouldn't happen on FOR_RECONFIGURE.
>>>
>>> ver #4)
>>> - When doing a FOR_SUBMOUNT mount, don't set the root label in SELinux or Smack.
>>>
>>> ver #5)
>>> - Removed unused variable.
>>> - Only allocate smack_mnt_opts if we're dealing with a submount.
>>>
>>> ver #6)
>>> - Rebase onto v6.5.0-rc4
>>> - Link to v6: https://lore.kernel.org/r/[email protected]
>>>
>>> ver #7)
>>> - Drop lsm_set boolean
>>> - Link to v7: https://lore.kernel.org/r/[email protected]
>>>
>>> ver #8)
>>> - Remove spurious semicolon in smack_fs_context_init
>>> - Make fs_context_init take a superblock as reference instead of dentry
>>> - WARN_ON_ONCE's when fc->purpose != FS_CONTEXT_FOR_SUBMOUNT
>>> - Call the security hook from fs_context_for_submount instead of alloc_fs_context
>>> - Link to v8: https://lore.kernel.org/r/[email protected]
>>>
>>> ver #9)
>>> - rename *_fs_context_init to *_fs_context_submount
>>> - remove checks for FS_CONTEXT_FOR_SUBMOUNT and NULL reference pointers
>>> - fix prototype on smack_fs_context_submount
>> Thanks, this looks good from my perspective. If it looks fine to LSM
>> folks as well I can put it with the rest of the super work for this
>> cycle or it can go through the LSM tree.