Skip to content

Commit 10835c8

Browse files
committed
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 <[email protected]> Cc: <[email protected]> Tested-by: Rolf Eike Beer <[email protected]> Signed-off-by: Helge Deller <[email protected]>
1 parent c309b6f commit 10835c8

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

arch/parisc/kernel/ptrace.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ long arch_ptrace(struct task_struct *child, long request,
167167
if ((addr & (sizeof(unsigned long)-1)) ||
168168
addr >= sizeof(struct pt_regs))
169169
break;
170+
if (addr == PT_IAOQ0 || addr == PT_IAOQ1) {
171+
data |= 3; /* ensure userspace privilege */
172+
}
170173
if ((addr >= PT_GR1 && addr <= PT_GR31) ||
171174
addr == PT_IAOQ0 || addr == PT_IAOQ1 ||
172175
(addr >= PT_FR0 && addr <= PT_FR31 + 4) ||
@@ -228,16 +231,18 @@ long arch_ptrace(struct task_struct *child, long request,
228231

229232
static compat_ulong_t translate_usr_offset(compat_ulong_t offset)
230233
{
231-
if (offset < 0)
232-
return sizeof(struct pt_regs);
233-
else if (offset <= 32*4) /* gr[0..31] */
234-
return offset * 2 + 4;
235-
else if (offset <= 32*4+32*8) /* gr[0..31] + fr[0..31] */
236-
return offset + 32*4;
237-
else if (offset < sizeof(struct pt_regs)/2 + 32*4)
238-
return offset * 2 + 4 - 32*8;
234+
compat_ulong_t pos;
235+
236+
if (offset < 32*4) /* gr[0..31] */
237+
pos = offset * 2 + 4;
238+
else if (offset < 32*4+32*8) /* fr[0] ... fr[31] */
239+
pos = (offset - 32*4) + PT_FR0;
240+
else if (offset < sizeof(struct pt_regs)/2 + 32*4) /* sr[0] ... ipsw */
241+
pos = (offset - 32*4 - 32*8) * 2 + PT_SR0 + 4;
239242
else
240-
return sizeof(struct pt_regs);
243+
pos = sizeof(struct pt_regs);
244+
245+
return pos;
241246
}
242247

243248
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,
281286
addr = translate_usr_offset(addr);
282287
if (addr >= sizeof(struct pt_regs))
283288
break;
289+
if (addr == PT_IAOQ0+4 || addr == PT_IAOQ1+4) {
290+
data |= 3; /* ensure userspace privilege */
291+
}
284292
if (addr >= PT_FR0 && addr <= PT_FR31 + 4) {
285293
/* Special case, fp regs are 64 bits anyway */
286-
*(__u64 *) ((char *) task_regs(child) + addr) = data;
294+
*(__u32 *) ((char *) task_regs(child) + addr) = data;
287295
ret = 0;
288296
}
289297
else if ((addr >= PT_GR1+4 && addr <= PT_GR31+4) ||

0 commit comments

Comments
 (0)