Skip to content

Commit b0f892e

Browse files
committed
kboot_atc: Copy tunable_common_b before setting tunable_common
The insertion of the new property may update the fdt in a way that a pointer to fdt data becomes invalid and points to random data. Fixes: 31a60d7 ("kboot_atc: Rename tunables") Signed-off-by: Janne Grunau <j@jannau.net>
1 parent 76b4957 commit b0f892e

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/kboot_atc.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "kboot_atc.h"
55
#include "adt.h"
66
#include "devicetree.h"
7+
#include "malloc.h"
78
#include "pmgr.h"
89
#include "utils.h"
910

@@ -409,12 +410,23 @@ static void dt_copy_atc_tunables(void *dt, const char *adt_path, const char *dt_
409410
* Don't remove this before 2027-01-01.
410411
*/
411412
int prop_len;
412-
const void *tunable_common_b = fdt_getprop(dt, fdt_node, "apple,tunable-common-b", &prop_len);
413-
if (!tunable_common_b) {
413+
const void *tunable_common_b_fdt =
414+
fdt_getprop(dt, fdt_node, "apple,tunable-common-b", &prop_len);
415+
if (!tunable_common_b_fdt) {
414416
printf("kboot: Unable to find apple,tunable-common-b for %s\n", adt_path);
415417
goto cleanup;
416418
}
419+
420+
void *tunable_common_b = malloc(prop_len);
421+
if (!tunable_common_b) {
422+
printf("kboot: Unable to copy apple,tunable-common-b to apple,tunable-common for %s\n",
423+
adt_path);
424+
goto cleanup;
425+
}
426+
memcpy(tunable_common_b, tunable_common_b_fdt, prop_len);
427+
417428
ret = fdt_setprop(dt, fdt_node, "apple,tunable-common", tunable_common_b, prop_len);
429+
free(tunable_common_b);
418430
if (ret) {
419431
printf("kboot: Unable to copy apple,tunable-common-b to apple,tunable-common for %s\n",
420432
adt_path);

0 commit comments

Comments
 (0)