linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Andy Lutomirski <luto@kernel.org>, Borislav Petkov <bp@alien8.de>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	bristot@redhat.com, Ingo Molnar <mingo@kernel.org>
Subject: [PATCH 4.19 77/87] kprobes: Set unoptimized flag after unoptimizing code
Date: Tue,  3 Mar 2020 18:44:08 +0100	[thread overview]
Message-ID: <20200303174357.166761258@linuxfoundation.org> (raw)
In-Reply-To: <20200303174349.075101355@linuxfoundation.org>

From: Masami Hiramatsu <mhiramat@kernel.org>

commit f66c0447cca1281116224d474cdb37d6a18e4b5b upstream.

Set the unoptimized flag after confirming the code is completely
unoptimized. Without this fix, when a kprobe hits the intermediate
modified instruction (the first byte is replaced by an INT3, but
later bytes can still be a jump address operand) while unoptimizing,
it can return to the middle byte of the modified code, which causes
an invalid instruction exception in the kernel.

Usually, this is a rare case, but if we put a probe on the function
call while text patching, it always causes a kernel panic as below:

 # echo p text_poke+5 > kprobe_events
 # echo 1 > events/kprobes/enable
 # echo 0 > events/kprobes/enable

invalid opcode: 0000 [#1] PREEMPT SMP PTI
 RIP: 0010:text_poke+0x9/0x50
 Call Trace:
  arch_unoptimize_kprobe+0x22/0x28
  arch_unoptimize_kprobes+0x39/0x87
  kprobe_optimizer+0x6e/0x290
  process_one_work+0x2a0/0x610
  worker_thread+0x28/0x3d0
  ? process_one_work+0x610/0x610
  kthread+0x10d/0x130
  ? kthread_park+0x80/0x80
  ret_from_fork+0x3a/0x50

text_poke() is used for patching the code in optprobes.

This can happen even if we blacklist text_poke() and other functions,
because there is a small time window during which we show the intermediate
code to other CPUs.

 [ mingo: Edited the changelog. ]

Tested-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: bristot@redhat.com
Fixes: 6274de4984a6 ("kprobes: Support delayed unoptimizing")
Link: https://lkml.kernel.org/r/157483422375.25881.13508326028469515760.stgit@devnote2
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 kernel/kprobes.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -523,6 +523,8 @@ static void do_unoptimize_kprobes(void)
 	arch_unoptimize_kprobes(&unoptimizing_list, &freeing_list);
 	/* Loop free_list for disarming */
 	list_for_each_entry_safe(op, tmp, &freeing_list, list) {
+		/* Switching from detour code to origin */
+		op->kp.flags &= ~KPROBE_FLAG_OPTIMIZED;
 		/* Disarm probes if marked disabled */
 		if (kprobe_disabled(&op->kp))
 			arch_disarm_kprobe(&op->kp);
@@ -662,6 +664,7 @@ static void force_unoptimize_kprobe(stru
 {
 	lockdep_assert_cpus_held();
 	arch_unoptimize_kprobe(op);
+	op->kp.flags &= ~KPROBE_FLAG_OPTIMIZED;
 	if (kprobe_disabled(&op->kp))
 		arch_disarm_kprobe(&op->kp);
 }
@@ -689,7 +692,6 @@ static void unoptimize_kprobe(struct kpr
 		return;
 	}
 
-	op->kp.flags &= ~KPROBE_FLAG_OPTIMIZED;
 	if (!list_empty(&op->list)) {
 		/* Dequeue from the optimization queue */
 		list_del_init(&op->list);



  parent reply	other threads:[~2020-03-03 18:01 UTC|newest]

Thread overview: 102+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-03 17:42 [PATCH 4.19 00/87] 4.19.108-stable review Greg Kroah-Hartman
2020-03-03 17:42 ` [PATCH 4.19 01/87] irqchip/gic-v3-its: Fix misuse of GENMASK macro Greg Kroah-Hartman
2020-03-03 17:42 ` [PATCH 4.19 02/87] iwlwifi: pcie: fix rb_allocator workqueue allocation Greg Kroah-Hartman
2020-03-03 17:42 ` [PATCH 4.19 03/87] ipmi:ssif: Handle a possible NULL pointer reference Greg Kroah-Hartman
2020-03-03 17:42 ` [PATCH 4.19 04/87] drm/msm: Set dma maximum segment size for mdss Greg Kroah-Hartman
2020-03-04 15:13   ` Pavel Machek
2020-03-04 17:18     ` Greg Kroah-Hartman
2020-03-09 10:14       ` [PATCH] drm/msm: fix leaks if initialization fails Pavel Machek
2020-03-10 21:03         ` Doug Anderson
2020-03-03 17:42 ` [PATCH 4.19 05/87] sched/core: Dont skip remote tick for idle CPUs Greg Kroah-Hartman
2020-03-04 15:15   ` Pavel Machek
2020-03-04 17:17     ` Greg Kroah-Hartman
2020-03-03 17:42 ` [PATCH 4.19 06/87] dax: pass NOWAIT flag to iomap_apply Greg Kroah-Hartman
2020-03-03 17:42 ` [PATCH 4.19 07/87] mac80211: consider more elements in parsing CRC Greg Kroah-Hartman
2020-03-03 17:42 ` [PATCH 4.19 08/87] cfg80211: check wiphy driver existence for drvinfo report Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 09/87] s390/zcrypt: fix card and queue total counter wrap Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 10/87] qmi_wwan: re-add DW5821e pre-production variant Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 11/87] qmi_wwan: unconditionally reject 2 ep interfaces Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 12/87] arm/ftrace: Fix BE text poking Greg Kroah-Hartman
2020-03-05 13:49   ` Pavel Machek
2020-03-05 14:53     ` Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 13/87] ARM: dts: sti: fixup sound frame-inversion for stihxxx-b2120.dtsi Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 14/87] soc/tegra: fuse: Fix build with Tegra194 configuration Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 15/87] net: ena: fix potential crash when rxfh key is NULL Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 16/87] net: ena: fix uses of round_jiffies() Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 17/87] net: ena: add missing ethtool TX timestamping indication Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 18/87] net: ena: fix incorrect default RSS key Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 19/87] net: ena: rss: fix failure to get indirection table Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 20/87] net: ena: rss: store hash function as values and not bits Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 21/87] net: ena: fix incorrectly saving queue numbers when setting RSS indirection table Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 22/87] net: ena: ethtool: use correct value for crc32 hash Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 23/87] net: ena: ena-com.c: prevent NULL pointer dereference Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 24/87] cifs: Fix mode output in debugging statements Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 25/87] bcache: ignore pending signals when creating gc and allocator thread Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 26/87] cfg80211: add missing policy for NL80211_ATTR_STATUS_CODE Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 27/87] sysrq: Restore original console_loglevel when sysrq disabled Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 28/87] sysrq: Remove duplicated sysrq message Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 29/87] net: fib_rules: Correctly set table field when table number exceeds 8 bits Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 30/87] net: mscc: fix in frame extraction Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 31/87] net: phy: restore mdio regs in the iproc mdio driver Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 32/87] net: sched: correct flower port blocking Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 33/87] nfc: pn544: Fix occasional HW initialization failure Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 34/87] sctp: move the format error check out of __sctp_sf_do_9_1_abort Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 35/87] ipv6: Fix route replacement with dev-only route Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 36/87] ipv6: Fix nlmsg_flags when splitting a multipath route Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 37/87] qede: Fix race between rdma destroy workqueue and link change event Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 38/87] net/tls: Fix to avoid gettig invalid tls record Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 39/87] ext4: potential crash on allocation error in ext4_alloc_flex_bg_array() Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 40/87] audit: fix error handling in audit_data_to_entry() Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 41/87] ACPICA: Introduce ACPI_ACCESS_BYTE_WIDTH() macro Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 42/87] ACPI: watchdog: Fix gas->access_width usage Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 43/87] KVM: VMX: check descriptor table exits on instruction emulation Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 44/87] HID: ite: Only bind to keyboard USB interface on Acer SW5-012 keyboard dock Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 45/87] HID: core: fix off-by-one memset in hid_report_raw_event() Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 46/87] HID: core: increase HID report buffer size to 8KiB Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 47/87] macintosh: therm_windtunnel: fix regression when instantiating devices Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 48/87] tracing: Disable trace_printk() on post poned tests Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 49/87] Revert "PM / devfreq: Modify the device name as devfreq(X) for sysfs" Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 50/87] amdgpu/gmc_v9: save/restore sdpif regs during S3 Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 51/87] vhost: Check docket sk_family instead of call getname Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 52/87] HID: alps: Fix an error handling path in alps_input_configured() Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 53/87] HID: hiddev: Fix race in in hiddev_disconnect() Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 54/87] MIPS: VPE: Fix a double free and a memory leak in release_vpe() Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 55/87] i2c: altera: Fix potential integer overflow Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 56/87] i2c: jz4780: silence log flood on txabrt Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 57/87] drm/i915/gvt: Fix orphan vgpu dmabuf_objs lifetime Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 58/87] drm/i915/gvt: Separate display reset from ALL_ENGINES reset Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 59/87] hv_netvsc: Fix unwanted wakeup in netvsc_attach() Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 60/87] usb: charger: assign specific number for enum value Greg Kroah-Hartman
2020-03-04 17:27   ` Pavel Machek
2020-03-04 17:39     ` Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 61/87] s390/qeth: vnicc Fix EOPNOTSUPP precedence Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 62/87] net: netlink: cap max groups which will be considered in netlink_bind() Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 63/87] net: atlantic: fix use after free kasan warn Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 64/87] net: atlantic: fix potential error handling Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 65/87] net/smc: no peer ID in CLC decline for SMCD Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 66/87] net: ena: make ena rxfh support ETH_RSS_HASH_NO_CHANGE Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 67/87] namei: only return -ECHILD from follow_dotdot_rcu() Greg Kroah-Hartman
2020-03-03 17:43 ` [PATCH 4.19 68/87] mwifiex: drop most magic numbers from mwifiex_process_tdls_action_frame() Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 69/87] mwifiex: delete unused mwifiex_get_intf_num() Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 70/87] KVM: SVM: Override default MMIO mask if memory encryption is enabled Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 71/87] KVM: Check for a bad hva before dropping into the ghc slow path Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 72/87] sched/fair: Optimize update_blocked_averages() Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 73/87] sched/fair: Fix O(nr_cgroups) in the load balancing path Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 74/87] perf stat: Use perf_evsel__is_clocki() for clock events Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 75/87] perf stat: Fix shadow stats " Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 76/87] drivers: net: xgene: Fix the order of the arguments of alloc_etherdev_mqs() Greg Kroah-Hartman
2020-03-03 17:44 ` Greg Kroah-Hartman [this message]
2020-03-03 17:44 ` [PATCH 4.19 78/87] pwm: omap-dmtimer: put_device() after of_find_device_by_node() Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 79/87] perf hists browser: Restore ESC as "Zoom out" of DSO/thread/etc Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 80/87] KVM: x86: Remove spurious kvm_mmu_unload() from vcpu destruction path Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 81/87] KVM: x86: Remove spurious clearing of async #PF MSR Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 82/87] thermal: brcmstb_thermal: Do not use DT coefficients Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 83/87] netfilter: nft_tunnel: no need to call htons() when dumping ports Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 84/87] netfilter: nf_flowtable: fix documentation Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 85/87] padata: always acquire cpu_hotplug_lock before pinst->lock Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 86/87] mm/huge_memory.c: use head to check huge zero page Greg Kroah-Hartman
2020-03-03 17:44 ` [PATCH 4.19 87/87] mm, thp: fix defrag setting if newline is not used Greg Kroah-Hartman
2020-03-03 22:10 ` [PATCH 4.19 00/87] 4.19.108-stable review Jon Hunter
2020-03-03 23:18 ` shuah
2020-03-04  7:09 ` Naresh Kamboju
2020-03-04 16:52 ` Guenter Roeck

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=20200303174357.166761258@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=ast@kernel.org \
    --cc=bp@alien8.de \
    --cc=bristot@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.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;
as well as URLs for NNTP newsgroup(s).