Merge 4.14.222 into android-4.14-q
Linux 4.14.222
kvm: check tlbs_dirty directly
* usb: gadget: u_ether: Fix MTU size mismatch with RX packet size
drivers/usb/gadget/function/u_ether.c
* USB: Gadget Ethernet: Re-enable Jumbo frames.
drivers/usb/gadget/function/u_ether.c
scsi: qla2xxx: Fix crash during driver load on big endian machines
xen-blkback: fix error handling in xen_blkbk_map()
xen-scsiback: don't "handle" error by BUG()
xen-netback: don't "handle" error by BUG()
xen-blkback: don't "handle" error by BUG()
xen/arm: don't ignore return errors from set_phys_to_machine
Xen/gntdev: correct error checking in gntdev_map_grant_pages()
Xen/gntdev: correct dev_bus_addr handling in gntdev_map_grant_pages()
Xen/x86: also check kernel mapping in set_foreign_p2m_mapping()
Xen/x86: don't bail early from clear_foreign_p2m_mapping()
* tracing: Avoid calling cc-option -mrecord-mcount for every Makefile
Makefile
scripts/Makefile.build
* tracing: Fix SKIP_STACK_VALIDATION=1 build due to bad merge with -mrecord-mcount
scripts/Makefile.build
* trace: Use -mcount-record for dynamic ftrace
scripts/Makefile.build
x86/build: Disable CET instrumentation in the kernel for 32-bit too
h8300: fix PREEMPTION build, TI_PRE_COUNT undefined
i2c: stm32f7: fix configuration of the digital filter
vsock: fix locking in vsock_shutdown()
vsock/virtio: update credit only if socket is not closed
* net: watchdog: hold device global xmit lock during tx disable
include/linux/netdevice.h
net/vmw_vsock: improve locking in vsock_connect_timeout()
usb: dwc3: ulpi: Replace CPU-based busyloop with Protocol-based one
usb: dwc3: ulpi: fix checkpatch warning
* netfilter: conntrack: skip identical origin tuple in same zone only
net/netfilter/nf_conntrack_core.c
xen/netback: avoid race in xenvif_rx_ring_slots_available()
netfilter: xt_recent: Fix attempt to update deleted entry
* bpf: Check for integer overflow when using roundup_pow_of_two()
kernel/bpf/stackmap.c
* memblock: do not start bottom-up allocations with kernel_end
mm/memblock.c
ARM: ensure the signal page contains defined contents
ARM: dts: lpc32xx: Revert set default clock rate of HCLK PLL
* ovl: skip getxattr of security labels
fs/overlayfs/copy_up.c
* cap: fix conversions on getxattr
security/commoncap.c
* ovl: perform vfs_getxattr() with mounter creds
fs/overlayfs/inode.c
platform/x86: hp-wmi: Disable tablet-mode reporting by default
arm64: dts: rockchip: Fix PCIe DT properties on rk3399
MIPS: BMIPS: Fix section mismatch warning
arm/xen: Don't probe xenbus as part of an early initcall
* tracing: Check length before giving out the filter buffer
kernel/trace/trace.c
* tracing: Do not count ftrace events in top level enable output
kernel/trace/trace_events.c
squashfs: add more sanity checks in xattr id lookup
squashfs: add more sanity checks in inode lookup
squashfs: add more sanity checks in id lookup
* memcg: fix a crash in wb_workfn when a device disappears
fs/fs-writeback.c
include/linux/backing-dev.h
include/trace/events/writeback.h
mm/backing-dev.c
* include/trace/events/writeback.h: fix -Wstringop-truncation warnings
include/trace/events/writeback.h
* lib/string: Add strscpy_pad() function
include/linux/string.h
lib/string.c
SUNRPC: Handle 0 length opaque XDR object data properly
* SUNRPC: Move simple_get_bytes and simple_get_netobj into private header
include/linux/sunrpc/xdr.h
iwlwifi: mvm: guard against device removal in reprobe
iwlwifi: pcie: add a NULL check in iwl_pcie_txq_unmap
iwlwifi: mvm: take mutex for calling iwl_mvm_get_sync_time()
pNFS/NFSv4: Try to return invalid layout in pnfs_layout_process()
* af_key: relax availability checks for skb size calculation
net/key/af_key.c
remoteproc: qcom_q6v5_mss: Validate MBA firmware size before load
remoteproc: qcom_q6v5_mss: Validate modem blob firmware size before load
* fgraph: Initialize tracing_graph_pause at task creation
include/linux/ftrace.h
* BACKPORT: bpf: add bpf_ktime_get_boot_ns()
include/linux/bpf.h
include/uapi/linux/bpf.h
kernel/bpf/core.c
kernel/bpf/helpers.c
kernel/trace/bpf_trace.c
net/core/filter.c
* UPSTREAM: net: bpf: Make bpf_ktime_get_ns() available to non GPL programs
kernel/bpf/helpers.c
Merge 4.14.221 into android-4.14-q
Linux 4.14.221
net: dsa: mv88e6xxx: override existent unicast portvec in port_fdb_add
iommu/vt-d: Do not use flush-queue when caching-mode is on
* Input: xpad - sync supported devices with fork on GitHub
drivers/input/joystick/xpad.c
x86/apic: Add extra serialization for non-serializing MSRs
* x86/build: Disable CET instrumentation in the kernel
Makefile
mm: thp: fix MADV_REMOVE deadlock on shmem THP
mm: hugetlb: remove VM_BUG_ON_PAGE from page_huge_active
mm: hugetlb: fix a race between isolating and freeing page
* mm: hugetlbfs: fix cannot migrate the fallocated HugeTLB page
include/linux/hugetlb.h
ARM: footbridge: fix dc21285 PCI configuration accessors
nvme-pci: avoid the deepest sleep state on Kingston A2000 SSDs
mmc: core: Limit retries when analyse of SDIO tuples fails
smb3: Fix out-of-bounds bug in SMB2_negotiate()
cifs: report error instead of invalid when revalidating a dentry fails
* xhci: fix bounce buffer usage for non-sg list case
drivers/usb/host/xhci-ring.c
kretprobe: Avoid re-registration of the same kretprobe earlier
mac80211: fix station rate table updates on assoc
* ovl: fix dentry leak in ovl_get_redirect
fs/overlayfs/dir.c
usb: dwc2: Fix endpoint direction check in ep_from_windex
USB: usblp: don't call usb_set_interface if there's a single alt
USB: gadget: legacy: fix an error code in eth_bind()
* ipv4: fix race condition between route lookup and invalidation
net/ipv4/route.c
* elfcore: fix building with clang
include/linux/elfcore.h
kernel/Makefile
objtool: Support Clang non-section symbols in ORC generation
net: lapb: Copy the skb before sending a packet
arm64: dts: ls1046a: fix dcfg address range
Input: i8042 - unbreak Pegatron C15B
USB: serial: option: Adding support for Cinterion MV31
USB: serial: cp210x: add new VID/PID for supporting Teraoka AD2000
USB: serial: cp210x: add pid/vid for WSDA-200-USB
Merge 4.14.220 into android-4.14-q
Linux 4.14.220
* kthread: Extract KTHREAD_IS_PER_CPU
include/linux/kthread.h
kernel/kthread.c
kernel/smpboot.c
objtool: Don't fail on missing symbol table
scsi: ibmvfc: Set default timeout to avoid crash during migration
mac80211: fix fast-rx encryption check
scsi: libfc: Avoid invoking response handler twice if ep is already completed
scsi: scsi_transport_srp: Don't block target in failfast state
x86: __always_inline __{rd,wr}msr()
phy: cpcap-usb: Fix warning for missing regulator_disable
* driver core: Extend device_is_dependent()
drivers/base/core.c
* base: core: Remove WARN_ON from link dependencies check
drivers/base/core.c
* net_sched: gen_estimator: support large ewma log
net/core/gen_estimator.c
* net_sched: reject silly cell_log in qdisc_get_rtab()
net/sched/sch_api.c
ACPI: thermal: Do not call acpi_thermal_check() directly
ibmvnic: Ensure that CRQ entry read are correctly ordered
net: dsa: bcm_sf2: put device node before return
Merge 4.14.219 into android-4.14-q
Linux 4.14.219
* tcp: fix TLP timer not set when CA_STATE changes from DISORDER to OPEN
include/net/tcp.h
net/ipv4/tcp_input.c
net/ipv4/tcp_recovery.c
team: protect features update by RCU to avoid deadlock
NFC: fix possible resource leak
NFC: fix resource leak when target index is invalid
iommu/vt-d: Don't dereference iommu_device if IOMMU_API is not built
iommu/vt-d: Gracefully handle DMAR units with no supported address widths
x86/entry/64/compat: Fix "x86/entry/64/compat: Preserve r8-r11 in int $0x80"
x86/entry/64/compat: Preserve r8-r11 in int $0x80
can: dev: prevent potential information leak in can_fill_info()
mac80211: pause TX while changing interface type
iwlwifi: pcie: reschedule in long-running memory reads
iwlwifi: pcie: use jiffies for memory read spin time limit
RDMA/cxgb4: Fix the reported max_recv_sge value
* xfrm: Fix oops in xfrm_replay_advance_bmp
net/xfrm/xfrm_input.c
netfilter: nft_dynset: add timeout extension to template
ARM: imx: build suspend-imx6.S with arm instruction set
xen-blkfront: allow discard-* nodes to be optional
mt7601u: fix rx buffer refcounting
mt7601u: fix kernel crash unplugging the device
* leds: trigger: fix potential deadlock with libata
drivers/leds/led-triggers.c
xen: Fix XenStore initialisation for XS_LOCAL
KVM: x86: get smi pending status correctly
KVM: x86/pmu: Fix HW_REF_CPU_CYCLES event pseudo-encoding in intel_arch_events[]
drivers: soc: atmel: add null entry at the end of at91_soc_allowed_list[]
drivers: soc: atmel: Avoid calling at91_soc_init on non AT91 SoCs
net: usb: qmi_wwan: added support for Thales Cinterion PLSx3 modem family
* wext: fix NULL-ptr-dereference with cfg80211's lack of commit()
net/wireless/wext-core.c
ARM: dts: imx6qdl-gw52xx: fix duplicate regulator naming
ACPI: sysfs: Prefer "compatible" modalias
nbd: freeze the queue while we're adding connections
Bug: 181732917
Change-Id: Ie4724e236ad1ceb62e1c65b4cca6f6b63c9a27ff
Signed-off-by: Lucas Wei <lucaswei@google.com>
497 lines
15 KiB
C
497 lines
15 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#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
|
|
|
|
/* Wraps calls to strscpy()/memset(), no arch specific code required */
|
|
ssize_t strscpy_pad(char *dest, const char *src, size_t count);
|
|
|
|
#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_MEMSET16
|
|
extern void *memset16(uint16_t *, uint16_t, __kernel_size_t);
|
|
#endif
|
|
|
|
#ifndef __HAVE_ARCH_MEMSET32
|
|
extern void *memset32(uint32_t *, uint32_t, __kernel_size_t);
|
|
#endif
|
|
|
|
#ifndef __HAVE_ARCH_MEMSET64
|
|
extern void *memset64(uint64_t *, uint64_t, __kernel_size_t);
|
|
#endif
|
|
|
|
static inline void *memset_l(unsigned long *p, unsigned long v,
|
|
__kernel_size_t n)
|
|
{
|
|
if (BITS_PER_LONG == 32)
|
|
return memset32((uint32_t *)p, v, n);
|
|
else
|
|
return memset64((uint64_t *)p, v, n);
|
|
}
|
|
|
|
static inline void *memset_p(void **p, void *v, __kernel_size_t n)
|
|
{
|
|
if (BITS_PER_LONG == 32)
|
|
return memset32((uint32_t *)p, (uintptr_t)v, n);
|
|
else
|
|
return memset64((uint64_t *)p, (uintptr_t)v, n);
|
|
}
|
|
|
|
#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_BCMP
|
|
extern int bcmp(const void *,const void *,__kernel_size_t);
|
|
#endif
|
|
#ifndef __HAVE_ARCH_MEMCHR
|
|
extern void * memchr(const void *,int,__kernel_size_t);
|
|
#endif
|
|
#ifndef __HAVE_ARCH_MEMCPY_MCSAFE
|
|
static inline __must_check int memcpy_mcsafe(void *dst, const void *src,
|
|
size_t cnt)
|
|
{
|
|
memcpy(dst, src, cnt);
|
|
return 0;
|
|
}
|
|
#endif
|
|
#ifndef __HAVE_ARCH_MEMCPY_FLUSHCACHE
|
|
static inline void memcpy_flushcache(void *dst, const void *src, size_t cnt)
|
|
{
|
|
memcpy(dst, src, cnt);
|
|
}
|
|
#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);
|
|
|
|
int ptr_to_hashval(const void *ptr, unsigned long *hashval_out);
|
|
|
|
/**
|
|
* 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;
|
|
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 __read_overflow3(void) __compiletime_error("detected read beyond size of object passed as 3rd parameter");
|
|
void __write_overflow(void) __compiletime_error("detected write beyond size of object passed as 1st parameter");
|
|
|
|
#if !defined(__NO_FORTIFY) && defined(__OPTIMIZE__) && defined(CONFIG_FORTIFY_SOURCE)
|
|
|
|
#ifdef CONFIG_KASAN
|
|
extern void *__underlying_memchr(const void *p, int c, __kernel_size_t size) __RENAME(memchr);
|
|
extern int __underlying_memcmp(const void *p, const void *q, __kernel_size_t size) __RENAME(memcmp);
|
|
extern void *__underlying_memcpy(void *p, const void *q, __kernel_size_t size) __RENAME(memcpy);
|
|
extern void *__underlying_memmove(void *p, const void *q, __kernel_size_t size) __RENAME(memmove);
|
|
extern void *__underlying_memset(void *p, int c, __kernel_size_t size) __RENAME(memset);
|
|
extern char *__underlying_strcat(char *p, const char *q) __RENAME(strcat);
|
|
extern char *__underlying_strcpy(char *p, const char *q) __RENAME(strcpy);
|
|
extern __kernel_size_t __underlying_strlen(const char *p) __RENAME(strlen);
|
|
extern char *__underlying_strncat(char *p, const char *q, __kernel_size_t count) __RENAME(strncat);
|
|
extern char *__underlying_strncpy(char *p, const char *q, __kernel_size_t size) __RENAME(strncpy);
|
|
#else
|
|
#define __underlying_memchr __builtin_memchr
|
|
#define __underlying_memcmp __builtin_memcmp
|
|
#define __underlying_memcpy __builtin_memcpy
|
|
#define __underlying_memmove __builtin_memmove
|
|
#define __underlying_memset __builtin_memset
|
|
#define __underlying_strcat __builtin_strcat
|
|
#define __underlying_strcpy __builtin_strcpy
|
|
#define __underlying_strlen __builtin_strlen
|
|
#define __underlying_strncat __builtin_strncat
|
|
#define __underlying_strncpy __builtin_strncpy
|
|
#endif
|
|
|
|
__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 __underlying_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 __underlying_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);
|
|
|
|
/* Work around gcc excess stack consumption issue */
|
|
if (p_size == (size_t)-1 ||
|
|
(__builtin_constant_p(p[p_size - 1]) && p[p_size - 1] == '\0'))
|
|
return __underlying_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__);
|
|
__underlying_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 __underlying_strncat(p, q, count);
|
|
p_len = strlen(p);
|
|
copy_len = strnlen(q, count);
|
|
if (p_size < p_len + copy_len + 1)
|
|
fortify_panic(__func__);
|
|
__underlying_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 __underlying_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 __underlying_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 __underlying_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 __underlying_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 __underlying_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 __underlying_strcpy(p, q);
|
|
memcpy(p, q, strlen(q) + 1);
|
|
return p;
|
|
}
|
|
|
|
/* Don't use these outside the FORITFY_SOURCE implementation */
|
|
#undef __underlying_memchr
|
|
#undef __underlying_memcmp
|
|
#undef __underlying_memcpy
|
|
#undef __underlying_memmove
|
|
#undef __underlying_memset
|
|
#undef __underlying_strcat
|
|
#undef __underlying_strcpy
|
|
#undef __underlying_strlen
|
|
#undef __underlying_strncat
|
|
#undef __underlying_strncpy
|
|
#endif
|
|
|
|
/**
|
|
* memcpy_and_pad - Copy one buffer to another with padding
|
|
* @dest: Where to copy to
|
|
* @dest_len: The destination buffer size
|
|
* @src: Where to copy from
|
|
* @count: The number of bytes to copy
|
|
* @pad: Character to use for padding if space is left in destination.
|
|
*/
|
|
static inline void memcpy_and_pad(void *dest, size_t dest_len,
|
|
const void *src, size_t count, int pad)
|
|
{
|
|
if (dest_len > count) {
|
|
memcpy(dest, src, count);
|
|
memset(dest + count, pad, dest_len - count);
|
|
} else
|
|
memcpy(dest, src, dest_len);
|
|
}
|
|
|
|
#endif /* _LINUX_STRING_H_ */
|