clock_nanosleep01: Avoid dereferencing bad pointers in libc on 32bit
PATCH 1/2 clock_nanosleep01: Avoid dereferencing bad pointers in libc on 32bit
In 32-bit (regardless of kernel bits) glibc and musl will usually dereference the timespec pointers and try to read them. In some cases this might be avoidable, but they must do it in others.
Passing invalid pointers is undefined in POSIX. In any case, AFAICT libc would have to catch the signal in order to guarantee EFAULT is returned.
---
Possibly we shouldn't test things like this at all through libc wrappers.
.../kernel/syscalls/clock_nanosleep/clock_nanosleep01.c | 8 ++++++++ 1 file changed, 8 insertions(+)
testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c +8 -0
@@ -154,6 +154,14 @@ static void do_test(unsigned int i)else remain =tst_ts_get (rm); +if ((request == bad_addr || remain == bad_addr) && + tv->clock_nanosleep == libc_clock_nanosleep && +sizeof (long ) <8 ) { +tst_res (TCONF , +"The libc 32-bit wrapper may dereference req or rem" ); +return ; + } +TEST (tv->clock_nanosleep (tc->clk_id, tc->flags, request, remain));if (tv->clock_nanosleep == libc_clock_nanosleep) {
Signature · 5 lines
2.33.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 2/2 clock_nanosleep01: Add space to make make-check happy
--- testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c +1 -1
@@ -200,7 +200,7 @@ static void do_test(unsigned int i) }if (remain_ms > expect_ms) { -tst_res (TFAIL |TTERRNO , +tst_res (TFAIL |TTERRNO ,"remaining time > requested time (%lld > %lld)" , remain_ms, expect_ms);return ;
Signature · 5 lines
2.33.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 2/2] clock_nanosleep01: Add space to make make-check happy
Obviously correct.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Richie,
Quoted 7 lines
In 32-bit (regardless of kernel bits) glibc and musl will usually dereference the timespec pointers and try to read them. In some cases this might be avoidable, but they must do it in others.
Passing invalid pointers is undefined in POSIX. In any case, AFAICT libc would have to catch the signal in order to guarantee EFAULT is returned.
LGTM.
Quoted 2 lines
Possibly we shouldn't test things like this at all through libc wrappers.
Only for 32bit or also for 64 bit? Anyway, there has always been some cases where bad addr testing was problematic (e.g. non-intel arch).
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Jan Stancek
Acked-byQuoted 10 lines · Petr Vorel
Hi Richie,
Quoted 7 lines
In 32-bit (regardless of kernel bits) glibc and musl will usually dereference the timespec pointers and try to read them. In some cases this might be avoidable, but they must do it in others.
Passing invalid pointers is undefined in POSIX. In any case, AFAICT libc would have to catch the signal in order to guarantee EFAULT is returned.
Quoted 9 lines
LGTM.
Reviewed-by Petr Vorel <[email protected]>Quoted 2 lines
Possibly we shouldn't test things like this at all through libc wrappers.
Only for 32bit or also for 64 bit? Anyway, there has always been some cases where bad addr testing was problematic (e.g. non-intel arch).
I'd skip it for both, I recall that some implementations were crashing.
Quoted 8 lines
Kind regards,
Petr--
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
Hello Jan,
Quoted 16 lines · Jan Stancek
On Mon, Oct 4, 2021 at 8:07 AM Petr Vorel <[email protected]> wrote:
Hi Richie,
Quoted 7 lines
In 32-bit (regardless of kernel bits) glibc and musl will usually dereference the timespec pointers and try to read them. In some cases this might be avoidable, but they must do it in others.
Passing invalid pointers is undefined in POSIX. In any case, AFAICT libc would have to catch the signal in order to guarantee EFAULT is returned.
LGTM.
Reviewed-by Petr Vorel <[email protected]>
Quoted 7 lines
Quoted 2 lines
Possibly we shouldn't test things like this at all through libc wrappers.
Only for 32bit or also for 64 bit? Anyway, there has always been some cases where bad addr testing was problematic (e.g. non-intel arch).
I'd skip it for both, I recall that some implementations were crashing.
Yes, there is not much we can do if it fails.
Quoted 9 lines
Acked-by Jan Stancek <[email protected]>Kind regards,
Petr--
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Thank you, Richard. -- Mailing list info: https://lists.linux.it/listinfo/ltp