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, Ingo Molnar <mingo@redhat.com>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Andreas Ziegler <andreas.ziegler@fau.de>,
	"Steven Rostedt (VMware)" <rostedt@goodmis.org>
Subject: [PATCH 4.19 73/85] tracing/uprobes: Fix output for multiple string arguments
Date: Mon, 18 Feb 2019 14:43:39 +0100	[thread overview]
Message-ID: <20190218133506.940076780@linuxfoundation.org> (raw)
In-Reply-To: <20190218133459.758004711@linuxfoundation.org>

4.19-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Andreas Ziegler <andreas.ziegler@fau.de>

commit 0722069a5374b904ec1a67f91249f90e1cfae259 upstream.

When printing multiple uprobe arguments as strings the output for the
earlier arguments would also include all later string arguments.

This is best explained in an example:

Consider adding a uprobe to a function receiving two strings as
parameters which is at offset 0xa0 in strlib.so and we want to print
both parameters when the uprobe is hit (on x86_64):

$ echo 'p:func /lib/strlib.so:0xa0 +0(%di):string +0(%si):string' > \
    /sys/kernel/debug/tracing/uprobe_events

When the function is called as func("foo", "bar") and we hit the probe,
the trace file shows a line like the following:

  [...] func: (0x7f7e683706a0) arg1="foobar" arg2="bar"

Note the extra "bar" printed as part of arg1. This behaviour stacks up
for additional string arguments.

The strings are stored in a dynamically growing part of the uprobe
buffer by fetch_store_string() after copying them from userspace via
strncpy_from_user(). The return value of strncpy_from_user() is then
directly used as the required size for the string. However, this does
not take the terminating null byte into account as the documentation
for strncpy_from_user() cleary states that it "[...] returns the
length of the string (not including the trailing NUL)" even though the
null byte will be copied to the destination.

Therefore, subsequent calls to fetch_store_string() will overwrite
the terminating null byte of the most recently fetched string with
the first character of the current string, leading to the
"accumulation" of strings in earlier arguments in the output.

Fix this by incrementing the return value of strncpy_from_user() by
one if we did not hit the maximum buffer size.

Link: http://lkml.kernel.org/r/20190116141629.5752-1-andreas.ziegler@fau.de

Cc: Ingo Molnar <mingo@redhat.com>
Cc: stable@vger.kernel.org
Fixes: 5baaa59ef09e ("tracing/probes: Implement 'memory' fetch method for uprobes")
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Andreas Ziegler <andreas.ziegler@fau.de>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 kernel/trace/trace_uprobe.c |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

