From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from tor.source.kernel.org ([172.105.4.254]) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1vnykt-0002M5-47 for apparmor@lists.ubuntu.com; Thu, 05 Feb 2026 12:46:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1770295135; bh=G9qHb9p0MPYty9W2bqZeDirLOVPesrzx4Ei/lgeOCRA=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=AH2UzJ0oUDVcL390IygZ5kEiEAojgl8odoQ3KAjqbiFXfHBGLmz5bMu51boYaY+VD sAdILXp3eIJngbsv0/hIvYZNP9usrSjIp1vqGT5x51WhcxUN4NOg5i0D92Fkt3onWj Z6k8Lrgcq8NhtRpCBsSkxMklVvogfeWyn2TF89SHArhTOh2myE8CITFFMhH9k5KwgN X3rbQZQpCJfxSEERajtHka8wsvMw1fDk8idcYs7NfRKDwlPKGAjewutiezQm2na7Fr 1vDGRIPsPDHUgCsiVe1GcvsXveA0CuG1G4tTDyYNNGmepDqEYYrKqYrUO40iI0Awe6 +3/gkPxG11tfw== Message-ID: From: Jeff Layton Date: Thu, 05 Feb 2026 07:38:52 -0500 In-Reply-To: <20260204050726.177283-12-neilb@ownmail.net> References: <20260204050726.177283-1-neilb@ownmail.net> <20260204050726.177283-12-neilb@ownmail.net> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [apparmor] [PATCH 11/13] ovl: use is_subdir() for testing if one thing is a subdir of another List-Id: AppArmor discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: NeilBrown , Christian Brauner , Alexander Viro , David Howells , Jan Kara , Chuck Lever , Miklos Szeredi , Amir Goldstein , John Johansen , Paul Moore , James Morris , "Serge E. Hallyn" , Stephen Smalley Cc: linux-kernel@vger.kernel.org, netfs@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-unionfs@vger.kernel.org, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, selinux@vger.kernel.org On Wed, 2026-02-04 at 15:57 +1100, NeilBrown wrote: > From: NeilBrown >=20 > Rather than using lock_rename(), use the more obvious is_subdir() for > ensuring that neither upper nor workdir contain the other. > Also be explicit in the comment that the two directories cannot be the > same. >=20 > As this is a point-it-time sanity check and does not provide any > on-going guarantees, the removal of locking does not introduce any > interesting races. >=20 > Signed-off-by: NeilBrown > --- > fs/overlayfs/super.c | 15 +++++---------- > 1 file changed, 5 insertions(+), 10 deletions(-) >=20 > diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c > index ba9146f22a2c..2fd3e0aee50e 100644 > --- a/fs/overlayfs/super.c > +++ b/fs/overlayfs/super.c > @@ -451,18 +451,13 @@ static int ovl_lower_dir(const char *name, const st= ruct path *path, > return 0; > } > =20 > -/* Workdir should not be subdir of upperdir and vice versa */ > +/* > + * Workdir should not be subdir of upperdir and vice versa, and > + * they should not be the same. > + */ > static bool ovl_workdir_ok(struct dentry *workdir, struct dentry *upperd= ir) > { > - bool ok =3D false; > - > - if (workdir !=3D upperdir) { > - struct dentry *trap =3D lock_rename(workdir, upperdir); > - if (!IS_ERR(trap)) > - unlock_rename(workdir, upperdir); > - ok =3D (trap =3D=3D NULL); > - } > - return ok; > + return !is_subdir(workdir, upperdir) && !is_subdir(upperdir, workdir); > } > =20 > static int ovl_setup_trap(struct super_block *sb, struct dentry *dir, Reviewed-by: Jeff Layton