From: Kees Cook <keescook@chromium.org>
To: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>,
Eric Biggers <ebiggers3@gmail.com>,
Dmitry Vyukov <dvyukov@google.com>,
"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
syzbot
<syzbot+e93a80c1bb7c5c56e522461c149f8bf55eab1b2b@syzkaller.appspotmail.com>
Subject: Re: [PATCH v2 (resend)] fs: Allow opening only regular files during execve().
Date: Fri, 8 Mar 2019 07:45:02 -0800 [thread overview]
Message-ID: <CAGXu5j+-3ASx4DMonC0sso7Sb01s5zLMNL3VgDK8Y5z9mrAKiQ@mail.gmail.com> (raw)
In-Reply-To: <1552044017-7890-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp>
On Fri, Mar 8, 2019 at 3:20 AM Tetsuo Handa
<penguin-kernel@i-love.sakura.ne.jp> wrote:
>
> 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(), we can bail out if a non regular file
> is requested with FMODE_EXEC set.
>
> Since this deadlock followed by khungtaskd warnings is trivially
> reproducible by a local unprivileged user, and syzbot's frequent
> crash due to this deadlock defers finding other bugs, let's workaround
> this deadlock until we get a chance to find a better solution.
>
> [1] https://syzkaller.appspot.com/bug?id=b5095bfec44ec84213bac54742a82483aad578ce
>
> Reported-by: syzbot <syzbot+e93a80c1bb7c5c56e522461c149f8bf55eab1b2b@syzkaller.appspotmail.com>
> Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> Fixes: 8924feff66f35fe2 ("splice: lift pipe_lock out of splice_to_pipe()")
> Cc: <stable@vger.kernel.org> # 4.9+
Acked-by: Kees Cook <keescook@chromium.org>
Andrew, can you take this for -mm?
-Kees
> ---
> fs/open.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/fs/open.c b/fs/open.c
> index 0285ce7..f1c2f85 100644
> --- 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))
> --
> 1.8.3.1
>
--
Kees Cook
prev parent reply other threads:[~2019-03-08 15:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-08 11:20 [PATCH v2 (resend)] fs: Allow opening only regular files during execve() Tetsuo Handa
2019-03-08 15:45 ` Kees Cook [this message]
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=CAGXu5j+-3ASx4DMonC0sso7Sb01s5zLMNL3VgDK8Y5z9mrAKiQ@mail.gmail.com \
--to=keescook@chromium.org \
--cc=akpm@linux-foundation.org \
--cc=dvyukov@google.com \
--cc=ebiggers3@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=penguin-kernel@i-love.sakura.ne.jp \
--cc=syzbot+e93a80c1bb7c5c56e522461c149f8bf55eab1b2b@syzkaller.appspotmail.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
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).