Skip to content

Commit

Permalink
Merge tag 'trace-v5.10-rc6-bootconfig' of git://git.kernel.org/pub/sc…
Browse files Browse the repository at this point in the history
…m/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
  • Loading branch information
torvalds committed Dec 2, 2020
2 parents 509a154 + 0522749 commit 8a02ec8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion Documentation/admin-guide/bootconfig.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ Since the boot configuration file is loaded with initrd, it will be added
to the end of the initrd (initramfs) image file with padding, size,
checksum and 12-byte magic word as below.

[initrd][bootconfig][padding][size(u32)][checksum(u32)][#BOOTCONFIG\n]
[initrd][bootconfig][padding][size(le32)][checksum(le32)][#BOOTCONFIG\n]

The size and checksum fields are unsigned 32bit little endian value.

When the boot configuration is added to the initrd image, the total
file size is aligned to 4 bytes. To fill the gap, null characters
Expand Down
4 changes: 2 additions & 2 deletions init/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ static void * __init get_boot_config_from_initrd(u32 *_size, u32 *_csum)

found:
hdr = (u32 *)(data - 8);
size = hdr[0];
csum = hdr[1];
size = le32_to_cpu(hdr[0]);
csum = le32_to_cpu(hdr[1]);

data = ((void *)hdr) - size;
if ((unsigned long)data < initrd_start) {
Expand Down
7 changes: 5 additions & 2 deletions tools/bootconfig/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <endian.h>

#include <linux/kernel.h>
#include <linux/bootconfig.h>
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8a02ec8

Please sign in to comment.