linux-yocto/security/landlock
Tingmao Wang 7d9ec2cfe1 landlock: Fix warning from KUnit tests
[ Upstream commit e0a69cf2c0 ]

get_id_range() expects a positive value as first argument but
get_random_u8() can return 0.  Fix this by clamping it.

Validated by running the test in a for loop for 1000 times.

Note that MAX() is wrong as it is only supposed to be used for
constants, but max() is good here.

  [..]     ok 9 test_range2_rand1
  [..]     ok 10 test_range2_rand2
  [..]     ok 11 test_range2_rand15
  [..] ------------[ cut here ]------------
  [..] WARNING: CPU: 6 PID: 104 at security/landlock/id.c:99 test_range2_rand16 (security/landlock/id.c:99 (discriminator 1) security/landlock/id.c:234 (discriminator 1))
  [..] Modules linked in:
  [..] CPU: 6 UID: 0 PID: 104 Comm: kunit_try_catch Tainted: G                 N  6.16.0-rc1-dev-00001-g314a2f98b65f #1 PREEMPT(undef)
  [..] Tainted: [N]=TEST
  [..] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
  [..] RIP: 0010:test_range2_rand16 (security/landlock/id.c:99 (discriminator 1) security/landlock/id.c:234 (discriminator 1))
  [..] Code: 49 c7 c0 10 70 30 82 4c 89 ff 48 c7 c6 a0 63 1e 83 49 c7 45 a0 e0 63 1e 83 e8 3f 95 17 00 e9 1f ff ff ff 0f 0b e9 df fd ff ff <0f> 0b ba 01 00 00 00 e9 68 fe ff ff 49 89 45 a8 49 8d 4d a0 45 31

  [..] RSP: 0000:ffff888104eb7c78 EFLAGS: 00010246
  [..] RAX: 0000000000000000 RBX: 000000000870822c RCX: 0000000000000000
            ^^^^^^^^^^^^^^^^
  [..]
  [..] Call Trace:
  [..]
  [..] ---[ end trace 0000000000000000 ]---
  [..]     ok 12 test_range2_rand16
  [..] # landlock_id: pass:12 fail:0 skip:0 total:12
  [..] # Totals: pass:12 fail:0 skip:0 total:12
  [..] ok 1 landlock_id

Fixes: d9d2a68ed4 ("landlock: Add unique ID generator")
Signed-off-by: Tingmao Wang <m@maowtm.org>
Link: https://lore.kernel.org/r/73e28efc5b8cc394608b99d5bc2596ca917d7c4a.1750003733.git.m@maowtm.org
[mic: Minor cosmetic improvements]
Signed-off-by: Mickaël Salaün <mic@digikod.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2025-08-15 16:38:21 +02:00
..
errata landlock: Always allow signals between threads of the same process 2025-03-26 13:59:29 +01:00
.kunitconfig landlock: Add unique ID generator 2025-03-26 13:59:34 +01:00
access.h landlock: Log truncate and IOCTL denials 2025-03-26 13:59:41 +01:00
audit.c landlock: Improve bit operations in audit code 2025-05-12 11:38:53 +02:00
audit.h landlock: Log scoped denials 2025-03-26 13:59:42 +01:00
common.h landlock: Add support for KUnit tests 2024-02-27 11:21:45 +01:00
cred.c landlock: Identify domain execution crossing 2025-03-26 13:59:37 +01:00
cred.h landlock: Add LANDLOCK_RESTRICT_SELF_LOG_SUBDOMAINS_OFF 2025-03-26 13:59:43 +01:00
domain.c landlock: Log the TGID of the domain creator 2025-04-11 12:53:17 +02:00
domain.h landlock: Remove incorrect warning 2025-04-08 19:18:20 +02:00
errata.h landlock: Prepare to add second errata 2025-03-21 12:12:21 +01:00
fs.c Landlock update for v6.15-rc1 2025-03-28 12:37:13 -07:00
fs.h landlock: Log scoped denials 2025-03-26 13:59:42 +01:00
id.c landlock: Fix warning from KUnit tests 2025-08-15 16:38:21 +02:00
id.h landlock: Add unique ID generator 2025-03-26 13:59:34 +01:00
Kconfig landlock: Add support for KUnit tests 2024-02-27 11:21:45 +01:00
limits.h landlock: Add LANDLOCK_RESTRICT_SELF_LOG_SUBDOMAINS_OFF 2025-03-26 13:59:43 +01:00
Makefile landlock: Add AUDIT_LANDLOCK_ACCESS and log ptrace denials 2025-03-26 13:59:38 +01:00
net.c landlock: Log TCP bind and connect denials 2025-03-26 13:59:41 +01:00
net.h landlock: Support network rules with TCP bind and connect 2023-10-26 21:07:15 +02:00
object.c
object.h
ruleset.c landlock: Add AUDIT_LANDLOCK_DOMAIN and log domain status 2025-03-26 13:59:38 +01:00
ruleset.h landlock: Log mount-related denials 2025-03-26 13:59:39 +01:00
setup.c landlock: Add unique ID generator 2025-03-26 13:59:34 +01:00
setup.h landlock: Add the errata interface 2025-03-21 12:12:19 +01:00
syscalls.c landlock: Improve bit operations in audit code 2025-05-12 11:38:53 +02:00
task.c landlock: Log scoped denials 2025-03-26 13:59:42 +01:00
task.h landlock: Rename "ptrace" files to "task" 2024-03-08 18:22:16 +01:00