Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2191200iof; Tue, 7 Jun 2022 22:42:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwMmIhiiSfJ4lIhlNT2Nc45ExkGtciPRJa5ruIRVMG2VqXmLYZt64yExvZMxWhkw6p6creb X-Received: by 2002:a63:9142:0:b0:3fc:c021:e237 with SMTP id l63-20020a639142000000b003fcc021e237mr28951150pge.279.1654666947494; Tue, 07 Jun 2022 22:42:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654666947; cv=none; d=google.com; s=arc-20160816; b=BvsmnmeSDDhYxyVbC80B/MetKuZa77ghKkjqUjXSYnQlrLdfbRqT9b6qTZsgV/Bfpt 6MBwkrzp1/MBZrc8kLvljVySPPwv1KJ6JRO+pllmf0dZXCRl14Q3y/y3Tx7RGeNLNp6g E/YVk+Evucw6Zw+haf6koNPzFnlRy3rjbezkIq/W0NwleMfR0SGsq98H1DTura5H1Xkv a509/Woho+9V6LL6lO2uPMScDQgtBvzcbkopGZcU0ifjGYwat8go2AngiS+K6Vimmodm 3bqDAvwyp5zDpc6F+7/TPa+EHUO6kPsHJZJJkBy5zfP5tyw+qqwxTm6mUUunFdHIrua+ YaFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=iMwPoQklr0pfRqOvmp9c1KslxP6COJ9VSlU/H96Ppfc=; b=SohYi+ZtQtNnYMytl0Mb+HoU4/ME+zkEcCGQCM+ieKe23Hv2e/kUyE/i8JRj6MvfEd BmLZ6R1takqVR0WcqkbKAVM224HeufLT/hLroSzrPqXjU8RKi+VgY2vLkgzfSQW24fFo bNM3EXNxbVhrqoh6Tj2Vj7z8G5Jj6T5+Xq/UyH7s73VIrdJrGuuMUWzXlzbJNhmkPpUU xo/eAgOj/ZogSZiJ+4RvpnsLkoiumPQKd2Wn6FTCNzJQ0T0PBY8+bSyB9D6a+iyRhREM kwZp5jge/8ytv4WBPRAfnBZNdEKs4CZczantBWY2hX+6+55u0nUiSxUACLXOUxPIg+r/ AHRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LTGvK+r9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id d5-20020a170902728500b001624d97d474si24633112pll.183.2022.06.07.22.42.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:42:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LTGvK+r9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EB6933C5016; Tue, 7 Jun 2022 22:12:30 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1387519AbiFHA0d (ORCPT + 99 others); Tue, 7 Jun 2022 20:26:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382135AbiFGWch (ORCPT ); Tue, 7 Jun 2022 18:32:37 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B9F35C65E; Tue, 7 Jun 2022 12:25:43 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E29FDB823CA; Tue, 7 Jun 2022 19:25:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45366C385A2; Tue, 7 Jun 2022 19:25:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629940; bh=9JoonTWpoek9ttj4ytgijLTdKPzH4Dk8tLw0vFaebRM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LTGvK+r9mt7cu0tdyia12j7VFV9fHo2D8ilipEZmpzsEKGHA4RYMJZU8FSHw6TO17 zq+Dzw5Lf4wGufPH94KrjjxL3Y/dVpO0wke300PEjwGMgGrq4Y7zs8amXZqMhhXuyd /nVYQRgOqPi5M4tHp4lA9CK6FwxJe5a4Hvm0tQSg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, linux-fsdevel@vger.kernel.org, Giuseppe Scrivano , Amir Goldstein , Christoph Hellwig , "Christian Brauner (Microsoft)" , Miklos Szeredi Subject: [PATCH 5.18 872/879] fs: add two trivial lookup helpers Date: Tue, 7 Jun 2022 19:06:30 +0200 Message-Id: <20220607165028.168664855@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christian Brauner commit 00675017e0aeba5305665c52ded4ddce6a4c0231 upstream. Similar to the addition of lookup_one() add a version of lookup_one_unlocked() and lookup_one_positive_unlocked() that take idmapped mounts into account. This is required to port overlay to support idmapped base layers. Cc: Tested-by: Giuseppe Scrivano Reviewed-by: Amir Goldstein Reviewed-by: Christoph Hellwig Signed-off-by: Christian Brauner (Microsoft) Signed-off-by: Miklos Szeredi Signed-off-by: Greg Kroah-Hartman --- fs/namei.c | 70 ++++++++++++++++++++++++++++++++++++++++++-------- include/linux/namei.h | 6 ++++ 2 files changed, 66 insertions(+), 10 deletions(-) --- a/fs/namei.c +++ b/fs/namei.c @@ -2768,7 +2768,8 @@ struct dentry *lookup_one(struct user_na EXPORT_SYMBOL(lookup_one); /** - * lookup_one_len_unlocked - filesystem helper to lookup single pathname component + * lookup_one_unlocked - filesystem helper to lookup single pathname component + * @mnt_userns: idmapping of the mount the lookup is performed from * @name: pathname component to lookup * @base: base directory to lookup from * @len: maximum length @len should be interpreted to @@ -2779,14 +2780,15 @@ EXPORT_SYMBOL(lookup_one); * Unlike lookup_one_len, it should be called without the parent * i_mutex held, and will take the i_mutex itself if necessary. */ -struct dentry *lookup_one_len_unlocked(const char *name, - struct dentry *base, int len) +struct dentry *lookup_one_unlocked(struct user_namespace *mnt_userns, + const char *name, struct dentry *base, + int len) { struct qstr this; int err; struct dentry *ret; - err = lookup_one_common(&init_user_ns, name, base, len, &this); + err = lookup_one_common(mnt_userns, name, base, len, &this); if (err) return ERR_PTR(err); @@ -2795,6 +2797,59 @@ struct dentry *lookup_one_len_unlocked(c ret = lookup_slow(&this, base, 0); return ret; } +EXPORT_SYMBOL(lookup_one_unlocked); + +/** + * lookup_one_positive_unlocked - filesystem helper to lookup single + * pathname component + * @mnt_userns: idmapping of the mount the lookup is performed from + * @name: pathname component to lookup + * @base: base directory to lookup from + * @len: maximum length @len should be interpreted to + * + * This helper will yield ERR_PTR(-ENOENT) on negatives. The helper returns + * known positive or ERR_PTR(). This is what most of the users want. + * + * Note that pinned negative with unlocked parent _can_ become positive at any + * time, so callers of lookup_one_unlocked() need to be very careful; pinned + * positives have >d_inode stable, so this one avoids such problems. + * + * Note that this routine is purely a helper for filesystem usage and should + * not be called by generic code. + * + * The helper should be called without i_mutex held. + */ +struct dentry *lookup_one_positive_unlocked(struct user_namespace *mnt_userns, + const char *name, + struct dentry *base, int len) +{ + struct dentry *ret = lookup_one_unlocked(mnt_userns, name, base, len); + + if (!IS_ERR(ret) && d_flags_negative(smp_load_acquire(&ret->d_flags))) { + dput(ret); + ret = ERR_PTR(-ENOENT); + } + return ret; +} +EXPORT_SYMBOL(lookup_one_positive_unlocked); + +/** + * lookup_one_len_unlocked - filesystem helper to lookup single pathname component + * @name: pathname component to lookup + * @base: base directory to lookup from + * @len: maximum length @len should be interpreted to + * + * Note that this routine is purely a helper for filesystem usage and should + * not be called by generic code. + * + * Unlike lookup_one_len, it should be called without the parent + * i_mutex held, and will take the i_mutex itself if necessary. + */ +struct dentry *lookup_one_len_unlocked(const char *name, + struct dentry *base, int len) +{ + return lookup_one_unlocked(&init_user_ns, name, base, len); +} EXPORT_SYMBOL(lookup_one_len_unlocked); /* @@ -2808,12 +2863,7 @@ EXPORT_SYMBOL(lookup_one_len_unlocked); struct dentry *lookup_positive_unlocked(const char *name, struct dentry *base, int len) { - struct dentry *ret = lookup_one_len_unlocked(name, base, len); - if (!IS_ERR(ret) && d_flags_negative(smp_load_acquire(&ret->d_flags))) { - dput(ret); - ret = ERR_PTR(-ENOENT); - } - return ret; + return lookup_one_positive_unlocked(&init_user_ns, name, base, len); } EXPORT_SYMBOL(lookup_positive_unlocked); --- a/include/linux/namei.h +++ b/include/linux/namei.h @@ -69,6 +69,12 @@ extern struct dentry *lookup_one_len(con extern struct dentry *lookup_one_len_unlocked(const char *, struct dentry *, int); extern struct dentry *lookup_positive_unlocked(const char *, struct dentry *, int); struct dentry *lookup_one(struct user_namespace *, const char *, struct dentry *, int); +struct dentry *lookup_one_unlocked(struct user_namespace *mnt_userns, + const char *name, struct dentry *base, + int len); +struct dentry *lookup_one_positive_unlocked(struct user_namespace *mnt_userns, + const char *name, + struct dentry *base, int len); extern int follow_down_one(struct path *); extern int follow_down(struct path *);