Received: by 2002:a17:90a:9103:0:0:0:0 with SMTP id k3csp11794714pjo; Thu, 2 Jan 2020 14:24:14 -0800 (PST) X-Google-Smtp-Source: APXvYqxBu5EemtgAxUz/JBNr9R5sf8mil7Lxb1Sh8oVWQ0dYP+8TZgbzS1/ZXqrf+qL0luj9dveL X-Received: by 2002:a05:6830:1cd3:: with SMTP id p19mr90137094otg.118.1578003853941; Thu, 02 Jan 2020 14:24:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578003853; cv=none; d=google.com; s=arc-20160816; b=WE0ZMQnjvH4KgA47qXpGkHNeDfWoW+tCR7YCdoUTv+9xrXco22LtKyMww2lpH01xrU Yms/kgwzbHhkDaSiMszWsBYHkZWSFYDTh3O1lCCP82DYmg5ugIQ3dQ6bQn0SDeIEgFnP IFWEojPIoG+Qw4irP+N/8HtvGGCkNsq3asFWEQs3Q563jWWDdR170m7nnZMvJAK2lkJA nQJJgNbSGI2YcprTObKm24grSyz5ApRp33LZUS5RDrc2BGBaQnlDdmn5d/7FMTUx1Uhl eG8uauEg4YHI+Cvzm75/dD6OyR45HaVdoTrkogZzT5XTNOecvRrQ7/W4QdA3nC/EFL0U 2G5A== 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=iuafYLN7Jhq2KvpYSVRrckTSM6qm5QNACyoqu6cv9rs=; b=agz6jR2g+r4PFB5swk+1953yEPvJ0Os08O+xFniRKovkfIdwCmColAqrX/PpO5ruKt 2NT4V+0GKecsyGXY2iQ4ATTLqyEX38c7OXpY2hySx4wEWsuutBX3QlGId62R9rsS0zAV bKImwkdwaUpO3JfX+GDedJ039dSQ1x0JfneP8d5bURjyvEM04nMnIF8vQp/LsFKZfUia yaiKo+sHTBg8KRLlHxqBArqNENy1/xvhDwcTwSfCV4x9+xsew9e+fz8AQrcOKKalx4bz 0YaxeWjLLt9kepP2S1Lo8OnsUPESOM8kL9TvBLWenM1t+K8uDyQ9h4DV39kdiIex1+xu RolQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tKyIIeMB; 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 e73si29371395oib.145.2020.01.02.14.24.02; Thu, 02 Jan 2020 14:24: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=tKyIIeMB; 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 S1728909AbgABWX0 (ORCPT + 99 others); Thu, 2 Jan 2020 17:23:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:45414 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729239AbgABWXY (ORCPT ); Thu, 2 Jan 2020 17:23:24 -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 331B921835; Thu, 2 Jan 2020 22:23:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578003802; bh=TCNtj8JLZts8V49Z1W+5EOba1+rRErBBd94PFw8z4Rs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tKyIIeMBH9v8A6K83Fp6kRc+4EpNeW/Lv1Xtd3HBTvC5rrGXVpXQmbgNrY4/GuQNq 1ZeRqZpLeXvDMzwVpHIdUxkcac6Mnk/ymcBxnApSPsRjPWTSfJzE3pRAP6REcFUjo5 MJBpznBVlvcLoveZpzED7eVP4C5vopQNNWfuec94= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Taehee Yoo , Jakub Kicinski Subject: [PATCH 4.19 109/114] gtp: fix wrong condition in gtp_genl_dump_pdp() Date: Thu, 2 Jan 2020 23:08:01 +0100 Message-Id: <20200102220040.127179483@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102220029.183913184@linuxfoundation.org> References: <20200102220029.183913184@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 94a6d9fb88df43f92d943c32b84ce398d50bf49f ] gtp_genl_dump_pdp() is ->dumpit() callback of GTP module and it is used to dump pdp contexts. it would be re-executed because of dump packet size. If dump packet size is too big, it saves current dump pointer (gtp interface pointer, bucket, TID value) then it restarts dump from last pointer. Current GTP code allows adding zero TID pdp context but dump code ignores zero TID value. So, last dump pointer will not be found. In addition, this patch adds missing rcu_read_lock() in gtp_genl_dump_pdp(). 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 | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -42,7 +42,6 @@ struct pdp_ctx { struct hlist_node hlist_addr; union { - u64 tid; struct { u64 tid; u16 flow; @@ -1249,43 +1248,46 @@ static int gtp_genl_dump_pdp(struct sk_b struct netlink_callback *cb) { struct gtp_dev *last_gtp = (struct gtp_dev *)cb->args[2], *gtp; + int i, j, bucket = cb->args[0], skip = cb->args[1]; struct net *net = sock_net(skb->sk); - struct gtp_net *gn = net_generic(net, gtp_net_id); - unsigned long tid = cb->args[1]; - int i, k = cb->args[0], ret; struct pdp_ctx *pctx; + struct gtp_net *gn; + + gn = net_generic(net, gtp_net_id); if (cb->args[4]) return 0; + rcu_read_lock(); list_for_each_entry_rcu(gtp, &gn->gtp_dev_list, list) { if (last_gtp && last_gtp != gtp) continue; else last_gtp = NULL; - for (i = k; i < gtp->hash_size; i++) { - hlist_for_each_entry_rcu(pctx, >p->tid_hash[i], hlist_tid) { - if (tid && tid != pctx->u.tid) - continue; - else - tid = 0; - - ret = gtp_genl_fill_info(skb, - NETLINK_CB(cb->skb).portid, - cb->nlh->nlmsg_seq, - cb->nlh->nlmsg_type, pctx); - if (ret < 0) { + for (i = bucket; i < gtp->hash_size; i++) { + j = 0; + hlist_for_each_entry_rcu(pctx, >p->tid_hash[i], + hlist_tid) { + if (j >= skip && + gtp_genl_fill_info(skb, + NETLINK_CB(cb->skb).portid, + cb->nlh->nlmsg_seq, + cb->nlh->nlmsg_type, pctx)) { cb->args[0] = i; - cb->args[1] = pctx->u.tid; + cb->args[1] = j; cb->args[2] = (unsigned long)gtp; goto out; } + j++; } + skip = 0; } + bucket = 0; } cb->args[4] = 1; out: + rcu_read_unlock(); return skb->len; }