* [PATCH v2 0/2] trace-cmd record: Fix compression on big-endian systems
@ 2025-04-11 22:49 Ilya Leoshkevich
2025-04-11 22:49 ` [PATCH v2 1/2] " Ilya Leoshkevich
2025-04-11 22:49 ` [PATCH v2 2/2] libtracecmd: Add missing error handling to trace-compress.c Ilya Leoshkevich
0 siblings, 2 replies; 3+ messages in thread
From: Ilya Leoshkevich @ 2025-04-11 22:49 UTC (permalink / raw)
To: Steven Rostedt
Cc: linux-trace-devel, Heiko Carstens, Vasily Gorbik,
Alexander Gordeev, Ilya Leoshkevich
v1: https://lore.kernel.org/linux-trace-devel/20250411172815.61477-1-iii@linux.ibm.com/
v1 -> v2: Factor out read_size_val(), split out the error handling
change (Steven).
Hi,
While running trace-cmd on s390x, I ran into a few issues.
This is the fix for the first one: trace-cmd report prints nothing.
The second one is a kernel issue [1], which causes trace-cmd to print
a lot of bogus space characters.
The final one is "error in size of file '/proc/kallsyms'" caused by
delayed removal of a BPF program from /proc/kallsyms. I plan to fix it
by reading the contents of /proc/kallsyms into a temporary file before
writing it into the trace file.
[1] https://lore.kernel.org/lkml/20250411172207.61332-1-iii@linux.ibm.com/
Best regards,
Ilya
Ilya Leoshkevich (2):
trace-cmd record: Fix compression on big-endian systems
libtracecmd: Add missing error handling to trace-compress.c
lib/trace-cmd/trace-compress.c | 32 +++++++++++++++++++++++++-------
1 file changed, 25 insertions(+), 7 deletions(-)
--
2.49.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v2 1/2] trace-cmd record: Fix compression on big-endian systems
2025-04-11 22:49 [PATCH v2 0/2] trace-cmd record: Fix compression on big-endian systems Ilya Leoshkevich
@ 2025-04-11 22:49 ` Ilya Leoshkevich
2025-04-11 22:49 ` [PATCH v2 2/2] libtracecmd: Add missing error handling to trace-compress.c Ilya Leoshkevich
1 sibling, 0 replies; 3+ messages in thread
From: Ilya Leoshkevich @ 2025-04-11 22:49 UTC (permalink / raw)
To: Steven Rostedt
Cc: linux-trace-devel, Heiko Carstens, Vasily Gorbik,
Alexander Gordeev, Ilya Leoshkevich
trace-cmd report prints nothing on s390x when compression is used.
The reason is that the code treats size_t pointers as int pointers when
serializing size_t values into 32-bit on-disk fields, which works only
on little-endian systems.
Fix serialization by copying size_t values into int values first.
While at it, add overflow checks.
Fixes: 176bc1f14419 ("trace-cmd record: Fix compression when files are greater than 2GB")
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
lib/trace-cmd/trace-compress.c | 25 ++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
diff --git a/lib/trace-cmd/trace-compress.c b/lib/trace-cmd/trace-compress.c
index 03215ad1..e18af3dd 100644
--- a/lib/trace-cmd/trace-compress.c
+++ b/lib/trace-cmd/trace-compress.c
@@ -7,6 +7,7 @@
#include <sys/time.h>
#include <fcntl.h>
#include <errno.h>
+#include <limits.h>
#include <unistd.h>
#include "trace-cmd-private.h"
@@ -77,6 +78,16 @@ static ssize_t write_fd(int fd, const void *data, size_t size)
return tot;
}
+static int read_size_val(struct tep_handle *tep, size_t size, int *endian4)
+{
+ if (size > UINT_MAX)
+ return -1;
+
+ *endian4 = size;
+ *endian4 = tep_read_number(tep, endian4, 4);
+ return 0;
+}
+
static ssize_t do_write(struct tracecmd_compression *handle,
const void *data, size_t size)
{
@@ -331,7 +342,8 @@ int tracecmd_compress_block(struct tracecmd_compression *handle)
goto out;
/* Write uncompressed data size */
- endian4 = tep_read_number(handle->tep, &handle->pointer, 4);
+ if (read_size_val(handle->tep, handle->pointer, &endian4) < 0)
+ goto out;
ret = do_write(handle, &endian4, 4);
if (ret != 4) {
ret = -1;
@@ -735,13 +747,15 @@ int tracecmd_compress_copy_from(struct tracecmd_compression *handle, int fd, int
}
size = ret;
/* Write compressed data size */
- endian4 = tep_read_number(handle->tep, &size, 4);
+ if (read_size_val(handle->tep, size, &endian4) < 0)
+ break;
ret = write_fd(handle->fd, &endian4, 4);
if (ret != 4)
break;
/* Write uncompressed data size */
- endian4 = tep_read_number(handle->tep, &all, 4);
+ if (read_size_val(handle->tep, all, &endian4) < 0)
+ break;
ret = write_fd(handle->fd, &endian4, 4);
if (ret != 4)
break;
@@ -763,9 +777,10 @@ int tracecmd_compress_copy_from(struct tracecmd_compression *handle, int fd, int
if (lseek(handle->fd, offset, SEEK_SET) == (off_t)-1)
return -1;
- endian4 = tep_read_number(handle->tep, &chunks, 4);
+ if (read_size_val(handle->tep, chunks, &endian4) < 0)
+ return -1;
/* write chunks count*/
- write_fd(handle->fd, &chunks, 4);
+ write_fd(handle->fd, &endian4, 4);
end_offset = lseek(handle->fd, 0, SEEK_END);
if (end_offset == (off_t)-1)
return -1;
--
2.49.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v2 2/2] libtracecmd: Add missing error handling to trace-compress.c
2025-04-11 22:49 [PATCH v2 0/2] trace-cmd record: Fix compression on big-endian systems Ilya Leoshkevich
2025-04-11 22:49 ` [PATCH v2 1/2] " Ilya Leoshkevich
@ 2025-04-11 22:49 ` Ilya Leoshkevich
1 sibling, 0 replies; 3+ messages in thread
From: Ilya Leoshkevich @ 2025-04-11 22:49 UTC (permalink / raw)
To: Steven Rostedt
Cc: linux-trace-devel, Heiko Carstens, Vasily Gorbik,
Alexander Gordeev, Ilya Leoshkevich
Add missing error handling to a few writes.
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
lib/trace-cmd/trace-compress.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/lib/trace-cmd/trace-compress.c b/lib/trace-cmd/trace-compress.c
index e18af3dd..2a7a3e24 100644
--- a/lib/trace-cmd/trace-compress.c
+++ b/lib/trace-cmd/trace-compress.c
@@ -715,7 +715,8 @@ int tracecmd_compress_copy_from(struct tracecmd_compression *handle, int fd, int
/* save the initial offset and write 0 as initial chunk count */
offset = lseek(handle->fd, 0, SEEK_CUR);
- write_fd(handle->fd, &chunks, 4);
+ if (write_fd(handle->fd, &chunks, 4) != 4)
+ return -1;
do {
all = 0;
@@ -780,7 +781,8 @@ int tracecmd_compress_copy_from(struct tracecmd_compression *handle, int fd, int
if (read_size_val(handle->tep, chunks, &endian4) < 0)
return -1;
/* write chunks count*/
- write_fd(handle->fd, &endian4, 4);
+ if (write_fd(handle->fd, &endian4, 4) != 4)
+ return -1;
end_offset = lseek(handle->fd, 0, SEEK_END);
if (end_offset == (off_t)-1)
return -1;
@@ -989,7 +991,8 @@ int tracecmd_uncompress_copy_to(struct tracecmd_compression *handle, int fd,
if (ret < 0)
break;
- write_fd(fd, bytes_out, ret);
+ if (write_fd(fd, bytes_out, ret) != ret)
+ break;
wsize += ret;
chunks--;
}
--
2.49.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-04-11 22:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-11 22:49 [PATCH v2 0/2] trace-cmd record: Fix compression on big-endian systems Ilya Leoshkevich
2025-04-11 22:49 ` [PATCH v2 1/2] " Ilya Leoshkevich
2025-04-11 22:49 ` [PATCH v2 2/2] libtracecmd: Add missing error handling to trace-compress.c Ilya Leoshkevich
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).