From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B28EC04E53 for ; Wed, 15 May 2019 11:25:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0D48E2089E for ; Wed, 15 May 2019 11:25:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557919509; bh=lgP2eJjeACuVhUDY1zgIkgmzILEegNIYX0SgacTjsOc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=LjMJbET+lpw7XitpFVpAHiSmTT4E2h9Jl81eGPS+xIR/vCKudAoOnEZQbXIP0Cz0s D9avwyhZidzpLM1XdI5CiBbuim7whqMzzi277ri9uCFhAyRDs51p13vSkjM3cOqF1i Fe1w1/0G67N9IeM0sIqMhx2H2rk7syzIiCKBGGXw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731929AbfEOLZH (ORCPT ); Wed, 15 May 2019 07:25:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:35778 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729575AbfEOLZH (ORCPT ); Wed, 15 May 2019 07:25:07 -0400 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 671B320818; Wed, 15 May 2019 11:25:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557919506; bh=lgP2eJjeACuVhUDY1zgIkgmzILEegNIYX0SgacTjsOc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FX5P+6jIRD72Cuj2Huv7oBVZkbiapBfyVoNsGVgLojVc0C85FmpNvkIE0rn+8hAbd r3j07SXywNop6568yyTdxP0uOzJQUnW89a+gvYo/ysp/S3BaAL3MH84sc6BjCUdGRd A9SiHK2Ih7tx1fFXzg/ejgB3W50v86mRqp7WDlvM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , Jason Wang , Eric Dumazet , "David S. Miller" Subject: [PATCH 4.19 102/113] tuntap: fix dividing by zero in ebpf queue selection Date: Wed, 15 May 2019 12:56:33 +0200 Message-Id: <20190515090701.371335121@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515090652.640988966@linuxfoundation.org> References: <20190515090652.640988966@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Jason Wang [ Upstream commit a35d310f03a692bf4798eb309a1950a06a150620 ] We need check if tun->numqueues is zero (e.g for the persist device) before trying to use it for modular arithmetic. Reported-by: Eric Dumazet Fixes: 96f84061620c6("tun: add eBPF based queue selection method") Signed-off-by: Jason Wang Reviewed-by: Eric Dumazet Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/tun.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -599,13 +599,18 @@ static u16 tun_automq_select_queue(struc static u16 tun_ebpf_select_queue(struct tun_struct *tun, struct sk_buff *skb) { struct tun_prog *prog; + u32 numqueues; u16 ret = 0; + numqueues = READ_ONCE(tun->numqueues); + if (!numqueues) + return 0; + prog = rcu_dereference(tun->steering_prog); if (prog) ret = bpf_prog_run_clear_cb(prog->prog, skb); - return ret % tun->numqueues; + return ret % numqueues; } static u16 tun_select_queue(struct net_device *dev, struct sk_buff *skb,