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 73DD4803BB for ; Tue, 17 Nov 2026 05:55:57 +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 6AH5reP2003735; Tue, 17 Nov 2026 08:53:41 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AH5reP2003735 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="c6jubt2F" Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AH5rY9K003720 (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 6AH5rY9K003720 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-48e1d839ddaso2532645f8f.3 for ; Mon, 16 Nov 2026 21:53:34 -0800 (PST) X-Gm-Message-State: APuU4Z8VY1LaN2p5LpSTd16tN+4wmFKv9z/p26Ywn1nb0dngBeErBT5F g1/BFLVowJ3b1+MsCXcQe74jYDx6511+kmT/r0+7NZfhL3Pln+UV1BVX8WFK169dd4J+cqeAUxm 1GHHUPCDNPVvxKTAkLCDVcaTsGnLFd5lJ1WRv72p+Otyh1z3UQWBwyQ== X-Gm-Gg: AZFdTZd7gJ138au37iTR8Coz4Y7REKrp4nTQsbw319oYSZoM1NdtW+qbsZoJY0S4MMY ocrXXu+gYy92k0UgCeG7J8gKrquspno2lhP5Fmhs5JqWiYs43ORttBpzcAKtB4l0loYkdE+Tm4z uAVMyI5RDzmh+XO/ZFN+Efz2aZD3wUwBjq0GZxEiAeHDYiouDyV4EBMSRmh/kL9kQTbypnWQKmi FaXr4dZSUEkS2lQPo4muKRkz/9MXp6ZyEsNa7TI2hJrgch7qIJUitG5uIhv1SDWF+0VTraNCGf8 n9k7OrZCgJh5QMwKNgwynuvKf8AC2AQi+Man6kG8AN48KbJDxd6WlJJOgkmv/kZ/qTDM9G121HW 0WM6BYmGJIeSU5FK3glzauSis X-Received: by 2002:a05:6000:240b:b0:490:7fb3:cb41 with SMTP id ffacd0b85a97d-49c714a2e3bmr26383120f8f.24.1794894814551; Mon, 16 Nov 2026 21:53:34 -0800 (PST) X-Received: by 2002:a05:6000:240b:b0:490:7fb3:cb41 with SMTP id ffacd0b85a97d-49c714a2e3bmr26383090f8f.24.1794894814014; 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=TLApgmViRn9JZd8GAYQIV6s/FU4vs3fLG6BkEvlj6K6YM+IH/5vvaJVoQTsTitU/xP Dp2RJYL/gYwcbfn1eJbii0kUsRpbxVErKM0cR4NUYpEfGsWHMX7/uZ9WNqidFN1NE60D 2OQuabvAU92BiHXbPDAAM8jJmJmW+OPn3VLW60N6p9COuUHRinJokCZ9SFBtI3qMiAct +cy7+hJ9zrvINmWXN4vesLPu4TLPWLXVMw89ctZ05D9rOGMdLWw1hAfm/FtGWP79roiO zgY2nilN2+rTXRdhUwsfcv8w170gb5eYlJuNTazYfEbx0X+mlS94BJiOmrwM9DPLW6xI WLIw== 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=vuzR8lYJ7xnr78jWBV69m1JSFUoZ4+mUNmcyHp13xLQ=; fh=WpT6aB7RBAGHZeWZzqAr71yzRFbPTYkPWKsRagLn48Q=; b=UebmdsTapEv6+3p/s52OzfgGKuwSobYzLw/E2gaU+0oHallQJhFlTIkC4P83O9kVTN Ogk290DCLlDvzOByNJ09tuAs1rtcRph+Mev7uSiwu6fQWyb/wBuAt1ICpjjS8u78u8jQ Wox4UkwjM1/1kkLsNJmi6u5mj3J4j5O0bvyKh3s8LkfY2NOodKm/dx7ZKSlClsFu3Tij cMdhEj8GnlgplX/YCf4fLEv2ReuPBm3saACeDozmtty7oRclGFn95Wk5nf0Lk00atyU5 tZfG2wf4304I2GmDELZGlH+CJhW7L1eAtByDnWiZAF7Gl/HBPe9DFbeYPih5EqBUrKa6 likA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=c6jubt2F; 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-4a3df05efd9si3786994f8f.438.2026.11.16.21.53.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2026 21:53:33 -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=c6jubt2F; 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=vuzR8lYJ7xnr78jWBV69m1JSFUoZ4+mUNmcyHp13xLQ=; b=c6jubt2FPlIv /O8kiEooiXMzqxpxr3kDuixlC+oqoV9l7TBVOh3vKr4IX8G7zPq29X8BziVrrbY4RotOpOS7hLbrv sGc3OzYHGXjXOFehkUtld1O8Rw37/KibEqHZnlTEjr5zueKXq2U+rbnqBMmRLTNFg3ZrWMC6/7qdQ r2wcHgWe4a6M6YBKSAxz/Bs2FCduqzOv9kQY1h7q523cm28WAHA5crzRrX8G1zgNYMAkw5b1kzaaY zL2FT/dzI6ZIR4bV/lZTondl2AAYv5nZJEI3tvbLjuk3D0bK2h0OM/Y/ka8TRgRcsIj8+OY+1EgTG e78oZBdHThGTnr9+2tzl0g==; 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-28; Tue, 17 Nov 2026 06:53:24 +0100 From: Eva Kurchatova To: khorenko@virtuozzo.com Date: Tue, 17 Nov 2026 07:52:12 +0200 Message-ID: <20261117055330.810827-2-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 1/2] ms/ext4: free the sbi 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 [ Upstream commit c17b44266a1f9fcb49b894d4611d1254bf1aa313 ] ext4_get_link() follows a symlink that keeps its target in a data block in rcu pathwalk mode with ext4_getblk(EXT4_GET_BLOCKS_CACHED_NOWAIT). That reads s_mount_state in the ASSERT() of ext4_getblk() and again in ext4_es_lookup_extent(), and the lookup bumps the extent status hit or miss counter, all through sb->s_fs_info. ext4_put_super() destroys those counters, clears sb->s_fs_info and frees the sbi without waiting for a grace period. A pathwalk that is still in ext4_get_link() when the last reference to the mount goes away then dereferences a NULL s_fs_info, the freed sbi or the destroyed percpu counters. With a pathwalk held up in ext4_get_link() while the last reference goes away: KASAN: null-ptr-deref in range [0x00000000000000a8-0x00000000000000af] RIP: 0010:ext4_getblk+0xf0/0x640 Call Trace: ext4_get_link+0x26c/0x410 pick_link+0xf96/0x1780 step_into_slowpath+0x9b8/0x1250 path_lookupat+0x484/0xb00 filename_lookup+0x1f1/0x5b0 vfs_statx+0xd7/0x3b0 vfs_fstatat+0x4d/0x90 __do_sys_newfstatat+0xa0/0x100 do_syscall_64+0x10e/0x5e0 entry_SYSCALL_64_after_hwframe+0x77/0x7f 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. Keep sb->s_fs_info and free the sbi together with the extent status counters after a grace period. Split the counters out of ext4_es_unregister_shrinker() for that. The shrinker still gets wasted in ext4_put_super(), the counters go with the sbi. Fixes: 6493792d3299 ("ext4: convert symlink external data block mapping to bdev") Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20261009-work-fixes-rcu-v1-1-7446d2d335e6@kernel.org Signed-off-by: Christian Brauner (Amutable) [ sashal: omitted ext4_es_destroy_stats() integration with the extent KUnit tests ] Signed-off-by: Sasha Levin (cherry picked from commit 4ce0e27ea610663a9cdc04e3bca38559147428d4) https://virtuozzo.atlassian.net/browse/VSTOR-155414 Feature: fix ms/fs Signed-off-by: Eva Kurchatova --- fs/ext4/ext4.h | 2 ++ fs/ext4/extents_status.c | 7 ++++++- fs/ext4/extents_status.h | 1 + fs/ext4/super.c | 13 +++++++++++-- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 3fe70a19e2a7..3de0fc6e77f2 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1690,6 +1690,8 @@ struct ext4_sb_info { struct list_head s_es_list; /* List of inodes with reclaimable extents */ long s_es_nr_inode; struct ext4_es_stats s_es_stats; + /* ext4_get_link() reads the sbi in rcu pathwalk */ + struct rcu_head s_rcu; struct mb_cache *s_ea_block_cache; struct mb_cache *s_ea_inode_cache; spinlock_t s_es_lock ____cacheline_aligned_in_smp; diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c index 89fc81a80f9a..cb3432b812a6 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c @@ -1804,12 +1804,17 @@ int ext4_es_register_shrinker(struct ext4_sb_info *sbi) } void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi) +{ + shrinker_free(sbi->s_es_shrinker); +} + +/* ext4_get_link() bumps the hit and miss counters in rcu pathwalk */ +void ext4_es_destroy_stats(struct ext4_sb_info *sbi) { percpu_counter_destroy(&sbi->s_es_stats.es_stats_cache_hits); percpu_counter_destroy(&sbi->s_es_stats.es_stats_cache_misses); percpu_counter_destroy(&sbi->s_es_stats.es_stats_all_cnt); percpu_counter_destroy(&sbi->s_es_stats.es_stats_shk_cnt); - shrinker_free(sbi->s_es_shrinker); } /* diff --git a/fs/ext4/extents_status.h b/fs/ext4/extents_status.h index 8f9c008d11e8..502d9110a73c 100644 --- a/fs/ext4/extents_status.h +++ b/fs/ext4/extents_status.h @@ -238,6 +238,7 @@ static inline void ext4_es_store_pblock_status(struct extent_status *es, extern int ext4_es_register_shrinker(struct ext4_sb_info *sbi); extern void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi); +extern void ext4_es_destroy_stats(struct ext4_sb_info *sbi); extern int ext4_seq_es_shrinker_info_show(struct seq_file *seq, void *v); diff --git a/fs/ext4/super.c b/fs/ext4/super.c index e292c0597eaf..e450ea1df71d 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1273,6 +1273,14 @@ static void ext4_flex_groups_free(struct ext4_sb_info *sbi) rcu_read_unlock(); } +static void ext4_put_sbi_rcu(struct rcu_head *head) +{ + struct ext4_sb_info *sbi = container_of(head, struct ext4_sb_info, s_rcu); + + ext4_es_destroy_stats(sbi); + kfree(sbi); +} + static void ext4_put_super(struct super_block *sb) { struct ext4_sb_info *sbi = EXT4_SB(sb); @@ -1369,7 +1377,6 @@ static void ext4_put_super(struct super_block *sb) ext4_stop_mmpd(sbi); brelse(sbi->s_sbh); - sb->s_fs_info = NULL; /* * Now that we are completely done shutting down the * superblock, we need to actually destroy the kobject. @@ -1382,7 +1389,8 @@ static void ext4_put_super(struct super_block *sb) #if IS_ENABLED(CONFIG_UNICODE) utf8_unload(sb->s_encoding); #endif - kfree(sbi); + /* ext4_get_link() reads the sbi and the counters in rcu pathwalk */ + call_rcu(&sbi->s_rcu, ext4_put_sbi_rcu); } static struct kmem_cache *ext4_inode_cachep; @@ -5777,6 +5785,7 @@ failed_mount8: __maybe_unused } failed_mount3a: ext4_es_unregister_shrinker(sbi); + ext4_es_destroy_stats(sbi); failed_mount3: /* flush s_sb_upd_work before sbi destroy */ flush_work(&sbi->s_sb_upd_work); -- 2.56.1 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel