From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
patches@lists.linux.dev, Mark Rutland <mark.rutland@arm.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH 5.15 31/80] arm64: probes: Fix uprobes for big-endian kernels
Date: Mon, 28 Oct 2024 07:25:11 +0100 [thread overview]
Message-ID: <20241028062253.492228912@linuxfoundation.org> (raw)
In-Reply-To: <20241028062252.611837461@linuxfoundation.org>
5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Rutland <mark.rutland@arm.com>
[ Upstream commit 13f8f1e05f1dc36dbba6cba0ae03354c0dafcde7 ]
The arm64 uprobes code is broken for big-endian kernels as it doesn't
convert the in-memory instruction encoding (which is always
little-endian) into the kernel's native endianness before analyzing and
simulating instructions. This may result in a few distinct problems:
* The kernel may may erroneously reject probing an instruction which can
safely be probed.
* The kernel may erroneously erroneously permit stepping an
instruction out-of-line when that instruction cannot be stepped
out-of-line safely.
* The kernel may erroneously simulate instruction incorrectly dur to
interpretting the byte-swapped encoding.
The endianness mismatch isn't caught by the compiler or sparse because:
* The arch_uprobe::{insn,ixol} fields are encoded as arrays of u8, so
the compiler and sparse have no idea these contain a little-endian
32-bit value. The core uprobes code populates these with a memcpy()
which similarly does not handle endianness.
* While the uprobe_opcode_t type is an alias for __le32, both
arch_uprobe_analyze_insn() and arch_uprobe_skip_sstep() cast from u8[]
to the similarly-named probe_opcode_t, which is an alias for u32.
Hence there is no endianness conversion warning.
Fix this by changing the arch_uprobe::{insn,ixol} fields to __le32 and
adding the appropriate __le32_to_cpu() conversions prior to consuming
the instruction encoding. The core uprobes copies these fields as opaque
ranges of bytes, and so is unaffected by this change.
At the same time, remove MAX_UINSN_BYTES and consistently use
AARCH64_INSN_SIZE for clarity.
Tested with the following:
| #include <stdio.h>
| #include <stdbool.h>
|
| #define noinline __attribute__((noinline))
|
| static noinline void *adrp_self(void)
| {
| void *addr;
|
| asm volatile(
| " adrp %x0, adrp_self\n"
| " add %x0, %x0, :lo12:adrp_self\n"
| : "=r" (addr));
| }
|
|
| int main(int argc, char *argv)
| {
| void *ptr = adrp_self();
| bool equal = (ptr == adrp_self);
|
| printf("adrp_self => %p\n"
| "adrp_self() => %p\n"
| "%s\n",
| adrp_self, ptr, equal ? "EQUAL" : "NOT EQUAL");
|
| return 0;
| }
.... where the adrp_self() function was compiled to:
| 00000000004007e0 <adrp_self>:
| 4007e0: 90000000 adrp x0, 400000 <__ehdr_start>
| 4007e4: 911f8000 add x0, x0, #0x7e0
| 4007e8: d65f03c0 ret
Before this patch, the ADRP is not recognized, and is assumed to be
steppable, resulting in corruption of the result:
| # ./adrp-self
| adrp_self => 0x4007e0
| adrp_self() => 0x4007e0
| EQUAL
| # echo 'p /root/adrp-self:0x007e0' > /sys/kernel/tracing/uprobe_events
| # echo 1 > /sys/kernel/tracing/events/uprobes/enable
| # ./adrp-self
| adrp_self => 0x4007e0
| adrp_self() => 0xffffffffff7e0
| NOT EQUAL
After this patch, the ADRP is correctly recognized and simulated:
| # ./adrp-self
| adrp_self => 0x4007e0
| adrp_self() => 0x4007e0
| EQUAL
| #
| # echo 'p /root/adrp-self:0x007e0' > /sys/kernel/tracing/uprobe_events
| # echo 1 > /sys/kernel/tracing/events/uprobes/enable
| # ./adrp-self
| adrp_self => 0x4007e0
| adrp_self() => 0x4007e0
| EQUAL
Fixes: 9842ceae9fa8 ("arm64: Add uprobe support")
Cc: stable@vger.kernel.org
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20241008155851.801546-4-mark.rutland@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
arch/arm64/include/asm/uprobes.h | 8 +++-----
arch/arm64/kernel/probes/uprobes.c | 4 ++--
2 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/arch/arm64/include/asm/uprobes.h b/arch/arm64/include/asm/uprobes.h
index ba4bff5ca6749..98f29a43bfe89 100644
--- a/arch/arm64/include/asm/uprobes.h
+++ b/arch/arm64/include/asm/uprobes.h
@@ -10,11 +10,9 @@
#include <asm/insn.h>
#include <asm/probes.h>
-#define MAX_UINSN_BYTES AARCH64_INSN_SIZE
-
#define UPROBE_SWBP_INSN cpu_to_le32(BRK64_OPCODE_UPROBES)
#define UPROBE_SWBP_INSN_SIZE AARCH64_INSN_SIZE
-#define UPROBE_XOL_SLOT_BYTES MAX_UINSN_BYTES
+#define UPROBE_XOL_SLOT_BYTES AARCH64_INSN_SIZE
typedef u32 uprobe_opcode_t;
@@ -23,8 +21,8 @@ struct arch_uprobe_task {
struct arch_uprobe {
union {
- u8 insn[MAX_UINSN_BYTES];
- u8 ixol[MAX_UINSN_BYTES];
+ __le32 insn;
+ __le32 ixol;
};
struct arch_probe_insn api;
bool simulate;
diff --git a/arch/arm64/kernel/probes/uprobes.c b/arch/arm64/kernel/probes/uprobes.c
index d49aef2657cdf..a2f137a595fc1 100644
--- a/arch/arm64/kernel/probes/uprobes.c
+++ b/arch/arm64/kernel/probes/uprobes.c
@@ -42,7 +42,7 @@ int arch_uprobe_analyze_insn(struct arch_uprobe *auprobe, struct mm_struct *mm,
else if (!IS_ALIGNED(addr, AARCH64_INSN_SIZE))
return -EINVAL;
- insn = *(probe_opcode_t *)(&auprobe->insn[0]);
+ insn = le32_to_cpu(auprobe->insn);
switch (arm_probe_decode_insn(insn, &auprobe->api)) {
case INSN_REJECTED:
@@ -108,7 +108,7 @@ bool arch_uprobe_skip_sstep(struct arch_uprobe *auprobe, struct pt_regs *regs)
if (!auprobe->simulate)
return false;
- insn = *(probe_opcode_t *)(&auprobe->insn[0]);
+ insn = le32_to_cpu(auprobe->insn);
addr = instruction_pointer(regs);
if (auprobe->api.handler)
--
2.43.0
next prev parent reply other threads:[~2024-10-28 6:32 UTC|newest]
Thread overview: 89+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-28 6:24 [PATCH 5.15 00/80] 5.15.170-rc1 review Greg Kroah-Hartman
2024-10-28 6:24 ` [PATCH 5.15 01/80] bpf: Make sure internal and UAPI bpf_redirect flags dont overlap Greg Kroah-Hartman
2024-10-28 6:24 ` [PATCH 5.15 02/80] bpf: devmap: provide rxq after redirect Greg Kroah-Hartman
2024-10-28 6:24 ` [PATCH 5.15 03/80] RDMA/bnxt_re: Fix incorrect AVID type in WQE structure Greg Kroah-Hartman
2024-10-28 6:24 ` [PATCH 5.15 04/80] RDMA/bnxt_re: Add a check for memory allocation Greg Kroah-Hartman
2024-10-28 6:24 ` [PATCH 5.15 05/80] x86/resctrl: Avoid overflow in MB settings in bw_validate() Greg Kroah-Hartman
2024-10-28 6:24 ` [PATCH 5.15 06/80] ARM: dts: bcm2837-rpi-cm3-io3: Fix HDMI hpd-gpio pin Greg Kroah-Hartman
2024-10-28 6:24 ` [PATCH 5.15 07/80] ALSA: hda/cs8409: Fix possible NULL dereference Greg Kroah-Hartman
2024-10-28 6:24 ` [PATCH 5.15 08/80] RDMA/cxgb4: Fix RDMA_CM_EVENT_UNREACHABLE error for iWARP Greg Kroah-Hartman
2024-10-28 6:24 ` [PATCH 5.15 09/80] RDMA/irdma: Fix misspelling of "accept*" Greg Kroah-Hartman
2024-10-28 6:24 ` [PATCH 5.15 10/80] ipv4: give an IPv4 dev to blackhole_netdev Greg Kroah-Hartman
2024-10-28 6:24 ` [PATCH 5.15 11/80] RDMA/bnxt_re: Return more meaningful error Greg Kroah-Hartman
2024-10-28 6:24 ` [PATCH 5.15 12/80] RDMA/bnxt_re: Fix a bug while setting up Level-2 PBL pages Greg Kroah-Hartman
2024-10-28 6:24 ` [PATCH 5.15 13/80] drm/msm/dsi: fix 32-bit signed integer extension in pclk_rate calculation Greg Kroah-Hartman
2024-10-28 6:24 ` [PATCH 5.15 14/80] drm/msm: Avoid NULL dereference in msm_disp_state_print_regs() Greg Kroah-Hartman
2024-10-28 6:24 ` [PATCH 5.15 15/80] drm/msm: Allocate memory for disp snapshot with kvzalloc() Greg Kroah-Hartman
2024-10-28 6:24 ` [PATCH 5.15 16/80] net: usb: usbnet: fix race in probe failure Greg Kroah-Hartman
2024-10-28 6:24 ` [PATCH 5.15 17/80] octeontx2-af: Fix potential integer overflows on integer shifts Greg Kroah-Hartman
2024-10-28 6:24 ` [PATCH 5.15 18/80] macsec: dont increment counters for an unrelated SA Greg Kroah-Hartman
2024-10-28 6:24 ` [PATCH 5.15 19/80] net: ethernet: aeroflex: fix potential memory leak in greth_start_xmit_gbit() Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 20/80] net/smc: Fix searching in list of known pnetids in smc_pnet_add_pnetid Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 21/80] net: xilinx: axienet: fix potential memory leak in axienet_start_xmit() Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 22/80] net: systemport: fix potential memory leak in bcm_sysport_xmit() Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 23/80] tcp/dccp: Dont use timer_pending() in reqsk_queue_unlink() Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 24/80] genetlink: hold RCU in genlmsg_mcast() Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 25/80] scsi: target: core: Fix null-ptr-deref in target_alloc_device() Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 26/80] smb: client: fix OOBs when building SMB2_IOCTL request Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 27/80] usb: typec: altmode should keep reference to parent Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 28/80] s390: Initialize psw mask in perf_arch_fetch_caller_regs() Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 29/80] Bluetooth: bnep: fix wild-memory-access in proto_unregister Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 30/80] arm64:uprobe fix the uprobe SWBP_INSN in big-endian Greg Kroah-Hartman
2024-10-28 6:25 ` Greg Kroah-Hartman [this message]
2024-10-28 6:25 ` [PATCH 5.15 32/80] KVM: s390: gaccess: Refactor gpa and length calculation Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 33/80] KVM: s390: gaccess: Refactor access address range check Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 34/80] KVM: s390: gaccess: Cleanup access to guest pages Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 35/80] KVM: s390: gaccess: Check if guest address is in memslot Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 36/80] usb: gadget: Add function wakeup support Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 37/80] XHCI: Separate PORT and CAPs macros into dedicated file Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 38/80] usb: dwc3: core: Fix system suspend on TI AM62 platforms Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 39/80] block, bfq: fix procress reference leakage for bfqq in merge chain Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 40/80] exec: dont WARN for racy path_noexec check Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 41/80] drm/vboxvideo: Replace fake VLA at end of vbva_mouse_pointer_shape with real VLA Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 42/80] ASoC: codecs: lpass-rx-macro: add missing CDC_RX_BCL_VBAT_RF_PROC2 to default regs values Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 43/80] ASoC: fsl_sai: Enable FIFO continue on error FCONT bit Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 44/80] arm64: Force position-independent veneers Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 45/80] udf: fix uninit-value use in udf_get_fileshortad Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 46/80] platform/x86: dell-wmi: Ignore suspend notifications Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 47/80] arm64/uprobes: change the uprobe_opcode_t typedef to fix the sparse warning Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 48/80] ASoC: qcom: sm8250: add qrb4210-rb2-sndcard compatible string Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 49/80] platform/x86: dell-sysman: add support for alienware products Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 50/80] jfs: Fix sanity check in dbMount Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 51/80] tracing: Consider the NULL character when validating the event length Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 52/80] xfrm: extract dst lookup parameters into a struct Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 53/80] xfrm: respect ip protocols rules criteria when performing dst lookups Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 54/80] net/sun3_82586: fix potential memory leak in sun3_82586_send_packet() Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 55/80] be2net: fix potential memory leak in be_xmit() Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 56/80] net: plip: fix break; causing plip to never transmit Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 57/80] net: dsa: mv88e6xxx: Fix error when setting port policy on mv88e6393x Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 58/80] netfilter: xtables: fix typo causing some targets not to load on IPv6 Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 59/80] net: wwan: fix global oob in wwan_rtnl_policy Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 60/80] net: usb: usbnet: fix name regression Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 61/80] net: sched: fix use-after-free in taprio_change() Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 62/80] r8169: avoid unsolicited interrupts Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 63/80] posix-clock: posix-clock: Fix unbalanced locking in pc_clock_settime() Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 64/80] bpf,perf: Fix perf_event_detach_bpf_prog error handling Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 65/80] ALSA: firewire-lib: Avoid division by zero in apply_constraint_to_size() Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 66/80] ALSA: hda/realtek: Update default depop procedure Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 67/80] btrfs: zoned: fix zone unusable accounting for freed reserved extent Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 68/80] drm/amd: Guard against bad data for ATIF ACPI method Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 69/80] ACPI: resource: Add LG 16T90SP to irq1_level_low_skip_override[] Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 70/80] ACPI: button: Add DMI quirk for Samsung Galaxy Book2 to fix initial lid detection issue Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 71/80] nilfs2: fix kernel bug due to missing clearing of buffer delay flag Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 72/80] openat2: explicitly return -E2BIG for (usize > PAGE_SIZE) Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 73/80] KVM: nSVM: Ignore nCR3[4:0] when loading PDPTEs from memory Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 74/80] ALSA: hda/realtek: Add subwoofer quirk for Acer Predator G9-593 Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 75/80] xfrm: fix one more kernel-infoleak in algo dumping Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 76/80] hv_netvsc: Fix VF namespace also in synthetic NIC NETDEV_REGISTER event Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 77/80] selinux: improve error checking in sel_write_load() Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 78/80] serial: protect uart_port_dtr_rts() in uart_shutdown() too Greg Kroah-Hartman
2024-10-28 6:25 ` [PATCH 5.15 79/80] net: phy: dp83822: Fix reset pin definitions Greg Kroah-Hartman
2024-10-28 6:26 ` [PATCH 5.15 80/80] ASoC: qcom: Fix NULL Dereference in asoc_qcom_lpass_cpu_platform_probe() Greg Kroah-Hartman
2024-10-28 14:21 ` [PATCH 5.15 00/80] 5.15.170-rc1 review Mark Brown
2024-10-28 17:49 ` SeongJae Park
2024-10-28 19:08 ` Florian Fainelli
2024-10-29 2:07 ` [PATCH 5.15] " Hardik Garg
2024-10-29 5:05 ` [PATCH 5.15 00/80] " Harshit Mogalapalli
2024-10-29 7:34 ` Naresh Kamboju
2024-10-29 13:49 ` Muhammad Usama Anjum
2024-10-30 1:46 ` Ron Economos
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241028062253.492228912@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=catalin.marinas@arm.com \
--cc=mark.rutland@arm.com \
--cc=patches@lists.linux.dev \
--cc=sashal@kernel.org \
--cc=stable@vger.kernel.org \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox