linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] vfs: set fs_context::user_ns for reconfigure
       [not found] <0000000000007bc3a0058e460627@google.com>
@ 2019-08-22  5:16 ` Eric Biggers
  2019-08-31  3:12   ` Eric Biggers
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Biggers @ 2019-08-22  5:16 UTC (permalink / raw)
  To: Alexander Viro, linux-fsdevel
  Cc: syzkaller-bugs, syzbot+7d6a57304857423318a5, David Howells,
	Miklos Szeredi

From: Eric Biggers <ebiggers@google.com>

fs_context::user_ns is used by fuse_parse_param(), even during remount,
so it needs to be set to the existing value for reconfigure.

Reproducer:

	#include <fcntl.h>
	#include <sys/mount.h>

	int main()
	{
		char opts[128];
		int fd = open("/dev/fuse", O_RDWR);

		sprintf(opts, "fd=%d,rootmode=040000,user_id=0,group_id=0", fd);
		mkdir("mnt", 0777);
		mount("foo",  "mnt", "fuse.foo", 0, opts);
		mount("foo", "mnt", "fuse.foo", MS_REMOUNT, opts);
	}

Crash:
	BUG: kernel NULL pointer dereference, address: 0000000000000000
	#PF: supervisor read access in kernel mode
	#PF: error_code(0x0000) - not-present page
	PGD 0 P4D 0
	Oops: 0000 [#1] SMP
	CPU: 0 PID: 129 Comm: syz_make_kuid Not tainted 5.3.0-rc5-next-20190821 #3
	Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-20181126_142135-anatol 04/01/2014
	RIP: 0010:map_id_range_down+0xb/0xc0 kernel/user_namespace.c:291
	[...]
	Call Trace:
	 map_id_down kernel/user_namespace.c:312 [inline]
	 make_kuid+0xe/0x10 kernel/user_namespace.c:389
	 fuse_parse_param+0x116/0x210 fs/fuse/inode.c:523
	 vfs_parse_fs_param+0xdb/0x1b0 fs/fs_context.c:145
	 vfs_parse_fs_string+0x6a/0xa0 fs/fs_context.c:188
	 generic_parse_monolithic+0x85/0xc0 fs/fs_context.c:228
	 parse_monolithic_mount_data+0x1b/0x20 fs/fs_context.c:708
	 do_remount fs/namespace.c:2525 [inline]
	 do_mount+0x39a/0xa60 fs/namespace.c:3107
	 ksys_mount+0x7d/0xd0 fs/namespace.c:3325
	 __do_sys_mount fs/namespace.c:3339 [inline]
	 __se_sys_mount fs/namespace.c:3336 [inline]
	 __x64_sys_mount+0x20/0x30 fs/namespace.c:3336
	 do_syscall_64+0x4a/0x1a0 arch/x86/entry/common.c:290
	 entry_SYSCALL_64_after_hwframe+0x49/0xbe

Reported-by: syzbot+7d6a57304857423318a5@syzkaller.appspotmail.com
Fixes: 408cbe695350 ("vfs: Convert fuse to use the new mount API")
Cc: David Howells <dhowells@redhat.com>
Cc: Miklos Szeredi <miklos@szeredi.hu>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 fs/fs_context.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/fs/fs_context.c b/fs/fs_context.c
index cc61d305dc4b..44c4174b250a 100644
--- a/fs/fs_context.c
+++ b/fs/fs_context.c
@@ -279,10 +279,8 @@ static struct fs_context *alloc_fs_context(struct file_system_type *fs_type,
 		fc->user_ns = get_user_ns(reference->d_sb->s_user_ns);
 		break;
 	case FS_CONTEXT_FOR_RECONFIGURE:
-		/* We don't pin any namespaces as the superblock's
-		 * subscriptions cannot be changed at this point.
-		 */
 		atomic_inc(&reference->d_sb->s_active);
+		fc->user_ns = get_user_ns(reference->d_sb->s_user_ns);
 		fc->root = dget(reference);
 		break;
 	}
-- 
2.22.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] vfs: set fs_context::user_ns for reconfigure
  2019-08-22  5:16 ` [PATCH] vfs: set fs_context::user_ns for reconfigure Eric Biggers
@ 2019-08-31  3:12   ` Eric Biggers
  2019-09-06  2:59     ` Eric Biggers
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Biggers @ 2019-08-31  3:12 UTC (permalink / raw)
  To: Alexander Viro, linux-fsdevel
  Cc: syzkaller-bugs, syzbot+7d6a57304857423318a5, David Howells,
	Miklos Szeredi

On Wed, Aug 21, 2019 at 10:16:33PM -0700, Eric Biggers wrote:
> From: Eric Biggers <ebiggers@google.com>
> 
> fs_context::user_ns is used by fuse_parse_param(), even during remount,
> so it needs to be set to the existing value for reconfigure.
> 
> Reproducer:
> 
> 	#include <fcntl.h>
> 	#include <sys/mount.h>
> 
> 	int main()
> 	{
> 		char opts[128];
> 		int fd = open("/dev/fuse", O_RDWR);
> 
> 		sprintf(opts, "fd=%d,rootmode=040000,user_id=0,group_id=0", fd);
> 		mkdir("mnt", 0777);
> 		mount("foo",  "mnt", "fuse.foo", 0, opts);
> 		mount("foo", "mnt", "fuse.foo", MS_REMOUNT, opts);
> 	}
> 
> Crash:
> 	BUG: kernel NULL pointer dereference, address: 0000000000000000
> 	#PF: supervisor read access in kernel mode
> 	#PF: error_code(0x0000) - not-present page
> 	PGD 0 P4D 0
> 	Oops: 0000 [#1] SMP
> 	CPU: 0 PID: 129 Comm: syz_make_kuid Not tainted 5.3.0-rc5-next-20190821 #3
> 	Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-20181126_142135-anatol 04/01/2014
> 	RIP: 0010:map_id_range_down+0xb/0xc0 kernel/user_namespace.c:291
> 	[...]
> 	Call Trace:
> 	 map_id_down kernel/user_namespace.c:312 [inline]
> 	 make_kuid+0xe/0x10 kernel/user_namespace.c:389
> 	 fuse_parse_param+0x116/0x210 fs/fuse/inode.c:523
> 	 vfs_parse_fs_param+0xdb/0x1b0 fs/fs_context.c:145
> 	 vfs_parse_fs_string+0x6a/0xa0 fs/fs_context.c:188
> 	 generic_parse_monolithic+0x85/0xc0 fs/fs_context.c:228
> 	 parse_monolithic_mount_data+0x1b/0x20 fs/fs_context.c:708
> 	 do_remount fs/namespace.c:2525 [inline]
> 	 do_mount+0x39a/0xa60 fs/namespace.c:3107
> 	 ksys_mount+0x7d/0xd0 fs/namespace.c:3325
> 	 __do_sys_mount fs/namespace.c:3339 [inline]
> 	 __se_sys_mount fs/namespace.c:3336 [inline]
> 	 __x64_sys_mount+0x20/0x30 fs/namespace.c:3336
> 	 do_syscall_64+0x4a/0x1a0 arch/x86/entry/common.c:290
> 	 entry_SYSCALL_64_after_hwframe+0x49/0xbe
> 
> Reported-by: syzbot+7d6a57304857423318a5@syzkaller.appspotmail.com
> Fixes: 408cbe695350 ("vfs: Convert fuse to use the new mount API")
> Cc: David Howells <dhowells@redhat.com>
> Cc: Miklos Szeredi <miklos@szeredi.hu>
> Signed-off-by: Eric Biggers <ebiggers@google.com>
> ---
>  fs/fs_context.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/fs/fs_context.c b/fs/fs_context.c
> index cc61d305dc4b..44c4174b250a 100644
> --- a/fs/fs_context.c
> +++ b/fs/fs_context.c
> @@ -279,10 +279,8 @@ static struct fs_context *alloc_fs_context(struct file_system_type *fs_type,
>  		fc->user_ns = get_user_ns(reference->d_sb->s_user_ns);
>  		break;
>  	case FS_CONTEXT_FOR_RECONFIGURE:
> -		/* We don't pin any namespaces as the superblock's
> -		 * subscriptions cannot be changed at this point.
> -		 */
>  		atomic_inc(&reference->d_sb->s_active);
> +		fc->user_ns = get_user_ns(reference->d_sb->s_user_ns);
>  		fc->root = dget(reference);
>  		break;
>  	}
> -- 
> 2.22.1

Ping.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] vfs: set fs_context::user_ns for reconfigure
  2019-08-31  3:12   ` Eric Biggers
