From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384669; b=e0IlHRLgUofWF3/HPv2JN4cg0iVdq/lVmJWEY6F93PjYRDOWQ9Cf9ejidJpBpj1XtgiJ qyh0bH86Ch/ysuuLKtVmxKadEllMxsD0kxV9E9r1XO5gK9DJ3E11RaAgpCP5ZiTCq9hVD JSNPxAMOfJawSvW7NEHQY5apAWvZ4gB2DtADaWU/LJZCUCrRKG4BILJADHrIIEvdfAA9Q mY4/GxzpwzlnAbYmumP4N7q9T44vFfcx1g7nhMGrDU7/TXpV9YSBRpznTsW/3w0/COo9n cW8RNNEVJy5f9AJZWD90dhmzHwW3HeNIMokJ7ojQxRTnsTbGfThC4LkaThFBCRVXqFg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384669; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=FGdQ7zY/KBsEPawmy8WHL9A6PQQJzWLdmA2FPh6bybM=; b=Y3fwuv2x5TGmDvSQxby2bV/rENohZoOrXXVYgIAhBObJC9oUXVyaPzQdKzXNrbBJcs4N NgxWU48idXj2u0ItJdHgG5oKYB27ntQ/L+1qKesdmDl4m7u2KZMRfuF0WGfRCLiATCUpf oq4ZVqWJ/k+uFfeu27+H90R48iIINnifZvSdvd4S9odgVUbS6XVKpXQ6wzLdb8ZCzlk9t dMINd3XrkveJ00gVwVz4FYK1X+GUwfu8QENuMB0U6m/RPiEW/LA50RKpzW6AUGaynF0ot RGZ32+z1feP/BZQTjmQGH4UDjwqbKVooKch8oEKhoHRwa5r5PmvsLLxVG9RgnIfUbxg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=FETPIoxF; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3EFB6606A32C; Fri, 4 Dec 2026 11:44:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=FETPIoxF Received: by smtp.kernel.org (Postfix) with ESMTPSA id 565301F000C2; Fri, 4 Dec 2026 11:44:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384668; bh=FGdQ7zY/KBsEPawmy8WHL9A6PQQJzWLdmA2FPh6bybM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=FETPIoxFlP2nBZgj5G4KZ2QFod2CGvtLqUB7WD5UgfG9HnCOcWLypXAkW5e5v/wOD c/Jsd1toYBmVJFMQX+pZ1l08Q5IGvs61Nagu4IRzjkYDDccfjJSJJHHrZXtPnKzA22 JORlM+trrw7qPifDUwGVgbaOKP99J28ujofQPaek= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Miklos Szeredi , Amir Goldstein , Pavel Tikhomirov , "Denis V. Lunev" , Sasha Levin Subject: [PATCH 6.6 0236/1167] ovl: release the upperdir/workdir in-use locks before the umount sync Date: Fri, 4 Dec 2026 18:54:23 +0900 Message-ID: <20261204100708.216171934@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Denis V. Lunev [ Upstream commit cb6c084182d4c69b7eeff0bd519dd7e018749602 ] The in-use locks on upperdir and workdir are released by ovl_free_fs() from ->put_super(). generic_shutdown_super() calls sync_filesystem() before that, and ovl_sync_fs() syncs the whole upper filesystem, so the locks stay held across a journal commit and a cache flush of the upper fs after the overlay is gone. With index=on a new overlay that uses the same upperdir, or uses it as a lowerdir, fails to mount in that window: overlayfs: upperdir is in-use as upperdir/workdir of another mount, mount with '-o index=off' to override exclusive upperdir protection. Userspace hits this when the last reference is not dropped by umount(2) itself. Docker with the containerd snapshotter mounts a snapshot on a thread with a private mount namespace for docker cp and for buildkit, and the superblock dies when that thread exits, after the reply to the client has gone out. The next request then gets EBUSY. The window grows with the flush latency of the upper fs and is there even if nothing was written through the overlay, as the mount itself dirties the upper. ->kill_sb() is called once s_active drops to zero, with no mount and no open file left. Release the locks there, before generic_shutdown_super() runs. What the dying superblock still does to the upper fs, the sync and dropping its references to upper dentries and inodes, does not touch the contents of upperdir or workdir. ovl_free_fs() still releases the locks for a failed mount, so clear the *_locked flags to keep it from unlocking a second time and dropping the lock of a newer mount. This takes the sync out of the window but does not close it: the final mntput of a dying mount namespace runs from task_work, after the exiting thread may have reported completion. Userspace that needs the directories free should umount(2) before saying the job is done. Fixes: 2cac0c00a6cd ("ovl: get exclusive ownership on upper/work dirs") Cc: Miklos Szeredi Cc: Amir Goldstein Cc: Pavel Tikhomirov Signed-off-by: Denis V. Lunev Signed-off-by: Amir Goldstein [ sashal: refreshed the .fs_flags context line, since adedb6a00a1e (FS_ALLOW_IDMAP) is not queued ] Signed-off-by: Sasha Levin --- fs/overlayfs/overlayfs.h | 1 + fs/overlayfs/params.c | 5 +---- fs/overlayfs/super.c | 12 +++++++++++- fs/overlayfs/util.c | 12 ++++++++++++ 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h index ceceefb6d2df5..aa48e260b7a8b 100644 --- a/fs/overlayfs/overlayfs.h +++ b/fs/overlayfs/overlayfs.h @@ -501,6 +501,7 @@ static inline int ovl_set_impure_dir(struct dentry *dentry) bool ovl_inuse_trylock(struct dentry *dentry); void ovl_inuse_unlock(struct dentry *dentry); bool ovl_is_inuse(struct dentry *dentry); +void ovl_inuse_unlock_all(struct ovl_fs *ofs); bool ovl_need_index(struct dentry *dentry); int ovl_nlink_start(struct dentry *dentry); void ovl_nlink_end(struct dentry *dentry); diff --git a/fs/overlayfs/params.c b/fs/overlayfs/params.c index 21d31aaef95d6..366f5bc93a071 100644 --- a/fs/overlayfs/params.c +++ b/fs/overlayfs/params.c @@ -723,17 +723,14 @@ void ovl_free_fs(struct ovl_fs *ofs) struct vfsmount **mounts; unsigned i; + ovl_inuse_unlock_all(ofs); iput(ofs->workbasedir_trap); iput(ofs->indexdir_trap); iput(ofs->workdir_trap); dput(ofs->whiteout); dput(ofs->indexdir); dput(ofs->workdir); - if (ofs->workdir_locked) - ovl_inuse_unlock(ofs->workbasedir); dput(ofs->workbasedir); - if (ofs->upperdir_locked) - ovl_inuse_unlock(ovl_upper_mnt(ofs)->mnt_root); /* Reuse ofs->config.lowerdirs as a vfsmount array before freeing it */ mounts = (struct vfsmount **) ofs->config.lowerdirs; diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index 8d00c2dc58d55..35c7ab918c314 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -1524,13 +1524,23 @@ int ovl_fill_super(struct super_block *sb, struct fs_context *fc) return err; } +static void ovl_kill_sb(struct super_block *sb) +{ + struct ovl_fs *ofs = OVL_FS(sb); + + /* Nothing can modify them now, do not hold them across the sync */ + if (ofs) + ovl_inuse_unlock_all(ofs); + kill_anon_super(sb); +} + struct file_system_type ovl_fs_type = { .owner = THIS_MODULE, .name = "overlay", .init_fs_context = ovl_init_fs_context, .parameters = ovl_parameter_spec, .fs_flags = FS_USERNS_MOUNT, - .kill_sb = kill_anon_super, + .kill_sb = ovl_kill_sb, }; MODULE_ALIAS_FS("overlay"); diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c index 0a40a4950e9f6..77d2f712e271c 100644 --- a/fs/overlayfs/util.c +++ b/fs/overlayfs/util.c @@ -946,6 +946,18 @@ bool ovl_is_inuse(struct dentry *dentry) return inuse; } +void ovl_inuse_unlock_all(struct ovl_fs *ofs) +{ + if (ofs->workdir_locked) { + ovl_inuse_unlock(ofs->workbasedir); + ofs->workdir_locked = false; + } + if (ofs->upperdir_locked) { + ovl_inuse_unlock(ovl_upper_mnt(ofs)->mnt_root); + ofs->upperdir_locked = false; + } +} + /* * Does this overlay dentry need to be indexed on copy up? */ -- 2.53.0