diff mbox series

[dhowells/mount-api] fs: fix checking an error code of security_fs_context_parse_param

Message ID 20180906001051.24015-1-avagin@openvz.org
State New, archived
Headers show
Series [dhowells/mount-api] fs: fix checking an error code of security_fs_context_parse_param | expand

Commit Message

Andrey Vagin Sept. 6, 2018, 12:10 a.m. UTC
From: Andrei Vagin <avagin@gmail.com>

security_fs_context_parse_param() returns 0 if everything is okay.

Signed-off-by: Andrei Vagin <avagin@gmail.com>
---
 fs/fs_context.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

David Howells Sept. 6, 2018, 10:16 a.m. UTC | #1
Andrei Vagin <avagin@openvz.org> wrote:

> security_fs_context_parse_param() returns 0 if everything is okay.

Not quite.  It returns 0 to indicate that it processed the argument and that
the argument doesn't belong to the filesystem.  It returns -ENOPARAM to
indicate that the argument should be passed along to the filesystem.  Any
other error is an actual error.

>  	ret = security_fs_context_parse_param(fc, param);
> -	if (ret != -ENOPARAM)
> +	if (ret)

So this change is wrong.

The change that needs making is to the documentation - in particular
lsm_hooks.h.

David
David Howells Sept. 6, 2018, 10:18 a.m. UTC | #2
> The change that needs making is to the documentation - in particular
> lsm_hooks.h.

And also the default for security_fs_context_parse_param() needs changing to
-ENOPARAM.

David
Andrey Vagin Sept. 6, 2018, 11:08 p.m. UTC | #3
On Thu, Sep 06, 2018 at 11:16:24AM +0100, David Howells wrote:
> Andrei Vagin <avagin@openvz.org> wrote:
> 
> > security_fs_context_parse_param() returns 0 if everything is okay.
> 
> Not quite.  It returns 0 to indicate that it processed the argument and that
> the argument doesn't belong to the filesystem.  It returns -ENOPARAM to
> indicate that the argument should be passed along to the filesystem.  Any
> other error is an actual error.
> 
> >  	ret = security_fs_context_parse_param(fc, param);
> > -	if (ret != -ENOPARAM)
> > +	if (ret)
> 
> So this change is wrong.

It depends from what point to see on it. Without this patch, the
linux-next kernel doesn't boot:

VFS: Cannot open root device "vda2" or unknown-block(253,2): error -2
Please append a correct "root=" boot option; here are the available partitions:
fd00        25165824 vda 
 driver: virtio_blk
  fd01          512000 vda1 5065bd2c-01

  fd02        23601152 vda2 5065bd2c-02

  fd03         1044480 vda3 5065bd2c-03

Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(253,2)
CPU: 1 PID: 1 Comm: swapper/0 Not tainted 4.19.0-rc1-00106-g679a89690477 #38
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS ?-20180531_142017-buildhw-08.phx2.fedoraproject.org-1.fc28 04/01/2014
Call Trace:
 dump_stack+0x85/0xc0
 panic+0xec/0x251
 mount_block_root+0x23e/0x2e7
 ? do_early_param+0x8e/0x8e
 prepare_namespace+0x135/0x16b
 kernel_init_freeable+0x28b/0x2af
 ? rest_init+0xb9/0xb9
 kernel_init+0xa/0x10e
 ret_from_fork+0x3a/0x50
Kernel Offset: 0x10000000 from 0xffffffff81000000 (relocation range: 0xffffffff80000000-0xffffffffbfffffff)
---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(253,2) ]---

I agree that I haven't understood the idea of this code. I found that
security_fs_context_parse_param returns 0 by default and decided that this
patch would fix the problem. I have sent an update version of the patch.

Pls, take a look at it. And we need to push this patch to linux-next. We can't
run CRIU tests for linux-next without it.

Thanks,
Andrei

> 
> The change that needs making is to the documentation - in particular
> lsm_hooks.h.
> 
> David
Andrei Vagin Sept. 11, 2018, 5:12 a.m. UTC | #4
On Thu, Sep 06, 2018 at 11:18:52AM +0100, David Howells wrote:
> > The change that needs making is to the documentation - in particular
> > lsm_hooks.h.
> 
> And also the default for security_fs_context_parse_param() needs changing to
> -ENOPARAM.

apparmor_fs_context_parse_param() should be fixed too, it never returns
-ENOPARAM.

> 
> David
David Howells Sept. 11, 2018, 8:13 p.m. UTC | #5
Andrei Vagin <avagin@gmail.com> wrote:

> apparmor_fs_context_parse_param() should be fixed too, it never returns
> -ENOPARAM.

Fixed, thanks.

David
diff mbox series

Patch

diff --git a/fs/fs_context.c b/fs/fs_context.c
index a82679441031..16bf2cb57534 100644
--- a/fs/fs_context.c
+++ b/fs/fs_context.c
@@ -146,7 +146,7 @@  int vfs_parse_fs_param(struct fs_context *fc, struct fs_parameter *param)
 		return ret;
 
 	ret = security_fs_context_parse_param(fc, param);
-	if (ret != -ENOPARAM)
+	if (ret)
 		/* Param belongs to the LSM or is disallowed by the LSM; so
 		 * don't pass to the FS.
 		 */