Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp524826yba; Mon, 1 Apr 2019 11:03:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqyFrsc42ZfyK2Xw9J8hFGwxuUTsluX+BWKK/eLmjME5atSsJkMnxW18P8+/IwoSZQ/n6OKk X-Received: by 2002:a17:902:362:: with SMTP id 89mr614226pld.172.1554141807378; Mon, 01 Apr 2019 11:03:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554141807; cv=none; d=google.com; s=arc-20160816; b=Js6msgEBPESk6AZjb5SQAYt626M7seogdrFcDpLgEd2mfaL7RAdaoWgft7ZyLHe7WI D5RXtlbmrGgZ1a5mu7QvN5FmWNGPhPUA4n7/0OsoskMUbTgtUdNTWInNNbvJrWtBnzZT IDyqV0gq2EUaEZgURcNNRCx5RH5MHSAyYYIlxMZOL3i8CvlvQaM4yNkYvGkFj0i66Kis IoW8NX/tc19vxtcv87wuWB4JTH7kTrdKUN/Ie638doSd2aYkPV05kQYyeSWjBkxjDmI1 EIJqYD35qqU+WdKVcFxGAkaSaNDDy/qTKPvkamIkZccMu6NeoXRTynckcMjt1hMDSQbf 23hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=sDzI9O+/PyKA97V7pbI7dd+1I7sZZCzogjC3EuzZuF0=; b=AiVHeG73L15INbAwrDEjHSE1rv+gwnCaM+zuHKESJS7u3PMLO3UEGv+dH3GQXw7Do+ giEJq1Y8FVUzjbLLkJBHibYcC0Ml4fOIJmClh+Zv3fdQNy1AeAXlQ8Pryc4v1LZYNAU4 0AjpGRehKurOl350fg+xkYvsoQZ0fg2xK67Vr/U6GLYxhmn2O2KBKJPPfpjd3kOQBJKU GU4S8JtXx6gsT2E7yQeKlr+MYLRSy9uRZkXqPqE3rZc9FkJFPsuloHslbY8Q4qyqhfWd DW43ZaexpEO4FoEepLhDkODEw/Hz1lsJKW2DNrens121aUBtTRx/SVZnofmyWLKhazRo gBFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="n/ayJi32"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s5si9080180plr.307.2019.04.01.11.03.11; Mon, 01 Apr 2019 11:03:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="n/ayJi32"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731173AbfDASBN (ORCPT + 99 others); Mon, 1 Apr 2019 14:01:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:41562 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728840AbfDARQY (ORCPT ); Mon, 1 Apr 2019 13:16:24 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4423320856; Mon, 1 Apr 2019 17:16:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554138982; bh=gPg5gBu16ydF314wfdOy720m9mqW5iN7hxSDNEPB3/8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n/ayJi321plDedCrmrnRIKlC301/Dv0OwLcto/XiTd9wLGtjt9KmiJ+c2UVzQTzZZ JFpdINVq+ppLgU6l4DAM19MUxOdT+mTtvzHbqaCgJ4ftuGew4FGzX7D9mju0fAgIev Ejs/3P2F3kIubm+DoyplQyl6fyyHOjG+ohzrDMd8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot , Tetsuo Handa , Kees Cook , Al Viro , Eric Biggers , Dmitry Vyukov , Andrew Morton , Linus Torvalds Subject: [PATCH 4.19 071/134] fs/open.c: allow opening only regular files during execve() Date: Mon, 1 Apr 2019 19:01:47 +0200 Message-Id: <20190401170051.097988841@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190401170044.243719205@linuxfoundation.org> References: <20190401170044.243719205@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tetsuo Handa commit 73601ea5b7b18eb234219ae2adf77530f389da79 upstream. 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 Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/open.c | 6 ++++++ 1 file changed, 6 insertions(+) --- 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))