diff options
author | Helge Deller <deller@gmx.de> | 2019-07-16 15:43:11 -0400 |
---|---|---|
committer | Helge Deller <deller@gmx.de> | 2019-07-17 17:11:27 -0400 |
commit | 10835c854685393a921b68f529bf740fa7c9984d (patch) | |
tree | 06bff8910b1370c736c4e189f775f6e2b8191e60 /arch/parisc | |
parent | c309b6f24222246c18a8b65d3950e6e755440865 (diff) |
parisc: Fix kernel panic due invalid values in IAOQ0 or IAOQ1
On parisc the privilege level of a process is stored in the lowest two bits of
the instruction pointers (IAOQ0 and IAOQ1). On Linux we use privilege level 0
for the kernel and privilege level 3 for user-space. So userspace should not be
allowed to modify IAOQ0 or IAOQ1 of a ptraced process to change it's privilege
level to e.g. 0 to try to gain kernel privileges.
This patch prevents such modifications by always setting the two lowest bits to
one (which relates to privilege level 3 for user-space) if IAOQ0 or IAOQ1 are
modified via ptrace calls in the native and compat ptrace paths.
Link: https://bugs.gentoo.org/481768
Reported-by: Jeroen Roovers <jer@gentoo.org>
Cc: <stable@vger.kernel.org>
Tested-by: Rolf Eike Beer <eike-kernel@sf-tec.de>
Signed-off-by: Helge Deller <deller@gmx.de>
Diffstat (limited to 'arch/parisc')
-rw-r--r-- | arch/parisc/kernel/ptrace.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/arch/parisc/kernel/ptrace.c b/arch/parisc/kernel/ptrace.c index f642ba378ffa..040ff16dd5e7 100644 --- a/arch/parisc/kernel/ptrace.c +++ b/arch/parisc/kernel/ptrace.c | |||
@@ -167,6 +167,9 @@ long arch_ptrace(struct task_struct *child, long request, | |||
167 | if ((addr & (sizeof(unsigned long)-1)) || | 167 | if ((addr & (sizeof(unsigned long)-1)) || |
168 | addr >= sizeof(struct pt_regs)) | 168 | addr >= sizeof(struct pt_regs)) |
169 | break; | 169 | break; |
170 | if (addr == PT_IAOQ0 || addr == PT_IAOQ1) { | ||
171 | data |= 3; /* ensure userspace privilege */ | ||
172 | } | ||
170 | if ((addr >= PT_GR1 && addr <= PT_GR31) || | 173 | if ((addr >= PT_GR1 && addr <= PT_GR31) || |
171 | addr == PT_IAOQ0 || addr == PT_IAOQ1 || | 174 | addr == PT_IAOQ0 || addr == PT_IAOQ1 || |
172 | (addr >= PT_FR0 && addr <= PT_FR31 + 4) || | 175 | (addr >= PT_FR0 && addr <= PT_FR31 + 4) || |
@@ -228,16 +231,18 @@ long arch_ptrace(struct task_struct *child, long request, | |||
228 | 231 | ||
229 | static compat_ulong_t translate_usr_offset(compat_ulong_t offset) | 232 | static compat_ulong_t translate_usr_offset(compat_ulong_t offset) |
230 | { | 233 | { |
231 | if (offset < 0) | 234 | compat_ulong_t pos; |
232 | return sizeof(struct pt_regs); | 235 | |
233 | else if (offset <= 32*4) /* gr[0..31] */ | 236 | if (offset < 32*4) /* gr[0..31] */ |
234 | return offset * 2 + 4; | 237 | pos = offset * 2 + 4; |
235 | else if (offset <= 32*4+32*8) /* gr[0..31] + fr[0..31] */ | 238 | else if (offset < 32*4+32*8) /* fr[0] ... fr[31] */ |
236 | return offset + 32*4; | 239 | pos = (offset - 32*4) + PT_FR0; |
237 | else if (offset < sizeof(struct pt_regs)/2 + 32*4) | 240 | else if (offset < sizeof(struct pt_regs)/2 + 32*4) /* sr[0] ... ipsw */ |
238 | return offset * 2 + 4 - 32*8; | 241 | pos = (offset - 32*4 - 32*8) * 2 + PT_SR0 + 4; |
239 | else | 242 | else |
240 | return sizeof(struct pt_regs); | 243 | pos = sizeof(struct pt_regs); |
244 | |||
245 | return pos; | ||
241 | } | 246 | } |
242 | 247 | ||
243 | long compat_arch_ptrace(struct task_struct *child, compat_long_t request, | 248 | long compat_arch_ptrace(struct task_struct *child, compat_long_t request, |
@@ -281,9 +286,12 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request, | |||
281 | addr = translate_usr_offset(addr); | 286 | addr = translate_usr_offset(addr); |
282 | if (addr >= sizeof(struct pt_regs)) | 287 | if (addr >= sizeof(struct pt_regs)) |
283 | break; | 288 | break; |
289 | if (addr == PT_IAOQ0+4 || addr == PT_IAOQ1+4) { | ||
290 | data |= 3; /* ensure userspace privilege */ | ||
291 | } | ||
284 | if (addr >= PT_FR0 && addr <= PT_FR31 + 4) { | 292 | if (addr >= PT_FR0 && addr <= PT_FR31 + 4) { |
285 | /* Special case, fp regs are 64 bits anyway */ | 293 | /* Special case, fp regs are 64 bits anyway */ |
286 | *(__u64 *) ((char *) task_regs(child) + addr) = data; | 294 | *(__u32 *) ((char *) task_regs(child) + addr) = data; |
287 | ret = 0; | 295 | ret = 0; |
288 | } | 296 | } |
289 | else if ((addr >= PT_GR1+4 && addr <= PT_GR31+4) || | 297 | else if ((addr >= PT_GR1+4 && addr <= PT_GR31+4) || |