Skip to content

Commit edb64bc

Browse files
Eugeniy Paltsevvineetgarc
authored andcommitted
ARC: u-boot args: check that magic number is correct
In case of devboards we really often disable bootloader and load Linux image in memory via JTAG. Even if kernel tries to verify uboot_tag and uboot_arg there is sill a chance that we treat some garbage in registers as valid u-boot arguments in JTAG case. E.g. it is enough to have '1' in r0 to treat any value in r2 as a boot command line. So check that magic number passed from u-boot is correct and drop u-boot arguments otherwise. That helps to reduce the possibility of using garbage as u-boot arguments in JTAG case. We can safely check U-boot magic value (0x0) in linux passed via r1 register as U-boot pass it from the beginning. So there is no backward-compatibility issues. Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com> Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
1 parent fbe025c commit edb64bc

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

arch/arc/kernel/head.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ ENTRY(stext)
111111
; r2 = pointer to uboot provided cmdline or external DTB in mem
112112
; These are handled later in handle_uboot_args()
113113
st r0, [@uboot_tag]
114+
st r1, [@uboot_magic]
114115
st r2, [@uboot_arg]
115116

116117
; setup "current" tsk and optionally cache it in dedicated r25

arch/arc/kernel/setup.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ unsigned int intr_to_DE_cnt;
3636

3737
/* Part of U-boot ABI: see head.S */
3838
int __initdata uboot_tag;
39+
int __initdata uboot_magic;
3940
char __initdata *uboot_arg;
4041

4142
const struct machine_desc *machine_desc;
@@ -504,6 +505,8 @@ static inline bool uboot_arg_invalid(unsigned long addr)
504505
#define UBOOT_TAG_NONE 0
505506
#define UBOOT_TAG_CMDLINE 1
506507
#define UBOOT_TAG_DTB 2
508+
/* We always pass 0 as magic from U-boot */
509+
#define UBOOT_MAGIC_VALUE 0
507510

508511
void __init handle_uboot_args(void)
509512
{
@@ -518,6 +521,11 @@ void __init handle_uboot_args(void)
518521
goto ignore_uboot_args;
519522
}
520523

524+
if (uboot_magic != UBOOT_MAGIC_VALUE) {
525+
pr_warn(IGNORE_ARGS "non zero uboot magic\n");
526+
goto ignore_uboot_args;
527+
}
528+
521529
if (uboot_tag != UBOOT_TAG_NONE &&
522530
uboot_arg_invalid((unsigned long)uboot_arg)) {
523531
pr_warn(IGNORE_ARGS "invalid uboot arg: '%px'\n", uboot_arg);

0 commit comments

Comments
 (0)