WARNING in landlock_merge_ruleset
Subsystems (2)
syzbot
syzbotHello,
syzbot found the following issue on:
HEAD commit: aac26bee2287 Add linux-next specific files for 20261008 git tree: linux-next console+strace: https://syzkaller.appspot.com/x/log.txt?x=1772f715580000 kernel config: https://syzkaller.appspot.com/x/.config?x=814b0d31d59c294 dashboard link: https://syzkaller.appspot.com/bug?extid=a0eecb22de4d821a9e5d compiler: Debian clang version 22.1.8 (++20260613092233+e80beda6e255-1~exp1~20260613092250.77), Debian LLD 22.1.8 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=1305c8e1580000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=15497c3e580000
Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/92e867ba9905/disk-aac26bee.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/c4cc176072c1/vmlinux-aac26bee.xz
kernel image: https://storage.googleapis.com/syzbot-assets/c603638afe28/bzImage-aac26bee.xz
IMPORTANT: if you fix the issue, please add the following tag to the commit:
------------[ cut here ]------------ memcpy: detected buffer overflow: 16 byte read of buffer size 0 WARNING: lib/string_helpers.c:1037 at __fortify_report+0x6b/0xa0 lib/string_helpers.c:1036, CPU#0: syz-executor347/5624 Modules linked in: CPU: 0 UID: 0 PID: 5624 Comm: syz-executor347 Not tainted syzkaller #0 PREEMPT(full) Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/16/2026 RIP: 0010:__fortify_report+0x89/0xa0 lib/string_helpers.c:1036 Code: e8 ec f1 4b fd 48 8d 3d c5 7e d7 0c 45 84 e4 49 8b 37 48 c7 c0 40 8d 8d 8c 48 c7 c1 60 8d 8d 8c 48 0f 44 c8 4c 89 f2 49 89 d8 <67> 48 0f b9 3a 5b 41 5c 41 5e 41 5f 5d e9 45 84 14 07 cc cc cc cc RSP: 0018:ffffc90003bb7dc8 EFLAGS: 00010246 RAX: ffffffff8c8d8d40 RBX: 0000000000000000 RCX: ffffffff8c8d8d40 RDX: 0000000000000010 RSI: ffffffff8c8d8c20 RDI: ffffffff91c743f0 RBP: 000000000000000e R08: 0000000000000000 R09: 1ffff11006d9ed01 R10: dffffc0000000000 R11: ffffed1006d9ed02 R12: 0000000000000000 R13: 0000000000000000 R14: 0000000000000010 R15: ffffffff8c8d8a78 FS: 000055558b41f400(0000) GS:ffff888123429000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000055c55f793000 CR3: 00000000359c2000 CR4: 00000000003526f0 Call Trace: <TASK> __fortify_panic+0x9/0x10 lib/string_helpers.c:1043 fortify_memcpy_chk include/linux/fortify-string.h:547 [inline] inherit_ruleset security/landlock/domain.c:407 [inline] landlock_merge_ruleset+0xc46/0xc90 security/landlock/domain.c:468 __do_sys_landlock_restrict_self security/landlock/syscalls.c:809 [inline] __se_sys_landlock_restrict_self+0x2bc/0xd40 security/landlock/syscalls.c:732 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline] do_syscall_64+0x166/0x520 arch/x86/entry/syscall_64.c:84 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7fc0d85c8c39 Code: c0 79 93 eb d5 48 8d 7c 1d 00 eb 99 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 d8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007fff6fcb7858 EFLAGS: 00000246 ORIG_RAX: 00000000000001be RAX: ffffffffffffffda RBX: 00007fff6fcb7988 RCX: 00007fc0d85c8c39 RDX: 00007fc0d85c8c39 RSI: 0000000000000000 RDI: 0000000000000004 RBP: 0000000000000001 R08: 00007fff6fcb7988 R09: 00007fff6fcb7988 R10: 00007fff6fcb7988 R11: 0000000000000246 R12: 00007fff6fcb7978 R13: 0000000000000002 R14: 00007fc0d8659ca0 R15: 0000000000000002 </TASK> ---------------- Code disassembly (best guess): 0: e8 ec f1 4b fd call 0xfd4bf1f1 5: 48 8d 3d c5 7e d7 0c lea 0xcd77ec5(%rip),%rdi # 0xcd77ed1 c: 45 84 e4 test %r12b,%r12b f: 49 8b 37 mov (%r15),%rsi 12: 48 c7 c0 40 8d 8d 8c mov $0xffffffff8c8d8d40,%rax 19: 48 c7 c1 60 8d 8d 8c mov $0xffffffff8c8d8d60,%rcx 20: 48 0f 44 c8 cmove %rax,%rcx 24: 4c 89 f2 mov %r14,%rdx 27: 49 89 d8 mov %rbx,%r8 * 2a: 67 48 0f b9 3a ud1 (%edx),%rdi <-- trapping instruction 2f: 5b pop %rbx 30: 41 5c pop %r12 32: 41 5e pop %r14 34: 41 5f pop %r15 36: 5d pop %rbp 37: e9 45 84 14 07 jmp 0x7148481 3c: cc int3 3d: cc int3 3e: cc int3 3f: cc int3
---
This report is generated by a bot. It may contain errors. See https://goo.gl/tpsmEJ for more information about syzbot. syzbot engineers can be reached at [email protected].
syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title
If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.
If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)
If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report
If you want to undo deduplication, reply with:
#syz undup
PATCH 1/1 landlock: Drop __counted_by from landlock_domain.layers
With clang 22 and CONFIG_FORTIFY_SOURCE, the second landlock_restrict_self() call hits a bogus fortify report in inherit_ruleset():
memcpy: detected buffer overflow: 16 byte read of buffer size 0
Call Trace: __fortify_panic landlock_merge_ruleset+0xc46/0xc90 __se_sys_landlock_restrict_self+0x2bc/0xd40
layers[] lives in an anonymous struct inside the anonymous union that overlays work_free. For such a flexible array, clang computes the address of the __counted_by counter as the start of the array instead of &num_layers. The bound is then read from layers[0], i.e. from the first layer's configuration, which is not a count. The same layout crashes clang itself in a standalone test.
The annotation was added as documentation, so drop it rather than restructure the union. Keep the information in the member comment.
---
Reproduced with clang 22.1.8 and FORTIFY_SOURCE on mic/next (64b9e6eff524):
the second landlock_restrict_self() hits the report, while 16 nested restricts run clean with this patch. Mickaël, if you prefer to just drop bd3a19800dd1 from next, that works as well.
security/landlock/domain.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
security/landlock/domain.h +5 -1
@@ -246,8 +246,12 @@ struct landlock_domain {* properly handle merged rulesets without overlapping * access rights. These layers are set once and never * changed for the lifetime of the domain. +* +* Not annotated with __counted_by(@num_layers): clang +* miscomputes the counter address for a FAM nested in an +* anonymous struct within a union, which trips FORTIFY. */ - struct layer_config layers[] __counted_by(num_layers); +struct layer_config layers[]; }; }; };
Signature · 1 line
2.43.0
Re: [PATCH] landlock: Drop __counted_by from landlock_domain.layers
Hello Nguyen,
Quoted 27 lines
Date: 2026-10-10 23:44:49+0700
From: Nguyen Ngoc Thang <[email protected]>With clang 22 and
CONFIG_FORTIFY_SOURCE, the secondlandlock_restrict_self()call hits a bogus fortify report ininherit_ruleset():memcpy: detected buffer overflow: 16 byte read of buffer size 0
Call Trace: __fortify_panic landlock_merge_ruleset+0xc46/0xc90 __se_sys_landlock_restrict_self+0x2bc/0xd40layers[] lives in an anonymous struct inside the anonymous union that overlays
work_free. For such a flexible array, clang computes the address of the__counted_bycounter as the start of the array instead of&num_layers. The bound is then read from layers[0], i.e. from the first layer's configuration, which is not a count. The same layout crashes clang itself in a standalone test.The annotation was added as documentation, so drop it rather than restructure the union. Keep the information in the member comment.
Reported-by [email protected]Fixes bd3a19800dd1 ("landlock: Add counted_by in landlock_domain")Signed-off-by Nguyen Ngoc Thang <[email protected]>
Quoted 5 lines
---
Reproduced with clang 22.1.8 andFORTIFY_SOURCEon mic/next (64b9e6eff524):
the secondlandlock_restrict_self()hits the report, while 16 nested restricts run clean with this patch. Mickaël, if you prefer to just dropbd3a19800dd1from next, that works as well.
Is this reproducible with Clang 23 or later?
Should __counted_by() expand to nothing for bogus versions of Clang? That would allow using it, and just ignore Clang when it's broken, rather than not using safety features.
Have a lovely day!
Alex
Quoted 25 lines
security/landlock/domain.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)security/landlock/domain.h +5
-1@@ -246,8 +246,12 @@ struct landlock_domain {* properly handle merged rulesets without overlapping * access rights. These layers are set once and never * changed for the lifetime of the domain. +* +* Not annotated with __counted_by(@num_layers): clang +* miscomputes the counter address for a FAM nested in an +* anonymous struct within a union, which trips FORTIFY. */ - struct layer_config layers[] __counted_by(num_layers); +struct layer_config layers[]; }; }; };Signature · 1 line
2.43.0
Signature · 1 line
<https://www.alejandro-colomar.es>
Re: [PATCH] landlock: Drop __counted_by from landlock_domain.layers
Quoted 35 lines · Alejandro Colomar
Hello Nguyen,
Quoted 27 lines
Date: 2026-10-10 23:44:49+0700
From: Nguyen Ngoc Thang <[email protected]>With clang 22 and
CONFIG_FORTIFY_SOURCE, the secondlandlock_restrict_self()call hits a bogus fortify report ininherit_ruleset():memcpy: detected buffer overflow: 16 byte read of buffer size 0
Call Trace: __fortify_panic landlock_merge_ruleset+0xc46/0xc90 __se_sys_landlock_restrict_self+0x2bc/0xd40layers[] lives in an anonymous struct inside the anonymous union that overlays
work_free. For such a flexible array, clang computes the address of the__counted_bycounter as the start of the array instead of&num_layers. The bound is then read from layers[0], i.e. from the first layer's configuration, which is not a count. The same layout crashes clang itself in a standalone test.The annotation was added as documentation, so drop it rather than restructure the union. Keep the information in the member comment.
Reported-by [email protected]Fixes bd3a19800dd1 ("landlock: Add counted_by in landlock_domain")Signed-off-by Nguyen Ngoc Thang <[email protected]>Quoted 5 lines
---
Reproduced with clang 22.1.8 andFORTIFY_SOURCEon mic/next (64b9e6eff524):
the secondlandlock_restrict_self()hits the report, while 16 nested restricts run clean with this patch. Mickaël, if you prefer to just dropbd3a19800dd1from next, that works as well.
Quoted 5 lines
Is this reproducible with Clang 23 or later?
Should
__counted_by()expand to nothing for bogus versions of Clang? That would allow using it, and just ignore Clang when it's broken, rather than not using safety features.
This is actively being discussed/investigated in another thread but yes, we will be marking clang versions affected by this problem as broken for __counted_by:
Quoted 28 lines
Quoted 25 lines
security/landlock/domain.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)security/landlock/domain.h +5
-1@@ -246,8 +246,12 @@ struct landlock_domain {* properly handle merged rulesets without overlapping * access rights. These layers are set once and never * changed for the lifetime of the domain. +* +* Not annotated with __counted_by(@num_layers): clang +* miscomputes the counter address for a FAM nested in an +* anonymous struct within a union, which trips FORTIFY. */ - struct layer_config layers[] __counted_by(num_layers); +struct layer_config layers[]; }; }; };Signature · 1 line
2.43.0Signature · 1 line
<https://www.alejandro-colomar.es>
Signature · 2 lines
Cheers, Nathan
Re: [PATCH] landlock: Drop __counted_by from landlock_domain.layers
Hi Nathan, Alex,
Thanks for the pointers. I wasn't aware of the earlier thread, so please disregard my patch in favor of the one from Qualcomm and the Clang version gating of __counted_by.
To answer Alex's question: I only tested with Clang 22.1.8 (Debian 22.1.8-1~deb13u4, same as the syzbot build). I did not try Clang 23 or later, so I can't say whether it is fixed there.
Thanks,
Nguyen
Re: [PATCH] landlock: Drop __counted_by from landlock_domain.layers
In reply to Nguyen Ngoc ThangQuoted 53 lines · Nguyen Ngoc Thang
With clang 22 and
CONFIG_FORTIFY_SOURCE, the secondlandlock_restrict_self()call hits a bogus fortify report ininherit_ruleset():memcpy: detected buffer overflow: 16 byte read of buffer size 0
Call Trace: __fortify_panic landlock_merge_ruleset+0xc46/0xc90 __se_sys_landlock_restrict_self+0x2bc/0xd40layers[] lives in an anonymous struct inside the anonymous union that overlays
work_free. For such a flexible array, clang computes the address of the__counted_bycounter as the start of the array instead of&num_layers. The bound is then read from layers[0], i.e. from the first layer's configuration, which is not a count. The same layout crashes clang itself in a standalone test.The annotation was added as documentation, so drop it rather than restructure the union. Keep the information in the member comment.
Reported-by [email protected]Fixes bd3a19800dd1 ("landlock: Add counted_by in landlock_domain")Signed-off-by Nguyen Ngoc Thang <[email protected]>---
Reproduced with clang 22.1.8 andFORTIFY_SOURCEon mic/next (64b9e6eff524):
the secondlandlock_restrict_self()hits the report, while 16 nested restricts run clean with this patch. Mickaël, if you prefer to just dropbd3a19800dd1from next, that works as well.security/landlock/domain.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)security/landlock/domain.h +5
-1@@ -246,8 +246,12 @@ struct landlock_domain {* properly handle merged rulesets without overlapping * access rights. These layers are set once and never * changed for the lifetime of the domain. +* +* Not annotated with __counted_by(@num_layers): clang +* miscomputes the counter address for a FAM nested in an +* anonymous struct within a union, which trips FORTIFY. */ - struct layer_config layers[] __counted_by(num_layers); +struct layer_config layers[]; }; }; };Signature · 1 line
2.43.0
I agree - it seems better to drop the __counted_by rather than restructuring the entire struct for that.
Thanks also for adding a comment about it. The __counted_by() has only been added very recently in September, in commit bd3a19800dd1 ("landlock: Add counted_by in landlock_domain"). Better to have a note about it so that we don't accidentally add it back. :)
–Günther
Mickaël Salaün
maintainerRe: [PATCH] landlock: Drop __counted_by from landlock_domain.layers
Quoted 18 lines · Günther Noack
Quoted 17 lines · Nguyen Ngoc Thang
With clang 22 and
CONFIG_FORTIFY_SOURCE, the secondlandlock_restrict_self()call hits a bogus fortify report ininherit_ruleset():memcpy: detected buffer overflow: 16 byte read of buffer size 0
Call Trace: __fortify_panic landlock_merge_ruleset+0xc46/0xc90 __se_sys_landlock_restrict_self+0x2bc/0xd40layers[] lives in an anonymous struct inside the anonymous union that overlays
work_free. For such a flexible array, clang computes the address of the__counted_bycounter as the start of the array instead of&num_layers. The bound is then read from layers[0], i.e. from the first layer's configuration, which is not a count. The same layout crashes clang itself in a standalone test.
Quoted 7 lines
Quoted 7 lines
The annotation was added as documentation, so drop it rather than restructure the union. Keep the information in the member comment.
Reported-by [email protected]Fixes bd3a19800dd1 ("landlock: Add counted_by in landlock_domain")Signed-off-by Nguyen Ngoc Thang <[email protected]>
Thanks for the patch.
Quoted 32 lines
Quoted 29 lines
---
Reproduced with clang 22.1.8 andFORTIFY_SOURCEon mic/next (64b9e6eff524):
the secondlandlock_restrict_self()hits the report, while 16 nested restricts run clean with this patch. Mickaël, if you prefer to just dropbd3a19800dd1from next, that works as well.security/landlock/domain.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)security/landlock/domain.h +5
-1@@ -246,8 +246,12 @@ struct landlock_domain {* properly handle merged rulesets without overlapping * access rights. These layers are set once and never * changed for the lifetime of the domain. +* +* Not annotated with __counted_by(@num_layers): clang +* miscomputes the counter address for a FAM nested in an +* anonymous struct within a union, which trips FORTIFY. */ - struct layer_config layers[] __counted_by(num_layers); +struct layer_config layers[]; }; }; };Signature · 1 line
2.43.0Reviewed-by Günther Noack <[email protected]>
Quoted 7 lines
I agree - it seems better to drop the
__counted_byrather than restructuring the entire struct for that.Thanks also for adding a comment about it. The
__counted_by()has only been added very recently in September, in commitbd3a19800dd1("landlock: Addcounted_byinlandlock_domain"). Better to have a note about it so that we don't accidentally add it back. :)
Actually, I independently wrote a quite similar patch (while traveling), but it applies to v7.3-rc5 instead of mic/next. I removed the patch series that I applied on mic/next because it conflicts with my patch and I need to send a new version anyway. If you don't mind, I'll keep Günther's Reviewed-by tag and credit other contributors in my patch. I'll propose it for v7.3-rc7 (today) because it is trivial and will help new patches on top of that.
Re: [PATCH] landlock: Drop __counted_by from landlock_domain.layers
Hi Mickaël, Günther,
Sounds good, no problem at all. Thanks for the quick review, and happy for you to take your version for v7.3-rc7.
Thanks,
Thang
Mickaël Salaün
maintainerRe: [PATCH] landlock: Drop __counted_by from landlock_domain.layers
In reply to Mickaël SalaünQuoted 69 lines · Mickaël Salaün
Quoted 18 lines · Günther Noack
Quoted 17 lines · Nguyen Ngoc Thang
With clang 22 and
CONFIG_FORTIFY_SOURCE, the secondlandlock_restrict_self()call hits a bogus fortify report ininherit_ruleset():memcpy: detected buffer overflow: 16 byte read of buffer size 0
Call Trace: __fortify_panic landlock_merge_ruleset+0xc46/0xc90 __se_sys_landlock_restrict_self+0x2bc/0xd40layers[] lives in an anonymous struct inside the anonymous union that overlays
work_free. For such a flexible array, clang computes the address of the__counted_bycounter as the start of the array instead of&num_layers. The bound is then read from layers[0], i.e. from the first layer's configuration, which is not a count. The same layout crashes clang itself in a standalone test.Quoted 7 lines
Quoted 7 lines
The annotation was added as documentation, so drop it rather than restructure the union. Keep the information in the member comment.
Reported-by [email protected]Fixes bd3a19800dd1 ("landlock: Add counted_by in landlock_domain")Signed-off-by Nguyen Ngoc Thang <[email protected]>Thanks for the patch.
Quoted 32 lines
Quoted 29 lines
---
Reproduced with clang 22.1.8 andFORTIFY_SOURCEon mic/next (64b9e6eff524):
the secondlandlock_restrict_self()hits the report, while 16 nested restricts run clean with this patch. Mickaël, if you prefer to just dropbd3a19800dd1from next, that works as well.security/landlock/domain.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)security/landlock/domain.h +5
-1@@ -246,8 +246,12 @@ struct landlock_domain {* properly handle merged rulesets without overlapping * access rights. These layers are set once and never * changed for the lifetime of the domain. +* +* Not annotated with __counted_by(@num_layers): clang +* miscomputes the counter address for a FAM nested in an +* anonymous struct within a union, which trips FORTIFY. */ - struct layer_config layers[] __counted_by(num_layers); +struct layer_config layers[]; }; }; };Signature · 1 line
2.43.0Reviewed-by Günther Noack <[email protected]>Quoted 7 lines
I agree - it seems better to drop the
__counted_byrather than restructuring the entire struct for that.Thanks also for adding a comment about it. The
__counted_by()has only been added very recently in September, in commitbd3a19800dd1("landlock: Addcounted_byinlandlock_domain"). Better to have a note about it so that we don't accidentally add it back. :)
Quoted 7 lines
Actually, I independently wrote a quite similar patch (while traveling), but it applies to v7.3-rc5 instead of mic/next. I removed the patch series that I applied on mic/next because it conflicts with my patch and I need to send a new version anyway. If you don't mind, I'll keep Günther's Reviewed-by tag and credit other contributors in my patch. I'll propose it for v7.3-rc7 (today) because it is trivial and will help new patches on top of that.
Here is my rebase:
https://git.kernel.org/mic/c/3d8cc52db2f86b624308321c58513019f6b21eec