From patchwork Wed Sep 1 17:51:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 12470017 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C4E2C432BE for ; Wed, 1 Sep 2021 17:51:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 766E96109E for ; Wed, 1 Sep 2021 17:51:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344648AbhIARwy (ORCPT ); Wed, 1 Sep 2021 13:52:54 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:19754 "EHLO mx0b-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236804AbhIARwt (ORCPT ); Wed, 1 Sep 2021 13:52:49 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 181HOLR5016764; Wed, 1 Sep 2021 17:51:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=mrZPNwyb9BbCdc/OdJI+hLneeob28IHL3mwzE/kTTyU=; b=nsrbDTCk10kpdgLTONK7RxficCJFb41epvZUqz74WQUIiBx9+STHJJL0BLruueFQB0vl IbqaqN/q619Fi3o6E5mfSx2JgLoqK68Ap7pG+OcToi9PZJp0R/0Omh3X0ekozQhKtGrh 3HYHcnoq8Rful3/h8ZWGQvBIRzYgrrpDly01ACVksp3lB9zUrE0IrIM1lBNepklzPN+M YLw6qbpj9ANyAMz170Ol6FeEpa8Qkm4Lr/+vNEVrxHcMlbwUI/X+nakUASdYqn9cwEiM dhAQ4GK54QVohp+KTXsvaXZ4sj3W54JDFkqMlmIeAEQSiabxrUlpIimA18PuCJgjoSBI dA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=mrZPNwyb9BbCdc/OdJI+hLneeob28IHL3mwzE/kTTyU=; b=UAbzgQrDe7UgnA46NjVbip0cuK1bDCCA3fhZYvhVfaH922uNwrqGkENyY1ygBOTwLKF8 oaCz3/c0JL1wN/US/sR62XxDvo9XFmT/Oauuzq7C4ed1n8uBGi/b7HBWHcMiU+DyXrES Gwb0M47p7Dhuz2eO+0+s71LK6mgEftsCLjjB0OaCJqSqHj1dxw5N0/yAUcVQMgMexFl4 9QcXGQ4qgrZsNU9t8pAnnkI+DyQz0RkGA48y0pTlC2UQ7AamogTVxe6pQtnMnQumCoZx EHDYsLP+RBe+MYUYVKiNk/7s9ploxIRC27zsGFiAGHZBOqTUFqzMqEqLir5Ygw7lqVz/ 1A== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3atdw0g2jd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 01 Sep 2021 17:51:50 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 181HpfKD183043; Wed, 1 Sep 2021 17:51:50 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2101.outbound.protection.outlook.com [104.47.70.101]) by aserp3020.oracle.com with ESMTP id 3atdyu8u1t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 01 Sep 2021 17:51:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CelVXOwqIs7nrJYXXqZsIZou3aPi3SIwSNDqXaO876aPUHlOxBQK8YtbkR1YLKzeHmbpiIjfZ9/Vw2F5XpoeXWOVhPROM6dkqixP6RdELPt71A6eGC2FtYIk3R637Aa+6MSYnhpY/mneMsCio9Eey3N+KumJGEf9ZJ/ooV/5FOG1FbW9c+ANMJkc8GiwRTTwnosGEo3/nexPecc2kngA1DLCjwEODy/EJqPa1msP0RgujHq69vhU375l+nCGMYHGEThjbrrBNUAExRaPdoC2sIN14TWgSTWJfqUJLCXK3SJA/975ZmeVWv8f9s546MH0Y7fPozD6/kaeelQPAZBW7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mrZPNwyb9BbCdc/OdJI+hLneeob28IHL3mwzE/kTTyU=; b=A71bl+ShVrzSiuEZVrCqCkTW9opU9QRBCQxFbUYfWthrhN4pqOKbZN+Fst5/Mjj7NmZEJGxPOeCnieXgtkNu+dqbLUGJrfwc1ku51DNk1lMfIhsiDSryL4I0vwYdY188/cvhxeiYivoT0WOp9asiEBH6v9jo3sqLoyBV4iWoGMbb4wZ8uWu7EMCfTcYAsayETl5srMtTzTzzTmOkJSfrj9WI72hDzxm0f+ZjUdiR6L7U1RiBm0uGEdVa9JQI2qm+z+RRAK3Ft2gm+/UrGZVXpLkSJxsj1qSuOTnCJlkr9YrCHrMf7OFamiyAS6JGn6E4+xf41rLMrREtBD/wXSC+wQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mrZPNwyb9BbCdc/OdJI+hLneeob28IHL3mwzE/kTTyU=; b=AvLgn7FMLu1BRayPS5+9UJ/a4yERN002aYylKXqBSBCqSrlzW/4e5EoytSKs7HqtZsppW08dIyYbcWw7VnTPa0frh7CgOzoGA8OfEjkSLrYFtFHywoE6ZkKas55+EMi9BESXtU2VW2fBFdyENWs6hi6zgDTCIt/20pFwVK7wCfo= Authentication-Results: zeniv.linux.org.uk; dkim=none (message not signed) header.d=none;zeniv.linux.org.uk; dmarc=none action=none header.from=oracle.com; Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by CH2PR10MB3863.namprd10.prod.outlook.com (2603:10b6:610:c::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.23; Wed, 1 Sep 2021 17:51:47 +0000 Received: from CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::2c22:7eb8:a2f0:e027]) by CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::2c22:7eb8:a2f0:e027%7]) with mapi id 15.20.4457.025; Wed, 1 Sep 2021 17:51:47 +0000 From: Stephen Brennan To: Alexander Viro , Jens Axboe , Dmitry Kadashev Cc: Stephen Brennan , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] namei: Fix use after free in kern_path_locked Date: Wed, 1 Sep 2021 10:51:41 -0700 Message-Id: <20210901175144.121048-2-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210901175144.121048-1-stephen.s.brennan@oracle.com> References: <20210901175144.121048-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: SJ0PR05CA0140.namprd05.prod.outlook.com (2603:10b6:a03:33d::25) To CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (148.87.23.10) by SJ0PR05CA0140.namprd05.prod.outlook.com (2603:10b6:a03:33d::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.4 via Frontend Transport; Wed, 1 Sep 2021 17:51:47 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a4f2bed7-7bdc-4e28-8b2e-08d96d712b4b X-MS-TrafficTypeDiagnostic: CH2PR10MB3863: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4303; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fnd1zrepxoV7FY96CCZSrshBfX1lUKXnMLqWvXC5MpzmT3bhZatoIniAJTMJDzBcBo1dNHTg5LqmIGsx0KgXpRfhOJ86romyI8cbPMQt0QPSf/b9nfVZnVW3IsaPvenyxy+/YGHaWlEg5nBnSNFGLWyPwyOeLXeoKuxVai2Ri6d9JSe2H2TE3p8pWN28mcoslBsz/i1qfwgmiiaK81oHgON6MK71qgDDBZMC32bJO5B8a/MFeJ5VMDwor3HKvDrc9LRK3TLBftpUWz6/AA9wDKwTxAITqO5sFdiaWSCWn9eixb6jucccZ9Jbr25RqraO3T8wA4EXf1gBq7mjOMrUCo3DH1x/HoBz+gvblVeF1JjDVCzOMZpp7rS4mXEeY/k+aTqWOCA7vIGhu7kMVQRvRamdxObESHF/F0riFHr9TfeFw4aeY/rVONCXXhP3i8BHk6JPZ3wFKwIQdBXCqFuISrESoJcyYFtOAy8jg8MgYY+bCJbqKNIi6OPB0dL+jTb0od66n986YHUjbwMaO+Eb6GlDAC6jQypucdvPYE3yfx+afo+vVSNLUY3Q9V9hcBYuw8zBTZLF0+VAJAl2W91P82kASONoKo4cTNyGDKoAiCYA/APuLXRTFIE8Ufr+4yDU4wp9p9+EBy9VXssKXeeTGZvreSVj3yVpB7aJOOOxmT8WN+xOEu4VrLKQxdsaSdx3KTCaeBQvNWHaBh7o5JBQrkfLVjt/zSw0vH6PXKeS8BGR74o48utYk1vwiJN+ZP1WLzpaZK9CvNoCw363kT9JslJ1qOBhC9bsGZ+TYpJPl7CejTPxvr9ZBNbYDqd0VND+tAODEkTTGVkZlflWIcmyZxYZdZv7hK0/oSIrYEFTJpDpeWlxt6LuvGwcNGgC05tfkPI8NUiwn4x8hffIJvV1AmkqGVcn9tMs5E0YQWjvAXzDFAIMDS0CfRyszSBw7h396vpDazdOhcuL6hji0E/FNcmQe7ZzfW4kufgHV9z+jHxZlydjAZS2r9aRHqB+ucQUd+yjzPd7uaqw/Gf/Mcz2pieC8LwycuJbb53pstLNYM51/q9UsLm8bMnLiXmojSS5gVCmN5PoxzD913GcyzHwZnKpdP1qY8bHNC4C3LWfm3fdSXQC5gQ0WsCjc4GwH9XlKqguP3HgD7WR6kDbbUdzQA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:5;SRV:;IPV:NLI;SFV:SPM;H:CH2PR10MB4166.namprd10.prod.outlook.com;PTR:;CAT:OSPM;SFS:(39860400002)(136003)(376002)(346002)(366004)(396003)(5660300002)(316002)(4326008)(38350700002)(38100700002)(6486002)(66946007)(66476007)(110136005)(66556008)(83380400001)(86362001)(8936002)(478600001)(36756003)(103116003)(8676002)(6666004)(6496006)(2906002)(52116002)(2616005)(956004)(966005)(26005)(1076003)(186003)(23200700001);DIR:OUT;SFP:1501; X-MS-Exchange-AntiSpam-Message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Dp8GeH5BpSG83omJHJNES97f3nkt9mgepf0nGqtn5Q/YaPDz+OREsp2LAFAjm+kMHF5GWWCR+Jn1ANz1XI67RqXFMn9njefDlrNTjwwwbiACdW/AV5q/chGYzHcOn3R4Pfmo5RRcU0xsXVPDDTMD7kooGZpJ2pYVQaxFUAExGZdV80a1VQRhDZBxbLeaPsqyZHrd8GktpYDeQxuylu67wR3bexRG/YjzLV4iuN6oV6Rjz+7ZHaLOcknvyM5BjJ9BkJbX2rAEE0mbxX6vTLGxvfVIHG07aL8lD0iaecBS2MB/NnXeaO8xe9ud4ueB5AGrOAmL X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: a4f2bed7-7bdc-4e28-8b2e-08d96d712b4b X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4166.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2021 17:51:47.6889 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: qFkR5H0pc68KENW57OmAuxBvVK/Ju0f+hXTS5eRjMA8CygCpb7Z9znHdiTv4GVGYMvB7wWEzQpeKZ++FhMHngrJYbZX0IMf92fb5ODJiO8Q= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR10MB3863 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10094 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 bulkscore=0 suspectscore=0 phishscore=0 adultscore=0 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2108310000 definitions=main-2109010102 X-Proofpoint-GUID: p7dpRHDQA3L0qtWHM6lwwlMLZ1AuFIHq X-Proofpoint-ORIG-GUID: p7dpRHDQA3L0qtWHM6lwwlMLZ1AuFIHq Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org In 0ee50b47532a ("namei: change filename_parentat() calling conventions"), filename_parentat() was made to always call putname() on the filename before returning, and kern_path_locked() was migrated to this calling convention. However, kern_path_locked() uses the "last" parameter to lookup and potentially create a new dentry. The last parameter contains the last component of the path and points within the filename, which was recently freed at the end of filename_parentat(). Thus, when kern_path_locked() calls __lookup_hash(), it is using the filename after it has already been freed. In this case, filename_parentat() is fundamentally broken due to this use after free. So, remove it, and rename __filename_parentat to filename_parentat, migrating all callers. Adjust kern_path_locked to put the filename once all users are done with it. Fixes: 0ee50b47532a ("namei: change filename_parentat() calling conventions") Link: https://lore.kernel.org/linux-fsdevel/YS9D4AlEsaCxLFV0@infradead.org/ Link: https://lore.kernel.org/linux-fsdevel/YS+csMTV2tTXKg3s@zeniv-ca.linux.org.uk/ Cc: Christoph Hellwig Cc: Al Viro Reported-by: syzbot+fb0d60a179096e8c2731@syzkaller.appspotmail.com Signed-off-by: Stephen Brennan Co-authored-by: Dmitry Kadashev --- fs/namei.c | 47 ++++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index d049d3972695..f2af301cc79f 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -2514,9 +2514,10 @@ static int path_parentat(struct nameidata *nd, unsigned flags, return err; } -static int __filename_parentat(int dfd, struct filename *name, - unsigned int flags, struct path *parent, - struct qstr *last, int *type) +/* Note: this does not consume "name" */ +static int filename_parentat(int dfd, struct filename *name, + unsigned int flags, struct path *parent, + struct qstr *last, int *type) { int retval; struct nameidata nd; @@ -2538,30 +2539,24 @@ static int __filename_parentat(int dfd, struct filename *name, return retval; } -static int filename_parentat(int dfd, struct filename *name, - unsigned int flags, struct path *parent, - struct qstr *last, int *type) -{ - int retval = __filename_parentat(dfd, name, flags, parent, last, type); - - putname(name); - return retval; -} - /* does lookup, returns the object with parent locked */ struct dentry *kern_path_locked(const char *name, struct path *path) { + struct filename *filename; struct dentry *d; struct qstr last; int type, error; - error = filename_parentat(AT_FDCWD, getname_kernel(name), 0, path, - &last, &type); - if (error) - return ERR_PTR(error); + filename = getname_kernel(name); + error = filename_parentat(AT_FDCWD, filename, 0, path, &last, &type); + if (error) { + d = ERR_PTR(error); + goto out; + } if (unlikely(type != LAST_NORM)) { path_put(path); - return ERR_PTR(-EINVAL); + d = ERR_PTR(-EINVAL); + goto out; } inode_lock_nested(path->dentry->d_inode, I_MUTEX_PARENT); d = __lookup_hash(&last, path->dentry, 0); @@ -2569,6 +2564,8 @@ struct dentry *kern_path_locked(const char *name, struct path *path) inode_unlock(path->dentry->d_inode); path_put(path); } +out: + putname(filename); return d; } @@ -3634,7 +3631,7 @@ static struct dentry *__filename_create(int dfd, struct filename *name, */ lookup_flags &= LOOKUP_REVAL; - error = __filename_parentat(dfd, name, lookup_flags, path, &last, &type); + error = filename_parentat(dfd, name, lookup_flags, path, &last, &type); if (error) return ERR_PTR(error); @@ -3996,7 +3993,7 @@ int do_rmdir(int dfd, struct filename *name) int type; unsigned int lookup_flags = 0; retry: - error = __filename_parentat(dfd, name, lookup_flags, &path, &last, &type); + error = filename_parentat(dfd, name, lookup_flags, &path, &last, &type); if (error) goto exit1; @@ -4135,7 +4132,7 @@ int do_unlinkat(int dfd, struct filename *name) struct inode *delegated_inode = NULL; unsigned int lookup_flags = 0; retry: - error = __filename_parentat(dfd, name, lookup_flags, &path, &last, &type); + error = filename_parentat(dfd, name, lookup_flags, &path, &last, &type); if (error) goto exit1; @@ -4683,13 +4680,13 @@ int do_renameat2(int olddfd, struct filename *from, int newdfd, target_flags = 0; retry: - error = __filename_parentat(olddfd, from, lookup_flags, &old_path, - &old_last, &old_type); + error = filename_parentat(olddfd, from, lookup_flags, &old_path, + &old_last, &old_type); if (error) goto put_names; - error = __filename_parentat(newdfd, to, lookup_flags, &new_path, &new_last, - &new_type); + error = filename_parentat(newdfd, to, lookup_flags, &new_path, &new_last, + &new_type); if (error) goto exit1; From patchwork Wed Sep 1 17:51:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 12470019 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B47CCC4320A for ; Wed, 1 Sep 2021 17:51:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B55A6109E for ; Wed, 1 Sep 2021 17:51:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344758AbhIARwz (ORCPT ); Wed, 1 Sep 2021 13:52:55 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:24692 "EHLO mx0b-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232026AbhIARww (ORCPT ); Wed, 1 Sep 2021 13:52:52 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 181HOL7c016767; Wed, 1 Sep 2021 17:51:54 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=tvz8+mSx/6hAxHUxDTynb8tn5ymhX7NY1MEMEv78HNI=; b=TcYARtR6dRKwdlC93SfMD8uhUjDIdz/ihLgetWVsZVaf19lxSL02z8CxpAMSs0Jw79Uv SqxrjHFWm/1WtTkFYVn5bfXUJHl3aPbTC+lebdLHzCaL/BWEjGT3iryUQhDJ82TWHFA1 TippdbktT9asf58IZKCwOEh7mHmrxxCR4m/Gzuy9yXZinkuGHtzoqrXrYSG+tHkWLxGd lkMR4xEWtGh/97GC3PsTbttXk5E8EEDtEBda2v8atC3XiYGbWZqY4riPiX9BP6lhjeP9 v2ibZ1fzebURg60mB46Rq+G+4VXRX93rOQAuVxfD593PUFqMVI70Mj3OXSYWTTmXrApg Yg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=tvz8+mSx/6hAxHUxDTynb8tn5ymhX7NY1MEMEv78HNI=; b=vdRWX1UVId+vqgRv490cZlFSDAPwXCj8DnpWCLKBHi+Me2Xp8Yiy6Eb5ex8B4bcKpv0+ k4+kLhRBWTzVw27vHXp6JQJBF0ezwDW/fCumfUhWnf91in4IE8MuX3ziNWW6ncnhM/+a 65eZSrcZ2F9uuqf/eqoJtglHk3F/X0i671mTnHY+D6EN+nIDKn2kESLXrQMyNA8c6Uxh AJV/kiX8ZFdEpAudT/b0/ZCxXKeAfBtfrLjuJzwDU2UtX1msAOupRNAXSpIx2X96mtBe aIyDT8g9JN6B+Y289r8QDJT/WuwTwdNdrnrZ8nvm6PmIywTs7ce8DXMeF4Trs9gMrHKb zQ== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3atdw0g2jn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 01 Sep 2021 17:51:54 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 181HnlEW128378; Wed, 1 Sep 2021 17:51:53 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2108.outbound.protection.outlook.com [104.47.70.108]) by aserp3030.oracle.com with ESMTP id 3atdyvrttb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 01 Sep 2021 17:51:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RxngmESI2Gp5vKI4AKS2QaW2vEnVu0cqj/uFAgkuruNNlzlMKw0B4QPfyb5CNlHDMXNjnse/4cA6LwL+9o5DWmXGgXfAjwFvBAqgLoKLROTumlpBrU0JyCSzugIn57FTct7sXYdQHVZ60fookYWQ0ltBhJs5R6xwLDim5XIp3h2IE0aRuBm3Y4yJ+qJlvIQiMHhXJid7wKTTkBXqrScRuIm2J9BMKD3RTaGbimFYTP05V1eHaIXUWkCDHIBok71nG6d2K13BPxFTDM0NI7vD+WKbKxiS3ouSVl4X80ti9JdqVnynm4tRCn/1ZmaUOnKNtAcEwGgea51ndNEdWWLURw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tvz8+mSx/6hAxHUxDTynb8tn5ymhX7NY1MEMEv78HNI=; b=ZOB00Ef6GcnI9TXI0stMC9zwntP8HaaTa6B82pXd6C75KpmwHAyWXvFs8Dgq43Q5zm+rIr/h9VBQqiaWHPc0OX9sRpUP8Id9ZLiyE+xq/ydEoflgw0cmXd2Lp0b+eSvUN55xUCNokq7g6aPL7WZchL/s2c7Gj9vx40C/zKwyKw3fO5jYJDEGYEQIg7reBwEQn+7JdiJCtos7HHrhxwmzJvfqDvuOiRGwdhgR7lccDndpVzgMe9H9/mAJerk7Lk58MoacRyITSjXFbYn1WjqihXZesIhNMT+jKZ3nH04n0TRfs4tkLm+rRFBShBMDuqH1KIYQs37ffoyIzhY4po6NWw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tvz8+mSx/6hAxHUxDTynb8tn5ymhX7NY1MEMEv78HNI=; b=uECNtMeCmnb2MAuR63yo55jETOe+Y00beB+76zYyk3AKQMgKPYnL0X3K2VRJMaQJZFPpzwZspimw0Cboloy512HmATcyVPqqaAuoRzDitr8p+GEWG3KX5IkWrpMM1PBKhW0vNQReBC09Mza/LvDd83okYJMnPDGuss8fkzV4llo= Authentication-Results: zeniv.linux.org.uk; dkim=none (message not signed) header.d=none;zeniv.linux.org.uk; dmarc=none action=none header.from=oracle.com; Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by CH2PR10MB3863.namprd10.prod.outlook.com (2603:10b6:610:c::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.23; Wed, 1 Sep 2021 17:51:51 +0000 Received: from CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::2c22:7eb8:a2f0:e027]) by CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::2c22:7eb8:a2f0:e027%7]) with mapi id 15.20.4457.025; Wed, 1 Sep 2021 17:51:50 +0000 From: Stephen Brennan To: Alexander Viro Cc: Stephen Brennan , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] namei: Standardize callers of filename_lookup() Date: Wed, 1 Sep 2021 10:51:42 -0700 Message-Id: <20210901175144.121048-3-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210901175144.121048-1-stephen.s.brennan@oracle.com> References: <20210901175144.121048-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: SJ0PR05CA0131.namprd05.prod.outlook.com (2603:10b6:a03:33d::16) To CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (148.87.23.10) by SJ0PR05CA0131.namprd05.prod.outlook.com (2603:10b6:a03:33d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.11 via Frontend Transport; Wed, 1 Sep 2021 17:51:50 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0e585880-2035-432d-5dbd-08d96d712d3f X-MS-TrafficTypeDiagnostic: CH2PR10MB3863: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3968; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8unfbx/Tg6vStpT2nT6UqK/0dnbYoAKfBjnxPEWylze6EahTMcGOhIBlNkf+UMfIqSB5BP234z33B2E7kHKz9c9j1syGS/xpjGRGnYPLfsJrjIn5V9LL7Qs630mLYiRukY2+KJOIthBypNE8Skd6uTrIWZKrZ1V/6biwNfWpVZugCOkT1Kd/vWW62R7AsRB1trq0JQ72lVjUjfuIXjc/OILoHrLv4iKUvmqH+2uebmRhOOm1kTzLnZYn2mk5yNe3FADc/EGU92V56yGLdEmFndo0ypOxuaUV2XRbdTQtp8mtMg+VEQnihBNlVfZoreb3p4jdn4lbAJXNJneiky2idQdp7/vO11nYIIm3f0yay4cmUNGXkV+j1Gwss146Z7XJ/o1Ykqg3DZOiBxngpKlciBEaceh1Dm+J+Mn3FqeGQxVLQgLNdXrDhWToD3hVWBMusPXb/KtX3RBpOPLVDojXox+r084Faoboz5Nw7Ofhr2HnirDVyhADpQP0XPS+OUS8DWNyh0Pa1xUguiRoGaQp0InRc5sbUTzUE+QJjrpDXFd9RMwOvdK1Lys0tjsozf6zs3dQ5ER9i/QO2Mh9kd/iTMP/xJ5oJEvKhug+OAdvobanQy/AeKmp0xD9tYjGbd9SuO8YCknau5udK/aywS5zsAnCGKftM1pyU3q5SPJmZ0Dwrim1j07TW7zuzveCif+lIysEdzhsVwRYfJukzZNa+5g6rU8FUxxPgupGgVwPseVTxhgPhMwVIMJ6i4KNXIr06hTNpLUfriAcHnhD6bJMlQ1R6b2Z97+/BCT7ASHLbleljNZ++4NYEtyjQr9kmg9BN80ATwJwZHN6d+TGin4LuhlgC/+CrjL4iNRL7YLmOszOQ+vgNsdeU171E9ijeQNFKcM6XkhwGD48TB57vSKMU6vos6FMC6xv2Hfm9MhzDSCBVx0i5BTrI2DXIBJlCRTd0beD/BIGzdCIrznpVa1fjX2ODnOHimMjvOXLFUNn9x1ebKlaq6tICxhvRJbzL1IU3gb0EMe35boeSh/U+KvZ4PiV0uvZX06bUirFcQES7rwkZhsAPW2tb9eQBzeVxVE4a++iPSszieMtyNCk+TL2jsUYQWNeVOzYq7oAup61k8g= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:5;SRV:;IPV:NLI;SFV:SPM;H:CH2PR10MB4166.namprd10.prod.outlook.com;PTR:;CAT:OSPM;SFS:(39860400002)(136003)(376002)(346002)(366004)(396003)(5660300002)(316002)(4326008)(38350700002)(38100700002)(6486002)(66946007)(66476007)(66556008)(83380400001)(86362001)(8936002)(478600001)(36756003)(103116003)(8676002)(6666004)(6496006)(2906002)(52116002)(2616005)(956004)(966005)(26005)(1076003)(186003)(6916009)(23200700001);DIR:OUT;SFP:1501; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 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OgZWMZ3Iuh3XoV4clL5FqtAn/zR66qYjqn0Bj7ocajwg/fRJffHvD0BbinK38ZM4LGb+HRaOjWyz0j+qe65nNKQ2+GmtUfR907xQQN7SnNyjWIaTXzpY4zEV0mck2h6eEak/O254twMLiK6iSeSa9zbMqdzmx+97MwM7lJ/7PglIiRC10CMp7TzmPgXr7zFf1Ndv2lOBuYCViVGw/KUAKjBRL3JWK9sb2b51IAe+pD6ng03tDetMIIBB3U67q02PhRzVlFgcOyNTRXaz X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0e585880-2035-432d-5dbd-08d96d712d3f X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4166.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2021 17:51:50.9108 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: uMEqJlN1+ay8OyIkKFJxfM7q99oRMJDa6tjzI/QXSjjkkX8hVguZbVs6hnK2ybGW2K0QK+CPl/HXw1mqc4mEk3Oq3ifLlWND/C2P6NudLCc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR10MB3863 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10094 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 phishscore=0 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2108310000 definitions=main-2109010102 X-Proofpoint-GUID: ErR0MIJ2nm1L5iDevcl87oEb5oeeK_Fz X-Proofpoint-ORIG-GUID: ErR0MIJ2nm1L5iDevcl87oEb5oeeK_Fz Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org filename_lookup() has two variants, one which drops the caller's reference to filename (filename_lookup), and one which does not (__filename_lookup). This can be confusing as it's unusual to drop a caller's reference. Remove filename_lookup, rename __filename_lookup to filename_lookup, and convert all callers. The cost is a few slightly longer functions, but the clarity is greater. Link: https://lore.kernel.org/linux-fsdevel/YS+dstZ3xfcLxhoB@zeniv-ca.linux.org.uk/ Cc: Christoph Hellwig Cc: Al Viro Signed-off-by: Stephen Brennan --- fs/fs_parser.c | 1 - fs/namei.c | 41 ++++++++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/fs/fs_parser.c b/fs/fs_parser.c index 980d44fd3a36..3df07c0e32b3 100644 --- a/fs/fs_parser.c +++ b/fs/fs_parser.c @@ -165,7 +165,6 @@ int fs_lookup_param(struct fs_context *fc, return invalf(fc, "%s: not usable as path", param->key); } - f->refcnt++; /* filename_lookup() drops our ref. */ ret = filename_lookup(param->dirfd, f, flags, _path, NULL); if (ret < 0) { errorf(fc, "%s: Lookup failure for '%s'", param->key, f->name); diff --git a/fs/namei.c b/fs/namei.c index f2af301cc79f..76871b7f127a 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -2467,7 +2467,7 @@ static int path_lookupat(struct nameidata *nd, unsigned flags, struct path *path return err; } -static int __filename_lookup(int dfd, struct filename *name, unsigned flags, +int filename_lookup(int dfd, struct filename *name, unsigned flags, struct path *path, struct path *root) { int retval; @@ -2488,15 +2488,6 @@ static int __filename_lookup(int dfd, struct filename *name, unsigned flags, return retval; } -int filename_lookup(int dfd, struct filename *name, unsigned flags, - struct path *path, struct path *root) -{ - int retval = __filename_lookup(dfd, name, flags, path, root); - - putname(name); - return retval; -} - /* Returns 0 and nd will be valid on success; Retuns error, otherwise. */ static int path_parentat(struct nameidata *nd, unsigned flags, struct path *parent) @@ -2571,8 +2562,14 @@ struct dentry *kern_path_locked(const char *name, struct path *path) int kern_path(const char *name, unsigned int flags, struct path *path) { - return filename_lookup(AT_FDCWD, getname_kernel(name), - flags, path, NULL); + struct filename *filename; + int ret; + + filename = getname_kernel(name); + ret = filename_lookup(AT_FDCWD, filename, flags, path, NULL); + putname(filename); + return ret; + } EXPORT_SYMBOL(kern_path); @@ -2588,10 +2585,15 @@ int vfs_path_lookup(struct dentry *dentry, struct vfsmount *mnt, const char *name, unsigned int flags, struct path *path) { + struct filename *filename; struct path root = {.mnt = mnt, .dentry = dentry}; + int ret; + + filename = getname_kernel(name); /* the first argument of filename_lookup() is ignored with root */ - return filename_lookup(AT_FDCWD, getname_kernel(name), - flags , path, &root); + ret = filename_lookup(AT_FDCWD, filename, flags, path, &root); + putname(filename); + return ret; } EXPORT_SYMBOL(vfs_path_lookup); @@ -2795,8 +2797,13 @@ int path_pts(struct path *path) int user_path_at_empty(int dfd, const char __user *name, unsigned flags, struct path *path, int *empty) { - return filename_lookup(dfd, getname_flags(name, flags, empty), - flags, path, NULL); + struct filename *filename; + int ret; + + filename = getname_flags(name, flags, empty); + ret = filename_lookup(dfd, filename, flags, path, NULL); + putname(filename); + return ret; } EXPORT_SYMBOL(user_path_at_empty); @@ -4421,7 +4428,7 @@ int do_linkat(int olddfd, struct filename *old, int newdfd, if (flags & AT_SYMLINK_FOLLOW) how |= LOOKUP_FOLLOW; retry: - error = __filename_lookup(olddfd, old, how, &old_path, NULL); + error = filename_lookup(olddfd, old, how, &old_path, NULL); if (error) goto out_putnames; From patchwork Wed Sep 1 17:51:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 12470021 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC70BC432BE for ; Wed, 1 Sep 2021 17:52:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B8A761075 for ; Wed, 1 Sep 2021 17:52:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346685AbhIARw5 (ORCPT ); Wed, 1 Sep 2021 13:52:57 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:28894 "EHLO mx0b-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236638AbhIARwy (ORCPT ); Wed, 1 Sep 2021 13:52:54 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 181HOKQX029706; Wed, 1 Sep 2021 17:51:56 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=zxrFHpHF7LiR92IiMd/PWlK5eA8W7tvPkk2kyekehR8=; b=hGkP8ImQXH/OQXhpH/rp3YOl6HX2hI0xNacWOhL4bkjI4kZ0xNPlpn1KMexN934sSDYD qRtu35GpK5QaesjJ4M1o/Ed1pyQnv+HFTvPaWfSHT4qNN6GlDH1upfQjK9sedoqSYJl8 CAbevciVIFlTLkD4GR6g96k1lEhacVzK3xqZw1DwzlXFliJdeWL90FBcd2m/r9TUo/aw 1H7XHjjgRXg8R2CPdtsrNa+wFUOmKEUwsYMDpPJpGoWFCGe/eWsnv9LD47hxK0Hm6JaH onVa6KCWut87Ve1hJedfpqWcHH1UjR86jaKNhKiHkhoP1B1/7uZl8H51gNUlprmxw3Fw eg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=zxrFHpHF7LiR92IiMd/PWlK5eA8W7tvPkk2kyekehR8=; b=cn8xC7qHch1e/FKFsihYi5DTv8UXf0jXDvp9dstjen8/d+UZ1dGP/SNX9NCWSm34FJqs axM0eBu2YlRkRwGs8MIJWaUtlsY7s63jJmlv0AyOliWQc8pAK/f2k1bB26yRlr3igi4l G0VwZ10TRwf25orASFQBusUV2ArM/LGfDlTMVsHRP8B6REFwlTqmoU5DBf671kRIViEC Cd2yH7jld8s85BV7pEqhaopCBxLSox95/zSDdRPFoYRh4aQ7QH6LhjWhaNErquQqDKUg dgq0enOJ/OXBpsUFgYkSEJ46VKUXed3jV2IE9hAtcJZXCj5/qX/l3lPkKYD61RNfJI96 0w== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3atdw002r4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 01 Sep 2021 17:51:56 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 181HoSwn136919; Wed, 1 Sep 2021 17:51:55 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2105.outbound.protection.outlook.com [104.47.70.105]) by userp3030.oracle.com with ESMTP id 3ate04gw2d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 01 Sep 2021 17:51:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cYDABBbpnqRAeQ0aO5UlOXZ0R9ZJLwSwPRiNYJOv5Bwm09K0RYGe4c7Qsm+UCYi4jX2KMlGy7dZA433MAU9BLqCoQphFF5X8dEsWsL2OKGx+hsqgi3pyzKkLyI1oTMtEyy4dHQXu+RtVGSQB9Zv4XQNOHQELPPfJvjDE5i2ovzoU21FTdjnZpsPDIRC2RFY5qxnEJi2SHldJAQ9hlZflVwZ7FGf5qCNbh9U5ScTYwpWWDzgbBevunya/v7/fBh0Fvs9hzyqu9wjyA4zzeydupS6v4pRmYxiS7qAJJjm/zhdzQXZJEgLbUgS7E+Xog9i02fGiHFJ6RVeF0APpaLK/ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zxrFHpHF7LiR92IiMd/PWlK5eA8W7tvPkk2kyekehR8=; b=VU9UtUC1FWmkC8awHjM5bvSwQBzPe/fXbrOPDfpKtP8hHFW/+QTA52z53fKxPPpQCGS6LPfwCFZumCxWsyoTC+DENA+AeRUEapv498z3q2JSA+72XeF1Z2cm7Ha7Ibb8ukjc3wusaO4jH97rTjvaIB7kRSktZMAfrzOXGe2kfBoCVyfnuIbrprv1/17As/15koHHn3aFXCvUG1nwpMyt3QGluyl5UiaJ1e7sQFzz0zbJHNR7Oq20QTveseNMGb/yQtIc+Mktc6QuJ9S8/tbLB9zSLy+6o2i44idcptDLvyfFlaDWhu8k5BP8tW4w1YiRpOiotIGZo1O3G/tA97x7dw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zxrFHpHF7LiR92IiMd/PWlK5eA8W7tvPkk2kyekehR8=; b=SKRuB/wJ6ktA5IQeoP1zqvcxFVrPrhWyqIhb8MD1imNtmXQ3MABPzRZ0TZ6R6P8oDyPqqMbKlGQNJF4OQ20w9F8EyvvdmgyiACKCTMWGUqeeHdksmfVCrNO7HZnVzk3Jih0z2RS8EefwZiHy0gRdhArCo6A5+k2m/uK7Eft+ca0= Authentication-Results: zeniv.linux.org.uk; dkim=none (message not signed) header.d=none;zeniv.linux.org.uk; dmarc=none action=none header.from=oracle.com; Received: from CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) by CH2PR10MB3863.namprd10.prod.outlook.com (2603:10b6:610:c::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.23; Wed, 1 Sep 2021 17:51:53 +0000 Received: from CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::2c22:7eb8:a2f0:e027]) by CH2PR10MB4166.namprd10.prod.outlook.com ([fe80::2c22:7eb8:a2f0:e027%7]) with mapi id 15.20.4457.025; Wed, 1 Sep 2021 17:51:53 +0000 From: Stephen Brennan To: Alexander Viro Cc: Stephen Brennan , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] namei: Standardize callers of filename_create() Date: Wed, 1 Sep 2021 10:51:43 -0700 Message-Id: <20210901175144.121048-4-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210901175144.121048-1-stephen.s.brennan@oracle.com> References: <20210901175144.121048-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: SJ0PR05CA0131.namprd05.prod.outlook.com (2603:10b6:a03:33d::16) To CH2PR10MB4166.namprd10.prod.outlook.com (2603:10b6:610:78::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (148.87.23.10) by SJ0PR05CA0131.namprd05.prod.outlook.com (2603:10b6:a03:33d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.11 via Frontend Transport; Wed, 1 Sep 2021 17:51:52 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 964e92a3-708a-40ea-6daf-08d96d712e88 X-MS-TrafficTypeDiagnostic: CH2PR10MB3863: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kxTOOXJC+jHAoQdjNCznukv30BZUayfwMIJ9EUu4z1p9/uyhAl5fScZfi8ACpPHe08j0Y7F/9bb35C4GApk5ekdeIDGdFNg6aAsSfvnOzfJKCa2B7R/N2cWTAjYmju/qSlqgW2+SyV3zPDxKYlp/IIRFMkbv1sq2WcpLdWWwTvn1Q0jetgjnaUuDa9SwhWmX/BzE1j+mFQpKs5eHfIVB2tN6MW5v9QXQ1Rhut+9qsvNIZYXi77Uly8nSslpp/0SgQU8YgE3544kcTOn8q3O9xpeXvgm/eRtE/U6C7aWCicgGkv5JcDtwXnS0SaC3qslGqEBriPTBeD0/hpSoMi3F35DPJ1j8nsWpjIJ1XdsYJyCvIwiKyanOuQQQkufUd1LfdlqEhQ+4YccsvaXGsuzxTeKNIvCykHot0qXVsu6l5SacYMM5RD8/gKFBSG60DzvkPbrB9r4plG20T+4gs/4epe0Lt937NS5spKCiI1GDe3rx7qgrqhmPIF7A4ddunsJ268no75Lv7kcP7LTshx2KpdiHivXQ8DYszjYjiRdJRC43m8qsrHt5GPjk3VFYDqreTl4TpSwFbptuHtto2zTvr4M1iYJOffGrfOpHstgRnX7ZZg4vxKgqnhJ2Tg3pJ3B4VhtgvjgqkUrfeGBSaRHyyvKIcKhfNH/W9MhGiisCHrrWKqCwfX0b7GfdlWfFBK1q1NhpW+lhUwx7CabaEyWXtOwJm5tcZ+nNOuUB4D3RF8K8YK2hxeA/zmaXo6686j8pNW0xSg6LspBmvCgz760TzMyFzvaH6XR/+dSPVU2QoV4b9vE2fDpl242oonDj+j4HdsqQ8UuIV00J9g7mvgZG4urF39/et1GMPTeA2nze3zxeBPVCi1PaQTd+lZc8LPUrwkQBLUbRZhk+cX89fKmadl95e5a0wmBbbyG63wWG0m4JM66yhAp+baPTrLXrQzva+E/SgEo5bxuS2EiTP7wLlaVwgRmmZWmPqbj26P3IOgXr7ehsbyMeQ3zIxuu1YpPGj1aZsW2TK756V0LzVq5gRG0DhY6wIkp6rI/09e1GSBLicp8u0qELzT4YTUTp2WwUL3hyC2jyIaLcXnTtPcxDoRu+hwemnjsNjBRR5u9leZ8= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:5;SRV:;IPV:NLI;SFV:SPM;H:CH2PR10MB4166.namprd10.prod.outlook.com;PTR:;CAT:OSPM;SFS:(39860400002)(136003)(376002)(346002)(366004)(396003)(5660300002)(316002)(4326008)(38350700002)(38100700002)(6486002)(66946007)(66476007)(66556008)(83380400001)(86362001)(8936002)(478600001)(36756003)(103116003)(8676002)(6666004)(6496006)(2906002)(52116002)(2616005)(956004)(966005)(26005)(1076003)(186003)(6916009)(23200700001);DIR:OUT;SFP:1501; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: KZ+6rWxY2/i8wyoeiN4sYd4LpmXocBRkvbi7h+OF8uV+ZlZ5OB/CqhTJBU9omal49FAgOuy8wggbMqXC/RXMeJ02o1wVHM4ddVaa/1Yfr7aOGHHc+JVPJppML7o1yWWqGEWIM22LefP0DEqxzKn7Tjbf+bU9APHdHJH2m/1qzLyZbMM8g81ivD2PY6w4cueqhid8wcmSGyszJlCx+wSv4+9hWf30lUgCBFxXmJ/L1ta2NrjYkApAYpLZ4MQvYyodXLdmejP8NejX8P8iKV/wsQhgr00aQLKyMgUIb0YCFKlIHRU9Nd4ndtobBTjp9ivO6YALrsCK3FRbhYO43z27+Y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712e88 X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4166.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2021 17:51:53.0633 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: bhz6gIShadBeuEB6gssvwJcf5NboSpyeB2Sk2GcXq6goPI2lWDVOmEOOyAWV0DVL1rgWRfixuqA8m0H+6g1QPsYSkNvHLcZNWVJ6PLcKnFs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR10MB3863 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10094 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 adultscore=0 mlxscore=0 phishscore=0 malwarescore=0 suspectscore=0 bulkscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2108310000 definitions=main-2109010102 X-Proofpoint-GUID: CRkRZ3JYqlNKmo34u3UsE6Yrebli5Lrd X-Proofpoint-ORIG-GUID: CRkRZ3JYqlNKmo34u3UsE6Yrebli5Lrd Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org filename_create() has two variants, one which drops the caller's reference to filename (filename_create) and one which does not (__filename_create). This can be confusing as it's unusual to drop a caller's reference. Remove filename_create, rename __filename_create to filename_create, and convert all callers. Link: https://lore.kernel.org/linux-fsdevel/f6238254-35bd-7e97-5b27-21050c745874@oracle.com/ Cc: Christoph Hellwig Cc: Al Viro Signed-off-by: Stephen Brennan --- fs/namei.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 76871b7f127a..ec76f533ee3e 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3622,8 +3622,8 @@ struct file *do_file_open_root(const struct path *root, return file; } -static struct dentry *__filename_create(int dfd, struct filename *name, - struct path *path, unsigned int lookup_flags) +static struct dentry *filename_create(int dfd, struct filename *name, + struct path *path, unsigned int lookup_flags) { struct dentry *dentry = ERR_PTR(-EEXIST); struct qstr last; @@ -3691,20 +3691,16 @@ static struct dentry *__filename_create(int dfd, struct filename *name, return dentry; } -static inline struct dentry *filename_create(int dfd, struct filename *name, - struct path *path, unsigned int lookup_flags) -{ - struct dentry *res = __filename_create(dfd, name, path, lookup_flags); - - putname(name); - return res; -} - struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path, unsigned int lookup_flags) { - return filename_create(dfd, getname_kernel(pathname), - path, lookup_flags); + struct filename *filename; + struct dentry *dentry; + + filename = getname_kernel(pathname); + dentry = filename_create(dfd, filename, path, lookup_flags); + putname(filename); + return dentry; } EXPORT_SYMBOL(kern_path_create); @@ -3720,7 +3716,13 @@ EXPORT_SYMBOL(done_path_create); inline struct dentry *user_path_create(int dfd, const char __user *pathname, struct path *path, unsigned int lookup_flags) { - return filename_create(dfd, getname(pathname), path, lookup_flags); + struct filename *filename; + struct dentry *dentry; + + filename = getname(pathname); + dentry = filename_create(dfd, getname(pathname), path, lookup_flags); + putname(filename); + return dentry; } EXPORT_SYMBOL(user_path_create); @@ -3801,7 +3803,7 @@ static int do_mknodat(int dfd, struct filename *name, umode_t mode, if (error) goto out1; retry: - dentry = __filename_create(dfd, name, &path, lookup_flags); + dentry = filename_create(dfd, name, &path, lookup_flags); error = PTR_ERR(dentry); if (IS_ERR(dentry)) goto out1; @@ -3901,7 +3903,7 @@ int do_mkdirat(int dfd, struct filename *name, umode_t mode) unsigned int lookup_flags = LOOKUP_DIRECTORY; retry: - dentry = __filename_create(dfd, name, &path, lookup_flags); + dentry = filename_create(dfd, name, &path, lookup_flags); error = PTR_ERR(dentry); if (IS_ERR(dentry)) goto out_putname; @@ -4268,7 +4270,7 @@ int do_symlinkat(struct filename *from, int newdfd, struct filename *to) goto out_putnames; } retry: - dentry = __filename_create(newdfd, to, &path, lookup_flags); + dentry = filename_create(newdfd, to, &path, lookup_flags); error = PTR_ERR(dentry); if (IS_ERR(dentry)) goto out_putnames; @@ -4432,7 +4434,7 @@ int do_linkat(int olddfd, struct filename *old, int newdfd, if (error) goto out_putnames; - new_dentry = __filename_create(newdfd, new, &new_path, + new_dentry = filename_create(newdfd, new, &new_path, (how & LOOKUP_REVAL)); error = PTR_ERR(new_dentry); if (IS_ERR(new_dentry))