Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp875504ybv; Sat, 22 Feb 2020 17:24:58 -0800 (PST) X-Google-Smtp-Source: APXvYqwIB/p1/Jhpo1VYym6vAohQ6V0eHHp8uCVz0fxpGnTsx4/BFU1yEiZ3BwSdEbwhpD5yWLht X-Received: by 2002:a9d:4f04:: with SMTP id d4mr34164893otl.78.1582421097892; Sat, 22 Feb 2020 17:24:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582421097; cv=none; d=google.com; s=arc-20160816; b=LauI7KWD0AQu5iEzlUVAnGrDsOhvyJhSrwxMtNjDL3U0HvaX9oyRK3Gv0rDQnqpYxG Ebk6EUxuneYrefk6Vdv4zebioVaX1mkGxvH5mi6BnsyxRgl7SRsPGvvyGnwc/Fm7jr+U VHqcksgvVBRUmlxc2BmzLUQbKiNKWrpHMAmehwqcKXaA16pV8mT6ZiF92pvm0iyNeQqr gdLVh7E5XBT9OEfmrUiwc00m+CIevuLtuYSKwK5sOW62vOkm43d9RGG3132KWt84HAX7 1qJDCuoJrMlJVBYYgnqhKV4q47+BCHguLSwtQUdrn7/wEBRnO3GbqJuT0R6fejeytvYX n7sA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=6Dj9Esdn/nkIoZqBwkN9/1s24f3PnYCU9E0pTHSWTWM=; b=d17u5eNm7jQwnGywbGARFIdt2nku8JMZWR1mv8Ath1vs5Vyy0vPY+/GxKhIKo1cCi0 h4iXGQkyOHH/dWAFj7gYk8pdNK1Jjd/1zjbDIkp/WghC8eVNI3xgxTYabBsNYCmgFzeI e8uWge5a+Fz3YHbKvwE3C+WgcH8QrQx+iBmhBHqqNLaVsTBtK2Z8ZFrVcNFaQ+u2+CsR j54WPJOkVtPKo4baO8cfb9v6X5jZ6YFN0jj1ARJrgzl9E8TMIf5TjSUC8DzPIVZWYgWT 4LHIylNiNr5x+Y2u5ZNqucWo3qDoeGMb/99fVa5nh7x7m0P8rbLfeXqpu8IrbKj3StNX RhrA== ARC-Authentication-Results: i=1; mx.google.com; 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 j143si3364735oib.16.2020.02.22.17.24.45; Sat, 22 Feb 2020 17:24:57 -0800 (PST) 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; 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 S1727207AbgBWBYe (ORCPT + 99 others); Sat, 22 Feb 2020 20:24:34 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:50244 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726943AbgBWBYe (ORCPT ); Sat, 22 Feb 2020 20:24:34 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1j5g0G-00HDmI-IU; Sun, 23 Feb 2020 01:24:23 +0000 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Linus Torvalds Subject: [RFC][PATCH v2 28/34] atomic_open(): lift the call of may_open() into do_last() Date: Sun, 23 Feb 2020 01:16:20 +0000 Message-Id: <20200223011626.4103706-28-viro@ZenIV.linux.org.uk> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200223011626.4103706-1-viro@ZenIV.linux.org.uk> References: <20200223011154.GY23230@ZenIV.linux.org.uk> <20200223011626.4103706-1-viro@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Al Viro there we'll be able to merge it with its counterparts in other cases, and there's no reason to do it before the parent has been unlocked Signed-off-by: Al Viro --- fs/namei.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index c2244ee4b2f0..16786be13050 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -2956,23 +2956,12 @@ static struct dentry *atomic_open(struct nameidata *nd, struct dentry *dentry, d_lookup_done(dentry); if (!error) { if (file->f_mode & FMODE_OPENED) { - int acc_mode = op->acc_mode; if (unlikely(dentry != file->f_path.dentry)) { dput(dentry); dentry = dget(file->f_path.dentry); } - /* - * We didn't have the inode before the open, so check open - * permission here. - */ - if (file->f_mode & FMODE_CREATED) { - WARN_ON(!(open_flag & O_CREAT)); + if (file->f_mode & FMODE_CREATED) fsnotify_create(dir, dentry); - acc_mode = 0; - } - error = may_open(&file->f_path, acc_mode, open_flag); - if (WARN_ON(error > 0)) - error = -EINVAL; } else if (WARN_ON(file->f_path.dentry == DENTRY_NOT_SET)) { error = -EIO; } else { @@ -3216,12 +3205,19 @@ static const char *do_last(struct nameidata *nd, } if (file->f_mode & FMODE_OPENED) { - if ((file->f_mode & FMODE_CREATED) || - !S_ISREG(file_inode(file)->i_mode)) + if (file->f_mode & FMODE_CREATED) { + open_flag &= ~O_TRUNC; + will_truncate = false; + acc_mode = 0; + } else if (!S_ISREG(file_inode(file)->i_mode)) will_truncate = false; audit_inode(nd->name, file->f_path.dentry, 0); - dput(dentry); + dput(nd->path.dentry); + nd->path.dentry = dentry; + error = may_open(&nd->path, acc_mode, open_flag); + if (error) + goto out; goto opened; } -- 2.11.0