--- a/kernel/trace/trace_uprobe.c
+++ b/kernel/trace/trace_uprobe.c
@@ -141,7 +141,14 @@ static void FETCH_FUNC_NAME(memory, stri
 
 	ret = strncpy_from_user(dst, src, maxlen);
 	if (ret == maxlen)
-		dst[--ret] = '\0';
+		dst[ret - 1] = '\0';
+	else if (ret >= 0)
+		/*
+		 * Include the terminating null byte. In this case it
+		 * was copied by strncpy_from_user but not accounted
+		 * for in ret.
+		 */
+		ret++;
 
 	if (ret < 0) {	/* Failed to fetch string */
 		((u8 *)get_rloc_data(dest))[0] = '\0';



  parent reply	other threads:[~2019-02-18 13:53 UTC|newest]

Thread overview: 89+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-18 13:42 [PATCH 4.19 00/85] 4.19.24-stable review Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 01/85] dt-bindings: eeprom: at24: add "atmel,24c2048" compatible string Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 02/85] eeprom: at24: add support for 24c2048 Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 03/85] blk-mq: fix a hung issue when fsync Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 04/85] ARM: 8789/1: signal: copy registers using __copy_to_user() Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 05/85] ARM: 8790/1: signal: always use __copy_to_user to save iwmmxt context Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 06/85] ARM: 8791/1: vfp: use __copy_to_user() when saving VFP state Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 07/85] ARM: 8792/1: oabi-compat: copy oabi events using __copy_to_user() Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 08/85] ARM: 8793/1: signal: replace __put_user_error with __put_user Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 09/85] ARM: 8794/1: uaccess: Prevent speculative use of the current addr_limit Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 10/85] ARM: 8795/1: spectre-v1.1: use put_user() for __put_user() Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 11/85] ARM: 8796/1: spectre-v1,v1.1: provide helpers for address sanitization Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 12/85] ARM: 8797/1: spectre-v1.1: harden __copy_to_user Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 13/85] ARM: 8810/1: vfp: Fix wrong assignement to ufp_exc Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 14/85] ARM: make lookup_processor_type() non-__init Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 15/85] ARM: split out processor lookup Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 16/85] ARM: clean up per-processor check_bugs method call Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 17/85] ARM: add PROC_VTABLE and PROC_TABLE macros Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 18/85] ARM: spectre-v2: per-CPU vtables to work around big.Little systems Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 19/85] ARM: ensure that processor vtables is not lost after boot Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 20/85] ARM: fix the cockup in the previous patch Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 21/85] drm/amdgpu/sriov:Correct pfvf exchange logic Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 22/85] ACPI: NUMA: Use correct type for printing addresses on i386-PAE Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 23/85] perf report: Fix wrong iteration count in --branch-history Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 24/85] perf test shell: Use a fallback to get the pathname in vfs_getname Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 25/85] tools uapi: fix RISC-V 64-bit support Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 26/85] riscv: fix trace_sys_exit hook Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 27/85] cpufreq: check if policy is inactive early in __cpufreq_get() Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 28/85] drm/bridge: tc358767: add bus flags Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 29/85] drm/bridge: tc358767: add defines for DP1_SRCCTRL & PHY_2LANE Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 30/85] drm/bridge: tc358767: fix single lane configuration Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 31/85] drm/bridge: tc358767: fix initial DP0/1_SRCCTRL value Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 32/85] drm/bridge: tc358767: reject modes which require too much BW Greg Kroah-Hartman
2019-02-18 13:42 ` [PATCH 4.19 33/85] drm/bridge: tc358767: fix output H/V syncs Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 34/85] nvme-pci: use the same attributes when freeing host_mem_desc_bufs Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 35/85] nvme-pci: fix out of bounds access in nvme_cqe_pending Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 36/85] nvme-multipath: zero out ANA log buffer Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 37/85] nvme: pad fake subsys NQN vid and ssvid with zeros Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 38/85] drm/amdgpu: set WRITE_BURST_LENGTH to 64B to workaround SDMA1 hang Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 39/85] ARM: dts: da850-evm: Correct the audio codec regulators Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 40/85] ARM: dts: da850-evm: Correct the sound card name Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 41/85] ARM: dts: da850-lcdk: Correct the audio codec regulators Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 42/85] ARM: dts: da850-lcdk: Correct the sound card name Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 43/85] ARM: dts: kirkwood: Fix polarity of GPIO fan lines Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 44/85] gpio: pl061: handle failed allocations Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 45/85] drm/nouveau: Dont disable polling in fallback mode Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 46/85] drm/nouveau/falcon: avoid touching registers if engine is off Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 47/85] cifs: Limit memory used by lock request calls to a page Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 48/85] kvm: sev: Fail KVM_SEV_INIT if already initialized Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 49/85] CIFS: Do not assume one credit for async responses Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 50/85] gpio: mxc: move gpio noirq suspend/resume to syscore phase Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 51/85] Revert "Input: elan_i2c - add ACPI ID for touchpad in ASUS Aspire F5-573G" Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 52/85] Input: elan_i2c - add ACPI ID for touchpad in Lenovo V330-15ISK Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 53/85] ARM: OMAP5+: Fix inverted nirq pin interrupts with irq_set_type Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 54/85] perf/core: Fix impossible ring-buffer sizes warning Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 55/85] perf/x86: Add check_period PMU callback Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 56/85] ALSA: hda - Add quirk for HP EliteBook 840 G5 Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 57/85] ALSA: usb-audio: Fix implicit fb endpoint setup by quirk Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 58/85] ASoC: hdmi-codec: fix oops on re-probe Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 59/85] tools uapi: fix Alpha support Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 60/85] riscv: Add pte bit to distinguish swap from invalid Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 61/85] x86/kvm/nVMX: read from MSR_IA32_VMX_PROCBASED_CTLS2 only when it is available Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 62/85] kvm: vmx: Fix entry number check for add_atomic_switch_msr() Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 63/85] mmc: sunxi: Filter out unsupported modes declared in the device tree Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 64/85] mmc: block: handle complete_work on separate workqueue Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 65/85] Input: bma150 - register input device after setting private data Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 66/85] Input: elantech - enable 3rd button support on Fujitsu CELSIUS H780 Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 67/85] Revert "nfsd4: return default lease period" Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 68/85] Revert "mm: dont reclaim inodes with many attached pages" Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 69/85] Revert "mm: slowly shrink slabs with a relatively small number of objects" Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 70/85] alpha: fix page fault handling for r16-r18 targets Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 71/85] alpha: Fix Eiger NR_IRQS to 128 Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 72/85] s390/zcrypt: fix specification exception on z196 during ap probe Greg Kroah-Hartman
2019-02-18 13:43 ` Greg Kroah-Hartman [this message]
2019-02-18 13:43 ` [PATCH 4.19 74/85] x86/platform/UV: Use efi_runtime_lock to serialise BIOS calls Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 75/85] scsi: sd: fix entropy gathering for most rotational disks Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 76/85] signal: Restore the stop PTRACE_EVENT_EXIT Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 77/85] md/raid1: dont clear bitmap bits on interrupted recovery Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 78/85] x86/a.out: Clear the dump structure initially Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 79/85] dm crypt: dont overallocate the integrity tag space Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 80/85] dm thin: fix bug where bio that overwrites thin block ignores FUA Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 81/85] drm: Use array_size() when creating lease Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 82/85] drm/vkms: Fix license inconsistent Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 83/85] drm/i915: Block fbdev HPD processing during suspend Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 84/85] drm/i915: Prevent a race during I915_GEM_MMAP ioctl with WC set Greg Kroah-Hartman
2019-02-18 13:43 ` [PATCH 4.19 85/85] mm: proc: smaps_rollup: fix pss_locked calculation Greg Kroah-Hartman
2019-02-19  5:41 ` [PATCH 4.19 00/85] 4.19.24-stable review Naresh Kamboju
2019-02-19 17:27 ` Guenter Roeck
2019-02-20  0:17 ` shuah

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=20190218133506.940076780@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=andreas.ziegler@fau.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=stable@vger.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;
as well as URLs for NNTP newsgroup(s).