Linux-Fsdevel Archive on lore.kernel.org
 help / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Cc: Al Viro <viro@zeniv.linux.org.uk>,
	Eric Biggers <ebiggers3@gmail.com>,
	Dmitry Vyukov <dvyukov@google.com>,
	Kees Cook <keescook@chromium.org>,
	syzbot 
	<bot+e93a80c1bb7c5c56e522461c149f8bf55eab1b2b@syzkaller.appspotmail.com>,
	"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	syzkaller-bugs <syzkaller-bugs@googlegroups.com>
Subject: Re: [PATCH v2] fs: Allow opening only regular files during execve().
Date: Mon, 28 Jan 2019 15:42:05 -0800
Message-ID: <20190128154205.214ae010da6c2f02d379bbc8@linux-foundation.org> (raw)
In-Reply-To: <201901220050.x0M0ommA008918@www262.sakura.ne.jp>

On Tue, 22 Jan 2019 09:50:48 +0900 Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp> wrote:

> Al Viro wrote:
> > On Mon, Jan 21, 2019 at 07:14:39PM +0900, Tetsuo Handa wrote:
> > > On Tue, Dec 12, 2017 at 2:06 PM, Eric Biggers <ebiggers3@gmail.com> wrote:
> > > > I'm not sure what the fix will be.  Maybe the proc handlers should take a
> > > > different lock instead of cred_guard_mutex.  Or perhaps execve should check that
> > > > the file is a regular file before it attempts to open it.
> > > 
> > > We can easily distinguish open() from execve() and open() from others. ;-)
> > 
> > > +	/* The file or a script interpreter has to be a regular file. */
> > > +	if (unlikely(current->in_execve && !S_ISREG(inode->i_mode))) {
> > > +		error = -EACCES;
> > > +		goto cleanup_file;
> > > +	}
> > 
> > We are *NOT* going to use current->in_execve to propagate that information.
> 
> You mean check FMODE_EXEC instead of current->in_execve ?
> 
> >From f80b32e1c3fbd65672387ee441a32ab58db456f8 Mon Sep 17 00:00:00 2001
> From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> Date: Tue, 22 Jan 2019 09:34:35 +0900
> Subject: [PATCH v2] fs: Allow opening only regular files during execve().
> 
> syzbot is hitting lockdep warning [1] due to trying to open a fifo during
> an execve() operation. But we don't need to open non regular files during
> an execve() operation, for all files which we will need are the executable
> file itself and the interpreter programs like /bin/sh and ld-linux.so.2 .
> 
> Since the manpage for execve(2) says that execve() returns EACCES when
> the file or a script interpreter is not a regular file, and the manpage
> for uselib(2) says that uselib() can return EACCES, and we use FMODE_EXEC
> when opening for execve()/uselib(), let's bail out if a non regular file
> is requested with FMODE_EXEC set.
> 
> [1] https://syzkaller.appspot.com/bug?id=b5095bfec44ec84213bac54742a82483aad578ce
> 
> ...
>
> --- a/fs/open.c
> +++ b/fs/open.c
> @@ -733,6 +733,12 @@ static int do_dentry_open(struct file *f,
>  		return 0;
>  	}
>  
> +	/* Any file opened for execve()/uselib() has to be a regular file. */
> +	if (unlikely(f->f_flags & FMODE_EXEC && !S_ISREG(inode->i_mode))) {
> +		error = -EACCES;
> +		goto cleanup_file;
> +	}
> +
>  	if (f->f_mode & FMODE_WRITE && !special_file(inode->i_mode)) {
>  		error = get_write_access(inode);
>  		if (unlikely(error))

This change sounds legitimate for various other reasons, but it's a
concern that this locking error occurred in the first place.  There's a
problem somewhere (probably the pipe code) which may bite us in other
situations, even with this workaround in place.


  reply index

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <001a113f711ae2110c055f45acb8@google.com>
2017-12-02  8:12 ` possible deadlock in seq_read syzbot
2017-12-03 22:02 ` syzbot
2017-12-12 22:06 ` Eric Biggers
2017-12-27 18:30   ` Dmitry Vyukov
2018-08-27 18:20   ` Kees Cook
2018-08-27 20:57     ` Dmitry Vyukov
2019-01-21 10:14       ` [PATCH] fs: Allow opening only regular files during execve() Tetsuo Handa
2019-01-21 20:24         ` Kees Cook
2019-01-21 21:18         ` Al Viro
2019-01-22  0:50           ` [PATCH v2] " Tetsuo Handa
2019-01-28 23:42             ` Andrew Morton [this message]
2019-02-12  2:01               ` Tetsuo Handa
2019-02-12  5:26               ` Tetsuo Handa
2019-02-19  9:51                 ` Tetsuo Handa
2019-01-22  0:51           ` [PATCH] " Kees Cook

Reply instructions:

You may reply publically 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=20190128154205.214ae010da6c2f02d379bbc8@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=bot+e93a80c1bb7c5c56e522461c149f8bf55eab1b2b@syzkaller.appspotmail.com \
    --cc=dvyukov@google.com \
    --cc=ebiggers3@gmail.com \
    --cc=keescook@chromium.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=viro@zeniv.linux.org.uk \
    /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

Linux-Fsdevel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-fsdevel/0 linux-fsdevel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-fsdevel linux-fsdevel/ https://lore.kernel.org/linux-fsdevel \
		linux-fsdevel@vger.kernel.org linux-fsdevel@archiver.kernel.org
	public-inbox-index linux-fsdevel


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-fsdevel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox