From f80127f8a754f423c46893196e029230c6f91403 Mon Sep 17 00:00:00 2001 From: Md Sadre Alam Date: Tue, 7 May 2019 11:14:57 +0530 Subject: [PATCH] common: cmd_boot: Add stack canary test command. This change will add stack canary test command in u-boot command list. The stack canary test command format like as : canary . The string must be 10 bytes long. e.g " #canary Helloworldhelloworld". After this command we can see the below print. Stack Canary test start. stack-protector: U-boot stack is corrupted. Resetting CPU ... If stack-protection not enabled and stack overflow occure then we will get the following print. prefetch abort pc : [<4a006f72>] lr : [<4a90faf0>] reloc pc : [<4a006f72>] lr : [<4a90faf0>] sp : 4a77f948 ip : 20f14495 fp : 4a90fab4 r10: 00000002 r9 : 4a77fea0 r8 : 00000000 r7 : 4a983d20 r6 : 6f6f6f6f r5 : 6f6f6f6f r4 : 6f6f6f6f r3 : 00000000 r2 : 4a77f946 r1 : 4a78233b r0 : 00000000 Flags: nZCv IRQs off FIQs off Mode SVC_32 Resetting CPU ... Change-Id: If36d1da3ecc1d0038cd1a6bad6ab3d265b47dac8 Signed-off-by: Md Sadre Alam --- board/qca/arm/common/cmd_bootqca.c | 1 + common/cmd_boot.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/board/qca/arm/common/cmd_bootqca.c b/board/qca/arm/common/cmd_bootqca.c index a787d556bf..d1a5ad068d 100644 --- a/board/qca/arm/common/cmd_bootqca.c +++ b/board/qca/arm/common/cmd_bootqca.c @@ -82,6 +82,7 @@ typedef struct { void __stack_chk_fail(void) { printf("stack-protector: U-boot stack is corrupted.\n"); + bad_mode (); } /* * Set the root device and bootargs for mounting root filesystem. diff --git a/common/cmd_boot.c b/common/cmd_boot.c index 8f2e0701b5..ad5fcdf050 100644 --- a/common/cmd_boot.c +++ b/common/cmd_boot.c @@ -44,6 +44,25 @@ static int do_go(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) printf ("## Application terminated, rc = 0x%lX\n", rc); return rcode; } +static int do_canary(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + char Buffer[10] = {'\0'}; + printf("Stack Canary test start.\n"); + + if (argc < 2 || argc > 2) + return CMD_RET_USAGE; + + strlcpy(Buffer, argv[1], strlen(argv[1])); + + return 0; +} + +U_BOOT_CMD( + canary, 2, 0, do_canary, + "test stack canary", + "\n canary HelloworldHelloWorld \n" +); /* -------------------------------------------------------------------- */