xref: /arm-trusted-firmware/lib/stack_protector/aarch32/asm_stack_protector.S (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu/*
2*91f16700Schasinglulu * Copyright (c) 2017, Arm Limited and Contributors. All rights reserved.
3*91f16700Schasinglulu *
4*91f16700Schasinglulu * SPDX-License-Identifier: BSD-3-Clause
5*91f16700Schasinglulu */
6*91f16700Schasinglulu
7*91f16700Schasinglulu#include <arch.h>
8*91f16700Schasinglulu#include <asm_macros.S>
9*91f16700Schasinglulu#include <assert_macros.S>
10*91f16700Schasinglulu
11*91f16700Schasinglulu	.globl	update_stack_protector_canary
12*91f16700Schasinglulu
13*91f16700Schasinglulu/* -----------------------------------------------------------------------
14*91f16700Schasinglulu * void update_stack_protector_canary(void)
15*91f16700Schasinglulu *
16*91f16700Schasinglulu * Change the value of the canary used for stack smashing attacks protection.
17*91f16700Schasinglulu * Note: This must be called when it is safe to call C code, but this cannot be
18*91f16700Schasinglulu * called by C code. Doing this will make the check fail when the calling
19*91f16700Schasinglulu * function returns.
20*91f16700Schasinglulu * -----------------------------------------------------------------------
21*91f16700Schasinglulu */
22*91f16700Schasinglulu
23*91f16700Schasinglulufunc update_stack_protector_canary
24*91f16700Schasinglulu	/* Use r4 as it is callee-saved */
25*91f16700Schasinglulu	mov	r4, lr
26*91f16700Schasinglulu	bl	plat_get_stack_protector_canary
27*91f16700Schasinglulu
28*91f16700Schasinglulu	/* Update the canary with the returned value */
29*91f16700Schasinglulu	ldr	r1,  =__stack_chk_guard
30*91f16700Schasinglulu	str	r0, [r1]
31*91f16700Schasinglulu	bx	r4
32*91f16700Schasingluluendfunc update_stack_protector_canary
33*91f16700Schasinglulu
34*91f16700Schasinglulu
35