0215-copy_from_user-CPU_SW_DOMAIN_PAN-compatibility.patch 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. From 226f58c078e55ba665fb49139cdc4990f4bde684 Mon Sep 17 00:00:00 2001
  2. From: Phil Elwell <phil@raspberrypi.org>
  3. Date: Tue, 29 Mar 2016 15:32:30 +0100
  4. Subject: [PATCH 215/381] copy_from_user: CPU_SW_DOMAIN_PAN compatibility
  5. The downstream copy_from_user acceleration must also play nice with
  6. CONFIG_CPU_SW_DOMAIN_PAN.
  7. See: https://github.com/raspberrypi/linux/issues/1381
  8. Signed-off-by: Phil Elwell <phil@raspberrypi.org>
  9. ---
  10. arch/arm/lib/uaccess_with_memcpy.c | 14 +++++++++++---
  11. 1 file changed, 11 insertions(+), 3 deletions(-)
  12. --- a/arch/arm/lib/uaccess_with_memcpy.c
  13. +++ b/arch/arm/lib/uaccess_with_memcpy.c
  14. @@ -186,6 +186,7 @@ out:
  15. unsigned long noinline
  16. __copy_from_user_memcpy(void *to, const void __user *from, unsigned long n)
  17. {
  18. + unsigned long ua_flags;
  19. int atomic;
  20. if (unlikely(segment_eq(get_fs(), KERNEL_DS))) {
  21. @@ -217,7 +218,9 @@ __copy_from_user_memcpy(void *to, const
  22. if (tocopy > n)
  23. tocopy = n;
  24. + ua_flags = uaccess_save_and_enable();
  25. memcpy(to, (const void *)from, tocopy);
  26. + uaccess_restore(ua_flags);
  27. to += tocopy;
  28. from += tocopy;
  29. n -= tocopy;
  30. @@ -261,9 +264,14 @@ arm_copy_from_user(void *to, const void
  31. * With frame pointer disabled, tail call optimization kicks in
  32. * as well making this test almost invisible.
  33. */
  34. - if (n < COPY_FROM_USER_THRESHOLD)
  35. - return __copy_from_user_std(to, from, n);
  36. - return __copy_from_user_memcpy(to, from, n);
  37. + if (n < COPY_TO_USER_THRESHOLD) {
  38. + unsigned long ua_flags = uaccess_save_and_enable();
  39. + n = __copy_from_user_std(to, from, n);
  40. + uaccess_restore(ua_flags);
  41. + } else {
  42. + n = __copy_from_user_memcpy(to, from, n);
  43. + }
  44. + return n;
  45. }
  46. static unsigned long noinline