Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp270735yba; Wed, 8 May 2019 20:21:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqy4Uxs16Yo5a5i/yGAyYMsjYCKy/vnIuqqrstTpBJ7ydSY+jlIaMVJu+vbLtccIryJvA27p X-Received: by 2002:aa7:86c3:: with SMTP id h3mr1800122pfo.169.1557372092288; Wed, 08 May 2019 20:21:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557372092; cv=none; d=google.com; s=arc-20160816; b=nw9pucbmcJYR1pYgH5HkJ5I+e2U1lm6YfRSecCabgltD09FoP+PO1DHFJMLgmVg6LT +5XRAc6zQ/rPUL2jgxhPLa1JJJQZX2gPvODBryIb/vSoSeH7PHfCd55UJiwalINsSqpp gYxhSn4LavsA+G6VaIND+wgCoScj4iy6IDTC8eGMdwIzHa1w7gvsbwgm50nHAXJ+x5Yt PGAAis6XMKbuzgXXTiAscMRNCqACmyCPWti748K7MOSRn2c/khCj51DJG55Cs2nAVftn ASZOBhft4tlc8GViyIdqB8IulNzfhGn9G8ctVr9L7c1U6fdlOF/GEE8ogTItcx2XZVEf LLyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=SEpVRT0sFSA4jKvBfITJ9tyoTPT9D4gvpxl8jWu+g1o=; b=vLKPc73TbsiWmMldNq6aZ6kWewu5Z6CSUAENGAxZ08/aI4LFB3zx78x+zCNOL2Jy0w utE9IWqmf4pE/tGQXY3gkujRBHgDaz4N6dzd0OgHFoXsyEQRzSXS3xgnlk7LRg3Hgk/9 DjKpXJ87S/v5LX/VV9hok1nV0tyK9a0TTQFzLD3cLvZTBg5MuH+EiMnVnBIKx2Ja2Mol OLnBvIew+ES5oYbWzpbh+jZAMsYg+yGY5vpD2k4lgA4aSnu/TcByAtIy5ah7xVmMXBII haNYCgAHdIYHjItyLfd+ueu7XzIal77xPjNOrn2ug9G1fQt0aOYTt9HMbKof8B7guZs5 e1Zg== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n19si1450450pgv.117.2019.05.08.20.21.15; Wed, 08 May 2019 20:21:32 -0700 (PDT) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726755AbfEIDUX (ORCPT + 99 others); Wed, 8 May 2019 23:20:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43052 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726251AbfEIDUW (ORCPT ); Wed, 8 May 2019 23:20:22 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C8EC33092649; Thu, 9 May 2019 03:20:22 +0000 (UTC) Received: from hp-dl380pg8-02.lab.eng.pek2.redhat.com (hp-dl380pg8-02.lab.eng.pek2.redhat.com [10.73.8.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id B8E295C221; Thu, 9 May 2019 03:20:20 +0000 (UTC) From: Jason Wang To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: yuehaibing@huawei.com, xiyou.wangcong@gmail.com, weiyongjun1@huawei.com, eric.dumazet@gmail.com, Jason Wang Subject: [PATCH net V3 1/2] tuntap: fix dividing by zero in ebpf queue selection Date: Wed, 8 May 2019 23:20:17 -0400 Message-Id: <1557372018-18544-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Thu, 09 May 2019 03:20:22 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/net/tun.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index e9ca1c0..dc62fc3 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -596,13 +596,18 @@ static u16 tun_automq_select_queue(struct tun_struct *tun, struct sk_buff *skb) 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, -- 1.8.3.1