linux/security/landlock
Nguyen Ngoc Thang 3d8cc52db2
landlock: Drop __counted_by from landlock_domain.handled_masks
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: 4 byte write of buffer size 0
  Call Trace:
   __fortify_panic
   landlock_merge_ruleset
   __se_sys_landlock_restrict_self

handled_masks[] 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 handled_masks[0], i.e. from
the first layer's access masks, 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: syzbot+a0eecb22de4d821a9e5d@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=a0eecb22de4d821a9e5d
Fixes: bd3a19800d ("landlock: Add counted_by in landlock_domain")
Signed-off-by: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>
Link: https://lore.kernel.org/r/20261010164450.194439-1-ngocthang2710.1999@gmail.com
Reviewed-by: Günther Noack <gnoack3000@gmail.com>
Reported-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Reported-by: Mike Bommarito <michael.bommarito@gmail.com>
Closes: https://lore.kernel.org/r/20261009115108.17819-1-michael.bommarito@gmail.com
[mic: Rebased on master, where the array is handled_masks[], updated the
fortify report, added the clang bug link and the other reports]
Signed-off-by: Mickaël Salaün <mic@digikod.net>
2026-10-11 17:54:21 +02:00
..
errata landlock: Require LANDLOCK_ACCESS_FS_MAKE_REG for whiteout creation 2026-08-15 09:14:43 +02:00
.kunitconfig landlock: Test trace path output boundaries 2026-09-08 11:49:39 +02:00
access.h landlock: Work around gcc-16 -Wuninitialized warning 2026-09-20 11:07:58 +02:00
audit.c landlock: Consolidate access-right and scope names in a shared header 2026-08-17 10:17:13 +02:00
audit.h landlock: Decouple the per-denial logging decision from CONFIG_AUDIT 2026-08-17 10:17:12 +02:00
common.h landlock: Add support for KUnit tests 2024-02-27 11:21:45 +01:00
cred.c landlock: Split denial logging from audit into common framework 2026-08-17 10:17:11 +02:00
cred.h landlock: Split denial logging from audit into common framework 2026-08-17 10:17:11 +02:00
domain.c landlock: Clean up ruleset validation checks 2026-09-08 11:49:32 +02:00
domain.h landlock: Drop __counted_by from landlock_domain.handled_masks 2026-10-11 17:54:21 +02:00
errata.h landlock: Prepare to add second errata 2025-03-21 12:12:21 +01:00
fs.c landlock: Fix rule tracepoint context 2026-09-20 11:08:02 +02:00
fs.h landlock: Add landlock_add_rule_fs and landlock_add_rule_net tracepoints 2026-08-17 10:17:14 +02:00
id.c landlock: Improve kernel-doc "Return:" section consistency 2026-04-07 18:51:04 +02:00
id.h landlock: Split denial logging from audit into common framework 2026-08-17 10:17:11 +02:00
Kconfig landlock: Add create_ruleset and free_ruleset tracepoints 2026-08-17 10:17:13 +02:00
limits.h landlock: Add LANDLOCK_RESTRICT_SELF_NO_NEW_PRIVS 2026-08-15 09:14:46 +02:00
log.c landlock: Add landlock_deny_access_fs and landlock_deny_access_net 2026-08-17 10:17:16 +02:00
log.h landlock: Report the effective signal number 2026-09-20 11:08:05 +02:00
Makefile landlock: Add create_ruleset and free_ruleset tracepoints 2026-08-17 10:17:13 +02:00
net.c landlock: Fix network denial trace context 2026-09-20 11:08:02 +02:00
net.h landlock: Add API support and docs for the quiet flags 2026-06-14 20:17:19 +02:00
object.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
object.h landlock: Format with clang-format 2022-05-09 12:31:10 +02:00
ruleset.c landlock: Clean up ruleset validation checks 2026-09-08 11:49:32 +02:00
ruleset.h landlock: Widen ruleset versions to 64 bits 2026-09-22 20:52:13 +02:00
setup.c lsm: replace the name field with a pointer to the lsm_id struct 2025-10-22 19:24:18 -04:00
setup.h landlock: Add the errata interface 2025-03-21 12:12:19 +01:00
syscalls.c landlock: Add landlock_enforce_domain tracepoint 2026-08-17 10:17:15 +02:00
task.c landlock: Report the effective signal number 2026-09-20 11:08:05 +02:00
task.h landlock: Rename "ptrace" files to "task" 2024-03-08 18:22:16 +01:00
trace.c landlock: Report the effective signal number 2026-09-20 11:08:05 +02:00
trace.h landlock: Add landlock_deny_access_fs and landlock_deny_access_net 2026-08-17 10:17:16 +02:00
tsync.c landlock: Add landlock_enforce_domain tracepoint 2026-08-17 10:17:15 +02:00
tsync.h landlock: Add LANDLOCK_RESTRICT_SELF_NO_NEW_PRIVS 2026-08-15 09:14:46 +02:00