From: Kris Van Hees Date: Wed, 15 Mar 2017 03:20:52 +0000 (-0400) Subject: dtrace: ensure we pass a limit to dtrace_stacktrace for stackdepth X-Git-Tag: v4.1.12-111.0.20170907_2225~3^2~3^2~22 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=d030a5bc7f9dfa0bcba020c16d1bb380b48bda09;p=users%2Fjedix%2Flinux-maple.git 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 --- diff --git a/dtrace/dtrace_isa.c b/dtrace/dtrace_isa.c index 5642cedef9e0..3d05586643a6 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;