mseal02: Handle multiple errnos for 32-bit compat mode
PATCH 1/1 mseal02: Handle multiple errnos for 32-bit compat mode
In 32-bit compat mode, the overflow_size (calculated using a 32-bit ULONG_MAX) does not cause a 64-bit integer wrap-around when added to the start address. Consequently, the kernel see valid range that points to unmapped space, returning ENOMEM instead of the expected EINVAL.
--- testcases/kernel/syscalls/mseal/mseal02.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
testcases/kernel/syscalls/mseal/mseal02.c +11 -9
@@ -21,6 +21,8 @@#include "tst_test.h" #include "lapi/syscalls.h" +#define MAX_ERRNOS 5 +static void *start_addr, *unaligned_start_addr, *unallocated_start_addr, *unallocated_end_addr;static size_t page_size, twopages_size, fourpages_size, overflow_size;
@@ -28,22 +30,22 @@ static struct tcase {void **addr;size_t *len;unsigned long flags; -int exp_err; +int exp_errs[MAX_ERRNOS ]; } tcases[] = { - {&start_addr, &page_size, ULONG_MAX, EINVAL}, - {&unaligned_start_addr, &page_size, 0, EINVAL}, - {&start_addr, &overflow_size, 0, EINVAL}, - {&unallocated_start_addr, &twopages_size, 0, ENOMEM}, - {&unallocated_end_addr, &twopages_size, 0, ENOMEM}, - {&start_addr, &fourpages_size, 0, ENOMEM}, + {&start_addr, &page_size, ULONG_MAX, {EINVAL}}, + {&unaligned_start_addr, &page_size, 0, {EINVAL}}, + {&start_addr, &overflow_size, 0, {EINVAL, ENOMEM}}, + {&unallocated_start_addr, &twopages_size, 0, {ENOMEM}}, + {&unallocated_end_addr, &twopages_size, 0, {ENOMEM}}, + {&start_addr, &fourpages_size, 0, {ENOMEM}}, };static void run (unsigned int n) {struct tcase *tc = &tcases[n]; - TST_EXP_FAIL(tst_syscall(__NR_mseal, *tc->addr, *tc->len, tc->flags), tc->exp_err, - "mseal(%p, %lu, %lu)", *tc->addr, *tc->len, tc->flags); +TST_EXP_FAIL2_ARR (tst_syscall (__NR_mseal, *tc->addr, *tc->len, tc->flags), + tc->exp_errs,MAX_ERRNOS ,"mseal(%p, %lu, %lu)" , *tc->addr, *tc->len, tc->flags); }static void setup (void )
Signature · 5 lines
2.52.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 45 lines · Wei Gao via ltp
In 32-bit compat mode, the
overflow_size(calculated using a 32-bitULONG_MAX) does not cause a 64-bit integer wrap-around when added to the start address. Consequently, the kernel see valid range that points to unmapped space, returning ENOMEM instead of the expected EINVAL.Signed-off-by Wei Gao <[email protected]>--- testcases/kernel/syscalls/mseal/mseal02.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)testcases/kernel/syscalls/mseal/mseal02.c +9
-7@@ -21,6 +21,8 @@#include "tst_test.h" #include "lapi/syscalls.h" +#define MAX_ERRNOS 5 +static void *start_addr, *unaligned_start_addr, *unallocated_start_addr, *unallocated_end_addr;static size_t page_size, twopages_size, fourpages_size, overflow_size;@@ -28,22 +30,22 @@ static struct tcase {void **addr;size_t *len;unsigned long flags; -int exp_err; +int exp_errs[MAX_ERRNOS ]; } tcases[] = { - {&start_addr, &page_size, ULONG_MAX, EINVAL}, - {&unaligned_start_addr, &page_size, 0, EINVAL}, - {&start_addr, &overflow_size, 0, EINVAL}, - {&unallocated_start_addr, &twopages_size, 0, ENOMEM}, - {&unallocated_end_addr, &twopages_size, 0, ENOMEM}, - {&start_addr, &fourpages_size, 0, ENOMEM}, + {&start_addr, &page_size, ULONG_MAX, {EINVAL}}, + {&unaligned_start_addr, &page_size, 0, {EINVAL}}, + {&start_addr, &overflow_size, 0, {EINVAL, ENOMEM}}, + {&unallocated_start_addr, &twopages_size, 0, {ENOMEM}}, + {&unallocated_end_addr, &twopages_size, 0, {ENOMEM}}, + {&start_addr, &fourpages_size, 0, {ENOMEM}}, };static void run (unsigned int n)
testcases/kernel/syscalls/mseal/mseal02.c static struct tcase { · line 51
Quoted 10 lines
testcases/kernel/syscalls/mseal/mseal02.c +2
-2{struct tcase *tc = &tcases[n]; -TST_EXP_FAIL (tst_syscall (__NR_mseal, *tc->addr, *tc->len, tc->flags), tc->exp_err, -"mseal(%p, %lu, %lu)" , *tc->addr, *tc->len, tc->flags); +TST_EXP_FAIL2_ARR (tst_syscall (__NR_mseal, *tc->addr, *tc->len, tc->flags), + tc->exp_errs,MAX_ERRNOS ,"mseal(%p, %lu, %lu)" , *tc->addr, *tc->len, tc->flags); }static void setup (void )
Instead of checking multiple errno, you should pass the right type according to the architecture.
Signature · 7 lines
Andrea Cervesato SUSE QE Automation Engineer Linux [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 54 lines
Quoted 54 lines
In 32-bit compat mode, the
overflow_size(calculated using a 32-bitULONG_MAX) does not cause a 64-bit integer wrap-around when added to the start address. Consequently, the kernel see valid range that points to unmapped space, returning ENOMEM instead of the expected EINVAL.Signed-off-by Wei Gao <[email protected]>--- testcases/kernel/syscalls/mseal/mseal02.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)testcases/kernel/syscalls/mseal/mseal02.c +11
-9@@ -21,6 +21,8 @@#include "tst_test.h" #include "lapi/syscalls.h" +#define MAX_ERRNOS 5 +static void *start_addr, *unaligned_start_addr, *unallocated_start_addr, *unallocated_end_addr;static size_t page_size, twopages_size, fourpages_size, overflow_size;@@ -28,22 +30,22 @@ static struct tcase {void **addr;size_t *len;unsigned long flags; -int exp_err; +int exp_errs[MAX_ERRNOS ]; } tcases[] = { - {&start_addr, &page_size, ULONG_MAX, EINVAL}, - {&unaligned_start_addr, &page_size, 0, EINVAL}, - {&start_addr, &overflow_size, 0, EINVAL}, - {&unallocated_start_addr, &twopages_size, 0, ENOMEM}, - {&unallocated_end_addr, &twopages_size, 0, ENOMEM}, - {&start_addr, &fourpages_size, 0, ENOMEM}, + {&start_addr, &page_size, ULONG_MAX, {EINVAL}}, + {&unaligned_start_addr, &page_size, 0, {EINVAL}}, + {&start_addr, &overflow_size, 0, {EINVAL, ENOMEM}}, + {&unallocated_start_addr, &twopages_size, 0, {ENOMEM}}, + {&unallocated_end_addr, &twopages_size, 0, {ENOMEM}}, + {&start_addr, &fourpages_size, 0, {ENOMEM}}, };static void run (unsigned int n) {struct tcase *tc = &tcases[n]; - TST_EXP_FAIL(tst_syscall(__NR_mseal, *tc->addr, *tc->len, tc->flags), tc->exp_err, - "mseal(%p, %lu, %lu)", *tc->addr, *tc->len, tc->flags); +TST_EXP_FAIL2_ARR (tst_syscall (__NR_mseal, *tc->addr, *tc->len, tc->flags), + tc->exp_errs,MAX_ERRNOS ,"mseal(%p, %lu, %lu)" , *tc->addr, *tc->len, tc->flags); }
Quoted 4 lines
testcases/kernel/syscalls/mseal/mseal02.c static struct tcase { · line 51
Quoted 1 line
testcases/kernel/syscalls/mseal/mseal02.c +0
-0static void setup (void )Instead of checking multiple errno, you should pass the right type according to the architecture.
That would be slightly more complex here since the problem happens only in compat mode, which can be only detected at runtime with tst_is_compat_mode(). We would have to call that in the test setup and adjust expectations accordinlgy.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/1 mseal02: Handle multiple errnos for 32-bit compat mode
In reply to Wei Gao via ltpIn 32-bit compat mode, the overflow_size (calculated using a 32-bit ULONG_MAX) does not cause a 64-bit integer wrap-around when added to the start address. Consequently, the kernel see valid range that points to unmapped space, returning ENOMEM instead of the expected EINVAL.
--- testcases/kernel/syscalls/mseal/mseal02.c | 3 +++ 1 file changed, 3 insertions(+)
testcases/kernel/syscalls/mseal/mseal02.c +3 -0
@@ -58,6 +58,9 @@ static void setup(void)SAFE_MUNMAP (start_addr + twopages_size, page_size); unallocated_start_addr = start_addr + twopages_size; unallocated_end_addr = start_addr + page_size; + +if (tst_is_compat_mode ()) + tcases[2 ].exp_err =ENOMEM ; }static void cleanup (void )
Signature · 5 lines
2.52.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Wei,
LGTM
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi all,
Quoted 4 lines
In 32-bit compat mode, the
overflow_size(calculated using a 32-bitULONG_MAX) does not cause a 64-bit integer wrap-around when added to the start address. Consequently, the kernel see valid range that points to unmapped space, returning ENOMEM instead of the expected EINVAL.
Also LGTM.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Wei, all,
testcases/kernel/syscalls/mseal/mseal02.c static void setup(void) · line 63
Quoted 13 lines
Hi all,
Quoted 4 lines
In 32-bit compat mode, the
overflow_size(calculated using a 32-bitULONG_MAX) does not cause a 64-bit integer wrap-around when added to the start address. Consequently, the kernel see valid range that points to unmapped space, returning ENOMEM instead of the expected EINVAL.Also LGTM.
Reviewed-by Petr Vorel <[email protected]>testcases/kernel/syscalls/mseal/mseal02.c +2
-0+if (tst_is_compat_mode ()) + tcases[2 ].exp_err =ENOMEM ;
I was about to merge, but thinking about it twice, it'd make sense instead hardcoding index 2 (we talked about it in the past, that hardcoding indexes can cause problems the future) to add attribute .check_kver, similar way Jan Polensky did in dcf0c145d9 ("setxattr02: Adapt test for kernel 7.1.0+ socket xattr support").
Could you please modify it in v3?
Kind regards,
Petr
[1] https://github.com/linux-test-project/ltp/commit/dcf0c145d90531b919e633bb3f481f59a867aa06
Quoted 2 lines
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 1/1 mseal02: Handle multiple errnos for 32-bit compat mode
In reply to Wei Gao via ltpIn 32-bit compat mode, the overflow_size (calculated using a 32-bit ULONG_MAX) does not cause a 64-bit integer wrap-around when added to the start address. Consequently, the kernel see valid range that points to unmapped space, returning ENOMEM instead of the expected EINVAL.
---v2->v3: Add compat_err replace hardcoding index similar with dcf0c145d9 ("setxattr02: Adapt test for kernel 7.1.0+ socket xattr support").
testcases/kernel/syscalls/mseal/mseal02.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
testcases/kernel/syscalls/mseal/mseal02.c +9 -7
@@ -29,20 +29,22 @@ static struct tcase {size_t *len;unsigned long flags;int exp_err; +int compat_err; } tcases[] = { - {&start_addr, &page_size, ULONG_MAX, EINVAL}, - {&unaligned_start_addr, &page_size, 0, EINVAL}, - {&start_addr, &overflow_size, 0, EINVAL}, - {&unallocated_start_addr, &twopages_size, 0, ENOMEM}, - {&unallocated_end_addr, &twopages_size, 0, ENOMEM}, - {&start_addr, &fourpages_size, 0, ENOMEM}, + {.addr = &start_addr, .len = &page_size, .flags = ULONG_MAX, .exp_err = EINVAL}, + {.addr = &unaligned_start_addr, .len = &page_size, .flags = 0, .exp_err = EINVAL}, + {.addr = &start_addr, .len = &overflow_size, .flags = 0, .exp_err = EINVAL, .compat_err = ENOMEM}, + {.addr = &unallocated_start_addr, .len = &twopages_size, .flags = 0, .exp_err = ENOMEM}, + {.addr = &unallocated_end_addr, .len = &twopages_size, .flags = 0, .exp_err = ENOMEM}, + {.addr = &start_addr, .len = &fourpages_size, .flags = 0, .exp_err = ENOMEM}, }; static void run(unsigned int n) { struct tcase *tc = &tcases[n]; + int exp_err = tc->compat_err && tst_is_compat_mode() ? tc->compat_err : tc->exp_err; - TST_EXP_FAIL(tst_syscall(__NR_mseal, *tc->addr, *tc->len, tc->flags), tc->exp_err, + TST_EXP_FAIL(tst_syscall(__NR_mseal, *tc->addr, *tc->len, tc->flags), exp_err, "mseal(%p, %lu, %lu)", *tc->addr, *tc->len, tc->flags); }
Signature · 5 lines
2.52.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
LGTM
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Andrea Cervesato via ltp
AppliedMerged, thanks!
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi all,
Quoted 9 lines
+++
b/testcases/kernel/syscalls/mseal/mseal02.ctestcases/kernel/syscalls/mseal/mseal02.c +1
-2@@ -29,20 +29,22 @@ static struct tcase {size_t *len;unsigned long flags;int exp_err; +int compat_err; } tcases[] = { - {&start_addr, &page_size, ULONG_MAX, EINVAL}, - {&unaligned_start_addr, &page_size, 0, EINVAL},
testcases/kernel/syscalls/mseal/mseal02.c static struct tcase { · line 39
Quoted 10 lines
testcases/kernel/syscalls/mseal/mseal02.c +6
-4- {&start_addr, &overflow_size, 0, EINVAL}, - {&unallocated_start_addr, &twopages_size, 0, ENOMEM}, - {&unallocated_end_addr, &twopages_size, 0, ENOMEM}, - {&start_addr, &fourpages_size, 0, ENOMEM}, + {.addr = &start_addr, .len = &page_size, .flags = ULONG_MAX, .exp_err = EINVAL}, + {.addr = &unaligned_start_addr, .len = &page_size, .flags = 0, .exp_err = EINVAL}, + {.addr = &start_addr, .len = &overflow_size, .flags = 0, .exp_err = EINVAL, .compat_err = ENOMEM}, + {.addr = &unallocated_start_addr, .len = &twopages_size, .flags = 0, .exp_err = ENOMEM}, + {.addr = &unallocated_end_addr, .len = &twopages_size, .flags = 0, .exp_err = ENOMEM}, + {.addr = &start_addr, .len = &fourpages_size, .flags = 0, .exp_err = ENOMEM},
FYI I remove useless .flags = 0, in following commit. 55e16df13a ("mseal02: Remove useless zero initialization") (The default zero initialization can shorten code in some cases.)
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp