]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
FreeBSD: add intercepts to timingsafe variants of memcmp and bcmp
authorPaul Floyd <pjfloyd@wanadoo.fr>
Wed, 20 Sep 2023 06:16:43 +0000 (08:16 +0200)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Wed, 20 Sep 2023 06:16:43 +0000 (08:16 +0200)
.gitignore
memcheck/tests/freebsd/Makefile.am
memcheck/tests/freebsd/timingsafe.c [new file with mode: 0644]
memcheck/tests/freebsd/timingsafe.stderr.exp [new file with mode: 0644]
memcheck/tests/freebsd/timingsafe.vgtest [new file with mode: 0644]
shared/vg_replace_strmem.c

index a82f147a7500896249a39ea8bbdc9dd425e52129..6769403f09b69ec156fb86719e9f3c0cf2a2fb72 100644 (file)
 /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
 
index 5cccba91899ec04efb4e069f6bd4eae603b45302..23298e9ecdccc896d463263d87e567a0e1108c49 100644 (file)
@@ -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 (file)
index 0000000..abc1b42
--- /dev/null
@@ -0,0 +1,42 @@
+#include <string.h>
+#include <assert.h>
+#include <stdlib.h>
+
+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 (file)
index 0000000..5cca1f7
--- /dev/null
@@ -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 (file)
index 0000000..6ce16bc
--- /dev/null
@@ -0,0 +1,3 @@
+prog: timingsafe
+vgopts: -q
+
index b32f13f76d54cd480093cdc64a6bebdfbaead4dc..10195b3348533a588f44b62cb151f066e0be3fa0 100644 (file)
@@ -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