Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp806788pxb; Tue, 3 Nov 2020 13:04:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJyyDrC748Pfr5DnaQb8igBJo57BICdf/xPHDm/QlRqtRl8INoaKoSBUmf4TcW609Ly5j/P7 X-Received: by 2002:a05:6402:c8d:: with SMTP id cm13mr21017697edb.340.1604437472494; Tue, 03 Nov 2020 13:04:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604437472; cv=none; d=google.com; s=arc-20160816; b=hRV4XkW5ABxRKpQZexJn1KAK/KjGMGrxe46yCsTeFnanRZKuCgJo+DePfcvS7+b9FT 3qaa7zk9wbP3DXtSn2y8Dq7jMB8u314ET+ivkgWSmEUnlxSrW+EBIjj8c88v/2lHQp7Q cA8osVb5qEzAxpbkXf6hCcZk9BKSHyBxQf4JmE2SCu30ZOkLoLwnDW0tlnPgMuKy+FDv m5P4UE5ImCBtYvsjyI0MGUIz+I4noqsVnjuWFrlXvbkmk4I7CTZ/ZFcrBGJNj9AWObXJ apIcRB6+Noy3F0/4uS9FfkOkRiNxW1YEwvdKmnj/qKuZC8AEVPQ3yBEd3X54Dj/yQmdM TmrQ== 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=sqM5N4uJ/ZJoWxQtZov76MGplwbCcs1o4DQ52t0EhXNEaBjEyMnTUwGBFoHlXU3nq/ YnEnL1xhzUEp3wmez84usIhhBgNFMtikS0MlUsu2Ya0bcEfALknel58yP2z/wpKlNOQ8 5WhdAitI7dNQoG0zjxShSs2wU2qoeq8MyqU0fhCOX0w0hFAbHR2JXfVq7ftGDesEEveo 9vc7ewKzfTH0Jn5QelRHalVJpFLW1dA2xdkcxD/RCV4u32+hc5o6iD2FTFedhr45QRLR pSzjEPj8PbYd+nozcidB3f5G2/FvTMIbQ5ewcdbRjfC4dKdB5q6jioVDBJbLNiIvYtKG +aPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Xz3jZFg8; 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 b1si4433ejb.290.2020.11.03.13.04.09; Tue, 03 Nov 2020 13:04:32 -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=Xz3jZFg8; 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 S1733284AbgKCVC5 (ORCPT + 99 others); Tue, 3 Nov 2020 16:02:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:40140 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387699AbgKCVCw (ORCPT ); Tue, 3 Nov 2020 16:02:52 -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 00CED206B5; Tue, 3 Nov 2020 21:02:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437372; bh=F+MgyJy3M9UZmGV3BHb6dggJrNM6JemLtPXVNdjfttk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xz3jZFg89wWpNuqq2/yjHQ9qcrQTUf7ckC/pUdrQC07HfwvQMnzP4h2yw2b4RaWTK 9jmM/iY2pV5Rrv+yqIRRhKfNp8UYWBvKl1Nd8q7Wor0G3wcFUeyTJUaNqN8oRshbw8 yG9dkprKC8nTFhatudu8R/YayJmzMOj8jQfTtJVM= 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.19 010/191] gtp: fix an use-before-init in gtp_newlink() Date: Tue, 3 Nov 2020 21:35:02 +0100 Message-Id: <20201103203234.006055498@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203232.656475008@linuxfoundation.org> References: <20201103203232.656475008@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; }