Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA3C4C43381 for ; Fri, 29 Mar 2019 03:43:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B0EA0218A5 for ; Fri, 29 Mar 2019 03:43:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553831013; bh=ugUVBvgBxih7nEMxAp1qYzKyaezovz9OXj9bUmX9bW0=; h=Date:From:To:Subject:List-ID:From; b=fyP8DR/n3qWox35tKpR2/W87w3yO5ELPIXFyhJgCXGfjs6IuDubv9NHCxcZMQw08f LWU/GXOQY2R6a85We++o+ikqbBxs9kACGkUTX5JOVNBT0DP6Jq8SK5R8KqW91D8d4B 5BI7QE3Md2bzrc4fQBki/j0Sio5RMCJdvyxEBt9Y= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728559AbfC2Dnd (ORCPT ); Thu, 28 Mar 2019 23:43:33 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:48654 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728551AbfC2Dnc (ORCPT ); Thu, 28 Mar 2019 23:43:32 -0400 Received: from localhost.localdomain (c-73-223-200-170.hsd1.ca.comcast.net [73.223.200.170]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id A1F28B79; Fri, 29 Mar 2019 03:43:31 +0000 (UTC) Date: Thu, 28 Mar 2019 20:43:30 -0700 From: akpm@linux-foundation.org To: akpm@linux-foundation.org, dvyukov@google.com, ebiggers3@gmail.com, keescook@chromium.org, mm-commits@vger.kernel.org, penguin-kernel@I-love.SAKURA.ne.jp, stable@vger.kernel.org, syzbot+e93a80c1bb7c5c56e522461c149f8bf55eab1b2b@syzkaller.appspotmail.com, torvalds@linux-foundation.org, viro@zeniv.linux.org.uk Subject: [patch 05/22] fs/open.c: allow opening only regular files during execve() Message-ID: <20190329034330.ZXIhVdQe3%akpm@linux-foundation.org> User-Agent: s-nail v14.8.16 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Tetsuo Handa Subject: fs/open.c: 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(), 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 Link: http://lkml.kernel.org/r/1552044017-7890-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp Reported-by: syzbot Fixes: 8924feff66f35fe2 ("splice: lift pipe_lock out of splice_to_pipe()") Signed-off-by: Tetsuo Handa Acked-by: Kees Cook Cc: Al Viro Cc: Eric Biggers Cc: Dmitry Vyukov Cc: [4.9+] Signed-off-by: Andrew Morton --- fs/open.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/fs/open.c~fs-allow-opening-only-regular-files-during-execve +++ a/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)) _