Received: by 10.192.165.148 with SMTP id m20csp296145imm; Fri, 20 Apr 2018 06:59:44 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+qaL1UP9+526iBE4mqb2r36FNGlW4XdV5QLzIjQ29drPWyjN+w+zVcNfDuh9ZpCeiPMLCB X-Received: by 2002:a17:902:788b:: with SMTP id q11-v6mr10334101pll.76.1524232784493; Fri, 20 Apr 2018 06:59:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524232784; cv=none; d=google.com; s=arc-20160816; b=GeHtCUmcYaueOUrynbDZ9Bz677OFrBX/gGCYR0ZuhOCrUj7Uec8pLrh3cCgue3LWaq XIjuCeu1hcijR/6k/1oocwyOXpP8JHZAaCXM1m7neESwiXdQUbDST6Ia4CbczE4XZhhI 4EelMJXVQ9sPrT5TDQ8zIKW7M8pTm4L9LwkuqhDsnAd9/Tl9Evy93WG3PsQ6tvNNS4XS U06AMpFLzxWRGWHYLJCOoM6lOdZLNIN3jQSU+3heER0uBkPhK2d7FA4+RTcl9lA/ramf 9G6hqzpT1cbMqkt6ebS8bBs/d2E60eiSVPV9eO/2p5nSsYyDfZkBa1P+1mlEDwhXvz/J eOvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=3mxOUBP8iKWUAgdF9SD57+MYt9Nkb37ieP9nBvCmiZY=; b=Q35rmli1JpW6vPvrA3BUrOgR31+YZzqP65Bwz/QXdwtM2HZdi4peO8WxhK33HDIwqM 9BK//Q65cJ8nxhinvaOKb9KgmLFlSikDf7t0D47BF/7clMy/edyuvBE55Y5cTee4kmCZ HLrvjoc0y+fFqihWfEbsBHyPQw0yDM4toHTKLe9tZf09EoqDEOP5mE47q7lhlb+o2B4P oy0XaBX8HaHkyo2/EANjO36ki5paM8zN7OWHivvscsF/tEC/lB2TdXjamGKoybhqeDjV ovZNsuns95QgqbCJTFzSM66UcILDBFlI2pCCfTk36eInUxI8i6Y//xR4JCyODwb0UQr0 cEwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nIa3a3ph; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w12si4976389pgm.565.2018.04.20.06.59.30; Fri, 20 Apr 2018 06:59:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nIa3a3ph; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755142AbeDTN6Q (ORCPT + 99 others); Fri, 20 Apr 2018 09:58:16 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:43947 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754982AbeDTN6O (ORCPT ); Fri, 20 Apr 2018 09:58:14 -0400 Received: by mail-wr0-f194.google.com with SMTP id v15-v6so5186259wrm.10; Fri, 20 Apr 2018 06:58:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=3mxOUBP8iKWUAgdF9SD57+MYt9Nkb37ieP9nBvCmiZY=; b=nIa3a3phtIN/1uzweY+MVFO0rYmT/qoyRWNYL3E3W3pR/3n6KXrnPHnpmj1JNzrx/I 5A7IYWguekwgV1udfMBIkU0pXohHXQwTMQDy/2Rm5OkFmYCsW2rcks9zOsCtZNmw9NsJ mipMswynmUDNKTx9fBLzr32bbUS+6esMEC4R0Rxf4xILeVMwfTfG5u5+xAcfzXROb7Rp lYj++Lx1W2i947H3nQZwBU+LCiUBUpydKaiEypbpmylo7zPwlNjqNAqaQLHPJXibsC9e lNR7Kg7FKiVpp98JAjrM/BmKlukIvcyyXf6ZKqtyfmV6sNh8Ff5zANpAQKrQUgAIdz7o V6/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=3mxOUBP8iKWUAgdF9SD57+MYt9Nkb37ieP9nBvCmiZY=; b=HZZKd7PmXoLLWGVkBspZvXcidBDgETh7zF98eljmEqd36pv6YvS2sozVx6Q0m5/PGh QZ+ZWnP47rz0OG9utbOUWeIOGhQmtrcrgLe3RK22RluaFceUZ/VAdtPv7bEHaeDPS5Ar +16HkVzcBH6R+etvZPVAbRO8c3mpTp/z5IQF8HAfKO8fXbXvase24bKtvhmhuEuz+ZIc kFnAz0FxoPIl0Qldx/5bODW3kQuAnY9g7nN0qxl0+yljiea6bzm63anD4YfkV5J7uz4x AyRwnEAW3BtXzZD8r9hBei04gkNuthU6d+qqUVEplpfMUypt0gO1QgZKhniWYfxiHSLH +YPQ== X-Gm-Message-State: ALQs6tBLdZW7FNCfpZn7DMtYW5/58g5Sv092SD50pyKT9xiS0QvSoD2h lz06ZCU6oMHupuom7pt66Tw= X-Received: by 10.28.147.8 with SMTP id v8mr2226702wmd.13.1524232692595; Fri, 20 Apr 2018 06:58:12 -0700 (PDT) Received: from sr6.gssi.infn.it ([192.135.27.141]) by smtp.gmail.com with ESMTPSA id a10-v6sm9443766wri.10.2018.04.20.06.58.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 20 Apr 2018 06:58:11 -0700 (PDT) From: Ahmed Abdelsalam To: davem@davemloft.net, dlebrun@google.com, kuznet@ms2.inr.ac.ru, yoshfuji@linux-ipv6.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: amsalam20@gmail.com Subject: [PATCH] [net] ipv6: sr: fix NULL pointer dereference in seg6_do_srh_encap()- v4 pkts Date: Fri, 20 Apr 2018 15:58:05 +0200 Message-Id: <1524232685-1203-1-git-send-email-amsalam20@gmail.com> X-Mailer: git-send-email 2.1.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In case of seg6 in encap mode, seg6_do_srh_encap() calls set_tun_src() in order to set the src addr of outer IPv6 header. The net_device is required for set_tun_src(). However calling ip6_dst_idev() on dst_entry in case of IPv4 traffic results on the following bug. Using just dst->dev should fix this BUG. [ 196.242461] BUG: unable to handle kernel NULL pointer dereference at 0000000000000000 [ 196.242975] PGD 800000010f076067 P4D 800000010f076067 PUD 10f060067 PMD 0 [ 196.243329] Oops: 0000 [#1] SMP PTI [ 196.243468] Modules linked in: nfsd auth_rpcgss nfs_acl nfs lockd grace fscache sunrpc crct10dif_pclmul crc32_pclmul ghash_clmulni_intel pcbc aesni_intel aes_x86_64 crypto_simd cryptd input_leds glue_helper led_class pcspkr serio_raw mac_hid video autofs4 hid_generic usbhid hid e1000 i2c_piix4 ahci pata_acpi libahci [ 196.244362] CPU: 2 PID: 1089 Comm: ping Not tainted 4.16.0+ #1 [ 196.244606] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006 [ 196.244968] RIP: 0010:seg6_do_srh_encap+0x1ac/0x300 [ 196.245236] RSP: 0018:ffffb2ce00b23a60 EFLAGS: 00010202 [ 196.245464] RAX: 0000000000000000 RBX: ffff8c7f53eea300 RCX: 0000000000000000 [ 196.245742] RDX: 0000f10000000000 RSI: ffff8c7f52085a6c RDI: ffff8c7f41166850 [ 196.246018] RBP: ffffb2ce00b23aa8 R08: 00000000000261e0 R09: ffff8c7f41166800 [ 196.246294] R10: ffffdce5040ac780 R11: ffff8c7f41166828 R12: ffff8c7f41166808 [ 196.246570] R13: ffff8c7f52085a44 R14: ffffffffb73211c0 R15: ffff8c7e69e44200 [ 196.246846] FS: 00007fc448789700(0000) GS:ffff8c7f59d00000(0000) knlGS:0000000000000000 [ 196.247286] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 196.247526] CR2: 0000000000000000 CR3: 000000010f05a000 CR4: 00000000000406e0 [ 196.247804] Call Trace: [ 196.247972] seg6_do_srh+0x15b/0x1c0 [ 196.248156] seg6_output+0x3c/0x220 [ 196.248341] ? prandom_u32+0x14/0x20 [ 196.248526] ? ip_idents_reserve+0x6c/0x80 [ 196.248723] ? __ip_select_ident+0x90/0x100 [ 196.248923] ? ip_append_data.part.50+0x6c/0xd0 [ 196.249133] lwtunnel_output+0x44/0x70 [ 196.249328] ip_send_skb+0x15/0x40 [ 196.249515] raw_sendmsg+0x8c3/0xac0 [ 196.249701] ? _copy_from_user+0x2e/0x60 [ 196.249897] ? rw_copy_check_uvector+0x53/0x110 [ 196.250106] ? _copy_from_user+0x2e/0x60 [ 196.250299] ? copy_msghdr_from_user+0xce/0x140 [ 196.250508] sock_sendmsg+0x36/0x40 [ 196.250690] ___sys_sendmsg+0x292/0x2a0 [ 196.250881] ? _cond_resched+0x15/0x30 [ 196.251074] ? copy_termios+0x1e/0x70 [ 196.251261] ? _copy_to_user+0x22/0x30 [ 196.251575] ? tty_mode_ioctl+0x1c3/0x4e0 [ 196.251782] ? _cond_resched+0x15/0x30 [ 196.251972] ? mutex_lock+0xe/0x30 [ 196.252152] ? vvar_fault+0xd2/0x110 [ 196.252337] ? __do_fault+0x1f/0xc0 [ 196.252521] ? __handle_mm_fault+0xc1f/0x12d0 [ 196.252727] ? __sys_sendmsg+0x63/0xa0 [ 196.252919] __sys_sendmsg+0x63/0xa0 [ 196.253107] do_syscall_64+0x72/0x200 [ 196.253305] entry_SYSCALL_64_after_hwframe+0x3d/0xa2 [ 196.253530] RIP: 0033:0x7fc4480b0690 [ 196.253715] RSP: 002b:00007ffde9f252f8 EFLAGS: 00000246 ORIG_RAX: 000000000000002e [ 196.254053] RAX: ffffffffffffffda RBX: 0000000000000040 RCX: 00007fc4480b0690 [ 196.254331] RDX: 0000000000000000 RSI: 000000000060a360 RDI: 0000000000000003 [ 196.254608] RBP: 00007ffde9f253f0 R08: 00000000002d1e81 R09: 0000000000000002 [ 196.254884] R10: 00007ffde9f250c0 R11: 0000000000000246 R12: 0000000000b22070 [ 196.255205] R13: 20c49ba5e353f7cf R14: 431bde82d7b634db R15: 00007ffde9f278fe [ 196.255484] Code: a5 0f b6 45 c0 41 88 41 28 41 0f b6 41 2c 48 c1 e0 04 49 8b 54 01 38 49 8b 44 01 30 49 89 51 20 49 89 41 18 48 8b 83 b0 00 00 00 <48> 8b 30 49 8b 86 08 0b 00 00 48 8b 40 20 48 8b 50 08 48 0b 10 [ 196.256190] RIP: seg6_do_srh_encap+0x1ac/0x300 RSP: ffffb2ce00b23a60 [ 196.256445] CR2: 0000000000000000 [ 196.256676] ---[ end trace 71af7d093603885c ]--- Fixes: 8936ef7604c11 ipv6: sr: fix NULL pointer dereference when setting encap source address Signed-off-by: Ahmed Abdelsalam --- I tested the patch for IPv6 and IPv4 traffic net/ipv6/seg6_iptunnel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv6/seg6_iptunnel.c b/net/ipv6/seg6_iptunnel.c index f343e6f..5fe1394 100644 --- a/net/ipv6/seg6_iptunnel.c +++ b/net/ipv6/seg6_iptunnel.c @@ -136,7 +136,7 @@ int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh, int proto) isrh->nexthdr = proto; hdr->daddr = isrh->segments[isrh->first_segment]; - set_tun_src(net, ip6_dst_idev(dst)->dev, &hdr->daddr, &hdr->saddr); + set_tun_src(net, dst->dev, &hdr->daddr, &hdr->saddr); #ifdef CONFIG_IPV6_SEG6_HMAC if (sr_has_hmac(isrh)) { -- 2.1.4