Received: by 2002:a05:6622:f08:0:0:0:0 with SMTP id l8csp4487997ivc; Tue, 3 Nov 2020 13:21:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJwSnZSoZ7szTb99tfrXPqQCuFhZ7hTSpu4MIo2QiH9brVytIjXPWSNWxj5DcZ04UzB7snsm X-Received: by 2002:a17:906:bce6:: with SMTP id op6mr12581539ejb.2.1604438477643; Tue, 03 Nov 2020 13:21:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604438477; cv=none; d=google.com; s=arc-20160816; b=rMBBLXtN8PyUZ9qz0Dhr2SLAmDH3HNd85EP/JbrGB/J4kBx3PdmrIc/5arGeIe+rAQ 1/bkZ7/nq3X/fTnVfHTXEw7e+r/ZupposdLbVsy6l4xXu8x4BHKl0vgji0vLsF1vqtoa C+mbHPKuhn4/97KIV+0MX54Qx4majgGdU0rr+UO3JaW5PEQS8Tf5Obp2c0Z1h24k5iWL 2yE/0rJVYejlXrtrROUJpVx2pLoOqjNV8hJsCkz5RB5oEpvCQ7ksPcGizciGMbjtRGSr YfAXKPngLhaa8k5oZPdyUR+xOwPWWW7Gu8YVFR/lB5xytgkPH3imPErKQph/ojQC60Ez Al9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tTz4HpX6AMh5gqlwznyehes2LufNJKbbn/J/Mgoauno=; b=SodmuY/h6FYiNaGbFkSrLfCuMzqVxCyEt8e+vzIxoIWNgvkmtGWJFYa1PORU2xpPsH S8ZNClMiZWslovDBo+JyPKLNe30pupGaDkhfIc8TnDgp3JCE+JzsNsdFOsOuGT4jqzVT RXTUYs7744uPMCZ7o01GYFXybBq2ULyj2uH+SfnDAAYJbkx+tHi82GkLyJ3YGvyAc4Nz 8Itwf4bBP31bAdMiTC56F7o5JuumiJsIsC7Ix5ek+sQPN1aO3P88UJfSojPNtyIEdQk3 AEyrTc59uKi5on3kK7jFkkeLWlQo1RlHegRw/lJZTj7aAZ8l+/Nc1B31pta1CNDVO9Tq gINA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zMqbMt5u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v4si11070101edl.447.2020.11.03.13.20.54; Tue, 03 Nov 2020 13:21:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zMqbMt5u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388645AbgKCVS3 (ORCPT + 99 others); Tue, 3 Nov 2020 16:18:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:49298 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388270AbgKCVJT (ORCPT ); Tue, 3 Nov 2020 16:09:19 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 1ACB7206B5; Tue, 3 Nov 2020 21:09:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437758; bh=F+MgyJy3M9UZmGV3BHb6dggJrNM6JemLtPXVNdjfttk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zMqbMt5u4zAsfN7KXW6K1mChXK3sNcQTONegFOo+wNcfskCfhKpggDXSGrQDkpT5k pwdl10mnArZmBreNzlR08pNB4iX1MoNU3pILvhc0Qhz1cl/kH/pl6rV+o8tDTKm7r4 YOq93A3xBHjEiXeQ0gQTkmPkO/U4AnFqrEAvcaaE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Masahiro Fujiwara , Jakub Kicinski Subject: [PATCH 4.14 004/125] gtp: fix an use-before-init in gtp_newlink() Date: Tue, 3 Nov 2020 21:36:21 +0100 Message-Id: <20201103203157.043802698@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203156.372184213@linuxfoundation.org> References: <20201103203156.372184213@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Masahiro Fujiwara [ Upstream commit 51467431200b91682b89d31317e35dcbca1469ce ] *_pdp_find() from gtp_encap_recv() would trigger a crash when a peer sends GTP packets while creating new GTP device. RIP: 0010:gtp1_pdp_find.isra.0+0x68/0x90 [gtp] Call Trace: gtp_encap_recv+0xc2/0x2e0 [gtp] ? gtp1_pdp_find.isra.0+0x90/0x90 [gtp] udp_queue_rcv_one_skb+0x1fe/0x530 udp_queue_rcv_skb+0x40/0x1b0 udp_unicast_rcv_skb.isra.0+0x78/0x90 __udp4_lib_rcv+0x5af/0xc70 udp_rcv+0x1a/0x20 ip_protocol_deliver_rcu+0xc5/0x1b0 ip_local_deliver_finish+0x48/0x50 ip_local_deliver+0xe5/0xf0 ? ip_protocol_deliver_rcu+0x1b0/0x1b0 gtp_encap_enable() should be called after gtp_hastable_new() otherwise *_pdp_find() will access the uninitialized hash table. Fixes: 1e3a3abd8b28 ("gtp: make GTP sockets in gtp_newlink optional") Signed-off-by: Masahiro Fujiwara Link: https://lore.kernel.org/r/20201027114846.3924-1-fujiwara.masahiro@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- drivers/net/gtp.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -667,10 +667,6 @@ static int gtp_newlink(struct net *src_n gtp = netdev_priv(dev); - err = gtp_encap_enable(gtp, data); - if (err < 0) - return err; - if (!data[IFLA_GTP_PDP_HASHSIZE]) { hashsize = 1024; } else { @@ -681,12 +677,16 @@ static int gtp_newlink(struct net *src_n err = gtp_hashtable_new(gtp, hashsize); if (err < 0) - goto out_encap; + return err; + + err = gtp_encap_enable(gtp, data); + if (err < 0) + goto out_hashtable; err = register_netdevice(dev); if (err < 0) { netdev_dbg(dev, "failed to register new netdev %d\n", err); - goto out_hashtable; + goto out_encap; } gn = net_generic(dev_net(dev), gtp_net_id); @@ -697,11 +697,11 @@ static int gtp_newlink(struct net *src_n return 0; +out_encap: + gtp_encap_disable(gtp); out_hashtable: kfree(gtp->addr_hash); kfree(gtp->tid_hash); -out_encap: - gtp_encap_disable(gtp); return err; }