From: Kris Van Hees Date: Mon, 23 May 2016 17:38:49 +0000 (-0700) Subject: dtrace: ensure pdata and sdt_tab handling works on module reload X-Git-Tag: v4.1.12-111.0.20170907_2225~3^2~3^2~46 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=269477c2cf31a50cd7bdd0e8948e2e2413796fee;p=users%2Fjedix%2Flinux-maple.git dtrace: ensure pdata and sdt_tab handling works on module reload The handling of the sdt_tab member in pdata caused crashes when the sdt module was unloaded and then reloaded. This member holds the trampolines for SDT probe points in kernel modules, and is allocated when a module is loaded and resides in modules-only address space). This memory block was incorrectly free'd from the sdt module code when sdt was unloaded. This commit also adds verification that the anticipated trampoline max size as used in the kernel is sufficient for what the sdt module needs. This commit also adds verification (at runtime, with an assert) that the reserved allocation to hold the pdata for a module is of a sufficient size. Orabug: 23331667 Signed-off-by: Kris Van Hees Acked-by: Nick Alcock --- diff --git a/dtrace/dtrace_dev.c b/dtrace/dtrace_dev.c index f512c3a30ef81..8d79da22d46b8 100644 --- a/dtrace/dtrace_dev.c +++ b/dtrace/dtrace_dev.c @@ -21,7 +21,7 @@ * * CDDL HEADER END * - * Copyright 2010-2014 Oracle, Inc. All rights reserved. + * Copyright 2010-2016 Oracle, Inc. All rights reserved. * Use is subject to license terms. */ @@ -1385,6 +1385,12 @@ int dtrace_dev_init(void) int rc = 0; struct cred *cred; + /* + * Sanity check to ensure that the memory allocated by the kernel is + * sufficient for what PDATA needs. + */ + ASSERT(sizeof(dtrace_module_t) < DTRACE_PDATA_SIZE); + /* * Register the device for the DTrace core. */ diff --git a/dtrace/sdt_sparc64.c b/dtrace/sdt_sparc64.c index 44d50f38b397f..8fe02a0b08b65 100644 --- a/dtrace/sdt_sparc64.c +++ b/dtrace/sdt_sparc64.c @@ -21,7 +21,7 @@ * * CDDL HEADER END * - * Copyright 2010, 2011, 2012 Oracle, Inc. All rights reserved. + * Copyright 2010-2016 Oracle, Inc. All rights reserved. * Use is subject to license terms. */ @@ -61,7 +61,9 @@ * ret * restore */ -#define SDT_TRAMP_SIZE 11 +#if SDT_TRAMP_SIZE < 11 +# error SDT_TRAMP_SIZE is less than the required 11 instructions. +#endif #define SA(x) ((long)ALIGN((x), 4)) #define MINFRAME STACKFRAME_SZ @@ -162,10 +164,6 @@ int sdt_provide_module_arch(void *arg, struct module *mp) void sdt_cleanup_module(void *dmy, struct module *mp) { - if (PDATA(mp)->sdt_tab) { - vfree(PDATA(mp)->sdt_tab); - PDATA(mp)->sdt_tab = NULL; - } } void sdt_enable_arch(sdt_probe_t *sdp, dtrace_id_t id, void *arg) @@ -183,15 +181,6 @@ int sdt_dev_init_arch(void) return 0; } -static void module_del_sdt_tab(void *dmy, struct module *mp) -{ - if (PDATA(mp)->sdt_tab) { - vfree(PDATA(mp)->sdt_tab); - PDATA(mp)->sdt_tab = NULL; - } -} - void sdt_dev_exit_arch(void) { - dtrace_for_each_module(module_del_sdt_tab, NULL); }