public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] clock_nanosleep01: Avoid dereferencing bad pointers in libc on 32bit
@ 2021-09-29  8:59 Richard Palethorpe via ltp
  2021-09-29  8:59 ` [LTP] [PATCH 2/2] clock_nanosleep01: Add space to make make-check happy Richard Palethorpe via ltp
  2021-10-04  6:07 ` [LTP] [PATCH 1/2] clock_nanosleep01: Avoid dereferencing bad pointers in libc on 32bit Petr Vorel
  0 siblings, 2 replies; 6+ messages in thread
From: Richard Palethorpe via ltp @ 2021-09-29  8:59 UTC (permalink / raw)
  To: ltp; +Cc: Richard Palethorpe

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.

Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
---

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(+)

diff --git a/testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c b/testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c
index 382497918..7dc5a043d 100644
--- a/testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c
+++ b/testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c
@@ -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) {
-- 
2.33.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-10-05 12:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-29  8:59 [LTP] [PATCH 1/2] clock_nanosleep01: Avoid dereferencing bad pointers in libc on 32bit Richard Palethorpe via ltp
2021-09-29  8:59 ` [LTP] [PATCH 2/2] clock_nanosleep01: Add space to make make-check happy Richard Palethorpe via ltp
2021-10-04  6:07   ` Petr Vorel
2021-10-04  6:07 ` [LTP] [PATCH 1/2] clock_nanosleep01: Avoid dereferencing bad pointers in libc on 32bit Petr Vorel
2021-10-04 10:16   ` Jan Stancek
2021-10-05 12:04     ` Richard Palethorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox