]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
dtrace: ensure we pass a limit to dtrace_stacktrace for stackdepth
authorKris Van Hees <kris.van.hees@oracle.com>
Wed, 15 Mar 2017 03:20:52 +0000 (23:20 -0400)
committerKris Van Hees <kris.van.hees@oracle.com>
Wed, 15 Mar 2017 12:42:20 +0000 (08:42 -0400)
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 <kris.van.hees@oracle.com>
dtrace/dtrace_isa.c

index 5642cedef9e009e7f7c5a88064e7ee9aac376019..3d05586643a6fae46b3233fc82221af342353593 100644 (file)
@@ -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;