From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AH8x226b+RHEY7VTkttXywSIxevkV3lcIb/LHUNhARh6nNAGVQCcPTcqanFH6s9LhjuFK1UIyvEs ARC-Seal: i=1; a=rsa-sha256; t=1517256824; cv=none; d=google.com; s=arc-20160816; b=Ww7LVL8Wu01hEDTPqte2BZLjEC0j8N+vBu1VOImtCCn/gH4z6cXgq+RkVW7HThExs0 icj7zkoSDe/xwU+RK4FhXQlspxFjo8HZD7JKefVtm3iJdUi/ZiMV3ANjHrJl0bjTjer4 HOsGOnds3rtQJ0jONyUHG0FTPRIDQrAHllDvIpBhUSrhDJ9j4lJSwsZvXKNSuMe1IyYd wV/W70OKqOyQWmr34eHovovkwNPXpRnVOAOik9VRLJE9fUC20aVPySzmzDtCKbtRpzQL GJbDRD32JUyGB/9/idxdI7UTud9KVkBbYNV+ms4pHDzyaQFQEkuEvmzS6pPUk+nraJ5I gtAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=Az63aiSm9SEiJgyYOYj/0yYzt2oVxUzjz8ERwio1qRM=; b=Q6Kbd76DEUKEbBDKHpODdRaO7gmsUz36jtyi4s50cRAz04UjtxZPG6JLv8uXK1qHYR qLUpRS/fWWDnswLfs25PqhqDzgR0QXw2oSk5IE0T2WI9LEZsB8jmc6jebwAqWl9VK0b4 llw/qnn8njTIED6S+Dai/UveTpyNc+VD8Nqn+haeBRBnXE2vPS46GSH4gsEBja2AgBGo 7GxPhVNWHFlBL4NzCDu+KY06Jg13T+10d4QWSWCSuZ+W/mkM8ACd/5Rcn2zG4OOpM4nx qx8O3/th4CZ/F2OxHGlXJWgUZgg+x15pH8T7yIEJBE11lKj9QIZY872T7wErwtIvly9/ 9j2g== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning gregkh@linuxfoundation.org does not designate 90.92.71.90 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning gregkh@linuxfoundation.org does not designate 90.92.71.90 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "ast@kernel.org, stable@vger.kernel.org, Eric Dumazet" , syzbot , Alexei Starovoitov , Eric Dumazet Subject: [PATCH 4.9 64/66] bpf: fix divides by zero Date: Mon, 29 Jan 2018 13:57:28 +0100 Message-Id: <20180129123843.260028231@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180129123839.842860149@linuxfoundation.org> References: <20180129123839.842860149@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-LABELS: =?utf-8?b?IlxcU2VudCI=?= X-GMAIL-THRID: =?utf-8?q?1590958930789791287?= X-GMAIL-MSGID: =?utf-8?q?1590959091976033887?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet [ upstream commit c366287ebd698ef5e3de300d90cd62ee9ee7373e ] Divides by zero are not nice, lets avoid them if possible. Also do_div() seems not needed when dealing with 32bit operands, but this seems a minor detail. Fixes: bd4cf0ed331a ("net: filter: rework/optimize internal BPF interpreter's instruction set") Signed-off-by: Eric Dumazet Reported-by: syzbot Signed-off-by: Alexei Starovoitov Signed-off-by: Greg Kroah-Hartman --- kernel/bpf/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -642,7 +642,7 @@ select_insn: DST = tmp; CONT; ALU_MOD_X: - if (unlikely(SRC == 0)) + if (unlikely((u32)SRC == 0)) return 0; tmp = (u32) DST; DST = do_div(tmp, (u32) SRC); @@ -661,7 +661,7 @@ select_insn: DST = div64_u64(DST, SRC); CONT; ALU_DIV_X: - if (unlikely(SRC == 0)) + if (unlikely((u32)SRC == 0)) return 0; tmp = (u32) DST; do_div(tmp, (u32) SRC);