openwrt/target/linux/generic/backport-4.19
Kevin Darbyshire-Bryant 8f4841462c kernel: MIPS: math-emu Write-protect delay slot emulation pages
Backport https://git.kernel.org/pub/scm/linux/kernel/git/mips/linux.git/commit/?id=adcc81f148d733b7e8e641300c5590a2cdc13bf3

"Mapping the delay slot emulation page as both writeable & executable
presents a security risk, in that if an exploit can write to & jump into
the page then it can be used as an easy way to execute arbitrary code.

Prevent this by mapping the page read-only for userland, and using
access_process_vm() with the FOLL_FORCE flag to write to it from
mips_dsemul().

This will likely be less efficient due to copy_to_user_page() performing
cache maintenance on a whole page, rather than a single line as in the
previous use of flush_cache_sigtramp(). However this delay slot
emulation code ought not to be running in any performance critical paths
anyway so this isn't really a problem, and we can probably do better in
copy_to_user_page() anyway in future.

A major advantage of this approach is that the fix is small & simple to
backport to stable kernels.

Reported-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Paul Burton <paul.burton@mips.com>
Fixes: 432c6bacbd0c ("MIPS: Use per-mm page to execute branch delay slot instructions")"

Without patch:

cat /proc/self/maps
00400000-0047a000 r-xp 00000000 1f:03 1823       /bin/busybox
00489000-0048a000 r-xp 00079000 1f:03 1823       /bin/busybox
0048a000-0048b000 rwxp 0007a000 1f:03 1823       /bin/busybox
77ec8000-77eed000 r-xp 00000000 1f:03 2296       /lib/libgcc_s.so.1
77eed000-77eee000 rwxp 00015000 1f:03 2296       /lib/libgcc_s.so.1
77eee000-77f81000 r-xp 00000000 1f:03 2470       /lib/libc.so
77f90000-77f92000 rwxp 00092000 1f:03 2470       /lib/libc.so
77f92000-77f94000 rwxp 00000000 00:00 0
7f946000-7f967000 rw-p 00000000 00:00 0          [stack]
7fefb000-7fefc000 rwxp 00000000 00:00 0
7ffac000-7ffad000 r--p 00000000 00:00 0          [vvar]
7ffad000-7ffae000 r-xp 00000000 00:00 0          [vdso]

Patch applied:

cat /proc/self/maps
00400000-0047a000 r-xp 00000000 1f:03 1825       /bin/busybox
00489000-0048a000 r-xp 00079000 1f:03 1825       /bin/busybox
0048a000-0048b000 rwxp 0007a000 1f:03 1825       /bin/busybox
77ed0000-77ef5000 r-xp 00000000 1f:03 2298       /lib/libgcc_s.so.1
77ef5000-77ef6000 rwxp 00015000 1f:03 2298       /lib/libgcc_s.so.1
77ef6000-77f89000 r-xp 00000000 1f:03 2474       /lib/libc.so
77f98000-77f9a000 rwxp 00092000 1f:03 2474       /lib/libc.so
77f9a000-77f9c000 rwxp 00000000 00:00 0
7fbed000-7fc0e000 rw-p 00000000 00:00 0          [stack]
7fefb000-7fefc000 r-xp 00000000 00:00 0
7fff6000-7fff7000 r--p 00000000 00:00 0          [vvar]
7fff7000-7fff8000 r-xp 00000000 00:00 0          [vdso]

Note lack of write permission to 7fefb000-7fefc000

Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
2018-12-24 21:52:08 +00:00
..
010-Kbuild-don-t-hardcode-path-to-awk-in-scripts-ld-vers.patch
011-kbuild-export-SUBARCH.patch kernel: Make the patches apply on top of 4.19 2018-12-15 14:28:48 +01:00
020-backport_netfilter_rtcache.patch kernel: Make the patches apply on top of 4.19 2018-12-15 14:28:48 +01:00
047-v4.21-mtd-keep-original-flags-for-every-struct-mtd_info.patch kernel: Make the patches apply on top of 4.19 2018-12-15 14:28:48 +01:00
048-v4.21-mtd-improve-calculating-partition-boundaries-when-ch.patch kernel: Make the patches apply on top of 4.19 2018-12-15 14:28:48 +01:00
095-Allow-class-e-address-assignment-via-ifconfig-ioctl.patch kernel: backport ifconfig ioctl support for class e addresses 2018-12-17 10:40:20 +00:00
096-mips-math-emu-Write-protect-delay-slot-emulation-pages.patch kernel: MIPS: math-emu Write-protect delay slot emulation pages 2018-12-24 21:52:08 +00:00
096-v4.20-netfilter-ipv6-Preserve-link-scope-traffic-original-.patch kernel: preserve oif of IPv6 link scope packets 2018-12-17 21:42:23 +01:00
100-arm-cns3xxx-fix-writing-to-wrong-PCI-registers-after.patch cns3xxx: fix writing to wrong PCI registers 2018-12-18 14:24:57 +01:00
343-netfilter-nft_flow_offload-handle-netdevice-events-f.patch kernel: Make the patches apply on top of 4.19 2018-12-15 14:28:48 +01:00
366-netfilter-nf_flow_table-clean-up-and-fix-dst-handlin.patch kernel: Make the patches apply on top of 4.19 2018-12-15 14:28:48 +01:00
370-netfilter-nf_flow_table-fix-offloaded-connection-tim.patch kernel: Make the patches apply on top of 4.19 2018-12-15 14:28:48 +01:00
371-netfilter-nf_flow_table-fix-up-ct-state-of-flows-aft.patch kernel: Make the patches apply on top of 4.19 2018-12-15 14:28:48 +01:00
424-v4.20-net-dsa-fix-88e6060-roaming.patch kernel: mv88e6060: disable hardware level MAC learning 2018-12-16 00:57:20 +01:00
500-ubifs-Handle-re-linking-of-inodes-correctly-while-re.patch kernel: Make the patches apply on top of 4.19 2018-12-15 14:28:48 +01:00