@ 2019-09-06  2:59     ` Eric Biggers
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Biggers @ 2019-09-06  2:59 UTC (permalink / raw)
  To: David Howells, Alexander Viro, Miklos Szeredi
  Cc: syzkaller-bugs, syzbot+7d6a57304857423318a5, linux-fsdevel

On Fri, Aug 30, 2019 at 10:12:28PM -0500, Eric Biggers wrote:
> On Wed, Aug 21, 2019 at 10:16:33PM -0700, Eric Biggers wrote:
> > From: Eric Biggers <ebiggers@google.com>
> > 
> > fs_context::user_ns is used by fuse_parse_param(), even during remount,
> > so it needs to be set to the existing value for reconfigure.
> > 
> > Reproducer:
> > 
> > 	#include <fcntl.h>
> > 	#include <sys/mount.h>
> > 
> > 	int main()
> > 	{
> > 		char opts[128];
> > 		int fd = open("/dev/fuse", O_RDWR);
> > 
> > 		sprintf(opts, "fd=%d,rootmode=040000,user_id=0,group_id=0", fd);
> > 		mkdir("mnt", 0777);
> > 		mount("foo",  "mnt", "fuse.foo", 0, opts);
> > 		mount("foo", "mnt", "fuse.foo", MS_REMOUNT, opts);
> > 	}
> > 
> > Crash:
> > 	BUG: kernel NULL pointer dereference, address: 0000000000000000
> > 	#PF: supervisor read access in kernel mode
> > 	#PF: error_code(0x0000) - not-present page
> > 	PGD 0 P4D 0
> > 	Oops: 0000 [#1] SMP
> > 	CPU: 0 PID: 129 Comm: syz_make_kuid Not tainted 5.3.0-rc5-next-20190821 #3
> > 	Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-20181126_142135-anatol 04/01/2014
> > 	RIP: 0010:map_id_range_down+0xb/0xc0 kernel/user_namespace.c:291
> > 	[...]
> > 	Call Trace:
> > 	 map_id_down kernel/user_namespace.c:312 [inline]
> > 	 make_kuid+0xe/0x10 kernel/user_namespace.c:389
> > 	 fuse_parse_param+0x116/0x210 fs/fuse/inode.c:523
> > 	 vfs_parse_fs_param+0xdb/0x1b0 fs/fs_context.c:145
> > 	 vfs_parse_fs_string+0x6a/0xa0 fs/fs_context.c:188
> > 	 generic_parse_monolithic+0x85/0xc0 fs/fs_context.c:228
> > 	 parse_monolithic_mount_data+0x1b/0x20 fs/fs_context.c:708
> > 	 do_remount fs/namespace.c:2525 [inline]
> > 	 do_mount+0x39a/0xa60 fs/namespace.c:3107
> > 	 ksys_mount+0x7d/0xd0 fs/namespace.c:3325
> > 	 __do_sys_mount fs/namespace.c:3339 [inline]
> > 	 __se_sys_mount fs/namespace.c:3336 [inline]
> > 	 __x64_sys_mount+0x20/0x30 fs/namespace.c:3336
> > 	 do_syscall_64+0x4a/0x1a0 arch/x86/entry/common.c:290
> > 	 entry_SYSCALL_64_after_hwframe+0x49/0xbe
> > 
> > Reported-by: syzbot+7d6a57304857423318a5@syzkaller.appspotmail.com
> > Fixes: 408cbe695350 ("vfs: Convert fuse to use the new mount API")
> > Cc: David Howells <dhowells@redhat.com>
> > Cc: Miklos Szeredi <miklos@szeredi.hu>
> > Signed-off-by: Eric Biggers <ebiggers@google.com>
> > ---
> >  fs/fs_context.c | 4 +---
> >  1 file changed, 1 insertion(+), 3 deletions(-)
> > 
> > diff --git a/fs/fs_context.c b/fs/fs_context.c
> > index cc61d305dc4b..44c4174b250a 100644
> > --- a/fs/fs_context.c
> > +++ b/fs/fs_context.c
> > @@ -279,10 +279,8 @@ static struct fs_context *alloc_fs_context(struct file_system_type *fs_type,
> >  		fc->user_ns = get_user_ns(reference->d_sb->s_user_ns);
> >  		break;
> >  	case FS_CONTEXT_FOR_RECONFIGURE:
> > -		/* We don't pin any namespaces as the superblock's
> > -		 * subscriptions cannot be changed at this point.
> > -		 */
> >  		atomic_inc(&reference->d_sb->s_active);
> > +		fc->user_ns = get_user_ns(reference->d_sb->s_user_ns);
> >  		fc->root = dget(reference);
> >  		break;
> >  	}
> > -- 
> > 2.22.1
> 
> Ping.
> 

Ping.  This is still broken in linux-next.

- Eric

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-09-06  2:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <0000000000007bc3a0058e460627@google.com>
2019-08-22  5:16 ` [PATCH] vfs: set fs_context::user_ns for reconfigure Eric Biggers
2019-08-31  3:12   ` Eric Biggers
2019-09-06  2:59     ` Eric Biggers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).