Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp871075ybv; Sat, 22 Feb 2020 17:18:52 -0800 (PST) X-Google-Smtp-Source: APXvYqytUuctSyd+8C1C3Ml/burT3FAxaiky377FuAjtNfI9ahX5gCP1UnLk6MgV4/nef4+V9yKq X-Received: by 2002:a9d:6215:: with SMTP id g21mr14836157otj.265.1582420732329; Sat, 22 Feb 2020 17:18:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582420732; cv=none; d=google.com; s=arc-20160816; b=ykU/+5kwZoLpScaswybFobQ019WGU83ZvqIdzw/ua8TQx6lFJgzMJU/oLLJzpz/v5V Lu152POCwAF6KzPiK/SIbBzZ+o9wdaYqfWTeOj1wIRhz2Fqhrt7nJ34zoWmepPy2N0yb OEZS3PJ/gbv6B8HUIFKgl3nmrIBaWkw9o57jQO3Cl8MmQQapz0dAjD2DJObk0YU7pQHY UV66JkuR+xfcnVUkR3JqhOzJHs221rzdjxF7lg3SzdE9sEE90B+cZ1Z4pgUTurqumRJJ bNsezdNei8gxoRPbLyRGfN9+dOu58Plrx4hb/IkGceyqs0grYsL3NlLqY53Faha15t29 Kfcw== 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=E77ey3WgRwC6/qtEqHqCLAKMqHN/t8Mw3PeuvmKTgnI=; b=olu/qc+f3CeT/yMe3HeIk2jOzOJHMhLw5EspVAXyE1AeL95lQCyZzm3TOcAh+n+05N RL4Zf2B5cK/uyONnckJpHzS8t1ZdZu4iaOZEFdwjpMJt4nmJMatUwS3t8ue1/j3lQ94O 4auF8WvHFAZ2OB7AlwbZvljzf067FLsAcc/94ovQZOlMh3NcvgiYOLo3rnt9x2uD0IHC qmS8lLnVLMv+auN3sC/oFsJZM4V0GswxUwD/p3MW+MWR/4r11/GpOwRchb7A0S/PqKyU n7pbZ7jTus/VTZ1ry49zHF+1e2cCMJtN7YpgOoHVJUrasHCltmVMRIcTgtohh+Z2lpc2 CIBQ== 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 d8si3997279otp.295.2020.02.22.17.18.40; Sat, 22 Feb 2020 17:18:52 -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 S1727215AbgBWBRd (ORCPT + 99 others); Sat, 22 Feb 2020 20:17:33 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:50098 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726943AbgBWBRd (ORCPT ); Sat, 22 Feb 2020 20:17:33 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1j5ftR-00HDad-Nq; Sun, 23 Feb 2020 01:17:22 +0000 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Linus Torvalds Subject: [RFC][PATCH v2 05/34] make build_open_flags() treat O_CREAT | O_EXCL as implying O_NOFOLLOW Date: Sun, 23 Feb 2020 01:15:57 +0000 Message-Id: <20200223011626.4103706-5-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 O_CREAT | O_EXCL means "-EEXIST if we run into a trailing symlink". As it is, we might or might not have LOOKUP_FOLLOW in op->intent in that case - that depends upon having O_NOFOLLOW in open flags. It doesn't matter, since we won't be checking it in that case - do_last() bails out earlier. However, making sure it's not set (i.e. acting as if we had an explicit O_NOFOLLOW) makes the behaviour more explicit and allows to reorder the check for O_CREAT | O_EXCL in do_last() with the call of step_into() immediately following it. Signed-off-by: Al Viro --- fs/namei.c | 15 +++++---------- fs/open.c | 4 +++- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 6721c5f7e9d5..6938d20aa73a 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3396,22 +3396,17 @@ static int do_last(struct nameidata *nd, if (unlikely(error < 0)) return error; - /* - * create/update audit record if it already exists. - */ - audit_inode(nd->name, path.dentry, 0); - - if (unlikely((open_flag & (O_EXCL | O_CREAT)) == (O_EXCL | O_CREAT))) { - path_to_nameidata(&path, nd); - return -EEXIST; - } - seq = 0; /* out of RCU mode, so the value doesn't matter */ inode = d_backing_inode(path.dentry); finish_lookup: error = step_into(nd, &path, 0, inode, seq); if (unlikely(error)) return error; + + if (unlikely((open_flag & (O_EXCL | O_CREAT)) == (O_EXCL | O_CREAT))) { + audit_inode(nd->name, nd->path.dentry, 0); + return -EEXIST; + } finish_open: /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */ error = complete_walk(nd); diff --git a/fs/open.c b/fs/open.c index 0788b3715731..e5227cd533f4 100644 --- a/fs/open.c +++ b/fs/open.c @@ -1049,8 +1049,10 @@ inline int build_open_flags(const struct open_how *how, struct open_flags *op) if (flags & O_CREAT) { op->intent |= LOOKUP_CREATE; - if (flags & O_EXCL) + if (flags & O_EXCL) { op->intent |= LOOKUP_EXCL; + flags |= O_NOFOLLOW; + } } if (flags & O_DIRECTORY) -- 2.11.0