Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17945474ybl; Thu, 2 Jan 2020 15:20:13 -0800 (PST) X-Google-Smtp-Source: APXvYqwaa7czX1l+o4uG91a6V63jcZQBxFr/KFu2rcMM+Lz2J0niJHhwAmwsVt6NiRpp/XkQ8FKZ X-Received: by 2002:aca:cf11:: with SMTP id f17mr3278524oig.40.1578007213616; Thu, 02 Jan 2020 15:20:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578007213; cv=none; d=google.com; s=arc-20160816; b=mjhK/bdElxcUMT+GAiz9+rFCqPhAgPFZXSSutkkdgiHWUiPr5OngsK4GlbqALgp8A+ LcdcmI9y7iwuFHcdc5MrR+qcoBWNJTQeCOlBZWMzUVDZm+NyvywvA6wB0CG6hkzbMFVh zjfo6duXQ6mWsFmmK8VJssGK9/uoV/UfNbI/GCockZaf54eimIsf46wv/BTpngEiL6C+ y5uQtiX9aVJbLOsT/pKbZ48Kb+aMDoMIPV3lbBKVJO4swJAu4dt1o3ygFn6URlzf9FTP nIywLOdfRoEJSedJJItyIsioIbERpZBgW1E7gyU0kb1SHORNG+sv25sYqjPHYihX+MrM ukFg== 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=6ILqN3ZMaAMHJaNpN3U2W5VQlF00Kb9mkib43CL5Isw=; b=eytt6ADhOYS7Bvd33cHj++hZUgiFMr/PwIDclT3q+8Cs+IsX5ewt/VRMZF+5fHD5q8 TT0gzXdt/CNLYCRGXcFj+3l5V0B/bE5yh1PvpTGLDzMYHi9fK1jAfVz5Y/Z4uRbGiTvH pMZIOS9xVemPQBaeDR9nRIvCyngNXL0EFNj7wjwLT5MjVKC8Cm+j1I/oDPK61iY5AAYB DAkjhZSO/rj5Y9CSMgdHesONH902zLQuI8sHMDnpWQJD3D5aDUkwYSRyT3/36yVDcMBM 2B404jXl7IKbHrKr15XlhviemJw1RjBZLmqAy2DLLxmL+Gs1hp9FF6qNJJH9F5LXfw7A KYyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Vy2G5yRw; 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 v141si26421752oif.161.2020.01.02.15.19.59; Thu, 02 Jan 2020 15:20:13 -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=Vy2G5yRw; 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 S1728171AbgABWSX (ORCPT + 99 others); Thu, 2 Jan 2020 17:18:23 -0500 Received: from mail.kernel.org ([198.145.29.99]:33236 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727677AbgABWSN (ORCPT ); Thu, 2 Jan 2020 17:18:13 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 88B9721582; Thu, 2 Jan 2020 22:18:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578003493; bh=LSdjDLvKNHfNxie0XJXACoE9tDOscECLo/lBTlcOcjU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vy2G5yRwoLcO/4pgw0wdTzqEHAfPXfnlXRtW4Oq0GRnBpDgYqJ+lLQM4VQQlpa+Oo /YmAO8BdgfSus3SytlQOX2fM5btcEP1Ndi79EJEn0BpJkAw4KaQD8LUK3TA++7DnxF b1IgwwPwTRuktDYyo0XjPSi7eC+XC/POhjKmjOTE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Taehee Yoo , Jakub Kicinski Subject: [PATCH 5.4 184/191] gtp: do not allow adding duplicate tid and ms_addr pdp context Date: Thu, 2 Jan 2020 23:07:46 +0100 Message-Id: <20200102215849.150307012@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102215829.911231638@linuxfoundation.org> References: <20200102215829.911231638@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Taehee Yoo [ Upstream commit 6b01b1d9b2d38dc84ac398bfe9f00baff06a31e5 ] GTP RX packet path lookups pdp context with TID. If duplicate TID pdp contexts are existing in the list, it couldn't select correct pdp context. So, TID value should be unique. GTP TX packet path lookups pdp context with ms_addr. If duplicate ms_addr pdp contexts are existing in the list, it couldn't select correct pdp context. So, ms_addr value should be unique. Fixes: 459aa660eb1d ("gtp: add initial driver for datapath of GPRS Tunneling Protocol (GTP-U)") Signed-off-by: Taehee Yoo Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- drivers/net/gtp.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -928,24 +928,31 @@ static void ipv4_pdp_fill(struct pdp_ctx } } -static int ipv4_pdp_add(struct gtp_dev *gtp, struct sock *sk, - struct genl_info *info) +static int gtp_pdp_add(struct gtp_dev *gtp, struct sock *sk, + struct genl_info *info) { + struct pdp_ctx *pctx, *pctx_tid = NULL; struct net_device *dev = gtp->dev; u32 hash_ms, hash_tid = 0; - struct pdp_ctx *pctx; + unsigned int version; bool found = false; __be32 ms_addr; ms_addr = nla_get_be32(info->attrs[GTPA_MS_ADDRESS]); hash_ms = ipv4_hashfn(ms_addr) % gtp->hash_size; + version = nla_get_u32(info->attrs[GTPA_VERSION]); - hlist_for_each_entry_rcu(pctx, >p->addr_hash[hash_ms], hlist_addr) { - if (pctx->ms_addr_ip4.s_addr == ms_addr) { - found = true; - break; - } - } + pctx = ipv4_pdp_find(gtp, ms_addr); + if (pctx) + found = true; + if (version == GTP_V0) + pctx_tid = gtp0_pdp_find(gtp, + nla_get_u64(info->attrs[GTPA_TID])); + else if (version == GTP_V1) + pctx_tid = gtp1_pdp_find(gtp, + nla_get_u32(info->attrs[GTPA_I_TEI])); + if (pctx_tid) + found = true; if (found) { if (info->nlhdr->nlmsg_flags & NLM_F_EXCL) @@ -953,6 +960,11 @@ static int ipv4_pdp_add(struct gtp_dev * if (info->nlhdr->nlmsg_flags & NLM_F_REPLACE) return -EOPNOTSUPP; + if (pctx && pctx_tid) + return -EEXIST; + if (!pctx) + pctx = pctx_tid; + ipv4_pdp_fill(pctx, info); if (pctx->gtp_version == GTP_V0) @@ -1076,7 +1088,7 @@ static int gtp_genl_new_pdp(struct sk_bu goto out_unlock; } - err = ipv4_pdp_add(gtp, sk, info); + err = gtp_pdp_add(gtp, sk, info); out_unlock: rcu_read_unlock();