landlock: fix minimal required size for landlock_ruleset_attr copying
Subsystems (2)
RFC PATCH 1/1 landlock: fix minimal required size for landlock_ruleset_attr copying
As kernel commit fff69fb03dde ("landlock: Support network rules with TCP bind and connect") introducing a new field 'handled_access_net' in the structure landlock_ruleset_attr, but in the landlock_create_ruleset() it still uses the first field 'handled_access_fs' to calculate minimal size, so that made decrease 1 is useless in LTP landlock01.c to test the too-small-size.
Test code:
rule_small_size = sizeof(struct landlock_ruleset_attr) - 1; tst_syscall(__NR_landlock_create_ruleset, ..., rule_small_size, 0)
Result:
landlock01.c:49: TFAIL: Size is too small expected EINVAL: ENOMSG (42)
---
Notes:
Hi Mickael,
I'm not quite sure if that is on purpose to use the first field or kernel bug, can you take a look?
security/landlock/syscalls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
security/landlock/syscalls.c +1 -1
@@ -198,7 +198,7 @@ SYSCALL_DEFINE3(landlock_create_ruleset,/* Copies raw user space buffer. */ err =copy_min_struct_from_user (&ruleset_attr,sizeof (ruleset_attr),offsetofend (typeof (ruleset_attr), - handled_access_fs), + handled_access_net), attr, size);if (err)return err;
Signature · 1 line
2.45.2
Mickaël Salaün
maintainerQuoted 6 lines · Li Wang
As kernel commit
fff69fb03dde("landlock: Support network rules with TCP bind and connect") introducing a new field 'handled_access_net' in the structurelandlock_ruleset_attr, but in thelandlock_create_ruleset()it still uses the first field 'handled_access_fs' to calculate minimal size, so that made decrease 1 is useless in LTPlandlock01.cto test the too-small-size.
Quoted 6 lines
Test code:
rule_small_size = sizeof(struct landlock_ruleset_attr) - 1; tst_syscall(__NR_landlock_create_ruleset, ..., rule_small_size, 0)Result:
landlock01.c:49: TFAIL: Size is too small expected EINVAL: ENOMSG (42)
Interesting, this looks like a bug in these LTP tests.
Quoted 11 lines
Signed-off-by Li Wang <[email protected]>Cc Mickaël Salaün <[email protected]>Cc Konstantin Meskhidze <[email protected]>Cc Paul Moore <[email protected]>---
Notes:
Hi Mickael,
I'm not quite sure if that is on purpose to use the first field or kernel bug, can you take a look?
Hi Li,
Yes this is on purpose. The handled_access_fs minimal size check should never change for backward compatibility reason. User space built with old headers must still work with new kernels. This is tested with the "inconsistent_attr" test in tools/testing/selftests/landlock/base_test.c
Quoted 20 lines
security/landlock/syscalls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)security/landlock/syscalls.c +1
-1@@ -198,7 +198,7 @@ SYSCALL_DEFINE3(landlock_create_ruleset,/* Copies raw user space buffer. */ err =copy_min_struct_from_user (&ruleset_attr,sizeof (ruleset_attr),offsetofend (typeof (ruleset_attr), - handled_access_fs), + handled_access_net), attr, size);if (err)return err;Signature · 1 line
2.45.2
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 11 lines · Mickaël Salaün
Quoted 1 line · Li Wang
As kernel commit
fff69fb03dde("landlock: Support network rules with TCPbind and connect")
Quoted 1 line
introducing a new field '
handled_access_net' in the structure
landlock_ruleset_attr,Quoted 1 line
but in the
landlock_create_ruleset()it still uses the first field'
handled_access_fs'Quoted 1 line
to calculate minimal size, so that made decrease 1 is useless in LTP
landlock01.ctoQuoted 2 lines
test the too-small-size.
Quoted 9 lines
Quoted 6 lines
Test code:
rule_small_size = sizeof(struct landlock_ruleset_attr) - 1; tst_syscall(__NR_landlock_create_ruleset, ..., rule_small_size, 0)Result:
landlock01.c:49: TFAIL: Size is too small expected EINVAL: ENOMSG (42)Interesting, this looks like a bug in these LTP tests.
Yes, Andrea drafted a series of landlock tests for LTP.
Quoted 12 lines
Quoted 11 lines
Signed-off-by Li Wang <[email protected]>Cc Mickaël Salaün <[email protected]>Cc Konstantin Meskhidze <[email protected]>Cc Paul Moore <[email protected]>---
Notes:
Hi Mickael,
I'm not quite sure if that is on purpose to use the first fieldor kernel
Quoted 9 lines
Quoted 1 line
bug, can you take a look?
Hi Li,
Yes this is on purpose. The
handled_access_fsminimal size check should never change for backward compatibility reason. User space built with old headers must still work with new kernels. This is tested with the "inconsistent_attr" test intools/testing/selftests/landlock/base_test.c
Thanks for the confirmation, very helpful.
@Andrea Cervesato <[email protected]>, seems we have to adjust the test to use a real small
rule size which is at least small than sizeof(__u64).
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 55 lines · Li Wang
On Tue, Jul 2, 2024 at 9:00 PM Mickaël Salaün <[email protected]> wrote:
On Tue, Jul 02, 2024 at 05:47:45PM +0800, Li Wang wrote:
> As kernel commitfff69fb03dde("landlock: Support network rules with TCP bind and connect")
> introducing a new field 'handled_access_net' in the structurelandlock_ruleset_attr,
> but in thelandlock_create_ruleset()it still uses the first field 'handled_access_fs'
> to calculate minimal size, so that made decrease 1 is useless in LTPlandlock01.cto
> test the too-small-size.
>
> Test code:
>rule_small_size=sizeof(struct landlock_ruleset_attr)- 1; >tst_syscall(__NR_landlock_create_ruleset, ..., rule_small_size, 0)
>
> Result:
> landlock01.c:49: TFAIL: Size is too small expected EINVAL:
ENOMSG (42)Interesting, this looks like a bug in these LTP tests.
Yes, Andrea drafted a series of landlock tests for LTP.
FYI - https://patchwork.ozlabs.org/project/ltp/list/?series=&submitter=&state=&q=landlock&archive=&delegate= <https://patchwork.ozlabs.org/project/ltp/list/?series=&submitter=&state=&q=landlock&archive=&delegate=>
Quoted 10 lines
Signed-off-by Li Wang <[email protected]>Cc Mickaël Salaün <[email protected]>Cc Konstantin Meskhidze <[email protected]>Cc Paul Moore <[email protected]>---
Notes:
Hi Mickael,
I'm not quite sure if that is on purpose to use the firstfield or kernel
> bug, can you take a look?Hi Li,
Yes this is on purpose. The
handled_access_fsminimal size check should
never change for backward compatibility reason. User space built with old headers must still work with new kernels. This is tested with the "inconsistent_attr" test intools/testing/selftests/landlock/base_test.c
Quoted 6 lines
Thanks for the confirmation, very helpful.
@Andrea Cervesato <mailto:[email protected]>, seems we have to adjust the test to use a real small
rule size which is at least small thansizeof(__u64).
Sure, thanks for checking.
Quoted 4 lines
Signature · 3 lines
-- Regards, Li Wang
Andrea
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp