From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Elazar Leibovich <elazar@lightbitslabs.com>,
Orit Wasserman <orit.was@gmail.com>,
Oleg Nesterov <oleg@redhat.com>, Ingo Molnar <mingo@redhat.com>,
Steven Rostedt <rostedt@goodmis.org>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH AUTOSEL 4.9 25/74] tracing: Fix partial reading of trace event's id file
Date: Sat, 1 Jun 2019 09:24:12 -0400 [thread overview]
Message-ID: <20190601132501.27021-25-sashal@kernel.org> (raw)
In-Reply-To: <20190601132501.27021-1-sashal@kernel.org>
From: Elazar Leibovich <elazar@lightbitslabs.com>
[ Upstream commit cbe08bcbbe787315c425dde284dcb715cfbf3f39 ]
When reading only part of the id file, the ppos isn't tracked correctly.
This is taken care by simple_read_from_buffer.
Reading a single byte, and then the next byte would result EOF.
While this seems like not a big deal, this breaks abstractions that
reads information from files unbuffered. See for example
https://github.com/golang/go/issues/29399
This code was mentioned as problematic in
commit cd458ba9d5a5
("tracing: Do not (ab)use trace_seq in event_id_read()")
An example C code that show this bug is:
#include <stdio.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, char **argv) {
if (argc < 2)
return 1;
int fd = open(argv[1], O_RDONLY);
char c;
read(fd, &c, 1);
printf("First %c\n", c);
read(fd, &c, 1);
printf("Second %c\n", c);
}
Then run with, e.g.
sudo ./a.out /sys/kernel/debug/tracing/events/tcp/tcp_set_state/id
You'll notice you're getting the first character twice, instead of the
first two characters in the id file.
Link: http://lkml.kernel.org/r/20181231115837.4932-1-elazar@lightbitslabs.com
Cc: Orit Wasserman <orit.was@gmail.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: stable@vger.kernel.org
Fixes: 23725aeeab10b ("ftrace: provide an id file for each event")
Signed-off-by: Elazar Leibovich <elazar@lightbitslabs.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
kernel/trace/trace_events.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 9549ed120556e..af969f753e5e9 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -1310,9 +1310,6 @@ event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
char buf[32];
int len;
- if (*ppos)
- return 0;
-
if (unlikely(!id))
return -ENODEV;
--
2.20.1
next prev parent reply other threads:[~2019-06-01 13:30 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-01 13:23 [PATCH AUTOSEL 4.9 01/74] rapidio: fix a NULL pointer dereference when create_workqueue() fails Sasha Levin
2019-06-01 13:23 ` [PATCH AUTOSEL 4.9 02/74] fs/fat/file.c: issue flush after the writeback of FAT Sasha Levin
2019-06-01 13:23 ` [PATCH AUTOSEL 4.9 03/74] sysctl: return -EINVAL if val violates minmax Sasha Levin
2019-06-01 13:23 ` [PATCH AUTOSEL 4.9 04/74] ipc: prevent lockup on alloc_msg and free_msg Sasha Levin
2019-06-01 13:23 ` [PATCH AUTOSEL 4.9 05/74] ARM: prevent tracing IPI_CPU_BACKTRACE Sasha Levin
2019-06-01 13:23 ` [PATCH AUTOSEL 4.9 06/74] hugetlbfs: on restore reserve error path retain subpool reservation Sasha Levin
2019-06-01 13:23 ` [PATCH AUTOSEL 4.9 07/74] mem-hotplug: fix node spanned pages when we have a node with only ZONE_MOVABLE Sasha Levin
2019-06-01 13:23 ` [PATCH AUTOSEL 4.9 08/74] mm/cma.c: fix crash on CMA allocation if bitmap allocation fails Sasha Levin
2019-06-01 13:23 ` [PATCH AUTOSEL 4.9 09/74] mm/cma_debug.c: fix the break condition in cma_maxchunk_get() Sasha Levin
2019-06-01 13:23 ` [PATCH AUTOSEL 4.9 10/74] mm/slab.c: fix an infinite loop in leaks_show() Sasha Levin
2019-06-01 13:23 ` [PATCH AUTOSEL 4.9 11/74] kernel/sys.c: prctl: fix false positive in validate_prctl_map() Sasha Levin
2019-06-01 13:23 ` [PATCH AUTOSEL 4.9 12/74] drivers: thermal: tsens: Don't print error message on -EPROBE_DEFER Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 13/74] mfd: tps65912-spi: Add missing of table registration Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 14/74] mfd: intel-lpss: Set the device in reset state when init Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 15/74] mfd: twl6040: Fix device init errors for ACCCTL register Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 16/74] perf/x86/intel: Allow PEBS multi-entry in watermark mode Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 17/74] drm/bridge: adv7511: Fix low refresh rate selection Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 18/74] objtool: Don't use ignore flag for fake jumps Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 19/74] NFS4: Fix v4.0 client state corruption when mount Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 20/74] pwm: meson: Use the spin-lock only to protect register modifications Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 21/74] ntp: Allow TAI-UTC offset to be set to zero Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 22/74] f2fs: fix to avoid panic in do_recover_data() Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 23/74] f2fs: fix to clear dirty inode in error path of f2fs_iget() Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 24/74] f2fs: fix to do sanity check on valid block count of segment Sasha Levin
2019-06-01 13:24 ` Sasha Levin [this message]
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 26/74] configfs: fix possible use-after-free in configfs_register_group Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 27/74] uml: fix a boot splat wrt use of cpu_all_mask Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 28/74] mips: Make sure dt memory regions are valid Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 29/74] watchdog: Use depends instead of select for pretimeout governors Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 30/74] watchdog: imx2_wdt: Fix set_timeout for big timeout values Sasha Levin
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=20190601132501.27021-25-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=elazar@lightbitslabs.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=oleg@redhat.com \
--cc=orit.was@gmail.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
Powered by JetHome