Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp58087ybh; Fri, 13 Mar 2020 17:00:44 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvS02GIvj6TmkrikxkwyRkark3Vpet9b38ZA5QSS64hq5mP571M9G0sUV83K0S6FcWIPZbB X-Received: by 2002:a9d:67c7:: with SMTP id c7mr13635477otn.85.1584144043905; Fri, 13 Mar 2020 17:00:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584144043; cv=none; d=google.com; s=arc-20160816; b=t0OYGMufEtF4RmVm8H8oWaIqWsceXLAy4uzJjuTtnxWtHGJHxA25WoSFAw0Z4Nd8r1 b33AEjCiPLU0rW8F2DVkXjN0/i7NBCMkXO3OW2hhkDnmBq7gJJxVWgmSZSC8k2iecvTM t7/EJRKpYQ4EMApwArtzfPcBqnRHHISAQ0ZxKXC+DVNsWAbiGMMO8GXqiluxgIpimIGZ QApKlSOgtvo/91XRj8DkOlsXrefwi2v1Nimd3KxyKE7xvCBpS0P73prDE5nUme5dNkGZ c1+q3RaBQON61TmlTYjoL5PcwVWZ7j8HDPJMQXwfsQS/a5pW2NlIeO0xgRTmvJbsC8QA oHQg== 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=LUx1OBUHFAF7fO+walnbqckdt+OdF4ZlHXIOACkpXlWvO7oVW2kL5xrci4BYM7yRX8 GOU9i1QeMajC7fmBuqCks73/QpyLPuhrFFlNHJziXOCzydzZC7JsqF/ZLaJspTCNJRMN +nBGc7IJxfqOKz3iX7lfWZqtrEfpZd4krAGsNJkFC6vnyeQwvMeB9X54it7D0ec3bHx7 9sMqUS5CNC7+tH5z9DRu1bG103lzFd4DOmg8lMInAqOHDY2JorZaGdhDS1DvA3cresiC 9bkKpAvKNIV48akHL4Q34sJaaxbf2u19kZcX2a+Zq/4+32CbYwyPpMLaJ1CbGHVtFZKS WKcg== 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 z65si5535726otb.197.2020.03.13.17.00.30; Fri, 13 Mar 2020 17:00:43 -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; 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 S1727850AbgCMX6t (ORCPT + 99 others); Fri, 13 Mar 2020 19:58:49 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:49962 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727674AbgCMXx6 (ORCPT ); Fri, 13 Mar 2020 19:53:58 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jCu7p-00B6Yc-O1; Fri, 13 Mar 2020 23:53:57 +0000 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Linus Torvalds Subject: [RFC][PATCH v4 05/69] make build_open_flags() treat O_CREAT | O_EXCL as implying O_NOFOLLOW Date: Fri, 13 Mar 2020 23:52:53 +0000 Message-Id: <20200313235357.2646756-5-viro@ZenIV.linux.org.uk> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200313235357.2646756-1-viro@ZenIV.linux.org.uk> References: <20200313235303.GP23230@ZenIV.linux.org.uk> <20200313235357.2646756-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