From patchwork Thu Dec 13 11:57:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 10728539 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5AB296C5 for ; Thu, 13 Dec 2018 11:57:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4AFD629315 for ; Thu, 13 Dec 2018 11:57:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3F40E2BF39; Thu, 13 Dec 2018 11:57:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CADBA29315 for ; Thu, 13 Dec 2018 11:57:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728767AbeLML5V (ORCPT ); Thu, 13 Dec 2018 06:57:21 -0500 Received: from mx2.suse.de ([195.135.220.15]:50984 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728625AbeLML5V (ORCPT ); Thu, 13 Dec 2018 06:57:21 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 588BAAFDE; Thu, 13 Dec 2018 11:57:19 +0000 (UTC) Date: Thu, 13 Dec 2018 05:57:17 -0600 From: Goldwyn Rodrigues To: linux-fsdevel@vger.kernel.org Cc: amir73il@gmail.com, zohar@linux.ibm.com, syzbot+ae82084b07d0297e566b@syzkaller.appspotmail.com, syzkaller-bugs@googlegroups.com, linux-integrity@vger.kernel.org, linux-unionfs@vger.kernel.org, dvyukov@google.com Subject: [PATCH] fs: Evaluate O_WRONLY | O_RDWR to O_RDWR Message-ID: <20181213115717.p7ncktng2ihxw5md@merlin> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20180323 Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A user can open(O_WRONLY | O_RDWR) and the options are valid. However, OPEN_FMODE() evaluates both FMODE_READ and FMODE_WRITE, as negative. We also need to protect the lower layers from this anomaly. Solve it by dropping O_WRONLY, so O_RDWR takes precedence. Signed-off-by: Goldwyn Rodrigues Reported-by: syzbot+ae82084b07d0297e566b@syzkaller.appspotmail.com Fixes: a408e4a86b36 ("ima: open a new file instance if no read permissions") --- fs/open.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/open.c b/fs/open.c index 0285ce7dbd51..3d0a21600fa3 100644 --- a/fs/open.c +++ b/fs/open.c @@ -924,7 +924,12 @@ EXPORT_SYMBOL(open_with_fake_path); static inline int build_open_flags(int flags, umode_t mode, struct open_flags *op) { int lookup_flags = 0; - int acc_mode = ACC_MODE(flags); + int acc_mode; + + if ((flags & (O_RDWR | O_WRONLY)) == (O_RDWR | O_WRONLY)) + flags &= ~O_WRONLY; + + acc_mode = ACC_MODE(flags); /* * Clear out all open flags we don't know about so that we don't report