Skip to content

Commit

Permalink
In PowerPC top, don't delete addi r0, r0, 0
Browse files Browse the repository at this point in the history
Also don't delete addis r0, r0, 0.  These instructions are special
cases that set r0 to zero.  If we delete them, then r0 keeps its old
value.

I caught this bug because osxppc protects the .text segment against
writing.  (linuxppc doesn't protect it.)  A program tried to set r0 to
the NULL pointer, but top deleted the instruction, so r0 kept an old
return address pointing into .text.  Later the program checked that r0
wasn't NULL, tried to write to address r0, and crashed.
  • Loading branch information
kernigh committed Jan 26, 2017
1 parent 8c8f291 commit 1dfd552
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions mach/powerpc/top/table
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ LABEL_STARTER '.';

%%;

P, Q, R { TRUE };
RNZ { strcmp(VAL, "r0") }; /* not r0 */
X, Y, Z { TRUE };

%%;

/* Whitespace is significant here! */

addi X, X, 0 -> ;
addis X, X, 0 -> ;
addi RNZ, RNZ, 0 -> ;
addis RNZ, RNZ, 0 -> ;

mr X, X -> ;
fmr X, X -> ;
Expand Down

0 comments on commit 1dfd552

Please sign in to comment.