public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Richard Weinberger <richard@nod.at>
To: Gabriel de Perthuis <g2p.code@gmail.com>
Cc: Jeff Dike <jdike@addtoit.com>,
	user-mode-linux-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] um: Accept /dev/fd/* uml block devices
Date: Sun, 28 Jul 2013 10:12:37 +0200	[thread overview]
Message-ID: <51F4D275.70009@nod.at> (raw)
In-Reply-To: <1374938607-25747-1-git-send-email-g2p.code@gmail.com>

Am 27.07.2013 17:23, schrieb Gabriel de Perthuis:
> Useful for
> * limiting privileges
> * opening block devices O_EXCL

So, the goal of this patch is to allow passing a file descriptor
number as block device instead of a file?

I assume you have already a wrapper around UML which exec()'s it such that
it can reuse a fd?

> Use dup to work around the fact /proc/self/fd
> can't be opened after dropping privileges.
> This proc behaviour doesn't match TLPI and might be a bug.
> 
> Qemu has a slightly more complex fdset approach
> that provides fds with different access permissions.

I really don't like that you patch os_open_file(), this is a
generic function.

What about this one?
Allow ubda= (and all other UML block device kernel parameters) to
accept arguments like file:/foo/bar and fd:N.
Where N is a number and file: is default such that we do not break
old kernels.

Thanks,
//richard

> Signed-off-by: Gabriel de Perthuis <g2p.code@gmail.com>
> ---
>  arch/um/os-Linux/file.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/um/os-Linux/file.c b/arch/um/os-Linux/file.c
> index c17bd6f..cee65ba 100644
> --- a/arch/um/os-Linux/file.c
> +++ b/arch/um/os-Linux/file.c
> @@ -169,11 +169,11 @@ int os_file_mode(const char *file, struct openflags *mode_out)
>  	return err;
>  }
>  
>  int os_open_file(const char *file, struct openflags flags, int mode)
>  {
> -	int fd, err, f = 0;
> +	int fd, fd0, err, f = 0;
>  
>  	if (flags.r && flags.w)
>  		f = O_RDWR;
>  	else if (flags.r)
>  		f = O_RDONLY;
> @@ -190,11 +190,15 @@ int os_open_file(const char *file, struct openflags flags, int mode)
>  	if (flags.e)
>  		f |= O_EXCL;
>  	if (flags.a)
>  		f |= O_APPEND;
>  
> -	fd = open64(file, f, mode);
> +	if (!strncmp(file, "/dev/fd/", 8)
> +	    && sscanf(file, "/dev/fd/%d", &fd0) == 1)
> +		fd = dup(fd0);
> +	else
> +		fd = open64(file, f, mode);
>  	if (fd < 0)
>  		return -errno;
>  
>  	if (flags.cl && fcntl(fd, F_SETFD, 1)) {
>  		err = -errno;
> @@ -280,11 +284,11 @@ int os_file_size(const char *file, unsigned long long *size_out)
>  
>  	if (S_ISBLK(buf.ust_mode)) {
>  		int fd;
>  		long blocks;
>  
> -		fd = open(file, O_RDONLY, 0);
> +		fd = os_open_file(file, of_read(OPENFLAGS()), 0);
>  		if (fd < 0) {
>  			err = -errno;
>  			printk(UM_KERN_ERR "Couldn't open \"%s\", "
>  			       "errno = %d\n", file, errno);
>  			return err;
> 


  reply	other threads:[~2013-07-28  8:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-27 15:23 [PATCH] um: Accept /dev/fd/* uml block devices Gabriel de Perthuis
2013-07-28  8:12 ` Richard Weinberger [this message]
2013-07-28 10:25   ` Gabriel de Perthuis
2013-07-31 23:08     ` Gabriel de Perthuis

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=51F4D275.70009@nod.at \
    --to=richard@nod.at \
    --cc=g2p.code@gmail.com \
    --cc=jdike@addtoit.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=user-mode-linux-devel@lists.sourceforge.net \
    /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