Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1236860

Re: [PATCH 1/5] fs: Verify access of user towards block device file when mounting

From Mike Snitzer <snitzer@redhat.com>
Newsgroups linux.kernel
Subject Re: [PATCH 1/5] fs: Verify access of user towards block device file when mounting
Date 2015-10-01 01:50 +0200
Message-ID <qezih-3gr-9@gated-at.bofh.it> (permalink)
References <qew13-758-3@gated-at.bofh.it> <qew14-758-13@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Wed, Sep 30 2015 at  4:15pm -0400,
Seth Forshee <seth.forshee@canonical.com> wrote:

> When mounting a filesystem on a block device there is currently
> no verification that the user has appropriate access to the
> device file passed to mount. This has not been an issue so far
> since the user in question has always been root, but this must
> be changed before allowing unprivileged users to mount in user
> namespaces.
> 
> To fix this, add an argument to lookup_bdev() to specify the
> required permissions. If the mask of permissions is zero, or
> if the user has CAP_SYS_ADMIN, the permission check is skipped,
> otherwise the lookup fails if the user does not have the
> specified access rights for the inode at the supplied path.
> 
> Callers associated with mounting are updated to pass permission
> masks to lookup_bdev() so that these mounts will fail for an
> unprivileged user who lacks permissions for the block device
> inode. All other callers pass 0 to maintain their current
> behaviors.
> 
> Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
> ---
>  drivers/md/bcache/super.c |  2 +-
>  drivers/md/dm-table.c     |  2 +-
>  drivers/mtd/mtdsuper.c    |  6 +++++-
>  fs/block_dev.c            | 18 +++++++++++++++---
>  fs/quota/quota.c          |  2 +-
>  include/linux/fs.h        |  2 +-
>  6 files changed, 24 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
> index e76ed003769e..35bb3ea4cbe2 100644
> --- a/drivers/md/dm-table.c
> +++ b/drivers/md/dm-table.c
> @@ -380,7 +380,7 @@ int dm_get_device(struct dm_target *ti, const char *path, fmode_t mode,
>  	BUG_ON(!t);
>  
>  	/* convert the path to a device */
> -	bdev = lookup_bdev(path);
> +	bdev = lookup_bdev(path, 0);
>  	if (IS_ERR(bdev)) {
>  		dev = name_to_dev_t(path);
>  		if (!dev)

Given dm_get_device() is passed @mode why not have it do something like
you did in blkdev_get_by_path()? e.g.:

> diff --git a/fs/block_dev.c b/fs/block_dev.c
> index 26cee058dc02..54d94cd64577 100644
> --- a/fs/block_dev.c
> +++ b/fs/block_dev.c
> @@ -1394,9 +1394,14 @@ struct block_device *blkdev_get_by_path(const char *path, fmode_t mode,
>  					void *holder)
>  {
>  	struct block_device *bdev;
> +	int perm = 0;
>  	int err;
>  
> -	bdev = lookup_bdev(path);
> +	if (mode & FMODE_READ)
> +		perm |= MAY_READ;
> +	if (mode & FMODE_WRITE)
> +		perm |= MAY_WRITE;
> +	bdev = lookup_bdev(path, perm);
>  	if (IS_ERR(bdev))
>  		return bdev;
>  
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 1/5] fs: Verify access of user towards block device file when mounting Seth Forshee <seth.forshee@canonical.com> - 2015-09-30 22:20 +0200
  Re: [PATCH 1/5] fs: Verify access of user towards block device file  when mounting Mike Snitzer <snitzer@redhat.com> - 2015-10-01 01:50 +0200
    Re: [PATCH 1/5] fs: Verify access of user towards block device file  when mounting Seth Forshee <seth.forshee@canonical.com> - 2015-10-01 15:00 +0200
      Re: [PATCH 1/5] fs: Verify access of user towards block device file  when mounting Mike Snitzer <snitzer@redhat.com> - 2015-10-01 15:50 +0200
        Re: [PATCH 1/5] fs: Verify access of user towards block device file  when mounting Seth Forshee <seth.forshee@canonical.com> - 2015-10-01 16:50 +0200
        Re: [PATCH 1/5] fs: Verify access of user towards block device file when mounting ebiederm@xmission.com (Eric W. Biederman) - 2015-10-01 18:10 +0200
          Re: [PATCH 1/5] fs: Verify access of user towards block device file  when mounting Jan Kara <jack@suse.cz> - 2015-10-02 01:10 +0200
            Re: [PATCH 1/5] fs: Verify access of user towards block device file  when mounting Seth Forshee <seth.forshee@canonical.com> - 2015-10-05 16:30 +0200
  Re: [PATCH 1/5] fs: Verify access of user towards block device file when mounting ebiederm@xmission.com (Eric W. Biederman) - 2015-10-01 17:50 +0200
    Re: [PATCH 1/5] fs: Verify access of user towards block device file  when mounting Seth Forshee <seth.forshee@canonical.com> - 2015-10-01 18:00 +0200

csiph-web