android_kernel_motorola_sm6225/lib/usercopy.c
Greg Kroah-Hartman 6af002b301 This is the 4.19.274 stable release
-----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCAAdFiEEZH8oZUiU471FcZm+ONu9yGCSaT4FAmP56E4ACgkQONu9yGCS
 aT5TjQ//fjhU2pECdzAsZ0GCnXqMfVgdUQtvPfzU16cHqhDcAZORuX4bgn1SuGZq
 VOWjfTED2zYtd/dffM2J0eGssSQk2nYtCiMPhweeOITyP4bIGWpScYGuO7rdJFRY
 8AKUscMnIvH5y7cA8oMH/O/LlBD2JWEc5xBfSym99JICTrFOKvKKxWTbHPJS40/m
 Ppw4UVX229/ZgeSvrxIQ3ZCn74R90Wb60ZohaXp7uN9nIE1gjkk75l8Whhoaf4L6
 JuTZBdun1lY/nM/mhvw2efOzHEiobJZZkROKWHjJuEzTq0ZodV8wUaY/SSgBgDLh
 UDgzohjW/2pcEdlHCY+zkhTD4+UR7WlRP8y4XlMtMAtlg099Y6L1iO3aGTBdt/Ix
 Lkfk+CbjhWWqYIiatnT2XM6XJsqCLJVOueGbAUlTpctyzYdogqUML3Mp89t2EATV
 coqmVXULB7wYXn7iU5hDGtidmYB6fyADyT3SCezTEZ9u/Cqity3QRniWMyJxttfr
 RjLjAZx9GqFVVjAhaoOkc+PtEcxgZvimcu0t/9fixg551ssVfPJdikA4QrOlLoDK
 THZc8zJb8xeJakG+r/PMsJadwRuarTXQiNy2/HTrkn23APkxLZribG3ZKjpGL6t7
 S7q0ZU5pXtQhvqooFC4iS+l3QXZirSP97i6szQmWcmjcOPiViSg=
 =HaZo
 -----END PGP SIGNATURE-----

Merge 4.19.274 into android-4.19-stable

Changes in 4.19.274
	wifi: rtl8xxxu: gen2: Turn on the rate control
	powerpc: dts: t208x: Mark MAC1 and MAC2 as 10G
	random: always mix cycle counter in add_latent_entropy()
	can: kvaser_usb: hydra: help gcc-13 to figure out cmd_len
	powerpc: dts: t208x: Disable 10G on MAC1 and MAC2
	alarmtimer: Prevent starvation by small intervals and SIG_IGN
	drm/i915/gvt: fix double free bug in split_2MB_gtt_entry
	mac80211: mesh: embedd mesh_paths and mpp_paths into ieee80211_if_mesh
	uaccess: Add speculation barrier to copy_from_user()
	wifi: mwifiex: Add missing compatible string for SD8787
	ext4: Fix function prototype mismatch for ext4_feat_ktype
	bpf: add missing header file include
	Linux 4.19.274

Change-Id: Ibf649340dee25d21c329d09a1f19454dfd2e5e7f
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2023-02-25 15:35:59 +00:00

95 lines
2.2 KiB
C

// SPDX-License-Identifier: GPL-2.0
#include <linux/uaccess.h>
#include <linux/bitops.h>
#include <linux/nospec.h>
/* out-of-line parts */
#ifndef INLINE_COPY_FROM_USER
unsigned long _copy_from_user(void *to, const void __user *from, unsigned long n)
{
unsigned long res = n;
might_fault();
if (likely(access_ok(VERIFY_READ, from, n))) {
/*
* Ensure that bad access_ok() speculation will not
* lead to nasty side effects *after* the copy is
* finished:
*/
barrier_nospec();
kasan_check_write(to, n);
res = raw_copy_from_user(to, from, n);
}
if (unlikely(res))
memset(to + (n - res), 0, res);
return res;
}
EXPORT_SYMBOL(_copy_from_user);
#endif
#ifndef INLINE_COPY_TO_USER
unsigned long _copy_to_user(void __user *to, const void *from, unsigned long n)
{
might_fault();
if (likely(access_ok(VERIFY_WRITE, to, n))) {
kasan_check_read(from, n);
n = raw_copy_to_user(to, from, n);
}
return n;
}
EXPORT_SYMBOL(_copy_to_user);
#endif
/**
* check_zeroed_user: check if a userspace buffer only contains zero bytes
* @from: Source address, in userspace.
* @size: Size of buffer.
*
* This is effectively shorthand for "memchr_inv(from, 0, size) == NULL" for
* userspace addresses (and is more efficient because we don't care where the
* first non-zero byte is).
*
* Returns:
* * 0: There were non-zero bytes present in the buffer.
* * 1: The buffer was full of zero bytes.
* * -EFAULT: access to userspace failed.
*/
int check_zeroed_user(const void __user *from, size_t size)
{
unsigned long val;
uintptr_t align = (uintptr_t) from % sizeof(unsigned long);
if (unlikely(size == 0))
return 1;
from -= align;
size += align;
if (!user_access_begin(VERIFY_READ, from, size))
return -EFAULT;
unsafe_get_user(val, (unsigned long __user *) from, err_fault);
if (align)
val &= ~aligned_byte_mask(align);
while (size > sizeof(unsigned long)) {
if (unlikely(val))
goto done;
from += sizeof(unsigned long);
size -= sizeof(unsigned long);
unsafe_get_user(val, (unsigned long __user *) from, err_fault);
}
if (size < sizeof(unsigned long))
val &= aligned_byte_mask(size);
done:
user_access_end();
return (val == 0);
err_fault:
user_access_end();
return -EFAULT;
}
EXPORT_SYMBOL(check_zeroed_user);