From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.227.130 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796319224; b=GA8DqVrnZK5NH1Aj19FILKtGLA+oSD9I+zBWLikda55jqyR8gX6zoHeE8UXnW263pYwA QLW9KL5fdw1EtxZUCxqOqmkp313F+QktZlMTfz2/0eMSSIbiB3WtGqcpXOr2j7xCcraw1 nO1ESxSAWt85vtnlHqiJa6H20L9EcSlF7K2QAaaPiPjdN+dcNlQUjRHK6+yiuMJ65/A3L rlV1ytPxw2eWko8ET+x2faUcWW01kGj9yN9mS8XOLqZI9yc8Bg+l75BIOW8QX1iz/ST0D ntHYrE/poSRNvqLQG2xPWRTo8h9Hj83xYUDWjo/tDfKj0+3cmyrT4JVv8O8HgUDfOjw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796319224; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Date:From:To:Cc: Subject:Message-ID:MIME-Version:Content-Type:Content-Disposition: X-Mailer; bh=id3qJNYUuQngjkT20A0KEvPO76xJ1Lk1AUpUICvIABw=; b=UqJvfKZZ7ksbijiSXOlOU/BdumzVWulk3vxzy0y4ycS3nfe4Oguc9pwopKZY6u256kdC C5HBjEST9m049Ie+B3faH9CnnpW14nea1kYPPxjURK7mm4F4K2/HDrjLRwv74KZLWdbvk uj7XSqup0Ok0wqyBzZiAkhEyVgWZe8+ZgZfoZgZhX3iR6l7nuS7RKuPXBapwsO8D22Q7z 5JC48TDO3zMyXpdy6f1tfGYCaI0twZ6+sTeN4oN+n9LIz1Db2mAYi+gU58jrilU93gsps MyQ1167R2zTF/5GtJrd7ibO/pDsxHeNx2nDWSVlWSBNrmQiOLnVMKiGrcvWAv0dEIPQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="L/X5o8Hl"; arc=none smtp.remote-ip=74.125.227.130 Received: from mail-pj2-f2.google.com (mail-pj2-f2.google.com [74.125.227.130]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41F6E606A334 for ; Thu, 3 Dec 2026 17:33:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 41F6E606A334 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=L/X5o8Hl Received: by mail-pj2-f2.google.com with SMTP id d9443c01a7336-2efc8c9ba9fso605455ad.0 for ; Thu, 03 Dec 2026 09:33:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796319223; x=1796924023; darn=vger.kernel.org; h=content-disposition:content-type:mime-version:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=id3qJNYUuQngjkT20A0KEvPO76xJ1Lk1AUpUICvIABw=; b=L/X5o8HlKxaSkYAlVNdHNEn81tggMozvtJpmkp2ekDLOoTkk42Z2rzBnJ1Ns1VCoiF igBFPgCRoJFbq3cZnAyz5hLcEGtS/SFQsw7oV0zp5kwsbtzCV+jOAt27EXlaOazEbO2Y RxdFgl98SNo51DKjKRWrrNY5Uj3cFk/MLmd3LwJO5mah3uVQ1vbR2EO2lhCtChkvbf5y Yv8pk3p4O/upwaIvL3tmBU2QwF0Tm7W8nMLktNEMHMPI/Gn3XX92pjfDzJB8LyB7ACm4 ClcevuwLfSXG4Xns5RfXExaztj4DDajHSfewt8Q/U26fTFzepSZebMxhNRp0QnlsD/j9 HAtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796319223; x=1796924023; h=content-disposition:content-type:mime-version:message-id:subject:cc :to:from:date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=id3qJNYUuQngjkT20A0KEvPO76xJ1Lk1AUpUICvIABw=; b=r1ylIN8tgStwFA6+aoljVXDU/RLcDBZ5qp3/u3DMJbJQs+KC6iZA2lHtlocSAdmXqJ K5NxH/v+jtKRJ6w2zKxvwYkwJhaxR/X86/WvgfcABV9hwx6xwWavf7GRQ1fgxqNCVIus TWGaJztbE5Bj6YBpbmLMkzptZWyp3XlQ8eGWnyqHn8JCPV83E3J7itGBwUPy54o/rhtH xvOnXGG5WzYNLf0xhImV4G1w74MBPJsWmdYy83/zNMfGvf2Wh7IAFhzxibes87cOKj5A uYn196xeSea05Id4KD35lVH1ksXqwFjyrk2Tt3IzEqD8bnuhNdUAlrMzs7kjZ2idSsDf REWA== X-Gm-Message-State: APuU4Z/uWKGb/XMrcjnIZZ+MC044nCoqAN4fQbtt9/jtARBMFDfA4n1c qWPK/5Ri8vVISEQ1hWBT6dasPWlmD5zupY1QsuudzgkKfiHzqeRdQAn0UEuEbQUISnMqelF+ X-Gm-Gg: AZFdTZcIt8hedo3RSP9Y9Dp3vWe3aWaNFHs47l0NcK6s5MO3FHu0VdGRlMYT4WjVwPs sE8sRLfzWtAXc23bOjM6ZdfeawA9RT9rWyCua9tLGPnCawwZhv/mCTCZuLtJeEIJdo+9b1lcRxV PvEkpOKWSALBsLiRrB4rGuRFslEUZqkDxwGyOnPNfckIaUVUT0veJ7KAd3FzYqKlPYgydCrr413 SCLET4z196HoKOGjiAtNysfXWu1L0Z+kBpjy5f4FIGJ5Og/p8il9gtsmtumayQ9k2ZJSICE5tKw VW7pSm5jDocPrREwS1J9QzESE/V+Oxspjy13SCXfdL4znuvvbeVyiBEys4JafGFDvpAsWgxbmxk gJS/jRAbfv2BPKd3OZrDD2f/UCLE9oSDQUWYKfpYbemJEwpcSKT+Htnu9wj/suGE9Qmqlt7bIgz 2obwOBlYIaBejhaLc4pmW7WoVA0fTaHx4R9cXu0fkErbz3MYOK6+YtioL4pZFIYIylPvjH5H9ES sbHYH3psH3/pepR+SDtJzaOM5wFzoMwpKCvBTkC4AEZmyJZWfQdI6ASzVuEDyOdZg4reUha5QPa MKmcoa8eTe7TwnGGGLEOeQ== X-Received: by 2002:a17:902:e811:b0:2ed:3f47:96a3 with SMTP id d9443c01a7336-2f03f169628mr469165345ad.42.1796319222441; Thu, 03 Dec 2026 09:33:42 -0800 (PST) Received: from hhost ([2409:8a55:3161:29f0:7f14:2cb3:33a0:f9a3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f13aa98101sm88708305ad.28.2026.12.03.09.33.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 09:33:41 -0800 (PST) Date: Fri, 4 Dec 2026 01:33:04 +0800 From: Xingyuan Mo To: Theodore Ts'o , Andreas Dilger , Baokun Li , Jan Kara , Ojaswin Mujoo , Ritesh Harjani , Zhang Yi Cc: "open list:EXT4 FILE SYSTEM" , Xingyuan Mo , stable@vger.kernel.org Subject: [PATCH] ext4: do not toggle DQUOT_NOLIST_DIRTY with quotas already loaded Message-ID: <20261203173240.2282734-1-hdthky0@gmail.com> X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Mailer: git-send-email 2.43.0 ext4_quota_on() sets or clears the per-superblock DQUOT_NOLIST_DIRTY flag from s_qf_names[type] before dquot_quota_on() runs, so a Q_QUOTAON that fails afterwards (-EACCES for a directory, -EBUSY for a type that is already loaded) still flips the flag. With usrjquota= mounted and user quota active, root can therefore toggle the flag at will by alternating Q_QUOTAON(USRQUOTA) and Q_QUOTAON(GRPQUOTA). The quota core reads that flag without any locking in dquot_mark_dquot_dirty() and clear_dquot_dirty(). If the flag changes between a dquot's mark and its clear, which are separated by the sleeping ext4_journal_start() in ext4_write_dquot(), the clear takes the bit-only path and leaves the dquot linked on dqi_dirty_list with DQ_MOD_B clear. dquot_writeback_dquots() then spins forever on it, and once the dquot drops to refcount 0 and is moved to free_dquots, dqcache_shrink_scan() frees it while it is still linked. The next list_add() of any other dquot then reads and writes the freed object. Decide the flag only while no quota is loaded on the superblock, the one situation in which no dquot can be dirty or on the list. KASAN report: BUG: KASAN: slab-use-after-free in __list_add_valid_or_report+0x2f/0x110 Read of size 8 at addr ffff88801c1dfdf8 by task poc-q1/343 CPU: 0 UID: 0 PID: 343 Comm: poc-q1 Tainted: G W 7.4.0-rc4-00571-g9437ee8b6cf6 #1 PREEMPT(lazy) Tainted: [W]=WARN Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014 Call Trace: dump_stack_lvl+0x74/0xb0 print_report+0xce/0x5f0 ? __list_add_valid_or_report+0x2f/0x110 ? kasan_complete_mode_report_info+0x80/0x200 ? __list_add_valid_or_report+0x2f/0x110 kasan_report+0xd6/0x110 ? __list_add_valid_or_report+0x2f/0x110 __asan_load8+0x82/0xb0 __list_add_valid_or_report+0x2f/0x110 dquot_mark_dquot_dirty+0x15d/0x1a0 ext4_mark_dquot_dirty+0x77/0xc0 dquot_set_dqblk+0x306/0x830 quota_setquota+0x305/0x390 ? __pfx_quota_setquota+0x10/0x10 ? avc_has_perm_noaudit+0xda/0x290 ? __pfx_avc_has_perm+0x10/0x10 ? selinux_quotactl+0xcf/0x190 do_quotactl+0x750/0xb60 ? __pfx_do_quotactl+0x10/0x10 ? __kasan_slab_free+0x6d/0x80 ? kmem_cache_free+0x22a/0x530 ? putname+0x5b/0x90 ? putname+0x5b/0x90 ? quotactl_block+0x361/0x3f0 ? __pfx_quotactl_block+0x10/0x10 ? mntput_no_expire+0x92/0x130 __x64_sys_quotactl+0x113/0x280 ? __pfx___x64_sys_quotactl+0x10/0x10 ? __pfx_fput_close_sync+0x10/0x10 ? do_raw_spin_unlock+0x9f/0x100 ? rcu_is_watching+0x25/0x60 x64_sys_call+0x183a/0x21d0 do_syscall_64+0x11a/0x620 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f1c6a63809a Code: 73 01 c3 48 8b 0d 66 8d 0c 00 f7 d8 64 89 01 48 83 c8 ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 49 89 ca b8 b3 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 36 8d 0c 00 f7 d8 64 89 01 48 RSP: 002b:00007ffeff832798 EFLAGS: 00000206 ORIG_RAX: 00000000000000b3 RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 00007f1c6a63809a RDX: 0000000000001388 RSI: 00007ffeff833ebe RDI: 0000000080000800 RBP: 00007ffeff8328c0 R08: 0000000000000007 R09: 00005583316653d0 R10: 00007ffeff8327c0 R11: 0000000000000206 R12: 0000000000000001 R13: 0000000000001388 R14: 0000000000000004 R15: 00007f1c6a52b6c0 Allocated by task 348: kasan_save_stack+0x2c/0x60 kasan_save_track+0x18/0x50 kasan_save_alloc_info+0x3a/0x50 __kasan_slab_alloc+0x62/0x80 kmem_cache_alloc_noprof+0x1ed/0x5d0 dquot_alloc+0x1e/0x30 dqget+0x3db/0x6e0 __dquot_initialize+0x24c/0x6d0 dquot_initialize+0x17/0x20 __ext4_new_inode+0x41d/0x28c0 ext4_create+0x1f5/0x300 lookup_open+0x708/0xba0 path_openat+0x698/0xfb0 do_file_open+0x188/0x2c0 do_sys_openat2+0x110/0x170 __x64_sys_openat+0xea/0x170 x64_sys_call+0x1eac/0x21d0 do_syscall_64+0x11a/0x620 entry_SYSCALL_64_after_hwframe+0x77/0x7f Freed by task 343: kasan_save_stack+0x2c/0x60 kasan_save_track+0x18/0x50 kasan_save_free_info+0x3e/0x60 __kasan_slab_free+0x5c/0x80 kmem_cache_free+0x22a/0x530 dquot_destroy+0x1c/0x30 dqcache_shrink_scan+0x17a/0x320 shrink_slab+0x3fc/0xa70 drop_slab+0x91/0x130 drop_caches_sysctl_handler+0x8a/0xf0 proc_sys_call_handler+0x27e/0x390 proc_sys_write+0x17/0x20 vfs_write+0x609/0x7f0 ksys_write+0xd9/0x180 __x64_sys_write+0x47/0x60 x64_sys_call+0x16f5/0x21d0 do_syscall_64+0x11a/0x620 entry_SYSCALL_64_after_hwframe+0x77/0x7f The buggy address belongs to the object at ffff88801c1dfdc0 which belongs to the cache dquot of size 376 The buggy address is located 56 bytes inside of freed 376-byte region [ffff88801c1dfdc0, ffff88801c1dff38) The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1c1de head: order:1 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0 flags: 0x100000000000040(head|node=0|zone=1) page_type: f5(slab) raw: 0100000000000040 ffff888007f188c0 dead000000000122 0000000000000000 raw: 0000000000000000 0000000000120012 00000000f5000000 0000000000000000 head: 0100000000000040 ffff888007f188c0 dead000000000122 0000000000000000 head: 0000000000000000 0000000000120012 00000000f5000000 0000000000000000 head: 0100000000000001 ffffffffffffff81 00000000ffffffff 00000000ffffffff head: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff88801c1dfc80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ffff88801c1dfd00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 fc >ffff88801c1dfd80: fc fc fc fc fc fc fc fc fa fb fb fb fb fb fb fb ^ ffff88801c1dfe00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff88801c1dfe80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ================================================================== Fixes: 91389240a252 ("ext4: Disable dirty list tracking of dquots when journalling quotas") Cc: stable@vger.kernel.org Signed-off-by: Xingyuan Mo --- fs/ext4/super.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 880f664d6c04b..22438d9f2bb3b 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -7292,13 +7292,12 @@ static int ext4_quota_on(struct super_block *sb, int type, int format_id, ext4_msg(sb, KERN_WARNING, "Quota file not on filesystem root. " "Journaled quota will not work"); - sb_dqopt(sb)->flags |= DQUOT_NOLIST_DIRTY; - } else { - /* - * Clear the flag just in case mount options changed since - * last time. - */ - sb_dqopt(sb)->flags &= ~DQUOT_NOLIST_DIRTY; + } + if (!sb_any_quota_loaded(sb)) { + if (EXT4_SB(sb)->s_qf_names[type]) + sb_dqopt(sb)->flags |= DQUOT_NOLIST_DIRTY; + else + sb_dqopt(sb)->flags &= ~DQUOT_NOLIST_DIRTY; } lockdep_set_quota_inode(path->dentry->d_inode, I_DATA_SEM_QUOTA); -- 2.43.0