* Re: [PATCH 4.14 03/62] arm64: kprobe: make page to RO mode when allocate it
[not found] <20181126105051.213025360 () linuxfoundation ! org>
@ 2023-09-04 5:24 ` Behme Dirk (CM/ESO2)
2023-09-04 6:42 ` Greg Kroah-Hartman
0 siblings, 1 reply; 3+ messages in thread
From: Behme Dirk (CM/ESO2) @ 2023-09-04 5:24 UTC (permalink / raw)
To: Greg Kroah-Hartman, linux-kernel; +Cc: Dirk Behme
On 26.11.2018 11:50, Greg Kroah-Hartman wrote:
> 4.14-stable review patch. If anyone has any objections, please let me know.
It looks like that this patch which was back ported from v4.20 to
v4.14.100 needs the '__weak' on kernel/kprobes.c alloc_insn_page() from
v4.15 commit
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=63fef14fc98a8b4fad7
to make alloc_insn_page() being used properly.
But that '__weak' from 63fef14fc98a8b4fad7 was not back ported to
v4.14.x and is missing in v4.14.x ?
Best regards
Dirk
> ------------------
>
> [ Upstream commit 966866892cf89d606544bca22d584ba2ef9ec208 ]
>
> Commit 1404d6f13e47 ("arm64: dump: Add checking for writable and exectuable pages")
> has successfully identified code that leaves a page with W+X
> permissions.
>
> [ 3.245140] arm64/mm: Found insecure W+X mapping at address (____ptrval____)/0xffff000000d90000
> [ 3.245771] WARNING: CPU: 0 PID: 1 at ../arch/arm64/mm/dump.c:232 note_page+0x410/0x420
> [ 3.246141] Modules linked in:
> [ 3.246653] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.19.0-rc5-next-20180928-00001-ge70ae259b853-dirty #62
> [ 3.247008] Hardware name: linux,dummy-virt (DT)
> [ 3.247347] pstate: 80000005 (Nzcv daif -PAN -UAO)
> [ 3.247623] pc : note_page+0x410/0x420
> [ 3.247898] lr : note_page+0x410/0x420
> [ 3.248071] sp : ffff00000804bcd0
> [ 3.248254] x29: ffff00000804bcd0 x28: ffff000009274000
> [ 3.248578] x27: ffff00000921a000 x26: ffff80007dfff000
> [ 3.248845] x25: ffff0000093f5000 x24: ffff000009526f6a
> [ 3.249109] x23: 0000000000000004 x22: ffff000000d91000
> [ 3.249396] x21: ffff000000d90000 x20: 0000000000000000
> [ 3.249661] x19: ffff00000804bde8 x18: 0000000000000400
> [ 3.249924] x17: 0000000000000000 x16: 0000000000000000
> [ 3.250271] x15: ffffffffffffffff x14: 295f5f5f5f6c6176
> [ 3.250594] x13: 7274705f5f5f5f28 x12: 2073736572646461
> [ 3.250941] x11: 20746120676e6970 x10: 70616d20582b5720
> [ 3.251252] x9 : 6572756365736e69 x8 : 3039643030303030
> [ 3.251519] x7 : 306666666678302f x6 : ffff0000095467b2
> [ 3.251802] x5 : 0000000000000000 x4 : 0000000000000000
> [ 3.252060] x3 : 0000000000000000 x2 : ffffffffffffffff
> [ 3.252323] x1 : 4d151327adc50b00 x0 : 0000000000000000
> [ 3.252664] Call trace:
> [ 3.252953] note_page+0x410/0x420
> [ 3.253186] walk_pgd+0x12c/0x238
> [ 3.253417] ptdump_check_wx+0x68/0xf8
> [ 3.253637] mark_rodata_ro+0x68/0x98
> [ 3.253847] kernel_init+0x38/0x160
> [ 3.254103] ret_from_fork+0x10/0x18
>
> kprobes allocates a writable executable page with module_alloc() in
> order to store executable code.
> Reworked to that when allocate a page it sets mode RO. Inspired by
> commit 63fef14fc98a ("kprobes/x86: Make insn buffer always ROX and use text_poke()").
>
> Suggested-by: Arnd Bergmann <arnd@arndb.de>
> Suggested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> Acked-by: Will Deacon <will.deacon@arm.com>
> Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
> Reviewed-by: Laura Abbott <labbott@redhat.com>
> Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
> [catalin.marinas@arm.com: removed unnecessary casts]
> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> ---
> arch/arm64/kernel/probes/kprobes.c | 27 ++++++++++++++++++++-------
> 1 file changed, 20 insertions(+), 7 deletions(-)
>
> diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c
> index 22a5921562c7..0417c929d21a 100644
> --- a/arch/arm64/kernel/probes/kprobes.c
> +++ b/arch/arm64/kernel/probes/kprobes.c
> @@ -23,7 +23,9 @@
> #include <linux/slab.h>
> #include <linux/stop_machine.h>
> #include <linux/sched/debug.h>
> +#include <linux/set_memory.h>
> #include <linux/stringify.h>
> +#include <linux/vmalloc.h>
> #include <asm/traps.h>
> #include <asm/ptrace.h>
> #include <asm/cacheflush.h>
> @@ -42,10 +44,21 @@ DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
> static void __kprobes
> post_kprobe_handler(struct kprobe_ctlblk *, struct pt_regs *);
>
> +static int __kprobes patch_text(kprobe_opcode_t *addr, u32 opcode)
> +{
> + void *addrs[1];
> + u32 insns[1];
> +
> + addrs[0] = addr;
> + insns[0] = opcode;
> +
> + return aarch64_insn_patch_text(addrs, insns, 1);
> +}
> +
> static void __kprobes arch_prepare_ss_slot(struct kprobe *p)
> {
> /* prepare insn slot */
> - p->ainsn.api.insn[0] = cpu_to_le32(p->opcode);
> + patch_text(p->ainsn.api.insn, p->opcode);
>
> flush_icache_range((uintptr_t) (p->ainsn.api.insn),
> (uintptr_t) (p->ainsn.api.insn) +
> @@ -118,15 +131,15 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
> return 0;
> }
>
> -static int __kprobes patch_text(kprobe_opcode_t *addr, u32 opcode)
> +void *alloc_insn_page(void)
> {
> - void *addrs[1];
> - u32 insns[1];
> + void *page;
>
> - addrs[0] = (void *)addr;
> - insns[0] = (u32)opcode;
> + page = vmalloc_exec(PAGE_SIZE);
> + if (page)
> + set_memory_ro((unsigned long)page, 1);
>
> - return aarch64_insn_patch_text(addrs, insns, 1);
> + return page;
> }
>
> /* arm kprobe: install breakpoint in text */
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 4.14 00/62] 4.14.84-stable review
@ 2018-11-26 10:50 Greg Kroah-Hartman
2018-11-26 10:50 ` [PATCH 4.14 03/62] arm64: kprobe: make page to RO mode when allocate it Greg Kroah-Hartman
0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2018-11-26 10:50 UTC (permalink / raw)
To: linux-kernel
Cc: Greg Kroah-Hartman, torvalds, akpm, linux, shuah, patches,
ben.hutchings, lkft-triage, stable
This is the start of the stable review cycle for the 4.14.84 release.
There are 62 patches in this series, all will be posted as a response
to this one. If anyone has any issues with these being applied, please
let me know.
Responses should be made by Wed Nov 28 10:50:20 UTC 2018.
Anything received after that time might be too late.
The whole patch series can be found in one patch at:
https://www.kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.14.84-rc1.gz
or in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git linux-4.14.y
and the diffstat can be found below.
thanks,
greg k-h
-------------
Pseudo-Shortlog of commits:
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Linux 4.14.84-rc1
Ilya Dryomov <idryomov@gmail.com>
libceph: fall back to sendmsg for slab pages
Eric Biggers <ebiggers@google.com>
HID: uhid: forbid UHID_CREATE under KERNEL_DS or elevated privileges
Hans de Goede <hdegoede@redhat.com>
ACPI / platform: Add SMB0001 HID to forbidden_id_list
Gustavo A. R. Silva <gustavo@embeddedor.com>
drivers/misc/sgi-gru: fix Spectre v1 vulnerability
Johan Hovold <johan@kernel.org>
mtd: rawnand: atmel: fix OF child-node lookup
Mattias Jacobsson <2pi@mok.nu>
USB: misc: appledisplay: add 20" Apple Cinema Display
Nathan Chancellor <natechancellor@gmail.com>
misc: atmel-ssc: Fix section annotation on atmel_ssc_get_driver_data
Emmanuel Pescosta <emmanuelpescosta099@gmail.com>
usb: quirks: Add delay-init quirk for Corsair K70 LUX RGB
Kai-Heng Feng <kai.heng.feng@canonical.com>
USB: quirks: Add no-lpm quirk for Raydium touchscreens
Maarten Jacobs <maarten256@outlook.com>
usb: cdc-acm: add entry for Hiro (Conexant) modem
Dan Carpenter <dan.carpenter@oracle.com>
uio: Fix an Oops on load
Aaro Koskinen <aaro.koskinen@iki.fi>
MIPS: OCTEON: cavium_octeon_defconfig: re-enable OCTEON USB driver
Sakari Ailus <sakari.ailus@linux.intel.com>
media: v4l: event: Add subscription to list before calling "add" operation
Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
x86/ldt: Unmap PTEs for the slot before freeing LDT pages
Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
x86/mm: Move LDT remap out of KASLR region on 5-level paging
Adrian Hunter <adrian.hunter@intel.com>
perf test code-reading: Fix perf_env setup for PTI entry trampolines
Adrian Hunter <adrian.hunter@intel.com>
perf machine: Workaround missing maps for x86 PTI entry trampolines
Adrian Hunter <adrian.hunter@intel.com>
perf machine: Add nr_cpus_avail()
Adrian Hunter <adrian.hunter@intel.com>
perf tools: Fix kernel_start for PTI on x86
Adrian Hunter <adrian.hunter@intel.com>
perf machine: Add machine__is() to identify machine arch
Mika Westerberg <mika.westerberg@linux.intel.com>
ACPI / watchdog: Prefer iTCO_wdt always when WDAT table uses RTC SRAM
YueHaibing <yuehaibing@huawei.com>
SUNRPC: drop pointless static qualifier in xdr_get_next_encode_buffer()
Minchan Kim <minchan@kernel.org>
zram: close udev startup race condition as default groups
Thor Thayer <thor.thayer@linux.intel.com>
net: stmmac: Fix RX packet size > 8191
Sagiv Ozeri <sagiv.ozeri@cavium.com>
qed: Fix potential memory corruption
Denis Bolotin <denis.bolotin@cavium.com>
qed: Fix blocking/unlimited SPQ entries leak
Denis Bolotin <denis.bolotin@cavium.com>
qed: Fix memory/entry leak in qed_init_sp_request()
Jacob Keller <jacob.e.keller@intel.com>
i40e: restore NETIF_F_GSO_IPXIP[46] to netdev features
Gustavo Romero <gromero@linux.vnet.ibm.com>
perf tools: Fix undefined symbol scnprintf in libperf-jvmti.so
Valentin Schneider <valentin.schneider@arm.com>
sched/core: Take the hotplug lock in sched_init_smp()
Vignesh R <vigneshr@ti.com>
i2c: omap: Enable for ARCH_K3
Thomas Richter <tmricht@linux.ibm.com>
s390/perf: Change CPUM_CF return code in event init function
Jeremy Linton <jeremy.linton@arm.com>
lib/raid6: Fix arm64 test build
Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
clk: fixed-factor: fix of_node_get-put imbalance
Inki Dae <inki.dae@samsung.com>
Revert "drm/exynos/decon5433: implement frame counter"
Geert Uytterhoeven <geert@linux-m68k.org>
hwmon: (ibmpowernv) Remove bogus __init annotations
Julian Wiedmann <jwi@linux.ibm.com>
s390/qeth: fix HiperSockets sniffer
Taehee Yoo <ap420073@gmail.com>
netfilter: xt_IDLETIMER: add sysfs filename checking routine
Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
netfilter: ipset: Correct rcu_dereference() call in ip_set_put_comment()
Justin M. Forbes <jforbes@fedoraproject.org>
s390/mm: Fix ERROR: "__node_distance" undefined!
Eric Westbrook <eric@westbrook.io>
netfilter: ipset: actually allow allowable CIDR 0 in hash:net,port,net
Stefano Brivio <sbrivio@redhat.com>
netfilter: ipset: list:set: Decrease refcount synchronously on deletion and replace
Vasily Gorbik <gor@linux.ibm.com>
s390/vdso: add missing FORCE to build targets
Nathan Chancellor <natechancellor@gmail.com>
arm64: percpu: Initialize ret in the default case
Paul Gortmaker <paul.gortmaker@windriver.com>
platform/x86: acerhdf: Add BIOS entry for Gateway LT31 v1.3307
Feng Tang <feng.tang@intel.com>
x86/earlyprintk: Add a force option for pciserial device
Zubin Mithra <zsm@chromium.org>
apparmor: Fix uninitialized value in aa_split_fqname
Marek Szyprowski <m.szyprowski@samsung.com>
clk: samsung: exynos5420: Enable PERIS clocks for suspend
Chengguang Xu <cgxu519@gmx.com>
fs/exofs: fix potential memory leak in mount option parsing
David Miller <davem@davemloft.net>
perf symbols: Set PLT entry/header sizes properly on Sparc
Alan Tull <atull@kernel.org>
clk: fixed-rate: fix of_node_get-put imbalance
Rajneesh Bhardwaj <rajneesh.bhardwaj@linux.intel.com>
platform/x86: intel_telemetry: report debugfs failure
Lee, Shawn C <shawn.c.lee@intel.com>
drm/edid: Add 6 bpc quirk for BOE panel.
Richard Weinberger <richard@nod.at>
um: Give start_idle_thread() a return code
Ernesto A. Fernández <ernesto.mnd.fernandez@gmail.com>
hfsplus: prevent btree data loss on root split
Ernesto A. Fernández <ernesto.mnd.fernandez@gmail.com>
hfs: prevent btree data loss on root split
Jann Horn <jannh@google.com>
reiserfs: propagate errors from fill_with_dentries() properly
Radoslaw Tyl <radoslawx.tyl@intel.com>
ixgbe: fix MAC anti-spoofing filter after VFLR
Keith Busch <keith.busch@intel.com>
nvme-pci: fix conflicting p2p resource adds
Anders Roxell <anders.roxell@linaro.org>
arm64: kprobe: make page to RO mode when allocate it
Ronnie Sahlberg <lsahlber@redhat.com>
cifs: fix return value for cifs_listxattr
Colin Ian King <colin.king@canonical.com>
cifs: don't dereference smb_file_target before null check
-------------
Diffstat:
Documentation/admin-guide/kernel-parameters.txt | 6 +-
Documentation/x86/x86_64/mm.txt | 10 +-
Makefile | 4 +-
arch/arm64/include/asm/percpu.h | 3 +
arch/arm64/kernel/probes/kprobes.c | 27 +++--
arch/mips/configs/cavium_octeon_defconfig | 1 +
arch/s390/kernel/perf_cpum_cf.c | 2 +-
arch/s390/kernel/vdso32/Makefile | 6 +-
arch/s390/kernel/vdso64/Makefile | 6 +-
arch/s390/numa/numa.c | 1 +
arch/um/os-Linux/skas/process.c | 5 +
arch/x86/include/asm/page_64_types.h | 12 ++-
arch/x86/include/asm/pgtable_64_types.h | 7 +-
arch/x86/kernel/early_printk.c | 29 ++++--
arch/x86/kernel/ldt.c | 49 ++++++---
arch/x86/xen/mmu_pv.c | 6 +-
drivers/acpi/acpi_platform.c | 1 +
drivers/acpi/acpi_watchdog.c | 72 ++++++++-----
drivers/block/zram/zram_drv.c | 26 ++---
drivers/clk/clk-fixed-factor.c | 1 +
drivers/clk/clk-fixed-rate.c | 1 +
drivers/clk/samsung/clk-exynos5420.c | 1 +
drivers/gpu/drm/drm_edid.c | 3 +
drivers/gpu/drm/exynos/exynos5433_drm_decon.c | 9 --
drivers/gpu/drm/exynos/exynos_drm_crtc.c | 11 --
drivers/gpu/drm/exynos/exynos_drm_drv.h | 1 -
drivers/hid/uhid.c | 12 +++
drivers/hwmon/ibmpowernv.c | 7 +-
drivers/i2c/busses/Kconfig | 2 +-
drivers/media/v4l2-core/v4l2-event.c | 43 ++++----
drivers/misc/atmel-ssc.c | 2 +-
drivers/misc/sgi-gru/grukdump.c | 4 +
drivers/mtd/nand/atmel/nand-controller.c | 11 +-
drivers/net/ethernet/intel/i40e/i40e_main.c | 2 +
drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c | 4 +-
drivers/net/ethernet/qlogic/qed/qed_sp.h | 3 +
drivers/net/ethernet/qlogic/qed/qed_sp_commands.c | 16 ++-
drivers/net/ethernet/qlogic/qed/qed_spq.c | 69 ++++++-------
drivers/net/ethernet/stmicro/stmmac/common.h | 3 +-
drivers/net/ethernet/stmicro/stmmac/descs_com.h | 2 +-
drivers/net/ethernet/stmicro/stmmac/enh_desc.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/ring_mode.c | 2 +-
drivers/nvme/host/pci.c | 5 +-
drivers/platform/x86/acerhdf.c | 1 +
drivers/platform/x86/intel_telemetry_debugfs.c | 8 +-
drivers/s390/net/qeth_l3_main.c | 8 +-
drivers/uio/uio.c | 7 +-
drivers/usb/class/cdc-acm.c | 3 +
drivers/usb/core/quirks.c | 8 ++
drivers/usb/misc/appledisplay.c | 1 +
fs/cifs/cifsfs.c | 7 +-
fs/cifs/smb2ops.c | 11 +-
fs/exofs/super.c | 5 +-
fs/hfs/brec.c | 4 +
fs/hfsplus/brec.c | 4 +
fs/reiserfs/xattr.c | 7 ++
include/linux/netfilter/ipset/ip_set.h | 2 +-
include/linux/netfilter/ipset/ip_set_comment.h | 4 +-
kernel/sched/core.c | 5 +-
lib/raid6/test/Makefile | 4 +-
net/ceph/messenger.c | 12 ++-
net/netfilter/ipset/ip_set_core.c | 23 ++---
net/netfilter/ipset/ip_set_hash_netportnet.c | 8 +-
net/netfilter/ipset/ip_set_list_set.c | 17 ++--
net/netfilter/xt_IDLETIMER.c | 20 ++++
net/sunrpc/xdr.c | 2 +-
security/apparmor/lib.c | 6 +-
tools/perf/jvmti/jvmti_agent.c | 49 +++++++--
tools/perf/tests/code-reading.c | 1 +
tools/perf/util/env.c | 32 ++++++
tools/perf/util/env.h | 4 +
tools/perf/util/machine.c | 117 +++++++++++++++++++++-
tools/perf/util/machine.h | 6 ++
tools/perf/util/symbol-elf.c | 12 ++-
tools/perf/util/symbol.c | 12 ++-
75 files changed, 637 insertions(+), 262 deletions(-)
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH 4.14 03/62] arm64: kprobe: make page to RO mode when allocate it
2018-11-26 10:50 [PATCH 4.14 00/62] 4.14.84-stable review Greg Kroah-Hartman
@ 2018-11-26 10:50 ` Greg Kroah-Hartman
0 siblings, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2018-11-26 10:50 UTC (permalink / raw)
To: linux-kernel
Cc: Greg Kroah-Hartman, stable, Arnd Bergmann, Ard Biesheuvel,
Will Deacon, Masami Hiramatsu, Laura Abbott, Anders Roxell,
Catalin Marinas, Sasha Levin
4.14-stable review patch. If anyone has any objections, please let me know.
------------------
[ Upstream commit 966866892cf89d606544bca22d584ba2ef9ec208 ]
Commit 1404d6f13e47 ("arm64: dump: Add checking for writable and exectuable pages")
has successfully identified code that leaves a page with W+X
permissions.
[ 3.245140] arm64/mm: Found insecure W+X mapping at address (____ptrval____)/0xffff000000d90000
[ 3.245771] WARNING: CPU: 0 PID: 1 at ../arch/arm64/mm/dump.c:232 note_page+0x410/0x420
[ 3.246141] Modules linked in:
[ 3.246653] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.19.0-rc5-next-20180928-00001-ge70ae259b853-dirty #62
[ 3.247008] Hardware name: linux,dummy-virt (DT)
[ 3.247347] pstate: 80000005 (Nzcv daif -PAN -UAO)
[ 3.247623] pc : note_page+0x410/0x420
[ 3.247898] lr : note_page+0x410/0x420
[ 3.248071] sp : ffff00000804bcd0
[ 3.248254] x29: ffff00000804bcd0 x28: ffff000009274000
[ 3.248578] x27: ffff00000921a000 x26: ffff80007dfff000
[ 3.248845] x25: ffff0000093f5000 x24: ffff000009526f6a
[ 3.249109] x23: 0000000000000004 x22: ffff000000d91000
[ 3.249396] x21: ffff000000d90000 x20: 0000000000000000
[ 3.249661] x19: ffff00000804bde8 x18: 0000000000000400
[ 3.249924] x17: 0000000000000000 x16: 0000000000000000
[ 3.250271] x15: ffffffffffffffff x14: 295f5f5f5f6c6176
[ 3.250594] x13: 7274705f5f5f5f28 x12: 2073736572646461
[ 3.250941] x11: 20746120676e6970 x10: 70616d20582b5720
[ 3.251252] x9 : 6572756365736e69 x8 : 3039643030303030
[ 3.251519] x7 : 306666666678302f x6 : ffff0000095467b2
[ 3.251802] x5 : 0000000000000000 x4 : 0000000000000000
[ 3.252060] x3 : 0000000000000000 x2 : ffffffffffffffff
[ 3.252323] x1 : 4d151327adc50b00 x0 : 0000000000000000
[ 3.252664] Call trace:
[ 3.252953] note_page+0x410/0x420
[ 3.253186] walk_pgd+0x12c/0x238
[ 3.253417] ptdump_check_wx+0x68/0xf8
[ 3.253637] mark_rodata_ro+0x68/0x98
[ 3.253847] kernel_init+0x38/0x160
[ 3.254103] ret_from_fork+0x10/0x18
kprobes allocates a writable executable page with module_alloc() in
order to store executable code.
Reworked to that when allocate a page it sets mode RO. Inspired by
commit 63fef14fc98a ("kprobes/x86: Make insn buffer always ROX and use text_poke()").
Suggested-by: Arnd Bergmann <arnd@arndb.de>
Suggested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Acked-by: Will Deacon <will.deacon@arm.com>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Reviewed-by: Laura Abbott <labbott@redhat.com>
Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
[catalin.marinas@arm.com: removed unnecessary casts]
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
arch/arm64/kernel/probes/kprobes.c | 27 ++++++++++++++++++++-------
1 file changed, 20 insertions(+), 7 deletions(-)
diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c
index 22a5921562c7..0417c929d21a 100644
--- a/arch/arm64/kernel/probes/kprobes.c
+++ b/arch/arm64/kernel/probes/kprobes.c
@@ -23,7 +23,9 @@
#include <linux/slab.h>
#include <linux/stop_machine.h>
#include <linux/sched/debug.h>
+#include <linux/set_memory.h>
#include <linux/stringify.h>
+#include <linux/vmalloc.h>
#include <asm/traps.h>
#include <asm/ptrace.h>
#include <asm/cacheflush.h>
@@ -42,10 +44,21 @@ DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
static void __kprobes
post_kprobe_handler(struct kprobe_ctlblk *, struct pt_regs *);
+static int __kprobes patch_text(kprobe_opcode_t *addr, u32 opcode)
+{
+ void *addrs[1];
+ u32 insns[1];
+
+ addrs[0] = addr;
+ insns[0] = opcode;
+
+ return aarch64_insn_patch_text(addrs, insns, 1);
+}
+
static void __kprobes arch_prepare_ss_slot(struct kprobe *p)
{
/* prepare insn slot */
- p->ainsn.api.insn[0] = cpu_to_le32(p->opcode);
+ patch_text(p->ainsn.api.insn, p->opcode);
flush_icache_range((uintptr_t) (p->ainsn.api.insn),
(uintptr_t) (p->ainsn.api.insn) +
@@ -118,15 +131,15 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
return 0;
}
-static int __kprobes patch_text(kprobe_opcode_t *addr, u32 opcode)
+void *alloc_insn_page(void)
{
- void *addrs[1];
- u32 insns[1];
+ void *page;
- addrs[0] = (void *)addr;
- insns[0] = (u32)opcode;
+ page = vmalloc_exec(PAGE_SIZE);
+ if (page)
+ set_memory_ro((unsigned long)page, 1);
- return aarch64_insn_patch_text(addrs, insns, 1);
+ return page;
}
/* arm kprobe: install breakpoint in text */
--
2.17.1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-09-04 6:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20181126105051.213025360 () linuxfoundation ! org>
2023-09-04 5:24 ` [PATCH 4.14 03/62] arm64: kprobe: make page to RO mode when allocate it Behme Dirk (CM/ESO2)
2023-09-04 6:42 ` Greg Kroah-Hartman
2018-11-26 10:50 [PATCH 4.14 00/62] 4.14.84-stable review Greg Kroah-Hartman
2018-11-26 10:50 ` [PATCH 4.14 03/62] arm64: kprobe: make page to RO mode when allocate it Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®