Coverage Report

Created: 2026-11-28 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/barebox/lib/stackprot.c
Line
Count
Source
1
/* SPDX-License-Identifier: GPL-2.0-only */
2
3
#define pr_fmt(fmt) "stackprot: " fmt
4
5
#include <linux/printk.h>
6
#include <linux/kernel.h>
7
#include <linux/export.h>
8
#include <init.h>
9
#include <stdlib.h>
10
11
#ifdef __PBL__
12
#define STAGE "PBL"
13
#else
14
#define STAGE "barebox"
15
#endif
16
17
void __stack_chk_fail(void);
18
19
volatile ulong __stack_chk_guard = (ulong)(0xfeedf00ddeadbeef & ~0UL);
20
21
/*
22
 * Called when gcc's -fstack-protector feature is used, and
23
 * gcc detects corruption of the on-stack canary value
24
 */
25
noinstr void __stack_chk_fail(void)
26
0
{
27
0
  panic("stack-protector: " STAGE " stack is corrupted in: %pS\n",
28
0
        (void *)_RET_IP_);
29
0
}
30
EXPORT_SYMBOL(__stack_chk_fail);
31
32
static __no_stack_protector int stackprot_randomize_guard(void)
33
64
{
34
64
  ulong chk_guard;
35
64
  int ret;
36
37
64
  ret = get_crypto_bytes(&chk_guard, sizeof(chk_guard));
38
64
  if (ret)
39
64
    pr_warn("proceeding without randomized stack protector\n");
40
32
  else
41
32
    __stack_chk_guard = chk_guard;
42
43
64
  return 0;
44
64
}
45
late_initcall(stackprot_randomize_guard);