linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vivek Goyal <vgoyal@redhat.com>
To: Christoph Hellwig <hch@lst.de>
Cc: viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org, virtio-fs@redhat.com
Subject: Re: [PATCH 2/2] init: allow mounting arbitrary non-blockdevice filesystems as root
Date: Thu, 17 Jun 2021 12:26:10 -0400	[thread overview]
Message-ID: <20210617162610.GC1142820@redhat.com> (raw)
In-Reply-To: <20210617153649.1886693-3-hch@lst.de>

On Thu, Jun 17, 2021 at 05:36:49PM +0200, Christoph Hellwig wrote:

[..]
> +static int __init try_mount_nodev(char *fstype)
> +{
> +	struct file_system_type *fs = get_fs_type(fstype);
> +	int err = -EINVAL;
> +
> +	if (!fs)
> +		return -EINVAL;
> +	if (!(fs->fs_flags & (FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA)))

Not sure what FS_BINARY_MOUNTDATA is why fs should not have that set. nfs
seems to set it too. So that means they can't use try_mount_nodev().

> +		err = do_mount_root(root_device_name, fstype, root_mountflags,
> +					root_mount_data);
> +	put_filesystem(fs);
> +
> +	if (err != -EACCES && err != -EINVAL)

In case of success err == 0, but we still panic(). We will need to
check for success as well.
	if (err && err != -EACCES && err != -EINVAL)

> +		panic("VFS: Unable to mount root \"%s\" (%s), err=%d\n",
> +			      root_device_name, fstype, err);
> +	return err;
> +}
> +
> +static int __init mount_nodev_root(void)
> +{
> +	char *fs_names, *p;
> +	int err = -EINVAL;
> +
> +	fs_names = (void *)__get_free_page(GFP_KERNEL);
> +	if (!fs_names)
> +		return -EINVAL;
> +	split_fs_names(fs_names, root_fs_names);

root_fs_names can be NULL and it crashes with NULL pointer dereference.

Vivek

> +
> +	for (p = fs_names; *p; p += strlen(p) + 1) {
> +		err = try_mount_nodev(p);
> +		if (!err)
> +			break;
> +	}
> +
> +	free_page((unsigned long)fs_names);
> +	return err;
> +}
> +
>  void __init mount_root(void)
>  {
>  #ifdef CONFIG_ROOT_NFS
> @@ -550,6 +588,8 @@ void __init mount_root(void)
>  		return;
>  	}
>  #endif
> +	if (ROOT_DEV == 0 && mount_nodev_root() == 0)
> +		return;
>  #ifdef CONFIG_BLOCK
>  	{
>  		int err = create_dev("/dev/root", ROOT_DEV);
> -- 
> 2.30.2
> 


  reply	other threads:[~2021-06-17 16:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-17 15:36 support booting of arbitrary non-blockdevice file systems Christoph Hellwig
2021-06-17 15:36 ` [PATCH 1/2] init: split get_fs_names Christoph Hellwig
2021-06-17 15:36 ` [PATCH 2/2] init: allow mounting arbitrary non-blockdevice filesystems as root Christoph Hellwig
2021-06-17 16:26   ` Vivek Goyal [this message]
2021-06-18 13:20     ` Christoph Hellwig
2021-06-18 14:10       ` Vivek Goyal
2021-06-18 18:03 ` [Virtio-fs] support booting of arbitrary non-blockdevice file systems Stefan Hajnoczi
2021-06-21  6:26 support booting of arbitrary non-blockdevice file systems v2 Christoph Hellwig
2021-06-21  6:26 ` [PATCH 2/2] init: allow mounting arbitrary non-blockdevice filesystems as root Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210617162610.GC1142820@redhat.com \
    --to=vgoyal@redhat.com \
    --cc=hch@lst.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=virtio-fs@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).