From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 59D0E803F6 for ; Tue, 17 Nov 2026 05:55:01 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AH5rlRr003742; Tue, 17 Nov 2026 08:53:47 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AH5rlRr003742 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="ASbH70XQ" Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AH5rZY0003722 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Tue, 17 Nov 2026 08:53:35 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AH5rZY0003722 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-48e0af48c18so2786426f8f.2 for ; Mon, 16 Nov 2026 21:53:35 -0800 (PST) X-Gm-Message-State: APuU4Z+KjLr95K9rVrhlh09x8qOHhegWUfVTc1tgPVRHnCgjsYiK236z muF8PwEVSF5sP+K/2h/S8tdZCyXCTgg84hmWrq2tS2N2M9CYbAkjqUYlStY6geXW8uz5xHU3uj6 QM6poLRwJEnDsII8VcXoNR+Uj6J91/Uj4lzKfb4mcHnVZRNr9WRl99Q== X-Gm-Gg: AZFdTZcVUxrQt96u2vNwFjjEW4202cFilnyY3Dv0r+RQk7PT/G8WQw5mnDx9UzwuLTg AhfYU0Njd9HHjcPEFWjflSjCgeFA50EfRM1t9HK6NIU2lI8TAA77eINhQ5iBFjsZlQumh7n4Bpx XQUzZO+z9c94oi8V+WrJyAhdThFNZg3ymHG48CXHEKpJJDutidhuO0QK8S273MZjA7pgcXZqp2G 1Ezup7LZogDSUhXMUey/aCgxe0IB53CRJ4cjMEXNAqHcksmpw/K+L1ebZSX4b5Zdh7uTMR5ZxJ6 dz7EwLoiR2P+A5nAuWFolqwhpWRnThzYnyCIvVKwzr5dZ3XFyJTL54FQxhaYYuimlyKkbjCpd3T LXzTWggzDtsLUf6Fnh2vF60zxdQ== X-Received: by 2002:a05:6000:2dc9:b0:48d:f460:2c62 with SMTP id ffacd0b85a97d-49c71785323mr29854212f8f.33.1794894814753; Mon, 16 Nov 2026 21:53:34 -0800 (PST) X-Received: by 2002:a05:6000:2dc9:b0:48d:f460:2c62 with SMTP id ffacd0b85a97d-49c71785323mr29854180f8f.33.1794894814244; Mon, 16 Nov 2026 21:53:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794894814; cv=none; d=google.com; s=arc-20260327; b=PF32cYU/vGrB2v9p2uu3YpOpWQRiOimvqHGo9l9DrHza3a23OAvlbtR1tTBlOA3mxr fsQ5EjTnv66RmcjX9MlK15tZZZnhpF1TAtiIYuCm3jeseVZitu1b/VZVWr763P3SUj7/ rCIrcUEpya/bmfpl63lRQXydUK7ylL2ovmjgeVYH0ym+59NZeKgBBjmOKjm0qo2tIQZS yMUqkXx22OaWiFs0Vf7inr7r0ZY6c6LyEpuvjdgd4izMUfUXtevG6Bw5arxiHVs6D+4J +NtAmE/N/EAxW4YoUXXIiZRVsk/XvHT8iVRuNxqV08vdHXFQnuZqgUf9ZQxH2x+dZHF/ WUhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=8U+tWEYMhzJoQXqRaNjiXf6/Xnt0ZEFrDRT9ViAUzj8=; fh=WpT6aB7RBAGHZeWZzqAr71yzRFbPTYkPWKsRagLn48Q=; b=D2mSEJhQv8IFXSLAGzGF7Wff7rL2NdY2TVYai/ixsYsc1xKdUEtv5LuAXnVj/KuXUA oqQzQBfL9uDHvmHIAvzq68exQ9sRDEQCDEqmnm3BBWVawdOPaIa7KFwdkj/QtsTES6tZ mmh2T8Fevat2hZKvFJ1M0BmYDz/xklSAgaQdWYVtBMRKxriSLLsoIDoAr8i5AhHwkrX0 DgIL6mmKiMpQdPR9X1kOMvRRXwGQnPkCVdxohbMwjSrofpnZMoYrB3CypWtGFDWg6uvE WpDbflrqYUCX9f/4YsTkqnjGfr80wzs408VMc6QdyuTtWF0ZAgEpKvUjmYpXHhFeGJ0I UC3g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=ASbH70XQ; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id ffacd0b85a97d-4a3100a86edsi4569521f8f.228.2026.11.16.21.53.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2026 21:53:34 -0800 (PST) Received-SPF: pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=ASbH70XQ; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=8U+tWEYMhzJoQXqRaNjiXf6/Xnt0ZEFrDRT9ViAUzj8=; b=ASbH70XQdapw QKgWv7E3O79Go2xSFLNquFDR+jz8ueua1VEksfC/UYO5Z286t/2tQOLuk20QFE4wHajlD7AdF51gM q218pU6ACoG01DM4+ouou1cfrjPovnMDdXuOESB9x4sx9GahU60LAXYcMp6+rXhweLfeBM9T2IONp j8I3/DCbvfLij7XZkHRvB3VCtCTSotWF1VeINIP6pLC3jAWGKl2AZhZYCGavpVT9aLkVyroEZMmMV O4uMMTk/yGuWSuAjDJAMDYxQGB1CPbnti3YoHtrXv3agOYzmW6R8Ma9c98D3eP6YkLUx5xE7JPX/c VXgOIFVEHRprJkw9EPOoAg==; Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=LekKit-T14) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xTC45-004RDH-2w; Tue, 17 Nov 2026 06:53:24 +0100 From: Eva Kurchatova To: khorenko@virtuozzo.com Date: Tue, 17 Nov 2026 07:52:13 +0200 Message-ID: <20261117055330.810827-3-eva.kurchatova@virtuozzo.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261117055330.810827-1-eva.kurchatova@virtuozzo.com> References: <20261117055330.810827-1-eva.kurchatova@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 2/2] ms/unicode: free the map after a grace period X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org From: Christian Brauner commit a96c5299bd7305eb984377681eb3222a57376405 upstream. generic_ci_d_hash() and generic_ci_d_compare() read sb->s_encoding and dereference the unicode map while a pathwalk in rcu mode holds nothing but rcu_read_lock(). The filesystems that use them, ext4, f2fs and tmpfs, drop the map with utf8_unload() from ->put_super(), which runs when the last reference to the mount goes away. A lookup that is still inside such a filesystem at that point reads a freed map. With a pathwalk held up in utf8_casefold_hash() while the last reference to a casefolded tmpfs goes away: BUG: KASAN: slab-use-after-free in utf8nlookup+0x74c/0x950 Read of size 8 at addr ff110001030fe658 by task walker/98 Call Trace: utf8nlookup+0x74c/0x950 utf8byte+0x160/0x1560 utf8_casefold_hash+0x167/0x230 generic_ci_d_hash+0xdd/0x1c0 link_path_walk+0x11ad/0x1d30 path_lookupat+0x63/0xb00 filename_lookup+0x1f1/0x5b0 vfs_statx+0xd7/0x3b0 [...] Allocated by task 94: __kmalloc_cache_noprof+0x249/0x560 utf8_load+0x4e/0x570 shmem_parse_opt_casefold.isra.0+0x92/0x270 [...] Freed by task 97: kfree+0x1db/0x5b0 shmem_put_super+0x72/0x170 generic_shutdown_super+0x14c/0x530 kill_anon_super+0x3a/0x60 deactivate_locked_super+0x9c/0xf0 cleanup_mnt+0x9f/0x130 So far that has been hard to hit. umount(2) waits for a grace period in namespace_unlock() before it drops the mount, so only a mount whose last reference goes away elsewhere, like the close of a file or a chdir out of a lazily unmounted directory, can race a walker. So it is reachable. Delay the free until a grace period has passed. The map and the data table it holds a reference to then outlive any pathwalk that found the superblock before the mount went away. The reference on the data table module is dropped from the rcu callback as well. utf8-core is built in whenever CONFIG_UNICODE is set, so there is no module exit that would have to wait for the callbacks. Overlayfs points the s_encoding of an overlay at the map of its first layer without taking a reference of its own. That stays correct. The layer is held by the overlay, so its map is dropped only after the overlay is gone. Fixes: b886ee3e778e ("ext4: Support case-insensitive file name lookups") Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20261009-work-fixes-rcu-v1-6-7446d2d335e6@kernel.org Signed-off-by: Christian Brauner (Amutable) Signed-off-by: Greg Kroah-Hartman (cherry picked from commit 69a0d6b31d05e856c7335509222f25321e3c69ca) https://virtuozzo.atlassian.net/browse/VSTOR-155414 Feature: fix ms/fs Signed-off-by: Eva Kurchatova --- fs/unicode/utf8-core.c | 21 +++++++++++++++++---- include/linux/unicode.h | 1 + 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/fs/unicode/utf8-core.c b/fs/unicode/utf8-core.c index 8395066341a4..48ba70fba830 100644 --- a/fs/unicode/utf8-core.c +++ b/fs/unicode/utf8-core.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -205,12 +206,24 @@ struct unicode_map *utf8_load(unsigned int version) } EXPORT_SYMBOL(utf8_load); +static void utf8_unload_rcu(struct rcu_head *head) +{ + struct unicode_map *um = container_of(head, struct unicode_map, rcu); + + symbol_put(utf8_data_table); + kfree(um); +} + +/* + * A pathwalk in rcu mode may still be in ->d_hash() or ->d_compare() of a + * filesystem that is being torn down and read the map through its + * superblock, so the map and the tables it points to have to outlive the + * grace period. + */ void utf8_unload(struct unicode_map *um) { - if (um) { - symbol_put(utf8_data_table); - kfree(um); - } + if (um) + call_rcu(&um->rcu, utf8_unload_rcu); } EXPORT_SYMBOL(utf8_unload); diff --git a/include/linux/unicode.h b/include/linux/unicode.h index 4d39e6e11a95..f5ee53dc4dff 100644 --- a/include/linux/unicode.h +++ b/include/linux/unicode.h @@ -51,6 +51,7 @@ struct unicode_map { unsigned int version; const struct utf8data *ntab[UTF8_NMAX]; const struct utf8data_table *tables; + struct rcu_head rcu; }; int utf8_validate(const struct unicode_map *um, const struct qstr *str); -- 2.56.1 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel