From patchwork Mon Nov 26 16:38:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 10698639 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 22C7013BB for ; Mon, 26 Nov 2018 16:38:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 12933295EB for ; Mon, 26 Nov 2018 16:38:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 06B1D295F5; Mon, 26 Nov 2018 16:38:53 +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 84F7A295EB for ; Mon, 26 Nov 2018 16:38:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726328AbeK0Dd2 (ORCPT ); Mon, 26 Nov 2018 22:33:28 -0500 Received: from mx2.suse.de ([195.135.220.15]:57774 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726203AbeK0Dd2 (ORCPT ); Mon, 26 Nov 2018 22:33:28 -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 EB212ACAB; Mon, 26 Nov 2018 16:38:49 +0000 (UTC) Date: Mon, 26 Nov 2018 10:38:47 -0600 From: Goldwyn Rodrigues To: syzbot+ae82084b07d0297e566b@syzkaller.appspotmail.com Cc: Mimi Zohar , syzkaller-bugs@googlegroups.com, linux-integrity@vger.kernel.org, linux-unionfs@vger.kernel.org, amir73il@gmail.com Subject: [PATCH] IMA: Mask O_RDWR if FMODE_READ is set Message-ID: <20181126163847.xy3acvltyeb75nb4@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 file can be opened with open(O_WRONLY | O_RDWR), so a FMORE_READ will not be set, and overlayfs will consider another copy_up() on the same file leading to a deadlock on mnt_want_write(). Fix it by masking O_RDWR while opening the file in read-only mode. Reported-by: syzbot+ae82084b07d0297e566b@syzkaller.appspotmail.com Fixes: a408e4a86b36 ("ima: open a new file instance if no read permissions") Signed-off-by: Goldwyn Rodrigues diff --git a/security/integrity/ima/ima_crypto.c b/security/integrity/ima/ima_crypto.c index d9e7728027c6..2efa04e47ff0 100644 --- a/security/integrity/ima/ima_crypto.c +++ b/security/integrity/ima/ima_crypto.c @@ -422,7 +422,7 @@ int ima_calc_file_hash(struct file *file, struct ima_digest_data *hash) /* Open a new file instance in O_RDONLY if we cannot read */ if (!(file->f_mode & FMODE_READ)) { int flags = file->f_flags & ~(O_WRONLY | O_APPEND | - O_TRUNC | O_CREAT | O_NOCTTY | O_EXCL); + O_RDWR | O_TRUNC | O_CREAT | O_NOCTTY | O_EXCL); flags |= O_RDONLY; f = dentry_open(&file->f_path, flags, file->f_cred); if (IS_ERR(f)) {