summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2020-12-02 12:09:36 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2020-12-02 12:09:36 -0800
commit8a02ec8f35779335b81577903832c2b3c495e979 (patch)
treefcfea67b99cc17756549286858380eec410af68c /tools
parent509a15421674b9e1a3e1916939d0d0efd3e578da (diff)
parent05227490c5f0f1bbd3693a7a70b3fb5b09d2a996 (diff)
Merge tag 'trace-v5.10-rc6-bootconfig' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace
Pull bootconfig fixes from Steven Rostedt: "Have bootconfig size and checksum be little endian In case the bootconfig is created on one kind of endian machine, and then read on the other kind of endian kernel, the size and checksum will be incorrect. Instead, have both the size and checksum always be little endian and have the tool and the kernel convert it from little endian to or from the host endian" * tag 'trace-v5.10-rc6-bootconfig' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: docs: bootconfig: Add the endianness of fields tools/bootconfig: Store size and checksum in footer as le32 bootconfig: Load size and checksum in the footer as le32
Diffstat (limited to 'tools')
-rw-r--r--tools/bootconfig/main.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c
index 4a445b6304bb..7362bef1a368 100644
--- a/tools/bootconfig/main.c
+++ b/tools/bootconfig/main.c
@@ -10,6 +10,7 @@
#include <unistd.h>
#include <string.h>
#include <errno.h>
+#include <endian.h>
#include <linux/kernel.h>
#include <linux/bootconfig.h>
@@ -183,9 +184,11 @@ static int load_xbc_from_initrd(int fd, char **buf)
if (read(fd, &size, sizeof(u32)) < 0)
return pr_errno("Failed to read size", -errno);
+ size = le32toh(size);
if (read(fd, &csum, sizeof(u32)) < 0)
return pr_errno("Failed to read checksum", -errno);
+ csum = le32toh(csum);
/* Wrong size error */
if (stat.st_size < size + 8 + BOOTCONFIG_MAGIC_LEN) {
@@ -407,10 +410,10 @@ static int apply_xbc(const char *path, const char *xbc_path)
/* Add a footer */
p = data + size;
- *(u32 *)p = size;
+ *(u32 *)p = htole32(size);
p += sizeof(u32);
- *(u32 *)p = csum;
+ *(u32 *)p = htole32(csum);
p += sizeof(u32);
memcpy(p, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN);