From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.227.139 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796289877; b=W0UnI5OWFOuqcgdkcuypKAZpTG/Mri8R+PiKWkm1zenWHzrBzXImal09LUvalWPX8yId furOXl9amOVlExFW1UCxxMkG7QPZoI8FraAOJKRsUTwAFJze4T4x8+LzVkZIo8IpOPosw jzQlAC7Drs17vSIPp+fZwNkPeyJOBXozoZ75JTZD73m1h9VfiNqP4CgEgEGnTqdn2LNTT Pyvdc0XiGJlohINYKXbuyQj+r1uDBl6SUF4BQEHIYFvXrsF5bZVa87zbjmpdtmvq2w1LX FHNBWb6o+FG2S29w+mA3hrG1g//q2e7eJapuJQcgGEMNtQHW+nVCu2rKgytXEaXFSvg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796289877; 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=FLQhFRz+LjvBM4zho0qyaeJCHX36SvnbEatU56FtVkE=; b=SKqmDVE7c3m+40WVIxd+zitap16UXCSHAe8INKedoAFnb2UuxiweogYIwvt+YwuAYaE1 rbh8SE3lwEnYNUGwdtWWqaFkXZAX0cuvmZUESWz15qiuvn8gEnTalgJZLDG0RbUdTJbLn OIEkINuWKGkgaiD5wVEc2RFdZkXnUbAA5dndumvYQ3VVWAg1XbUmeI8hTE2WhA6osEJuF mqz3slRa9Js33PFNGsCP/TspKLLLNsoBape4QGFd70YhIvRHH7thEocJNIkUsUlZPRepK YgCzutrVvjkaUyyTKd2umx4I9x2rd7+UaC8M+0Hlbx+wNu5L7+dyXXjuYExsAy21MYw== 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=sdSeYaYY; arc=none smtp.remote-ip=74.125.227.139 Received: from mail-pj2-f11.google.com (mail-pj2-f11.google.com [74.125.227.139]) (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 DE7B7606A332 for ; Thu, 3 Dec 2026 09:24:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DE7B7606A332 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=sdSeYaYY Received: by mail-pj2-f11.google.com with SMTP id d9443c01a7336-2f138cc0a18so16486215ad.1 for ; Thu, 03 Dec 2026 01:24:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796289876; x=1796894676; 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=FLQhFRz+LjvBM4zho0qyaeJCHX36SvnbEatU56FtVkE=; b=sdSeYaYYczNF+bywZJf+zCzcXp8lyEan0tWuBigVkBah3Jr6UJq0NelschkmLw6Oqd Sl/i9OOlubuzD47uLYTeZJSX8AQU8vlBb1jbIn93zMSyDf9R6HAbcaheDX2jgQTVweku Rgb6Kq/T+fhPEPB9xYvppsKdA+NH8DV9azjp023DSUGLhi9ekB+Rc2w+RBRhOTQb5tOY q6ZUeOcQwO2M5DmpSNxzavA7lb7H53dWKsMmKwuq/if0HBaczriCqPZYUSvpMakBKCRZ RHfltWHmMThckqO84cEigF0RDiYFz5ql1YqhWxCasqyh9oHqbBBd7dJzXqK5CSnS/qS5 +/og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796289876; x=1796894676; 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=FLQhFRz+LjvBM4zho0qyaeJCHX36SvnbEatU56FtVkE=; b=BTbXAs5Eet/2BKYEu1G6qGwo9iVFgHJ76sAMUSLw29VoqeUL6N8s9ivhuHGi/ps5ZD oIluDO81PYmliaFFdv1+Bz2Q+YErvCKRidIXvS3Ok+pOxSMrQilPFywqpD78rSW5WImk WBmZJTtA47kg0dk3MQYFVqC3v89ncu6/TSGYwqPf7t6qaCb52nrkTMmNniGUZuUA1nie YMAqGY/CwW5eMw86rpFF3fT8/4Aw3A+pB2AC+xyzG1a7gb8Q3Bf68cWLKeXDY+zEhdvP m9Ki6svJm6kF2mO4SZ0O2LUhXJzV+2FCpo6xb7lhItYNIJU6kYQ1L6LEeU8PLBKgZ9F+ HXsA== X-Gm-Message-State: APuU4Z959eW+8G+QphsmuMCUyvb/E1ZSLkqDXYMiiTdyXGDR40cNdPES 3Y48u7NPApZPXLYiCua7+B4eMYnXgYOdLkHd4hum5KYcYAJFN5jwK2ER X-Gm-Gg: AZFdTZeYUl3ASvjkmr/GOzHGyMu2WX2BCqAJ5H3Yq80TfbpRpTnLFaDGirmSMh6+X7V nHUmjNl2v1bpyCRBX68ZOkKOM8oQoPbQTTAlwdQPpLac8FZ+0p6JvU/w0CU81CSBok6LvV5D4nX aSCdLB4//j4CpjTlvk9dHZjbZrCdIyKx6lHI9W+kmwUnBAbd3GXr9EKtBd/KHIiqalbBQH0u53J UA3ouFWifQDQqeIemz2et4UdqZay+SR3ymcBGmBzbYHN0HCT8vo7un0VE6TLannBC2V3ZZk4Ge0 Mf49BwXcVbsq9hahZdeL04kqL8KIW6AifEmQm4YafhJqAcJudT6qz10GW2rSUCsBFH3Nze4gm+3 AGDNkQzJ6mrZ3hp0skAGRO574Qz1TzC7XBk0xES5E50WxdCZjzHdPiupv1iywEGzWQqXcbpdyIs XhhgseVSBbPpEYoYml2evGB1S4dI7FS7upmoRPwYAEbQyf5CwAmDOrVyrEzzPaDh+uHiSXkuuVE FzVeIDjU1xWDea763fuyU3AqAIQVQmYp1kAMUDttR2KWhHhV3LZDO1YZZKLnjgFpQtMD87qr0hv 2tYLvlFprTR35xacTKIuL6qw1rMU/ZbX142JAZ0GFFU= X-Received: by 2002:a17:902:fc4b:b0:2e9:4b65:369f with SMTP id d9443c01a7336-2f03f1ba464mr387873015ad.34.1796289876092; Thu, 03 Dec 2026 01:24:36 -0800 (PST) Received: from hhost ([2409:8a55:3161:29f0:7f14:2cb3:33a0:f9a3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f03f10c9casm217835825ad.52.2026.12.03.01.24.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 01:24:35 -0800 (PST) Date: Thu, 3 Dec 2026 17:24:00 +0800 From: Xingyuan Mo To: Paul Moore , Eric Paris Cc: "open list:AUDIT SUBSYSTEM" , Xingyuan Mo , stable@vger.kernel.org Subject: [PATCH] audit: unlink tree rules in the update_lsm_rule() error path Message-ID: <20261203092331.2258226-1-hdthky0@gmail.com> X-Mailing-List: audit@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 When audit_dupe_rule() fails inside update_lsm_rule(), the error branch removes the old entry from the filter lists and frees it via call_rcu(), but it only unlinks the entry from its watch. A rule carrying an AUDIT_DIR field is linked into tree->rules through its rlist, and that link is left in place, so the freed audit_entry stays reachable from the audit_tree. The next kill_rules() for that tree (umount of the tagged mount, DELETE_SELF on the tagged directory, or a prune) walks tree->rules through the freed entry: KASAN reports a use-after-free read of rule->tree, and the subsequent list_del_rcu()/list_del() on the poisoned list pointers cause a general protection fault in __list_del_entry_valid_or_report(). The tree can never be pruned either, since its rule list never becomes empty. A rule mixing AUDIT_DIR, an LSM field and AUDIT_EXE reaches this path without memory pressure: audit_dupe_exe() fails with -ENOENT once the exe path no longer resolves, and the update is triggered by writing 1 to /sys/fs/selinux/enforce (avc_ss_reset() -> audit_update_lsm_rules()). Call audit_remove_tree_rule() for tree rules in the error branch, as audit_del_rule() does, so that the rlist is unlinked and the tree reference dropped before the entry is freed. KASAN report: ================================================================== BUG: KASAN: slab-use-after-free in kill_rules+0x39/0x4a0 Read of size 8 at addr ffff888015b30570 by task poc-a53-2/332 CPU: 1 UID: 0 PID: 332 Comm: poc-a53-2 Not tainted 7.4.0-rc4-00571-g9437ee8b6cf6 #1 PREEMPT(lazy) 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 kasan_report+0xd6/0x110 __asan_load8+0x82/0xb0 kill_rules+0x39/0x4a0 audit_tree_freeing_mark+0x337/0x560 fsnotify_free_mark+0x7c/0xa0 fsnotify_destroy_marks+0x1c1/0x270 fsnotify_unmount_inodes+0x128/0x230 fsnotify_sb_delete+0x9f/0x270 generic_shutdown_super+0x4f/0x240 kill_anon_super+0x29/0x50 deactivate_locked_super+0x6d/0xc0 deactivate_super+0x63/0x70 cleanup_mnt+0x5d/0xb0 __cleanup_mnt+0x16/0x20 task_work_run+0x10d/0x190 exit_to_user_mode_loop+0x18d/0x5b0 do_syscall_64+0x4dc/0x620 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7fe4e7864b87 Code: 7f a2 0c 00 f7 d8 64 89 01 48 83 c8 ff c3 0f 1f 44 00 00 31 f6 e9 09 00 00 00 66 0f 1f 84 00 00 00 00 00 b8 a6 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 01 c3 48 8b 15 49 a2 0c 00 f7 d8 64 89 02 b8 RSP: 002b:00007ffe32b8dbe8 EFLAGS: 00000246 ORIG_RAX: 00000000000000a6 RAX: 0000000000000000 RBX: 0000000000000000 RCX: 00007fe4e7864b87 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 000055ac53383092 RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000073 R10: 00007fe4e7772418 R11: 0000000000000246 R12: 0000000000000000 R13: 0000000000000000 R14: 000055ac53395100 R15: 0000000000000447 Allocated by task 332: kasan_save_stack+0x2c/0x60 kasan_save_track+0x18/0x50 kasan_save_alloc_info+0x3a/0x50 __kasan_kmalloc+0x88/0xa0 __kmalloc_cache_noprof+0x24d/0x600 audit_data_to_entry+0x13b/0xed0 audit_rule_change+0xe3/0x740 audit_receive_msg+0x26a/0x1bc0 audit_receive+0x17f/0x2a0 netlink_unicast+0x3d4/0x500 netlink_sendmsg+0x451/0x7f0 __sys_sendto+0x384/0x3a0 __x64_sys_sendto+0x84/0xa0 x64_sys_call+0xf18/0x21d0 do_syscall_64+0x11a/0x620 entry_SYSCALL_64_after_hwframe+0x77/0x7f Freed by task 318: kasan_save_stack+0x2c/0x60 kasan_save_track+0x18/0x50 kasan_save_free_info+0x3e/0x60 __kasan_slab_free+0x5c/0x80 kfree+0x240/0x500 audit_free_rule_rcu+0x128/0x140 rcu_core+0x431/0xe30 rcu_core_si+0x12/0x20 handle_softirqs+0x130/0x610 __irq_exit_rcu+0x10f/0x180 irq_exit_rcu+0x12/0x20 sysvec_apic_timer_interrupt+0x7e/0x90 asm_sysvec_apic_timer_interrupt+0x1f/0x30 Last potentially related work creation: kasan_save_stack+0x2c/0x60 __kasan_record_aux_stack+0x9d/0xb0 kasan_record_aux_stack+0xf/0x20 __call_rcu_common.constprop.0+0x88/0x200 call_rcu+0x12/0x20 audit_update_lsm_rules+0x201/0x530 selinux_audit_rule_avc_callback+0x1e/0x30 avc_ss_reset+0x193/0x290 sel_write_enforce+0x28a/0x2c0 vfs_write+0x1d1/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 ffff888015b30400 which belongs to the cache kmalloc-512 of size 512 The buggy address is located 368 bytes inside of freed 512-byte region [ffff888015b30400, ffff888015b30600) The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x15b30 head: order:2 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0 flags: 0x100000000000040(head|node=0|zone=1) page_type: f5(slab) raw: 0100000000000040 ffff888007441c80 dead000000000100 dead000000000122 raw: 0000000000000000 0000000000100010 00000000f5000000 0000000000000000 head: 0100000000000040 ffff888007441c80 dead000000000100 dead000000000122 head: 0000000000000000 0000000000100010 00000000f5000000 0000000000000000 head: 0100000000000002 ffffffffffffff01 00000000ffffffff 00000000ffffffff head: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff888015b30400: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff888015b30480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb >ffff888015b30500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ^ ffff888015b30580: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff888015b30600: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc ================================================================== Oops in the same run: Oops: general protection fault, probably for non-canonical address 0x18202950000013e: 0000 [#1] SMP KASAN PTI CPU: 0 UID: 0 PID: 332 Comm: poc-a53-2 Tainted: G B 7.4.0-rc4-00571-g9437ee8b6cf6 #1 PREEMPT(lazy) Tainted: [B]=BAD_PAGE Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014 RIP: 0010:__list_del_entry_valid_or_report+0x5f/0x160 Code: 48 b8 00 01 00 00 00 00 ad de 49 39 c6 74 7c 48 b8 22 01 00 00 00 00 ad de 49 39 c5 0f 84 87 00 00 00 4c 89 ef e8 f1 63 8f ff <4d> 39 65 00 0f 85 93 00 00 00 4d 8d 6e 08 4c 89 ef e8 db 63 8f ff RSP: 0018:ffff88801361fa80 EFLAGS: 00010282 RAX: 0000000000000000 RBX: ffff888015b30570 RCX: ffffffff81e808bf RDX: 0000000000000000 RSI: 0000000000000008 RDI: 018202950000013e RBP: ffff88801361fa98 R08: ffffffff8152883c R09: fffffbfff0ae5ed4 R10: ffffffff8572f6a7 R11: 74206c656e72656b R12: ffff888015b30400 R13: 018202950000013e R14: ffff88800a2fce40 R15: ffff888015b30400 FS: 00007fe4e7759740(0000) GS:ffff8880e7930000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f4e959f1358 CR3: 0000000015628000 CR4: 00000000000006f0 Call Trace: kill_rules+0x129/0x4a0 audit_tree_freeing_mark+0x337/0x560 fsnotify_free_mark+0x7c/0xa0 fsnotify_destroy_marks+0x1c1/0x270 fsnotify_unmount_inodes+0x128/0x230 fsnotify_sb_delete+0x9f/0x270 generic_shutdown_super+0x4f/0x240 kill_anon_super+0x29/0x50 deactivate_locked_super+0x6d/0xc0 deactivate_super+0x63/0x70 cleanup_mnt+0x5d/0xb0 __cleanup_mnt+0x16/0x20 task_work_run+0x10d/0x190 exit_to_user_mode_loop+0x18d/0x5b0 do_syscall_64+0x4dc/0x620 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7fe4e7864b87 Code: 7f a2 0c 00 f7 d8 64 89 01 48 83 c8 ff c3 0f 1f 44 00 00 31 f6 e9 09 00 00 00 66 0f 1f 84 00 00 00 00 00 b8 a6 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 01 c3 48 8b 15 49 a2 0c 00 f7 d8 64 89 02 b8 RSP: 002b:00007ffe32b8dbe8 EFLAGS: 00000246 ORIG_RAX: 00000000000000a6 RAX: 0000000000000000 RBX: 0000000000000000 RCX: 00007fe4e7864b87 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 000055ac53383092 RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000073 R10: 00007fe4e7772418 R11: 0000000000000246 R12: 0000000000000000 R13: 0000000000000000 R14: 000055ac53395100 R15: 0000000000000447 Modules linked in: Fixes: 74c3cbe33bc0 ("[PATCH] audit: watching subtrees") Cc: stable@vger.kernel.org Signed-off-by: Xingyuan Mo --- kernel/auditfilter.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c index cf91ba6f3617b..06fe7ab13eb7a 100644 --- a/kernel/auditfilter.c +++ b/kernel/auditfilter.c @@ -1422,6 +1422,8 @@ static int update_lsm_rule(struct audit_krule *r) audit_panic("error updating LSM filters"); if (r->watch) list_del(&r->rlist); + if (r->tree) + audit_remove_tree_rule(r); list_del_rcu(&entry->list); list_del(&r->list); audit_rule_unaccount(r); -- 2.43.0