Skip to content

Commit

Permalink
Do not replace whole memcpy in apply alternatives
Browse files Browse the repository at this point in the history
apply_alternatives uses memcpy() to apply alternatives.  Which has the
unfortunate effect that while applying memcpy alternative to memcpy
itself it tries to overwrite itself with nops - which causes #UD fault
as it overwrites half of an instruction in copy loop, and from this
point on only possible outcome is triplefault and reboot.

So let's overwrite only first two instructions of memcpy - as long as
the main memcpy loop is not in first two bytes it will work fine.

Signed-off-by: Petr Vandrovec <petr@vandrovec.name>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Petr Vandrovec authored and Linus Torvalds committed Aug 12, 2007
1 parent 3864e8c commit b8d3f24
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion arch/x86_64/lib/memcpy.S
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ ENDPROC(__memcpy)
.quad memcpy
.quad 1b
.byte X86_FEATURE_REP_GOOD
.byte .Lfinal - memcpy
/* Replace only beginning, memcpy is used to apply alternatives, so it
* is silly to overwrite itself with nops - reboot is only outcome... */
.byte 2b - 1b
.byte 2b - 1b
.previous

0 comments on commit b8d3f24

Please sign in to comment.