From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 029E0C433FE for ; Wed, 9 Feb 2022 19:29:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230139AbiBIT2x (ORCPT ); Wed, 9 Feb 2022 14:28:53 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:45362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235716AbiBIT2D (ORCPT ); Wed, 9 Feb 2022 14:28:03 -0500 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4F1AE015669 for ; Wed, 9 Feb 2022 11:26:06 -0800 (PST) Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 219HJGQv009817 for ; Wed, 9 Feb 2022 11:04:01 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=fZvcR926EtNpnnZ9VWlpiAHVZXDMxwKgWPyBPNM1S2Q=; b=R92NQnyUePL1kWo4TynEXRnt0VfK7WUuNvGaFJ4W6Ql4MUVEJkmNkkafrPJwnidvvsad GvS5r9LNNQb/ve37X5wGhnaN5HvKyOUXfZHJb3nBJtODgL0yJUui+MXJgCAaHu5j9Yj1 omBOX9ApPYoW5pqtu8hoGuOS/7VKMpPQuws= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3e4fxassmw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 09 Feb 2022 11:04:01 -0800 Received: from twshared14630.35.frc1.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 9 Feb 2022 11:03:59 -0800 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 37A10A855532; Wed, 9 Feb 2022 11:03:52 -0800 (PST) From: Stefan Roesch To: , , CC: , Subject: [PATCH v1 1/2] fs: replace const char* parameter in vfs_statx and do_statx with struct filename Date: Wed, 9 Feb 2022 11:03:44 -0800 Message-ID: <20220209190345.2374478-2-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220209190345.2374478-1-shr@fb.com> References: <20220209190345.2374478-1-shr@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-ORIG-GUID: MYJTVLjoOBitty874IfvXeAaXTCtYlU6 X-Proofpoint-GUID: MYJTVLjoOBitty874IfvXeAaXTCtYlU6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-09_10,2022-02-09_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=fb_outbound_notspam policy=fb_outbound score=0 spamscore=0 mlxscore=0 priorityscore=1501 suspectscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 adultscore=0 clxscore=1011 impostorscore=0 mlxlogscore=924 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202090100 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org This replaces the const char* __user filename parameter in the two functions do_statx and vfs_statx with a struct filename *. In addition to be able to correctly construct a filename object a new helper function getname_statx_lookup_flags is introduced. The function makes sure that do_statx and vfs_statx is invoked with the correct lookup flags= . Signed-off-by: Stefan Roesch --- fs/internal.h | 4 +++- fs/stat.c | 49 ++++++++++++++++++++++++++++++++++++------------- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/fs/internal.h b/fs/internal.h index 8590c973c2f4..56c0477f4215 100644 --- a/fs/internal.h +++ b/fs/internal.h @@ -184,7 +184,9 @@ int sb_init_dio_done_wq(struct super_block *sb); /* * fs/stat.c: */ -int do_statx(int dfd, const char __user *filename, unsigned flags, + +int getname_statx_lookup_flags(int flags); +int do_statx(int dfd, struct filename *filename, unsigned int flags, unsigned int mask, struct statx __user *buffer); =20 /* diff --git a/fs/stat.c b/fs/stat.c index 28d2020ba1f4..6a11cfe6a849 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -184,6 +184,20 @@ int vfs_fstat(int fd, struct kstat *stat) return error; } =20 +int getname_statx_lookup_flags(int flags) +{ + int lookup_flags =3D 0; + + if (!(flags & AT_SYMLINK_NOFOLLOW)) + lookup_flags |=3D LOOKUP_FOLLOW; + if (!(flags & AT_NO_AUTOMOUNT)) + lookup_flags |=3D LOOKUP_AUTOMOUNT; + if (flags & AT_EMPTY_PATH) + lookup_flags |=3D LOOKUP_EMPTY; + + return lookup_flags; +} + /** * vfs_statx - Get basic and extra attributes by filename * @dfd: A file descriptor representing the base dir for a relative file= name @@ -199,7 +213,7 @@ int vfs_fstat(int fd, struct kstat *stat) * * 0 will be returned on success, and a -ve error code if unsuccessful. */ -static int vfs_statx(int dfd, const char __user *filename, int flags, +static int vfs_statx(int dfd, struct filename *filename, int flags, struct kstat *stat, u32 request_mask) { struct path path; @@ -210,15 +224,8 @@ static int vfs_statx(int dfd, const char __user *fil= ename, int flags, AT_STATX_SYNC_TYPE)) return -EINVAL; =20 - if (!(flags & AT_SYMLINK_NOFOLLOW)) - lookup_flags |=3D LOOKUP_FOLLOW; - if (!(flags & AT_NO_AUTOMOUNT)) - lookup_flags |=3D LOOKUP_AUTOMOUNT; - if (flags & AT_EMPTY_PATH) - lookup_flags |=3D LOOKUP_EMPTY; - retry: - error =3D user_path_at(dfd, filename, lookup_flags, &path); + error =3D filename_lookup(dfd, filename, flags, &path, NULL); if (error) goto out; =20 @@ -240,8 +247,16 @@ static int vfs_statx(int dfd, const char __user *fil= ename, int flags, int vfs_fstatat(int dfd, const char __user *filename, struct kstat *stat, int flags) { - return vfs_statx(dfd, filename, flags | AT_NO_AUTOMOUNT, - stat, STATX_BASIC_STATS); + int ret; + int statx_flags =3D flags | AT_NO_AUTOMOUNT; + struct filename *name; + + name =3D getname_flags(filename, getname_statx_lookup_flags(statx_flags= ), NULL); + ret =3D vfs_statx(dfd, name, statx_flags, stat, STATX_BASIC_STATS); + if (name) + putname(name); + + return ret; } =20 #ifdef __ARCH_WANT_OLD_STAT @@ -602,7 +617,7 @@ cp_statx(const struct kstat *stat, struct statx __use= r *buffer) return copy_to_user(buffer, &tmp, sizeof(tmp)) ? -EFAULT : 0; } =20 -int do_statx(int dfd, const char __user *filename, unsigned flags, +int do_statx(int dfd, struct filename *filename, unsigned int flags, unsigned int mask, struct statx __user *buffer) { struct kstat stat; @@ -636,7 +651,15 @@ SYSCALL_DEFINE5(statx, unsigned int, mask, struct statx __user *, buffer) { - return do_statx(dfd, filename, flags, mask, buffer); + int ret; + struct filename *name; + + name =3D getname_flags(filename, getname_statx_lookup_flags(flags), NUL= L); + ret =3D do_statx(dfd, name, flags, mask, buffer); + if (name) + putname(name); + + return ret; } =20 #ifdef CONFIG_COMPAT --=20 2.30.2