Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp463395yba; Wed, 15 May 2019 04:33:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqwzNWB5Pzk4W3unv0S+wwPKi+p7jR0CLb8zlb1+FRL0UZ4xrIUaOApBrM+C9izrZqtQkJ/Z X-Received: by 2002:a63:5516:: with SMTP id j22mr40843822pgb.370.1557920019980; Wed, 15 May 2019 04:33:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557920019; cv=none; d=google.com; s=arc-20160816; b=qvd+u9kAGqDYn9hFmsKjKu9zUGEg8Bx5Lv6MGR7P0qP5BUAhttw7u3be9ABmKM/Vl/ eb/YuInbHkSpRMizHty1neYo9vV6h59z2FAok/H/KggkOf2bWzctgwYQmvFARGDOLO9A reSg0jIUnMcA3NkgMRG1lawm5Yj5dSX0A1rJ2CH5urRYmj1/lBUvCQecWh9WRvmIHQbn 2MqFYnUULqKVXR67HbcXxdSUPQFQRF+6z4sqc3ncbDr80fevOGLs718v0mKs/JNHVSGM xkeipYIRII2JZQUmJzXsEUf9FWGQrYWxipzwbL5D4tvbtWtyPeKK7cQT3zMTSDhbFpSE eVXw== 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=AsLUA7S5psw/tOhHxTZO6KodoINkg7Hb86BGk6lO0+A=; b=D1GGGurK30gBtnCDjDMPFh5qddkd6YDYqPBUEZbdiLvZJMhPAkX4bnJqUaQpPoXqAL NROMEJxvIizgiSnLfpVu6mUvde0MaId40GH/q0pspCPywgczI08sewINPK43tfA8Oy0q gFz4sZFMSgf1SAQXWCQu09Wb4/UWJuNCGRmLl4lnLL8H99eo6uQt10tXqfDaHJXA3gVr y5CKJiRRgJt9CKsLn6PTgZCu0ujj87GjCEoX7h3105vQt+S0hc6oXwytnov6wIR6hcvQ E1zexlb45fJcLyW9Gn2606ii67JMX+E9Zuz3O/Me2yKIDwPSfeoCoB2MqNyteaALYTnl wfWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1XB+UiEK; 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 h8si1560636pgk.221.2019.05.15.04.33.25; Wed, 15 May 2019 04:33:39 -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; dkim=pass header.i=@kernel.org header.s=default header.b=1XB+UiEK; 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 S1732933AbfEOLbs (ORCPT + 99 others); Wed, 15 May 2019 07:31:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:43494 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732904AbfEOLbn (ORCPT ); Wed, 15 May 2019 07:31:43 -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 F1BD92084A; Wed, 15 May 2019 11:31:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557919902; bh=iajolfmDkExgkErxz/VgBj8MRe1bH0OyF4BKtvzNiw4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1XB+UiEKYmYld7ROq3tGaHnxfwep3lfIwLwUieQ4D4NGRy5JRrdwXIQQzwlw/5UzP nbbgPQFIZhF+SLckWl1SkYY6p5tl7/mnhWOBcvrgwNb7sY9Qe/rr9jBqXpxZ1Hhng4 f+a+gpOg+oJBsi3m0cM8m9KxS/GgxLbyFm1DLfX0= 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 5.0 123/137] tuntap: fix dividing by zero in ebpf queue selection Date: Wed, 15 May 2019 12:56:44 +0200 Message-Id: <20190515090702.660420018@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515090651.633556783@linuxfoundation.org> References: <20190515090651.633556783@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: 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 @@ -596,13 +596,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,