Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 05908082 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "random,stackprotect: introduce get_random_canary function"

parents 39a22213 5d8ff1e5
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -57,6 +57,27 @@ static inline unsigned long get_random_long(void)
#endif
}

/*
 * On 64-bit architectures, protect against non-terminated C string overflows
 * by zeroing out the first byte of the canary; this leaves 56 bits of entropy.
 */
#ifdef CONFIG_64BIT
# ifdef __LITTLE_ENDIAN
#  define CANARY_MASK 0xffffffffffffff00UL
# else /* big endian, 64 bits: */
#  define CANARY_MASK 0x00ffffffffffffffUL
# endif
#else /* 32 bits: */
# define CANARY_MASK 0xffffffffUL
#endif

static inline unsigned long get_random_canary(void)
{
	unsigned long val = get_random_long();

	return val & CANARY_MASK;
}

unsigned long randomize_page(unsigned long start, unsigned long range);

u32 prandom_u32(void);