Files
twx-linux/include/linux
Dave Hansen e0fbff18bb uaccess: Add speculation barrier to copy_from_user()
commit 74e19ef0ff upstream.

The results of "access_ok()" can be mis-speculated.  The result is that
you can end speculatively:

	if (access_ok(from, size))
		// Right here

even for bad from/size combinations.  On first glance, it would be ideal
to just add a speculation barrier to "access_ok()" so that its results
can never be mis-speculated.

But there are lots of system calls just doing access_ok() via
"copy_to_user()" and friends (example: fstat() and friends).  Those are
generally not problematic because they do not _consume_ data from
userspace other than the pointer.  They are also very quick and common
system calls that should not be needlessly slowed down.

"copy_from_user()" on the other hand uses a user-controller pointer and
is frequently followed up with code that might affect caches.  Take
something like this:

	if (!copy_from_user(&kernelvar, uptr, size))
		do_something_with(kernelvar);

If userspace passes in an evil 'uptr' that *actually* points to a kernel
addresses, and then do_something_with() has cache (or other)
side-effects, it could allow userspace to infer kernel data values.

Add a barrier to the common copy_from_user() code to prevent
mis-speculated values which happen after the copy.

Also add a stub for architectures that do not define barrier_nospec().
This makes the macro usable in generic code.

Since the barrier is now usable in generic code, the x86 #ifdef in the
BPF code can also go away.

Reported-by: Jordy Zomer <jordyzomer@google.com>
Suggested-by: Linus Torvalds <torvalds@linuxfoundation.org>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>   # BPF bits
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-02-25 11:50:31 +01:00
..
2023-02-06 07:46:33 +01:00
2022-10-26 13:17:05 +02:00
2019-11-24 08:22:48 +01:00
2021-12-08 08:46:55 +01:00
2020-04-02 16:34:21 +02:00
2022-10-26 13:17:08 +02:00
2019-12-17 20:38:50 +01:00
2021-03-03 18:22:46 +01:00
2022-08-25 11:11:25 +02:00
2021-02-07 14:47:41 +01:00
2021-11-26 11:40:20 +01:00
2019-12-31 12:37:21 +01:00
2021-07-11 12:48:09 +02:00
2020-03-20 10:54:12 +01:00
2019-06-11 12:21:48 +02:00
2020-04-02 16:34:36 +02:00
2020-12-11 13:39:04 +01:00
2020-04-02 16:34:36 +02:00
2021-12-14 10:16:55 +01:00