| .. | .. | 
|---|
| 62 | 62 | #ifndef __HAVE_ARCH_STRCHRNUL | 
|---|
| 63 | 63 | extern char * strchrnul(const char *,int); | 
|---|
| 64 | 64 | #endif | 
|---|
|  | 65 | +extern char * strnchrnul(const char *, size_t, int); | 
|---|
| 65 | 66 | #ifndef __HAVE_ARCH_STRNCHR | 
|---|
| 66 | 67 | extern char * strnchr(const char *, size_t, int); | 
|---|
| 67 | 68 | #endif | 
|---|
| .. | .. | 
|---|
| 135 | 136 | return memset64((uint64_t *)p, (uintptr_t)v, n); | 
|---|
| 136 | 137 | } | 
|---|
| 137 | 138 |  | 
|---|
|  | 139 | +extern void **__memcat_p(void **a, void **b); | 
|---|
|  | 140 | +#define memcat_p(a, b) ({					\ | 
|---|
|  | 141 | +	BUILD_BUG_ON_MSG(!__same_type(*(a), *(b)),		\ | 
|---|
|  | 142 | +			 "type mismatch in memcat_p()");	\ | 
|---|
|  | 143 | +	(typeof(*a) *)__memcat_p((void **)(a), (void **)(b));	\ | 
|---|
|  | 144 | +}) | 
|---|
|  | 145 | + | 
|---|
| 138 | 146 | #ifndef __HAVE_ARCH_MEMCPY | 
|---|
| 139 | 147 | extern void * memcpy(void *,const void *,__kernel_size_t); | 
|---|
| 140 | 148 | #endif | 
|---|
| .. | .. | 
|---|
| 153 | 161 | #ifndef __HAVE_ARCH_MEMCHR | 
|---|
| 154 | 162 | extern void * memchr(const void *,int,__kernel_size_t); | 
|---|
| 155 | 163 | #endif | 
|---|
| 156 |  | -#ifndef __HAVE_ARCH_MEMCPY_MCSAFE | 
|---|
| 157 |  | -static inline __must_check unsigned long memcpy_mcsafe(void *dst, | 
|---|
| 158 |  | -		const void *src, size_t cnt) | 
|---|
| 159 |  | -{ | 
|---|
| 160 |  | -	memcpy(dst, src, cnt); | 
|---|
| 161 |  | -	return 0; | 
|---|
| 162 |  | -} | 
|---|
| 163 |  | -#endif | 
|---|
| 164 | 164 | #ifndef __HAVE_ARCH_MEMCPY_FLUSHCACHE | 
|---|
| 165 | 165 | static inline void memcpy_flushcache(void *dst, const void *src, size_t cnt) | 
|---|
| 166 | 166 | { | 
|---|
| 167 | 167 | memcpy(dst, src, cnt); | 
|---|
| 168 | 168 | } | 
|---|
| 169 | 169 | #endif | 
|---|
|  | 170 | + | 
|---|
| 170 | 171 | void *memchr_inv(const void *s, int c, size_t n); | 
|---|
| 171 | 172 | char *strreplace(char *s, char old, char new); | 
|---|
| 172 | 173 |  | 
|---|
| .. | .. | 
|---|
| 222 | 223 | } | 
|---|
| 223 | 224 |  | 
|---|
| 224 | 225 | size_t memweight(const void *ptr, size_t bytes); | 
|---|
| 225 |  | -void memzero_explicit(void *s, size_t count); | 
|---|
|  | 226 | + | 
|---|
|  | 227 | +/** | 
|---|
|  | 228 | + * memzero_explicit - Fill a region of memory (e.g. sensitive | 
|---|
|  | 229 | + *		      keying data) with 0s. | 
|---|
|  | 230 | + * @s: Pointer to the start of the area. | 
|---|
|  | 231 | + * @count: The size of the area. | 
|---|
|  | 232 | + * | 
|---|
|  | 233 | + * Note: usually using memset() is just fine (!), but in cases | 
|---|
|  | 234 | + * where clearing out _local_ data at the end of a scope is | 
|---|
|  | 235 | + * necessary, memzero_explicit() should be used instead in | 
|---|
|  | 236 | + * order to prevent the compiler from optimising away zeroing. | 
|---|
|  | 237 | + * | 
|---|
|  | 238 | + * memzero_explicit() doesn't need an arch-specific version as | 
|---|
|  | 239 | + * it just invokes the one of memset() implicitly. | 
|---|
|  | 240 | + */ | 
|---|
|  | 241 | +static inline void memzero_explicit(void *s, size_t count) | 
|---|
|  | 242 | +{ | 
|---|
|  | 243 | +	memset(s, 0, count); | 
|---|
|  | 244 | +	barrier_data(s); | 
|---|
|  | 245 | +} | 
|---|
| 226 | 246 |  | 
|---|
| 227 | 247 | /** | 
|---|
| 228 | 248 | * kbasename - return the last part of a pathname. | 
|---|
| .. | .. | 
|---|
| 246 | 266 |  | 
|---|
| 247 | 267 | #if !defined(__NO_FORTIFY) && defined(__OPTIMIZE__) && defined(CONFIG_FORTIFY_SOURCE) | 
|---|
| 248 | 268 |  | 
|---|
| 249 |  | -#ifdef CONFIG_KASAN | 
|---|
|  | 269 | +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) | 
|---|
| 250 | 270 | extern void *__underlying_memchr(const void *p, int c, __kernel_size_t size) __RENAME(memchr); | 
|---|
| 251 | 271 | extern int __underlying_memcmp(const void *p, const void *q, __kernel_size_t size) __RENAME(memcmp); | 
|---|
| 252 | 272 | extern void *__underlying_memcpy(void *p, const void *q, __kernel_size_t size) __RENAME(memcpy); | 
|---|
| .. | .. | 
|---|
| 494 | 514 | memcpy(dest, src, dest_len); | 
|---|
| 495 | 515 | } | 
|---|
| 496 | 516 |  | 
|---|
|  | 517 | +/** | 
|---|
|  | 518 | + * str_has_prefix - Test if a string has a given prefix | 
|---|
|  | 519 | + * @str: The string to test | 
|---|
|  | 520 | + * @prefix: The string to see if @str starts with | 
|---|
|  | 521 | + * | 
|---|
|  | 522 | + * A common way to test a prefix of a string is to do: | 
|---|
|  | 523 | + *  strncmp(str, prefix, sizeof(prefix) - 1) | 
|---|
|  | 524 | + * | 
|---|
|  | 525 | + * But this can lead to bugs due to typos, or if prefix is a pointer | 
|---|
|  | 526 | + * and not a constant. Instead use str_has_prefix(). | 
|---|
|  | 527 | + * | 
|---|
|  | 528 | + * Returns: | 
|---|
|  | 529 | + * * strlen(@prefix) if @str starts with @prefix | 
|---|
|  | 530 | + * * 0 if @str does not start with @prefix | 
|---|
|  | 531 | + */ | 
|---|
|  | 532 | +static __always_inline size_t str_has_prefix(const char *str, const char *prefix) | 
|---|
|  | 533 | +{ | 
|---|
|  | 534 | +	size_t len = strlen(prefix); | 
|---|
|  | 535 | +	return strncmp(str, prefix, len) == 0 ? len : 0; | 
|---|
|  | 536 | +} | 
|---|
|  | 537 | + | 
|---|
| 497 | 538 | #endif /* _LINUX_STRING_H_ */ | 
|---|