From: Paul Floyd Date: Wed, 20 Sep 2023 06:16:43 +0000 (+0200) Subject: FreeBSD: add intercepts to timingsafe variants of memcmp and bcmp X-Git-Tag: VALGRIND_3_22_0~54 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=db0dc5c66698a19e9e59f9e6a2ed0d6e8fd371a1;p=thirdparty%2Fvalgrind.git FreeBSD: add intercepts to timingsafe variants of memcmp and bcmp --- diff --git a/.gitignore b/.gitignore index a82f147a75..6769403f09 100644 --- a/.gitignore +++ b/.gitignore @@ -1392,6 +1392,7 @@ /memcheck/tests/freebsd/statfs /memcheck/tests/freebsd/static_allocs /memcheck/tests/freebsd/timerfd +/memcheck/tests/freebsd/timingsafe /memcheck/tests/freebsd/utimens /memcheck/tests/freebsd/utimes diff --git a/memcheck/tests/freebsd/Makefile.am b/memcheck/tests/freebsd/Makefile.am index 5cccba9189..23298e9ecd 100644 --- a/memcheck/tests/freebsd/Makefile.am +++ b/memcheck/tests/freebsd/Makefile.am @@ -121,6 +121,8 @@ EXTRA_DIST = \ timerfd.vgtest \ timerfd.stderr.exp \ timerfd.stdout.exp \ + timingsafe.vgtest \ + timingsafe.stderr.exp \ utimens.vgtest \ utimens.stderr.exp \ utimes.vgtest \ @@ -131,15 +133,24 @@ check_PROGRAMS = \ access aligned_alloc bug464476 bug470713 capsicum \ chflags \ chmod_chown delete_sized_mismatch errno_aligned_allocs \ + extattr \ fexecve \ + file_locking_wait6 \ get_set_context get_set_login getfh \ kqueue linkat memalign misc \ - statfs pdfork_pdkill getfsstat inlinfo inlinfo_nested.so extattr \ - sigwait revoke scalar \ + pdfork_pdkill getfsstat inlinfo inlinfo_nested.so \ + revoke scalar \ scalar_fork scalar_thr_exit scalar_abort2 scalar_pdfork \ - scalar_vfork stat file_locking_wait6 utimens \ - utimes static_allocs \ - setproctitle sctp sctp2 memalign + scalar_vfork \ + sctp sctp2 \ + setproctitle \ + sigwait \ + stat \ + statfs \ + static_allocs \ + timingsafe \ + utimens \ + utimes AM_CFLAGS += $(AM_FLAG_M3264_PRI) AM_CXXFLAGS += $(AM_FLAG_M3264_PRI) diff --git a/memcheck/tests/freebsd/timingsafe.c b/memcheck/tests/freebsd/timingsafe.c new file mode 100644 index 0000000000..abc1b42dd7 --- /dev/null +++ b/memcheck/tests/freebsd/timingsafe.c @@ -0,0 +1,42 @@ +#include +#include +#include + +int main(void) +{ + char* s1 = "the the the"; + char* s2 = "the cat zat"; + char* d1; + double undef1; + double undef2; + int res; + + res = timingsafe_bcmp(s1, s2, 3); + assert(res == 0); + res = timingsafe_bcmp(s1, s2, 5); + assert(res != 0); + res = timingsafe_bcmp(s1, s1+4, 3); + assert(res == 0); + + res = timingsafe_memcmp(s1, s2, 3); + assert(res == 0); + res = timingsafe_memcmp(s1, s2, 5); + assert(res > 0); + res = timingsafe_memcmp(s1+8, s2+8, 3); + assert(res < 0); + res = timingsafe_memcmp(s1, s1+4, 3); + assert(res == 0); + + timingsafe_bcmp(&undef1, &undef2, 8); + timingsafe_memcmp(&undef1, &undef2, 8); + + d1 = strdup(s1); + + timingsafe_bcmp(s1, d1, 13); + timingsafe_memcmp(s1, d1, 13); + + free(d1); + + timingsafe_bcmp(s1, d1, 10); + timingsafe_memcmp(s1, d1, 10); +} diff --git a/memcheck/tests/freebsd/timingsafe.stderr.exp b/memcheck/tests/freebsd/timingsafe.stderr.exp new file mode 100644 index 0000000000..5cca1f79f0 --- /dev/null +++ b/memcheck/tests/freebsd/timingsafe.stderr.exp @@ -0,0 +1,54 @@ +Conditional jump or move depends on uninitialised value(s) + at 0x........: timingsafe_bcmp (vg_replace_strmem.c:1228) + by 0x........: main (timingsafe.c:30) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: timingsafe_bcmp (vg_replace_strmem.c:0) + by 0x........: main (timingsafe.c:30) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: timingsafe_memcmp (vg_replace_strmem.c:1227) + by 0x........: main (timingsafe.c:31) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: timingsafe_memcmp (vg_replace_strmem.c:0) + by 0x........: main (timingsafe.c:31) + +Invalid read of size 1 + at 0x........: timingsafe_bcmp (vg_replace_strmem.c:1228) + by 0x........: main (timingsafe.c:35) + Address 0x........ is 0 bytes after a block of size 12 alloc'd + at 0x........: malloc (vg_replace_malloc.c:...) + ... + by 0x........: main (timingsafe.c:33) + +Invalid read of size 1 + at 0x........: timingsafe_memcmp (vg_replace_strmem.c:1227) + by 0x........: main (timingsafe.c:36) + Address 0x........ is 0 bytes after a block of size 12 alloc'd + at 0x........: malloc (vg_replace_malloc.c:...) + ... + by 0x........: main (timingsafe.c:33) + +Invalid read of size 1 + at 0x........: timingsafe_bcmp (vg_replace_strmem.c:1228) + by 0x........: main (timingsafe.c:40) + Address 0x........ is 0 bytes inside a block of size 12 free'd + at 0x........: free (vg_replace_malloc.c:...) + by 0x........: main (timingsafe.c:38) + Block was alloc'd at + at 0x........: malloc (vg_replace_malloc.c:...) + ... + by 0x........: main (timingsafe.c:33) + +Invalid read of size 1 + at 0x........: timingsafe_memcmp (vg_replace_strmem.c:1227) + by 0x........: main (timingsafe.c:41) + Address 0x........ is 0 bytes inside a block of size 12 free'd + at 0x........: free (vg_replace_malloc.c:...) + by 0x........: main (timingsafe.c:38) + Block was alloc'd at + at 0x........: malloc (vg_replace_malloc.c:...) + ... + by 0x........: main (timingsafe.c:33) + diff --git a/memcheck/tests/freebsd/timingsafe.vgtest b/memcheck/tests/freebsd/timingsafe.vgtest new file mode 100644 index 0000000000..6ce16bc59b --- /dev/null +++ b/memcheck/tests/freebsd/timingsafe.vgtest @@ -0,0 +1,3 @@ +prog: timingsafe +vgopts: -q + diff --git a/shared/vg_replace_strmem.c b/shared/vg_replace_strmem.c index b32f13f76d..10195b3348 100644 --- a/shared/vg_replace_strmem.c +++ b/shared/vg_replace_strmem.c @@ -1224,6 +1224,8 @@ static inline void my_exit ( int x ) #elif defined(VGO_freebsd) MEMCMP(VG_Z_LIBC_SONAME, memcmp) MEMCMP(VG_Z_LIBC_SONAME, bcmp) + MEMCMP(VG_Z_LIBC_SONAME, timingsafe_memcmp) + MEMCMP(VG_Z_LIBC_SONAME, timingsafe_bcmp) #elif defined(VGO_darwin) # if DARWIN_VERS >= DARWIN_10_9