From: Ilya Leoshkevich <iii@linux.ibm.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-trace-devel@vger.kernel.org,
Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>,
Ilya Leoshkevich <iii@linux.ibm.com>
Subject: [PATCH] trace-cmd record: Fix compression on big-endian systems
Date: Fri, 11 Apr 2025 19:27:56 +0200 [thread overview]
Message-ID: <20250411172815.61477-1-iii@linux.ibm.com> (raw)
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 | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/lib/trace-cmd/trace-compress.c b/lib/trace-cmd/trace-compress.c
index 03215ad1..1b599043 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"
@@ -331,7 +332,12 @@ int tracecmd_compress_block(struct tracecmd_compression *handle)
goto out;
/* Write uncompressed data size */
- endian4 = tep_read_number(handle->tep, &handle->pointer, 4);
+ if (handle->pointer > UINT_MAX) {
+ ret = -1;
+ goto out;
+ }
+ endian4 = handle->pointer;
+ endian4 = tep_read_number(handle->tep, &endian4, 4);
ret = do_write(handle, &endian4, 4);
if (ret != 4) {
ret = -1;
@@ -735,13 +741,19 @@ 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 (size > UINT_MAX)
+ break;
+ endian4 = size;
+ endian4 = tep_read_number(handle->tep, &endian4, 4);
ret = write_fd(handle->fd, &endian4, 4);
if (ret != 4)
break;
/* Write uncompressed data size */
- endian4 = tep_read_number(handle->tep, &all, 4);
+ if (all > UINT_MAX)
+ break;
+ endian4 = all;
+ endian4 = tep_read_number(handle->tep, &endian4, 4);
ret = write_fd(handle->fd, &endian4, 4);
if (ret != 4)
break;
@@ -763,9 +775,13 @@ 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 (chunks > UINT_MAX)
+ return -1;
+ endian4 = chunks;
+ endian4 = tep_read_number(handle->tep, &endian4, 4);
/* write chunks count*/
- write_fd(handle->fd, &chunks, 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;
--
2.49.0
next reply other threads:[~2025-04-11 17:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-11 17:27 Ilya Leoshkevich [this message]
2025-04-11 17:44 ` [PATCH] trace-cmd record: Fix compression on big-endian systems Steven Rostedt
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=20250411172815.61477-1-iii@linux.ibm.com \
--to=iii@linux.ibm.com \
--cc=agordeev@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.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).