From f64181f08d4a8d7c6074b8913561ea7df80275fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Piotrowski?= Date: Thu, 8 Dec 2016 15:34:40 +0000 Subject: [PATCH] add patch fixing icmp6_send nullpointer kernel panic --- PKGBUILD | 15 +++-- net_handle_no_dst_on_skb_in_icmp6_send.patch | 68 ++++++++++++++++++++ 2 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 net_handle_no_dst_on_skb_in_icmp6_send.patch diff --git a/PKGBUILD b/PKGBUILD index ef2a47c..a1eda2c 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -6,7 +6,7 @@ pkgbase=linux # Build stock -ARCH kernel #pkgbase=linux-custom # Build kernel with a different name _srcname=linux-4.8 pkgver=4.8.12 -pkgrel=2 +pkgrel=3 arch=('i686' 'x86_64') url="https://www.kernel.org/" license=('GPL2') @@ -24,6 +24,7 @@ source=("https://www.kernel.org/pub/linux/kernel/v4.x/${_srcname}.tar.xz" 'linux.preset' 'change-default-console-loglevel.patch' fix_race_condition_in_packet_set_ring.diff + net_handle_no_dst_on_skb_in_icmp6_send.patch ) sha256sums=('3e9150065f193d3d94bcf46a1fe9f033c7ef7122ab71d75a7fb5a2f0c9a7e11a' @@ -35,7 +36,8 @@ sha256sums=('3e9150065f193d3d94bcf46a1fe9f033c7ef7122ab71d75a7fb5a2f0c9a7e11a' '834bd254b56ab71d73f59b3221f056c72f559553c04718e350ab2a3e2991afe0' 'ad6344badc91ad0630caacde83f7f9b97276f80d26a20619a87952be65492c65' '1256b241cd477b265a3c2d64bdc19ffe3c9bbcee82ea3994c590c2c76e767d99' - 'ad1ee95f906f88d31fcdb9273cd08e02e8eda177449f0c98dc1bff8cbf1483c2') + 'ad1ee95f906f88d31fcdb9273cd08e02e8eda177449f0c98dc1bff8cbf1483c2' + 'b595a1588bafb3d732841cd1b73633970706914f57f2d215c9f1494212d13989') validpgpkeys=( 'ABAF11C65A2970B130ABE3C479BE3E4300411886' # Linus Torvalds '647F28654894E3BD457199BE38DBBDC86092693E' # Greg Kroah-Hartman @@ -53,6 +55,9 @@ prepare() { # https://marc.info/?l=linux-netdev&m=148054660230570&w=2 patch -p1 -i "${srcdir}/fix_race_condition_in_packet_set_ring.diff" + # https://bugzilla.kernel.org/show_bug.cgi?id=189851 + patch -p1 -i "${srcdir}/net_handle_no_dst_on_skb_in_icmp6_send.patch" + # add latest fixes from stable queue, if needed # http://git.kernel.org/?p=linux/kernel/git/stable/stable-queue.git @@ -151,7 +156,7 @@ _package() { mv "${pkgdir}/lib" "${pkgdir}/usr/" # add vmlinux - install -D -m644 vmlinux "${pkgdir}/usr/lib/modules/${_kernver}/build/vmlinux" + install -D -m644 vmlinux "${pkgdir}/usr/lib/modules/${_kernver}/build/vmlinux" } _package-headers() { @@ -255,7 +260,7 @@ _package-headers() { # add objtool for external module building and enabled VALIDATION_STACK option if [ -f tools/objtool/objtool ]; then mkdir -p "${pkgdir}/usr/lib/modules/${_kernver}/build/tools/objtool" - cp -a tools/objtool/objtool ${pkgdir}/usr/lib/modules/${_kernver}/build/tools/objtool/ + cp -a tools/objtool/objtool ${pkgdir}/usr/lib/modules/${_kernver}/build/tools/objtool/ fi chown -R root.root "${pkgdir}/usr/lib/modules/${_kernver}/build" @@ -275,7 +280,7 @@ _package-headers() { # remove unneeded architectures rm -rf "${pkgdir}"/usr/lib/modules/${_kernver}/build/arch/{alpha,arc,arm,arm26,arm64,avr32,blackfin,c6x,cris,frv,h8300,hexagon,ia64,m32r,m68k,m68knommu,metag,mips,microblaze,mn10300,openrisc,parisc,powerpc,ppc,s390,score,sh,sh64,sparc,sparc64,tile,unicore32,um,v850,xtensa} - + # remove a files already in linux-docs package rm -f "${pkgdir}/usr/lib/modules/${_kernver}/build/Documentation/kbuild/Kconfig.recursion-issue-01" rm -f "${pkgdir}/usr/lib/modules/${_kernver}/build/Documentation/kbuild/Kconfig.recursion-issue-02" diff --git a/net_handle_no_dst_on_skb_in_icmp6_send.patch b/net_handle_no_dst_on_skb_in_icmp6_send.patch new file mode 100644 index 0000000..06448a9 --- /dev/null +++ b/net_handle_no_dst_on_skb_in_icmp6_send.patch @@ -0,0 +1,68 @@ +From 79dc7e3f1cd323be4c81aa1a94faa1b3ed987fb2 Mon Sep 17 00:00:00 2001 +From: David Ahern +Date: Sun, 27 Nov 2016 18:52:53 -0800 +Subject: [PATCH] net: handle no dst on skb in icmp6_send + +Andrey reported the following while fuzzing the kernel with syzkaller: + +kasan: CONFIG_KASAN_INLINE enabled +kasan: GPF could be caused by NULL-ptr deref or user memory access +general protection fault: 0000 [#1] SMP KASAN +Modules linked in: +CPU: 0 PID: 3859 Comm: a.out Not tainted 4.9.0-rc6+ #429 +Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011 +task: ffff8800666d4200 task.stack: ffff880067348000 +RIP: 0010:[] [] +icmp6_send+0x5fc/0x1e30 net/ipv6/icmp.c:451 +RSP: 0018:ffff88006734f2c0 EFLAGS: 00010206 +RAX: ffff8800666d4200 RBX: 0000000000000000 RCX: 0000000000000000 +RDX: 0000000000000000 RSI: dffffc0000000000 RDI: 0000000000000018 +RBP: ffff88006734f630 R08: ffff880064138418 R09: 0000000000000003 +R10: dffffc0000000000 R11: 0000000000000005 R12: 0000000000000000 +R13: ffffffff84e7e200 R14: ffff880064138484 R15: ffff8800641383c0 +FS: 00007fb3887a07c0(0000) GS:ffff88006cc00000(0000) knlGS:0000000000000000 +CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 +CR2: 0000000020000000 CR3: 000000006b040000 CR4: 00000000000006f0 +Stack: + ffff8800666d4200 ffff8800666d49f8 ffff8800666d4200 ffffffff84c02460 + ffff8800666d4a1a 1ffff1000ccdaa2f ffff88006734f498 0000000000000046 + ffff88006734f440 ffffffff832f4269 ffff880064ba7456 0000000000000000 +Call Trace: + [] icmpv6_param_prob+0x2c/0x40 net/ipv6/icmp.c:557 + [< inline >] ip6_tlvopt_unknown net/ipv6/exthdrs.c:88 + [] ip6_parse_tlv+0x555/0x670 net/ipv6/exthdrs.c:157 + [] ipv6_parse_hopopts+0x199/0x460 net/ipv6/exthdrs.c:663 + [] ipv6_rcv+0xfa3/0x1dc0 net/ipv6/ip6_input.c:191 + ... + +icmp6_send / icmpv6_send is invoked for both rx and tx paths. In both +cases the dst->dev should be preferred for determining the L3 domain +if the dst has been set on the skb. Fallback to the skb->dev if it has +not. This covers the case reported here where icmp6_send is invoked on +Rx before the route lookup. + +Fixes: 5d41ce29e ("net: icmp6_send should use dst dev to determine L3 domain") +Reported-by: Andrey Konovalov +Signed-off-by: David Ahern +Signed-off-by: David S. Miller +--- + net/ipv6/icmp.c | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + +diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c +index 7370ad2..2772004 100644 +--- a/net/ipv6/icmp.c ++++ b/net/ipv6/icmp.c +@@ -447,8 +447,10 @@ static void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info, + + if (__ipv6_addr_needs_scope_id(addr_type)) + iif = skb->dev->ifindex; +- else +- iif = l3mdev_master_ifindex(skb_dst(skb)->dev); ++ else { ++ dst = skb_dst(skb); ++ iif = l3mdev_master_ifindex(dst ? dst->dev : skb->dev); ++ } + + /* + * Must not send error if the source does not uniquely