Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp8155993rdb; Thu, 4 Jan 2024 23:37:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IExl2f4xnckY0NXPth4qivuTRbrP3x742VOtevHEa/NfpmTIp7nafFWIRoYbVR4Zdqw35Xq X-Received: by 2002:a17:907:7635:b0:a27:ec6e:efaf with SMTP id jy21-20020a170907763500b00a27ec6eefafmr1497824ejc.46.1704440242175; Thu, 04 Jan 2024 23:37:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704440242; cv=none; d=google.com; s=arc-20160816; b=xDLGXEu8UKr9tRzd4AooJ9ZYkJ1dv39uT6OeH5zfZsXBdfgTx0q8pSv61zODZm7t9L 8zzHcKabebqQ4rXEvVVESE5KQ6re2kJp2NvuHakxjQcRmnqjW8mnp+y/f1wYNEeCfx5S ZABhl9lS7+UO58hVzwGdJaIRJ9K4GgioUfJwA96Ik8sMKMS/vF7WNpPisaRw28/3A/n8 7mYcvngRb+bBmapbLqpc2cO7xj/XIUz5Y4xVVrbTMHQlpHT5bhGUASjttyAsBtseKKj7 EwyUYHdOuo+wKQgAtLemWky8hEp1PvPty/UxfzborXdGxsD4pX4QN/VOZaVz8U1O/8K/ thPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=5/w5eJtCLO9gyzG6a3HPEPuxuRzY98TrfAvqmGNhpoA=; fh=IG/9Lel8EcCLDm6gz+CrejXCxETWr0ltF1b4Q3BTPfs=; b=tzizSmdO3wvvFvym+CXah/BS4Jjd5AhZA/HjBErNEldNeHJWn2X5EyagVoHmhghoMx IGa6k1k2V6PeuJEPRMgLD68Xti1xf7W7COeysTjbljcfQcDbJLBg2Ci2ecpiM8zwweF3 FKUCYFHHRF+bTXgr8iBgV5RLPI+lW9eu04swGlnlrPHdCCgOeHiKWmZn45BOl4zK4ziC uZEzWnpR28wrxTY42BSE71i0nHnQyj/xj9t2FtNQnxVGaxcw81A+OzweBSE9h4JnNrOz WoARkODX0IGhj/BUw0GWsUZRapLDn2ypEAb4zoZ4gdacEfVP3YtC0jOfs0YGSGG3HZ3O N5JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=GW5SQIgq; spf=pass (google.com: domain of linux-nfs+bounces-952-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-nfs+bounces-952-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id ga15-20020a170906b84f00b00a28d61c34a8si376783ejb.655.2024.01.04.23.37.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 23:37:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs+bounces-952-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=GW5SQIgq; spf=pass (google.com: domain of linux-nfs+bounces-952-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-nfs+bounces-952-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id C064E1F22EC0 for ; Fri, 5 Jan 2024 07:37:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AA09A20333; Fri, 5 Jan 2024 07:37:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GW5SQIgq" X-Original-To: linux-nfs@vger.kernel.org Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21E4E2032A; Fri, 5 Jan 2024 07:37:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-7815aad83acso25259185a.0; Thu, 04 Jan 2024 23:37:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704440223; x=1705045023; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=5/w5eJtCLO9gyzG6a3HPEPuxuRzY98TrfAvqmGNhpoA=; b=GW5SQIgqS+qt8Ug/S+tlqTmqhq8dH72q7YgTQ0AC3gb56kaOe/ezw/ioR0BNKYKUAq QJAK2qf4HYUPvyA2me+wnEHzBhg627xKAc9OKJrQaixC9mq2zeop+hQxgUoe2iDF0yIj JlHvocU3qN5LvuJDJkP9xGi0tN5lEf4MSb6fnUNsLZ5+HEOnhp/ZzbNb6eKCGT/ghn/g 2SoqAfcm0ILPFnu67SsTqqSFynCFZD2ENGRrmLb17SYmV00I+H7lWxjhoIK/EpUbnQOP btwAnrAzFAeRx5yyZl4+WDbjOqDbo7+MedwacDs62h9+0F0MooRgaKbYEWTa79GIkoEV /vVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704440223; x=1705045023; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5/w5eJtCLO9gyzG6a3HPEPuxuRzY98TrfAvqmGNhpoA=; b=Q/JDcUgvpOfGiYM2K+iqczEBnNo1SHmIsrPK7g9m9neVf/44XmQ0ZQ3eTEjpoU/nfV efXaX8qpzNTUipQqTzoYHRXBouot3bfD+zuSupNZllN3WnsJPomnU7RAGtR4eNLnggHC R3Kl7Du3ejjrVdIRvq9UtvZU2QKZ8hmS275sqP66+cIr/bweY/mvcqbmVkixJ86a6LX9 6lX4TGvWDg2tDipef4B+SlCSBrVHWyORFZ+EK2i3BgvoBubaSeezcXbz/najaHTV15JL FHftahvJIV1brjRpNqERArG5xWR0mpNzF27IpXIyCceI3pvVYh5z8aNbxIYWF7G5pJUH 3BGA== X-Gm-Message-State: AOJu0YyXZ2fi4CPXEV+GamVyjdDBtt6Qf7PYTJdFeuysEtfxnixn9gP9 EYdMHw/43CpZhAoP2hDAvoeG+NA+Spu5ToB0SLk= X-Received: by 2002:ad4:5def:0:b0:680:d159:ca5b with SMTP id jn15-20020ad45def000000b00680d159ca5bmr2804839qvb.50.1704440222871; Thu, 04 Jan 2024 23:37:02 -0800 (PST) Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <170440153940.204613.6839922871340228115.stgit@bazille.1015granger.net> <170440173389.204613.14502976575665083984.stgit@bazille.1015granger.net> In-Reply-To: <170440173389.204613.14502976575665083984.stgit@bazille.1015granger.net> From: Amir Goldstein Date: Fri, 5 Jan 2024 09:36:51 +0200 Message-ID: Subject: Re: [PATCH v4 2/2] fs: Create a generic is_dot_dotdot() utility To: Chuck Lever , viro@zeniv.linux.org.uk Cc: jlayton@redhat.com, Jeff Layton , Chuck Lever , linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, trondmy@hammerspace.com, brauner@kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jan 4, 2024 at 10:55=E2=80=AFPM Chuck Lever wrote: > > From: Chuck Lever > > De-duplicate the same functionality in several places by hoisting > the is_dot_dotdot() utility function into linux/fs.h. > > Suggested-by: Amir Goldstein > Reviewed-by: Jeff Layton > Signed-off-by: Chuck Lever Reviewed-by: Amir Goldstein > --- > fs/crypto/fname.c | 8 +------- > fs/ecryptfs/crypto.c | 10 ---------- > fs/exportfs/expfs.c | 4 +--- > fs/f2fs/f2fs.h | 11 ----------- > fs/namei.c | 6 ++---- > include/linux/fs.h | 13 +++++++++++++ > 6 files changed, 17 insertions(+), 35 deletions(-) > > diff --git a/fs/crypto/fname.c b/fs/crypto/fname.c > index 7b3fc189593a..0ad52fbe51c9 100644 > --- a/fs/crypto/fname.c > +++ b/fs/crypto/fname.c > @@ -74,13 +74,7 @@ struct fscrypt_nokey_name { > > static inline bool fscrypt_is_dot_dotdot(const struct qstr *str) > { > - if (str->len =3D=3D 1 && str->name[0] =3D=3D '.') > - return true; > - > - if (str->len =3D=3D 2 && str->name[0] =3D=3D '.' && str->name[1] = =3D=3D '.') > - return true; > - > - return false; > + return is_dot_dotdot(str->name, str->len); > } > > /** > diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c > index 03bd55069d86..2fe0f3af1a08 100644 > --- a/fs/ecryptfs/crypto.c > +++ b/fs/ecryptfs/crypto.c > @@ -1949,16 +1949,6 @@ int ecryptfs_encrypt_and_encode_filename( > return rc; > } > > -static bool is_dot_dotdot(const char *name, size_t name_size) > -{ > - if (name_size =3D=3D 1 && name[0] =3D=3D '.') > - return true; > - else if (name_size =3D=3D 2 && name[0] =3D=3D '.' && name[1] =3D= =3D '.') > - return true; > - > - return false; > -} > - > /** > * ecryptfs_decode_and_decrypt_filename - converts the encoded cipher te= xt name to decoded plaintext > * @plaintext_name: The plaintext name > diff --git a/fs/exportfs/expfs.c b/fs/exportfs/expfs.c > index 84af58eaf2ca..07ea3d62b298 100644 > --- a/fs/exportfs/expfs.c > +++ b/fs/exportfs/expfs.c > @@ -255,9 +255,7 @@ static bool filldir_one(struct dir_context *ctx, cons= t char *name, int len, > container_of(ctx, struct getdents_callback, ctx); > > buf->sequence++; > - /* Ignore the '.' and '..' entries */ > - if ((len > 2 || name[0] !=3D '.' || (len =3D=3D 2 && name[1] !=3D= '.')) && > - buf->ino =3D=3D ino && len <=3D NAME_MAX) { > + if (buf->ino =3D=3D ino && len <=3D NAME_MAX && !is_dot_dotdot(na= me, len)) { > memcpy(buf->name, name, len); > buf->name[len] =3D '\0'; > buf->found =3D 1; > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h > index 9043cedfa12b..322a3b8a3533 100644 > --- a/fs/f2fs/f2fs.h > +++ b/fs/f2fs/f2fs.h > @@ -3368,17 +3368,6 @@ static inline bool f2fs_cp_error(struct f2fs_sb_in= fo *sbi) > return is_set_ckpt_flags(sbi, CP_ERROR_FLAG); > } > > -static inline bool is_dot_dotdot(const u8 *name, size_t len) > -{ > - if (len =3D=3D 1 && name[0] =3D=3D '.') > - return true; > - > - if (len =3D=3D 2 && name[0] =3D=3D '.' && name[1] =3D=3D '.') > - return true; > - > - return false; > -} > - > static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, > size_t size, gfp_t flags) > { > diff --git a/fs/namei.c b/fs/namei.c > index 71c13b2990b4..2386a70667fa 100644 > --- a/fs/namei.c > +++ b/fs/namei.c > @@ -2667,10 +2667,8 @@ static int lookup_one_common(struct mnt_idmap *idm= ap, > if (!len) > return -EACCES; > > - if (unlikely(name[0] =3D=3D '.')) { > - if (len < 2 || (len =3D=3D 2 && name[1] =3D=3D '.')) > - return -EACCES; > - } > + if (is_dot_dotdot(name, len)) > + return -EACCES; > > while (len--) { > unsigned int c =3D *(const unsigned char *)name++; > diff --git a/include/linux/fs.h b/include/linux/fs.h > index 98b7a7a8c42e..53dd58a907e0 100644 > --- a/include/linux/fs.h > +++ b/include/linux/fs.h > @@ -2846,6 +2846,19 @@ extern bool path_is_under(const struct path *, con= st struct path *); > > extern char *file_path(struct file *, char *, int); > > +/** > + * is_dot_dotdot - returns true only if @name is "." or ".." > + * @name: file name to check > + * @len: length of file name, in bytes > + * > + * Coded for efficiency. > + */ > +static inline bool is_dot_dotdot(const char *name, size_t len) > +{ > + return len && unlikely(name[0] =3D=3D '.') && > + (len < 2 || (len =3D=3D 2 && name[1] =3D=3D '.')); > +} > + Looking back at the version that I suggested, (len < 2 here is silly and should be (len =3D=3D 1 || ... But let's wait for inputs from other developers on this helper, especially Al. Thanks, Amir.