parisc: Revise __get_user() to probe user read access
PATCH v2 1/1 parisc: Revise __get_user() to probe user read access
parisc: Revise __get_user() to probe user read access
Because of the way read access support is implemented, read access interruptions are only triggered at privilege levels 2 and 3. The kernel executes at privilege level 0, so __get_user() never triggers a read access interruption (code 26). Thus, it is currently possible for user code to access a read protected address via a system call.
Fix this by probing read access rights at privilege level 3 and setting __gu_err to -EFAULT (-14) if access isn't allowed.
---
arch/parisc/include/asm/uaccess.h +17 -3
@@ -42,9 +42,23 @@ __gu_err; \ }) -#define __get_user (val, ptr) \ -({ \ - __get_user_internal(SR_USER, val, ptr); \ +#define __probe_user_internal (sr, error, ptr) \ +({ \ + __asm__("\tproberi (%%sr%1,%2),3,%0\n" \ + "\tcmpiclr,= 1,%0,%0\n" \ + "\tldi -14,%0\n" \ + : "=r"(error) \ + : "i"(sr), "r"(ptr)); \ +}) + +#define __get_user (val, ptr) \ +({ \ + register long __gu_err; \ + \ + __gu_err = __get_user_internal(SR_USER, val, ptr); \ + if (likely(!__gu_err)) \ + __probe_user_internal(SR_USER, __gu_err, ptr); \ + __gu_err; \ })#define __get_user_asm (sr, val, ldx, ptr) \
Helge Deller
maintainerQuoted 8 lines · John David Anglin
parisc: Revise
__get_user()to probe user read accessBecause of the way read access support is implemented, read access interruptions are only triggered at privilege levels 2 and 3. The kernel executes at privilege level 0, so
__get_user()never triggers a read access interruption (code 26). Thus, it is currently possible for user code to access a read protected address via a system call.
Quoted 4 lines
Fix this by probing read access rights at privilege level 3 and setting
__gu_errto-EFAULT(-14) if access isn't allowed.Signed-off-by John David Anglin <[email protected]>
Thanks a lot, Dave!
I've applied that patch, but modified it to utilize PRIV_USER and EFAULT constants instead of the hardcoded values in the proberi instruction. Compiler does not seem to complain.
Maybe you want to check:
https://git.kernel.org/pub/scm/linux/kernel/git/deller/parisc-linux.git/log/?h=for-next
Helge
Quoted 33 lines
---
arch/parisc/include/asm/uaccess.h +17
-3@@ -42,9 +42,23 @@ __gu_err; \ }) -#define __get_user (val, ptr) \ -({ \ - __get_user_internal(SR_USER, val, ptr); \ +#define __probe_user_internal (sr, error, ptr) \ +({ \ + __asm__("\tproberi (%%sr%1,%2),3,%0\n" \ + "\tcmpiclr,= 1,%0,%0\n" \ + "\tldi -14,%0\n" \ + : "=r"(error) \ + : "i"(sr), "r"(ptr)); \ +}) + +#define __get_user (val, ptr) \ +({ \ + register long __gu_err; \ + \ + __gu_err = __get_user_internal(SR_USER, val, ptr); \ + if (likely(!__gu_err)) \ + __probe_user_internal(SR_USER, __gu_err, ptr); \ + __gu_err; \ })#define __get_user_asm (sr, val, ldx, ptr) \
Quoted 14 lines · Helge Deller
Quoted 8 lines · John David Anglin
parisc: Revise __get_user() to probe user read access
Because of the way read access support is implemented, read access interruptions are only triggered at privilege levels 2 and 3. The kernel executes at privilege level 0, so __get_user() never triggers a read access interruption (code 26). Thus, it is currently possible for user code to access a read protected address via a system call.
Quoted 4 lines
Fix this by probing read access rights at privilege level 3 and setting __gu_err to -EFAULT (-14) if access isn't allowed.
Signed-off-by John David Anglin <[email protected]>
Quoted 7 lines
Thanks a lot, Dave!
I've applied that patch, but modified it to utilize PRIV_USER and EFAULT constants instead of the hardcoded values in the proberi instruction. Compiler does not seem to complain.
Maybe you want to check:
https://git.kernel.org/pub/scm/linux/kernel/git/deller/parisc-linux.git/log/?h=for-next
Maybe that works since you added extra arguments to asm. It didn't work with EFAULT directly in asm.
Another minor issue to note is the cmpiclr instruction does a 32-bit compare because COND macro doesn't work inside asm.
Dave
Signature · 1 line
John David Anglin [email protected]
Helge Deller
maintainerQuoted 17 lines · John David Anglin
Quoted 16 lines · Helge Deller
Quoted 8 lines · John David Anglin
parisc: Revise __get_user() to probe user read access
Because of the way read access support is implemented, read access interruptions are only triggered at privilege levels 2 and 3. The kernel executes at privilege level 0, so __get_user() never triggers a read access interruption (code 26). Thus, it is currently possible for user code to access a read protected address via a system call.
Quoted 4 lines
Fix this by probing read access rights at privilege level 3 and setting __gu_err to -EFAULT (-14) if access isn't allowed.
Signed-off-by John David Anglin <[email protected]>Thanks a lot, Dave!
Quoted 8 lines
Quoted 5 lines
I've applied that patch, but modified it to utilize PRIV_USER and EFAULT constants instead of the hardcoded values in the proberi instruction. Compiler does not seem to complain.
Maybe you want to check:
https://git.kernel.org/pub/scm/linux/kernel/git/deller/parisc-linux.git/log/?h=for-nextMaybe that works since you added extra arguments to asm. It didn't work with EFAULT directly in asm.
Yes.
Quoted 2 lines
Another minor issue to note is the cmpiclr instruction does a 32-bit compare because COND macro doesn't work inside asm.
Good point. I'll add this info.
Helge