From d030a5bc7f9dfa0bcba020c16d1bb380b48bda09 Mon Sep 17 00:00:00 2001 From: Kris Van Hees Date: Tue, 14 Mar 2017 23:20:52 -0400 Subject: [PATCH] dtrace: ensure we pass a limit to dtrace_stacktrace for stackdepth When determining the (kernel) stackdepth, we pass scratch memory to the dtrace_stacktrace() function because we are not interested in the actual program counter values. However, we were passing in 0 as limit rather than the actual maximum number of PCs that could fit in the remaining scratch memory space. We now also add no-fault protection to dtrace_getstackdepth(). Orabug: 25559321 Signed-off-by: Kris Van Hees --- dtrace/dtrace_isa.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/dtrace/dtrace_isa.c b/dtrace/dtrace_isa.c index 5642cedef9e00..3d05586643a6f 100644 --- a/dtrace/dtrace_isa.c +++ b/dtrace/dtrace_isa.c @@ -190,7 +190,6 @@ void dtrace_getupcstack(uint64_t *pcstack, int pcstack_limit) int dtrace_getstackdepth(dtrace_mstate_t *mstate, int aframes) { uintptr_t old = mstate->dtms_scratch_ptr; - size_t size; stacktrace_state_t st = { NULL, NULL, @@ -199,15 +198,20 @@ int dtrace_getstackdepth(dtrace_mstate_t *mstate, int aframes) STACKTRACE_KERNEL }; - st.pcs = (uint64_t *)P2ROUNDUP(mstate->dtms_scratch_ptr, 8); - size = (uintptr_t)st.pcs - mstate->dtms_scratch_ptr + - aframes * sizeof(uint64_t); - if (mstate->dtms_scratch_ptr + size > + st.pcs = (uint64_t *)ALIGN(old, 8); + if ((uintptr_t)st.pcs > mstate->dtms_scratch_base + mstate->dtms_scratch_size) { DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH); return 0; } + /* + * Calculate how many (64-bit) PCs we can fit in the remaining scratch + * memory. + */ + st.limit = (mstate->dtms_scratch_base + mstate->dtms_scratch_size - + (uintptr_t)st.pcs) >> 3; + dtrace_stacktrace(&st); mstate->dtms_scratch_ptr = old; -- 2.50.1