From: Alexandra Hájková Date: Mon, 13 Jan 2020 17:29:55 +0000 (-0500) Subject: syswrap-linux.c: fix clock_adjtime handling X-Git-Tag: VALGRIND_3_16_0~137 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=58fc707804b9c1db66124737f5dcbb2715b230e1;p=thirdparty%2Fvalgrind.git syswrap-linux.c: fix clock_adjtime handling Not checking whether valgrind can dereference timex pointer casues VALGRIND INTERNAL ERROR while handling clock_adjtime. --- diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c index 25d9a95083..d04a081dd9 100644 --- a/coregrind/m_syswrap/syswrap-linux.c +++ b/coregrind/m_syswrap/syswrap-linux.c @@ -1291,24 +1291,28 @@ PRE(sys_clock_adjtime) PRE_REG_READ2(long, "clock_adjtime", vki_clockid_t, id, struct timex *, buf); PRE_MEM_READ( "clock_adjtime(timex->modes)", ARG2, sizeof(tx->modes)); -#define ADJX(bits,field) \ - if (tx->modes & (bits)) \ - PRE_MEM_READ( "clock_adjtime(timex->"#field")", \ - (Addr)&tx->field, sizeof(tx->field)) - - if (tx->modes & VKI_ADJ_ADJTIME) { - if (!(tx->modes & VKI_ADJ_OFFSET_READONLY)) - PRE_MEM_READ( "clock_adjtime(timex->offset)", (Addr)&tx->offset, sizeof(tx->offset)); - } else { - ADJX(VKI_ADJ_OFFSET, offset); - ADJX(VKI_ADJ_FREQUENCY, freq); - ADJX(VKI_ADJ_MAXERROR, maxerror); - ADJX(VKI_ADJ_ESTERROR, esterror); - ADJX(VKI_ADJ_STATUS, status); - ADJX(VKI_ADJ_TIMECONST|VKI_ADJ_TAI, constant); - ADJX(VKI_ADJ_TICK, tick); - } + if (ML_(safe_to_deref) (tx, sizeof(struct vki_timex))) { + PRE_MEM_READ( "clock_adjtime(timex->modes)", ARG2, sizeof(tx->modes)); + +#define ADJX(bits,field) \ + if (tx->modes & (bits)) \ + PRE_MEM_READ( "clock_adjtime(timex->"#field")", \ + (Addr)&tx->field, sizeof(tx->field)) + + if (tx->modes & VKI_ADJ_ADJTIME) { + if (!(tx->modes & VKI_ADJ_OFFSET_READONLY)) + PRE_MEM_READ( "clock_adjtime(timex->offset)", (Addr)&tx->offset, sizeof(tx->offset)); + } else { + ADJX(VKI_ADJ_OFFSET, offset); + ADJX(VKI_ADJ_FREQUENCY, freq); + ADJX(VKI_ADJ_MAXERROR, maxerror); + ADJX(VKI_ADJ_ESTERROR, esterror); + ADJX(VKI_ADJ_STATUS, status); + ADJX(VKI_ADJ_TIMECONST|VKI_ADJ_TAI, constant); + ADJX(VKI_ADJ_TICK, tick); + } #undef ADJX + } PRE_MEM_WRITE( "adjtimex(timex)", ARG2, sizeof(struct vki_timex)); }