Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6263044imu; Mon, 21 Jan 2019 06:03:42 -0800 (PST) X-Google-Smtp-Source: ALg8bN6RLopNID+tabd4V76HbwWc74i2ecFYZxRRhkNidXcqA8+/trEB5UQk6bTtu5eSgeQ7P64Q X-Received: by 2002:a63:1904:: with SMTP id z4mr21207061pgl.135.1548079422356; Mon, 21 Jan 2019 06:03:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548079422; cv=none; d=google.com; s=arc-20160816; b=j+FGYazkSF1DlTQXXzC3NhVIvpHjRtT8lK8g20zZSKJLtzG0B5wjaJovjKGP7U4Bp9 oA22pjIHpgdfAqvJjcWT3RiKvYPICceL06saukqdDMKywxSkB5gt5s/ASrUB0trY/xln WhBg6shHhxCzJEVC+z5mVYEUys4YezATQHVXgLZidx0KIYw7/7aLFBBQN88yIxTqjmsK TGcw0eyG7p36AIywxK31QOAh8DisyzF0308ciiM9GEIWNtrNpj8VrhOlTNjKj+Q1U0De VHXtuExgiWf5p37qtCCfpoGk+8l5gbeJhK041WEEN1EQnYINJympqrMS7/ZZPGgkL9tX bTpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=G7oq1+XEE2t8jLbMEcTOzQNO9Cc0Eb1f55dvp9UxU2k=; b=PyPDzWZEvJmZiyC7nKAaIMFNBSB4xRW+rhNXYE0KITsbSGfEjFjOJG4vK0E5gVl1W5 Rn6T+MevpRtDMI2lv2nqgw7wOfnIdGdvlxJy/ji3+xVopQIXYMFxKnCHxxtBy1c1gl/3 GUp1vcB2nv72GNGWXC1WUd99+IbQEG8WrhBTzFlTnDgEEg5mTbu+f4yUg1A+B9yVlPa/ 4ltjdJlHL1RGptcjeMyDitJCUJFTvHU9OliC1bkUHpngwdxLH/fkwI72S/7jEuu8b+ly VuBwil/2v/42G+X4ZYWtXQVHd6nTXjltxOcTuorkLnnL95pu7kFRa55mp9O0qxWbP4bW gpOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HyAaGz4V; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z22si12335329pfd.197.2019.01.21.06.03.16; Mon, 21 Jan 2019 06:03:42 -0800 (PST) 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=@kernel.org header.s=default header.b=HyAaGz4V; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732583AbfAUOBK (ORCPT + 99 others); Mon, 21 Jan 2019 09:01:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:48062 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732545AbfAUOBI (ORCPT ); Mon, 21 Jan 2019 09:01:08 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9E2162084C; Mon, 21 Jan 2019 14:01:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548079267; bh=qO4hrlfJeRROVq4QeOaayvUXPtCNXiyUW+7J75zUQdw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HyAaGz4V8s9q6qAgfpu+BGkZM+SSPUgdyZOGxWgF5+6Y6IPY8Lnr3emLgTvciLfdt NERWEuesskyTtsocus4v1UlO1wEYMUZTL4G5m0dp1EN3x3BnoEZcKwMzXK2jbrQfqO yKVM7rV9MIAcuyn1NnSFiQh7m6FJXHe+vNzXfP3w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , Piotr Sawicki , Casey Schaufler , syzbot , "David S. Miller" Subject: [PATCH 4.19 65/99] ipv6: make icmp6_send() robust against null skb->dev Date: Mon, 21 Jan 2019 14:48:57 +0100 Message-Id: <20190121134916.434406493@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190121134913.924726465@linuxfoundation.org> References: <20190121134913.924726465@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet commit 8d933670452107e41165bea70a30dffbd281bef1 upstream. syzbot was able to crash one host with the following stack trace : kasan: GPF could be caused by NULL-ptr deref or user memory access general protection fault: 0000 [#1] PREEMPT SMP KASAN CPU: 0 PID: 8625 Comm: syz-executor4 Not tainted 4.20.0+ #8 RIP: 0010:dev_net include/linux/netdevice.h:2169 [inline] RIP: 0010:icmp6_send+0x116/0x2d30 net/ipv6/icmp.c:426 icmpv6_send smack_socket_sock_rcv_skb security_sock_rcv_skb sk_filter_trim_cap __sk_receive_skb dccp_v6_do_rcv release_sock This is because a RX packet found socket owned by user and was stored into socket backlog. Before leaving RCU protected section, skb->dev was cleared in __sk_receive_skb(). When socket backlog was finally handled at release_sock() time, skb was fed to smack_socket_sock_rcv_skb() then icmp6_send() We could fix the bug in smack_socket_sock_rcv_skb(), or simply make icmp6_send() more robust against such possibility. In the future we might provide to icmp6_send() the net pointer instead of infering it. Fixes: d66a8acbda92 ("Smack: Inform peer that IPv6 traffic has been blocked") Signed-off-by: Eric Dumazet Cc: Piotr Sawicki Cc: Casey Schaufler Reported-by: syzbot Acked-by: Casey Schaufler Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv6/icmp.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/net/ipv6/icmp.c +++ b/net/ipv6/icmp.c @@ -421,10 +421,10 @@ static int icmp6_iif(const struct sk_buf static void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info, const struct in6_addr *force_saddr) { - struct net *net = dev_net(skb->dev); struct inet6_dev *idev = NULL; struct ipv6hdr *hdr = ipv6_hdr(skb); struct sock *sk; + struct net *net; struct ipv6_pinfo *np; const struct in6_addr *saddr = NULL; struct dst_entry *dst; @@ -435,12 +435,16 @@ static void icmp6_send(struct sk_buff *s int iif = 0; int addr_type = 0; int len; - u32 mark = IP6_REPLY_MARK(net, skb->mark); + u32 mark; if ((u8 *)hdr < skb->head || (skb_network_header(skb) + sizeof(*hdr)) > skb_tail_pointer(skb)) return; + if (!skb->dev) + return; + net = dev_net(skb->dev); + mark = IP6_REPLY_MARK(net, skb->mark); /* * Make sure we respect the rules * i.e. RFC 1885 2.4(e)