From dc24612c873809b64690c0ecfee28802c960012c Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Wed, 5 Oct 2016 19:51:53 +0000 Subject: [PATCH] Add a warning to the get/set_thread_area wrapper for bad info pointers. Also adjust the scalar.stderr.exp to catch the new warnings. Patch by Julian Seward git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16025 --- coregrind/m_syswrap/syswrap-x86-linux.c | 12 +++++++++--- memcheck/tests/x86-linux/scalar.stderr.exp | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/coregrind/m_syswrap/syswrap-x86-linux.c b/coregrind/m_syswrap/syswrap-x86-linux.c index 62d886a7fc..5bdf4c7d4b 100644 --- a/coregrind/m_syswrap/syswrap-x86-linux.c +++ b/coregrind/m_syswrap/syswrap-x86-linux.c @@ -596,7 +596,9 @@ SysRes write_ldt ( ThreadId tid, void* ptr, UInt bytecount, Int oldmode ) static SysRes sys_modify_ldt ( ThreadId tid, Int func, void* ptr, UInt bytecount ) { - SysRes ret; + /* Set return value to something "safe". I think this will never + actually be returned, though. */ + SysRes ret = VG_(mk_SysRes_Error)( VKI_ENOSYS ); if (func != 0 && func != 1 && func != 2 && func != 0x11) { ret = VG_(mk_SysRes_Error)( VKI_ENOSYS ); @@ -634,8 +636,10 @@ static SysRes sys_set_thread_area ( ThreadId tid, vki_modify_ldt_t* info ) vg_assert(8 == sizeof(VexGuestX86SegDescr)); vg_assert(sizeof(HWord) == sizeof(VexGuestX86SegDescr*)); - if (info == NULL || ! ML_(safe_to_deref)(info, sizeof(vki_modify_ldt_t))) + if (info == NULL || ! ML_(safe_to_deref)(info, sizeof(vki_modify_ldt_t))) { + VG_(umsg)("Warning: bad u_info address %p in set_thread_area\n", info); return VG_(mk_SysRes_Error)( VKI_EFAULT ); + } gdt = (VexGuestX86SegDescr*)VG_(threads)[tid].arch.vex.guest_GDT; @@ -686,8 +690,10 @@ static SysRes sys_get_thread_area ( ThreadId tid, vki_modify_ldt_t* info ) vg_assert(sizeof(HWord) == sizeof(VexGuestX86SegDescr*)); vg_assert(8 == sizeof(VexGuestX86SegDescr)); - if (info == NULL || ! ML_(safe_to_deref)(info, sizeof(vki_modify_ldt_t))) + if (info == NULL || ! ML_(safe_to_deref)(info, sizeof(vki_modify_ldt_t))) { + VG_(umsg)("Warning: bad u_info address %p in get_thread_area\n", info); return VG_(mk_SysRes_Error)( VKI_EFAULT ); + } idx = info->entry_number; diff --git a/memcheck/tests/x86-linux/scalar.stderr.exp b/memcheck/tests/x86-linux/scalar.stderr.exp index 30cfd1ce27..d1af3136c3 100644 --- a/memcheck/tests/x86-linux/scalar.stderr.exp +++ b/memcheck/tests/x86-linux/scalar.stderr.exp @@ -3380,6 +3380,7 @@ Syscall param set_thread_area(u_info) points to unaddressable byte(s) by 0x........: main (scalar.c:1084) Address 0x........ is not stack'd, malloc'd or (recently) free'd +Warning: bad u_info address 0x........ in set_thread_area ----------------------------------------------------- 244:__NR_get_thread_area 1s 1m ----------------------------------------------------- @@ -3392,6 +3393,7 @@ Syscall param get_thread_area(u_info) points to unaddressable byte(s) by 0x........: main (scalar.c:1088) Address 0x........ is not stack'd, malloc'd or (recently) free'd +Warning: bad u_info address 0x........ in get_thread_area ----------------------------------------------------- 245: __NR_io_setup 2s 1m ----------------------------------------------------- -- 2.47.2