Linux 4.9.114
* string: drop __must_check from strscpy() and restore strscpy() usages in cgroup
include/linux/string.h
* arm64: KVM: Add ARCH_WORKAROUND_2 discovery through ARCH_FEATURES_FUNC_ID
arch/arm64/include/asm/kvm_host.h
* arm64: KVM: Handle guest's ARCH_WORKAROUND_2 requests
arch/arm64/kernel/asm-offsets.c
* arm64: KVM: Add ARCH_WORKAROUND_2 support for guests
arch/arm64/include/asm/kvm_asm.h
arch/arm64/include/asm/kvm_host.h
* arm64: KVM: Add HYP per-cpu accessors
arch/arm64/include/asm/kvm_asm.h
* arm64: ssbd: Add prctl interface for per-thread mitigation
arch/arm64/kernel/Makefile
arch/arm64/kernel/ssbd.c
* arm64: ssbd: Introduce thread flag to control userspace mitigation
arch/arm64/include/asm/thread_info.h
arch/arm64/kernel/entry.S
* arm64: ssbd: Restore mitigation status on CPU resume
arch/arm64/include/asm/cpufeature.h
arch/arm64/kernel/cpu_errata.c
arch/arm64/kernel/suspend.c
* arm64: ssbd: Skip apply_ssbd if not using dynamic mitigation
arch/arm64/kernel/cpu_errata.c
arch/arm64/kernel/entry.S
* arm64: ssbd: Add global mitigation state accessor
arch/arm64/include/asm/cpufeature.h
* arm64: Add 'ssbd' command-line option
arch/arm64/include/asm/cpufeature.h
arch/arm64/kernel/cpu_errata.c
* arm64: Add ARCH_WORKAROUND_2 probing
arch/arm64/Kconfig
arch/arm64/include/asm/cpucaps.h
arch/arm64/kernel/cpu_errata.c
* arm64: Add per-cpu infrastructure to call ARCH_WORKAROUND_2
arch/arm64/kernel/cpu_errata.c
arch/arm64/kernel/entry.S
* arm64: Call ARCH_WORKAROUND_2 on transitions between EL0 and EL1
arch/arm64/kernel/cpu_errata.c
arch/arm64/kernel/entry.S
include/linux/arm-smccc.h
* arm/arm64: smccc: Add SMCCC-specific return codes
include/linux/arm-smccc.h
* KVM: arm64: Avoid storing the vcpu pointer on the stack
arch/arm64/include/asm/kvm_asm.h
arch/arm64/include/asm/kvm_host.h
arch/arm64/kernel/asm-offsets.c
KVM: arm/arm64: Do not use kern_hyp_va() with kvm_vgic_global_state
* arm64: alternatives: Add dynamic patching feature
arch/arm64/include/asm/alternative.h
arch/arm64/kernel/alternative.c
KVM: arm64: Stop save/restoring host tpidr_el1 on VHE
* arm64: alternatives: use tpidr_el2 on VHE hosts
arch/arm64/include/asm/alternative.h
arch/arm64/include/asm/assembler.h
arch/arm64/include/asm/percpu.h
arch/arm64/kernel/alternative.c
arch/arm64/kernel/cpufeature.c
* KVM: arm64: Change hyp_panic()s dependency on tpidr_el2
arch/arm64/include/asm/kvm_host.h
KVM: arm/arm64: Convert kvm_host_cpu_state to a static per-cpu allocation
KVM: arm64: Store vcpu on the stack during __guest_enter()
* arm64: assembler: introduce ldr_this_cpu
arch/arm64/include/asm/assembler.h
arch/arm64/kernel/entry.S
net/nfc: Avoid stalls when nfc_alloc_send_skb() returned NULL.
rds: avoid unenecessary cong_update in loop transport
* netfilter: ipv6: nf_defrag: drop skb dst before queueing
net/ipv6/netfilter/nf_conntrack_reasm.c
KEYS: DNS: fix parsing multiple options
reiserfs: fix buffer overflow with long warning messages
* netfilter: ebtables: reject non-bridge targets
net/bridge/netfilter/ebtables.c
net: lan78xx: Fix race in tx pending skb size calculation
rtlwifi: rtl8821ae: fix firmware is not ready to run
net: cxgb3_main: fix potential Spectre v1
net/mlx5: Fix command interface race in polling mode
* net/packet: fix use-after-free
net/packet/af_packet.c
vhost_net: validate sock before trying to put its fd
* tcp: prevent bogus FRTO undos with non-SACK flows
net/ipv4/tcp_input.c
* tcp: fix Fast Open key endianness
net/ipv4/sysctl_net_ipv4.c
r8152: napi hangup fix after disconnect
qmi_wwan: add support for the Dell Wireless 5821e module
qed: Limit msix vectors in kdump kernel to the minimum required count.
qed: Fix use of incorrect size in memcpy call.
net: sungem: fix rx checksum support
* net_sched: blackhole: tell upper qdisc about dropped packets
net/sched/sch_blackhole.c
net/mlx5: Fix wrong size allocation for QoS ETC TC regitster
net/mlx5: Fix incorrect raw command length parsing
net: dccp: switch rx_tstamp_last_feedback to monotonic clock
net: dccp: avoid crash in ccid3_hc_rx_send_feedback()
ipvlan: fix IFLA_MTU ignored on NEWLINK
atm: zatm: Fix potential Spectre v1
crypto: crypto4xx - fix crypto4xx_build_pdr, crypto4xx_build_sdr leak
crypto: crypto4xx - remove bad list_del
bcm63xx_enet: do not write to random DMA channel on BCM6345
bcm63xx_enet: correct clock usage
mtd: m25p80: consider max message size in m25p80_read
ocfs2: ip_alloc_sem should be taken in ocfs2_get_block()
ocfs2: subsystem.su_mutex is required while accessing the item->ci_parent
x86/paravirt: Make native_save_fl() extern inline
x86/asm: Add _ASM_ARG* constants for argument registers to <asm/asm.h>
* compiler-gcc.h: Add __attribute__((gnu_inline)) to all inline declarations
include/linux/compiler-gcc.h
* compiler, clang: always inline when CONFIG_OPTIMIZE_INLINING is disabled
include/linux/compiler-clang.h
include/linux/compiler-gcc.h
* compiler, clang: properly override 'inline' for clang
include/linux/compiler-clang.h
* compiler, clang: suppress warning for unused static inline functions
include/linux/compiler-clang.h
MIPS: Use async IPIs for arch_trigger_cpumask_backtrace()
Change-Id: I83785f84fccfa763d5fb528af71b35aca438ae5f
Signed-off-by: Petri Gynther <pgynther@google.com>
392 lines
11 KiB
C
392 lines
11 KiB
C
#ifndef _LINUX_STRING_H_
|
|
#define _LINUX_STRING_H_
|
|
|
|
|
|
#include <linux/compiler.h> /* for inline */
|
|
#include <linux/types.h> /* for size_t */
|
|
#include <linux/stddef.h> /* for NULL */
|
|
#include <stdarg.h>
|
|
#include <uapi/linux/string.h>
|
|
|
|
extern char *strndup_user(const char __user *, long);
|
|
extern void *memdup_user(const void __user *, size_t);
|
|
extern void *memdup_user_nul(const void __user *, size_t);
|
|
|
|
/*
|
|
* Include machine specific inline routines
|
|
*/
|
|
#include <asm/string.h>
|
|
|
|
#ifndef __HAVE_ARCH_STRCPY
|
|
extern char * strcpy(char *,const char *);
|
|
#endif
|
|
#ifndef __HAVE_ARCH_STRNCPY
|
|
extern char * strncpy(char *,const char *, __kernel_size_t);
|
|
#endif
|
|
#ifndef __HAVE_ARCH_STRLCPY
|
|
size_t strlcpy(char *, const char *, size_t);
|
|
#endif
|
|
#ifndef __HAVE_ARCH_STRSCPY
|
|
ssize_t strscpy(char *, const char *, size_t);
|
|
#endif
|
|
#ifndef __HAVE_ARCH_STRCAT
|
|
extern char * strcat(char *, const char *);
|
|
#endif
|
|
#ifndef __HAVE_ARCH_STRNCAT
|
|
extern char * strncat(char *, const char *, __kernel_size_t);
|
|
#endif
|
|
#ifndef __HAVE_ARCH_STRLCAT
|
|
extern size_t strlcat(char *, const char *, __kernel_size_t);
|
|
#endif
|
|
#ifndef __HAVE_ARCH_STRCMP
|
|
extern int strcmp(const char *,const char *);
|
|
#endif
|
|
#ifndef __HAVE_ARCH_STRNCMP
|
|
extern int strncmp(const char *,const char *,__kernel_size_t);
|
|
#endif
|
|
#ifndef __HAVE_ARCH_STRCASECMP
|
|
extern int strcasecmp(const char *s1, const char *s2);
|
|
#endif
|
|
#ifndef __HAVE_ARCH_STRNCASECMP
|
|
extern int strncasecmp(const char *s1, const char *s2, size_t n);
|
|
#endif
|
|
#ifndef __HAVE_ARCH_STRCHR
|
|
extern char * strchr(const char *,int);
|
|
#endif
|
|
#ifndef __HAVE_ARCH_STRCHRNUL
|
|
extern char * strchrnul(const char *,int);
|
|
#endif
|
|
#ifndef __HAVE_ARCH_STRNCHR
|
|
extern char * strnchr(const char *, size_t, int);
|
|
#endif
|
|
#ifndef __HAVE_ARCH_STRRCHR
|
|
extern char * strrchr(const char *,int);
|
|
#endif
|
|
extern char * __must_check skip_spaces(const char *);
|
|
|
|
extern char *strim(char *);
|
|
|
|
static inline __must_check char *strstrip(char *str)
|
|
{
|
|
return strim(str);
|
|
}
|
|
|
|
#ifndef __HAVE_ARCH_STRSTR
|
|
extern char * strstr(const char *, const char *);
|
|
#endif
|
|
#ifndef __HAVE_ARCH_STRNSTR
|
|
extern char * strnstr(const char *, const char *, size_t);
|
|
#endif
|
|
#ifndef __HAVE_ARCH_STRLEN
|
|
extern __kernel_size_t strlen(const char *);
|
|
#endif
|
|
#ifndef __HAVE_ARCH_STRNLEN
|
|
extern __kernel_size_t strnlen(const char *,__kernel_size_t);
|
|
#endif
|
|
#ifndef __HAVE_ARCH_STRPBRK
|
|
extern char * strpbrk(const char *,const char *);
|
|
#endif
|
|
#ifndef __HAVE_ARCH_STRSEP
|
|
extern char * strsep(char **,const char *);
|
|
#endif
|
|
#ifndef __HAVE_ARCH_STRSPN
|
|
extern __kernel_size_t strspn(const char *,const char *);
|
|
#endif
|
|
#ifndef __HAVE_ARCH_STRCSPN
|
|
extern __kernel_size_t strcspn(const char *,const char *);
|
|
#endif
|
|
|
|
#ifndef __HAVE_ARCH_MEMSET
|
|
extern void * memset(void *,int,__kernel_size_t);
|
|
#endif
|
|
#ifndef __HAVE_ARCH_MEMCPY
|
|
extern void * memcpy(void *,const void *,__kernel_size_t);
|
|
#endif
|
|
#ifndef __HAVE_ARCH_MEMMOVE
|
|
extern void * memmove(void *,const void *,__kernel_size_t);
|
|
#endif
|
|
#ifndef __HAVE_ARCH_MEMSCAN
|
|
extern void * memscan(void *,int,__kernel_size_t);
|
|
#endif
|
|
#ifndef __HAVE_ARCH_MEMCMP
|
|
extern int memcmp(const void *,const void *,__kernel_size_t);
|
|
#endif
|
|
#ifndef __HAVE_ARCH_MEMCHR
|
|
extern void * memchr(const void *,int,__kernel_size_t);
|
|
#endif
|
|
void *memchr_inv(const void *s, int c, size_t n);
|
|
char *strreplace(char *s, char old, char new);
|
|
|
|
extern void kfree_const(const void *x);
|
|
|
|
extern char *kstrdup(const char *s, gfp_t gfp) __malloc;
|
|
extern const char *kstrdup_const(const char *s, gfp_t gfp);
|
|
extern char *kstrndup(const char *s, size_t len, gfp_t gfp);
|
|
extern void *kmemdup(const void *src, size_t len, gfp_t gfp);
|
|
extern char *kmemdup_nul(const char *s, size_t len, gfp_t gfp);
|
|
|
|
extern char **argv_split(gfp_t gfp, const char *str, int *argcp);
|
|
extern void argv_free(char **argv);
|
|
|
|
extern bool sysfs_streq(const char *s1, const char *s2);
|
|
extern int kstrtobool(const char *s, bool *res);
|
|
static inline int strtobool(const char *s, bool *res)
|
|
{
|
|
return kstrtobool(s, res);
|
|
}
|
|
|
|
int match_string(const char * const *array, size_t n, const char *string);
|
|
int __sysfs_match_string(const char * const *array, size_t n, const char *s);
|
|
|
|
/**
|
|
* sysfs_match_string - matches given string in an array
|
|
* @_a: array of strings
|
|
* @_s: string to match with
|
|
*
|
|
* Helper for __sysfs_match_string(). Calculates the size of @a automatically.
|
|
*/
|
|
#define sysfs_match_string(_a, _s) __sysfs_match_string(_a, ARRAY_SIZE(_a), _s)
|
|
|
|
#ifdef CONFIG_BINARY_PRINTF
|
|
int vbin_printf(u32 *bin_buf, size_t size, const char *fmt, va_list args);
|
|
int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf);
|
|
int bprintf(u32 *bin_buf, size_t size, const char *fmt, ...) __printf(3, 4);
|
|
#endif
|
|
|
|
extern ssize_t memory_read_from_buffer(void *to, size_t count, loff_t *ppos,
|
|
const void *from, size_t available);
|
|
|
|
/**
|
|
* strstarts - does @str start with @prefix?
|
|
* @str: string to examine
|
|
* @prefix: prefix to look for.
|
|
*/
|
|
static inline bool strstarts(const char *str, const char *prefix)
|
|
{
|
|
return strncmp(str, prefix, strlen(prefix)) == 0;
|
|
}
|
|
|
|
size_t memweight(const void *ptr, size_t bytes);
|
|
void memzero_explicit(void *s, size_t count);
|
|
|
|
/**
|
|
* kbasename - return the last part of a pathname.
|
|
*
|
|
* @path: path to extract the filename from.
|
|
*/
|
|
static inline const char *kbasename(const char *path)
|
|
{
|
|
const char *tail = strrchr(path, '/');
|
|
return tail ? tail + 1 : path;
|
|
}
|
|
|
|
#define __FORTIFY_INLINE extern __always_inline __attribute__((gnu_inline))
|
|
#define __RENAME(x) __asm__(#x)
|
|
|
|
void fortify_panic(const char *name) __noreturn __cold;
|
|
|
|
#ifdef CONFIG_FORTIFY_COMPILE_CHECK
|
|
void __read_overflow(void) __compiletime_error("detected read beyond size of object passed as 1st parameter");
|
|
void __read_overflow2(void) __compiletime_error("detected read beyond size of object passed as 2nd parameter");
|
|
void __write_overflow(void) __compiletime_error("detected write beyond size of object passed as 1st parameter");
|
|
#else
|
|
#define __read_overflow(void) do { } while (0)
|
|
#define __read_overflow2(void) do { } while (0)
|
|
#define __write_overflow(void) do { } while (0)
|
|
#endif
|
|
|
|
#if !defined(__NO_FORTIFY) && defined(__OPTIMIZE__) && defined(CONFIG_FORTIFY_SOURCE)
|
|
__FORTIFY_INLINE char *strncpy(char *p, const char *q, __kernel_size_t size)
|
|
{
|
|
size_t p_size = __builtin_object_size(p, 0);
|
|
if (__builtin_constant_p(size) && p_size < size)
|
|
__write_overflow();
|
|
if (p_size < size)
|
|
fortify_panic(__func__);
|
|
return __builtin_strncpy(p, q, size);
|
|
}
|
|
|
|
__FORTIFY_INLINE char *strcat(char *p, const char *q)
|
|
{
|
|
size_t p_size = __builtin_object_size(p, 0);
|
|
if (p_size == (size_t)-1)
|
|
return __builtin_strcat(p, q);
|
|
if (strlcat(p, q, p_size) >= p_size)
|
|
fortify_panic(__func__);
|
|
return p;
|
|
}
|
|
|
|
__FORTIFY_INLINE __kernel_size_t strlen(const char *p)
|
|
{
|
|
__kernel_size_t ret;
|
|
size_t p_size = __builtin_object_size(p, 0);
|
|
if (p_size == (size_t)-1)
|
|
return __builtin_strlen(p);
|
|
ret = strnlen(p, p_size);
|
|
if (p_size <= ret)
|
|
fortify_panic(__func__);
|
|
return ret;
|
|
}
|
|
|
|
extern __kernel_size_t __real_strnlen(const char *, __kernel_size_t) __RENAME(strnlen);
|
|
__FORTIFY_INLINE __kernel_size_t strnlen(const char *p, __kernel_size_t maxlen)
|
|
{
|
|
size_t p_size = __builtin_object_size(p, 0);
|
|
__kernel_size_t ret = __real_strnlen(p, maxlen < p_size ? maxlen : p_size);
|
|
if (p_size <= ret && maxlen != ret)
|
|
fortify_panic(__func__);
|
|
return ret;
|
|
}
|
|
|
|
/* defined after fortified strlen to reuse it */
|
|
extern size_t __real_strlcpy(char *, const char *, size_t) __RENAME(strlcpy);
|
|
__FORTIFY_INLINE size_t strlcpy(char *p, const char *q, size_t size)
|
|
{
|
|
size_t ret;
|
|
size_t p_size = __builtin_object_size(p, 0);
|
|
size_t q_size = __builtin_object_size(q, 0);
|
|
if (p_size == (size_t)-1 && q_size == (size_t)-1)
|
|
return __real_strlcpy(p, q, size);
|
|
ret = strlen(q);
|
|
if (size) {
|
|
size_t len = (ret >= size) ? size - 1 : ret;
|
|
if (__builtin_constant_p(len) && len >= p_size)
|
|
__write_overflow();
|
|
if (len >= p_size)
|
|
fortify_panic(__func__);
|
|
__builtin_memcpy(p, q, len);
|
|
p[len] = '\0';
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
/* defined after fortified strlen and strnlen to reuse them */
|
|
__FORTIFY_INLINE char *strncat(char *p, const char *q, __kernel_size_t count)
|
|
{
|
|
size_t p_len, copy_len;
|
|
size_t p_size = __builtin_object_size(p, 0);
|
|
size_t q_size = __builtin_object_size(q, 0);
|
|
if (p_size == (size_t)-1 && q_size == (size_t)-1)
|
|
return __builtin_strncat(p, q, count);
|
|
p_len = strlen(p);
|
|
copy_len = strnlen(q, count);
|
|
if (p_size < p_len + copy_len + 1)
|
|
fortify_panic(__func__);
|
|
__builtin_memcpy(p + p_len, q, copy_len);
|
|
p[p_len + copy_len] = '\0';
|
|
return p;
|
|
}
|
|
|
|
__FORTIFY_INLINE void *memset(void *p, int c, __kernel_size_t size)
|
|
{
|
|
size_t p_size = __builtin_object_size(p, 0);
|
|
if (__builtin_constant_p(size) && p_size < size)
|
|
__write_overflow();
|
|
if (p_size < size)
|
|
fortify_panic(__func__);
|
|
return __builtin_memset(p, c, size);
|
|
}
|
|
|
|
__FORTIFY_INLINE void *memcpy(void *p, const void *q, __kernel_size_t size)
|
|
{
|
|
size_t p_size = __builtin_object_size(p, 0);
|
|
size_t q_size = __builtin_object_size(q, 0);
|
|
if (__builtin_constant_p(size)) {
|
|
if (p_size < size)
|
|
__write_overflow();
|
|
if (q_size < size)
|
|
__read_overflow2();
|
|
}
|
|
if (p_size < size || q_size < size)
|
|
fortify_panic(__func__);
|
|
return __builtin_memcpy(p, q, size);
|
|
}
|
|
|
|
__FORTIFY_INLINE void *memmove(void *p, const void *q, __kernel_size_t size)
|
|
{
|
|
size_t p_size = __builtin_object_size(p, 0);
|
|
size_t q_size = __builtin_object_size(q, 0);
|
|
if (__builtin_constant_p(size)) {
|
|
if (p_size < size)
|
|
__write_overflow();
|
|
if (q_size < size)
|
|
__read_overflow2();
|
|
}
|
|
if (p_size < size || q_size < size)
|
|
fortify_panic(__func__);
|
|
return __builtin_memmove(p, q, size);
|
|
}
|
|
|
|
extern void *__real_memscan(void *, int, __kernel_size_t) __RENAME(memscan);
|
|
__FORTIFY_INLINE void *memscan(void *p, int c, __kernel_size_t size)
|
|
{
|
|
size_t p_size = __builtin_object_size(p, 0);
|
|
if (__builtin_constant_p(size) && p_size < size)
|
|
__read_overflow();
|
|
if (p_size < size)
|
|
fortify_panic(__func__);
|
|
return __real_memscan(p, c, size);
|
|
}
|
|
|
|
__FORTIFY_INLINE int memcmp(const void *p, const void *q, __kernel_size_t size)
|
|
{
|
|
size_t p_size = __builtin_object_size(p, 0);
|
|
size_t q_size = __builtin_object_size(q, 0);
|
|
if (__builtin_constant_p(size)) {
|
|
if (p_size < size)
|
|
__read_overflow();
|
|
if (q_size < size)
|
|
__read_overflow2();
|
|
}
|
|
if (p_size < size || q_size < size)
|
|
fortify_panic(__func__);
|
|
return __builtin_memcmp(p, q, size);
|
|
}
|
|
|
|
__FORTIFY_INLINE void *memchr(const void *p, int c, __kernel_size_t size)
|
|
{
|
|
size_t p_size = __builtin_object_size(p, 0);
|
|
if (__builtin_constant_p(size) && p_size < size)
|
|
__read_overflow();
|
|
if (p_size < size)
|
|
fortify_panic(__func__);
|
|
return __builtin_memchr(p, c, size);
|
|
}
|
|
|
|
void *__real_memchr_inv(const void *s, int c, size_t n) __RENAME(memchr_inv);
|
|
__FORTIFY_INLINE void *memchr_inv(const void *p, int c, size_t size)
|
|
{
|
|
size_t p_size = __builtin_object_size(p, 0);
|
|
if (__builtin_constant_p(size) && p_size < size)
|
|
__read_overflow();
|
|
if (p_size < size)
|
|
fortify_panic(__func__);
|
|
return __real_memchr_inv(p, c, size);
|
|
}
|
|
|
|
extern void *__real_kmemdup(const void *src, size_t len, gfp_t gfp) __RENAME(kmemdup);
|
|
__FORTIFY_INLINE void *kmemdup(const void *p, size_t size, gfp_t gfp)
|
|
{
|
|
size_t p_size = __builtin_object_size(p, 0);
|
|
if (__builtin_constant_p(size) && p_size < size)
|
|
__read_overflow();
|
|
if (p_size < size)
|
|
fortify_panic(__func__);
|
|
return __real_kmemdup(p, size, gfp);
|
|
}
|
|
|
|
/* defined after fortified strlen and memcpy to reuse them */
|
|
__FORTIFY_INLINE char *strcpy(char *p, const char *q)
|
|
{
|
|
size_t p_size = __builtin_object_size(p, 0);
|
|
size_t q_size = __builtin_object_size(q, 0);
|
|
if (p_size == (size_t)-1 && q_size == (size_t)-1)
|
|
return __builtin_strcpy(p, q);
|
|
memcpy(p, q, strlen(q) + 1);
|
|
return p;
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif /* _LINUX_STRING_H_ */
|