stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Borkmann <daniel@iogearbox.net>
To: gregkh@linuxfoundation.org
Cc: ast@kernel.org, stable@vger.kernel.org,
	Eric Dumazet <edumazet@google.com>
Subject: [PATCH stable 4.14 3/6] bpf: fix divides by zero
Date: Mon, 29 Jan 2018 00:36:44 +0100	[thread overview]
Message-ID: <20180128233647.21154-4-daniel@iogearbox.net> (raw)
In-Reply-To: <20180128233647.21154-1-daniel@iogearbox.net>

From: Eric Dumazet <edumazet@google.com>

[ 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 <edumazet@google.com>
Reported-by: syzbot <syzkaller@googlegroups.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
 kernel/bpf/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index aaa4424..2246115 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -949,7 +949,7 @@ static unsigned int ___bpf_prog_run(u64 *regs, const struct bpf_insn *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);
@@ -968,7 +968,7 @@ static unsigned int ___bpf_prog_run(u64 *regs, const struct bpf_insn *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);
-- 
2.9.5

  parent reply	other threads:[~2018-01-28 23:37 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-28 23:36 [PATCH stable 4.14 0/6] BPF stable patches Daniel Borkmann
2018-01-28 23:36 ` [PATCH stable 4.14 1/6] bpf: introduce BPF_JIT_ALWAYS_ON config Daniel Borkmann
2018-01-29 12:20   ` Patch "bpf: introduce BPF_JIT_ALWAYS_ON config" has been added to the 4.14-stable tree gregkh
2018-01-28 23:36 ` [PATCH stable 4.14 2/6] bpf: avoid false sharing of map refcount with max_entries Daniel Borkmann
2018-01-29 12:20   ` Patch "bpf: avoid false sharing of map refcount with max_entries" has been added to the 4.14-stable tree gregkh
2018-01-28 23:36 ` Daniel Borkmann [this message]
2018-01-29 12:20   ` Patch "bpf: fix divides by zero" " gregkh
2018-01-28 23:36 ` [PATCH stable 4.14 4/6] bpf: fix 32-bit divide by zero Daniel Borkmann
2018-01-29 12:20   ` Patch "bpf: fix 32-bit divide by zero" has been added to the 4.14-stable tree gregkh
2018-01-28 23:36 ` [PATCH stable 4.14 5/6] bpf: reject stores into ctx via st and xadd Daniel Borkmann
2018-01-29 12:20   ` Patch "bpf: reject stores into ctx via st and xadd" has been added to the 4.14-stable tree gregkh
2018-01-28 23:36 ` [PATCH stable 4.14 6/6] bpf, arm64: fix stack_depth tracking in combination with tail calls Daniel Borkmann
2018-01-29 12:20   ` Patch "bpf, arm64: fix stack_depth tracking in combination with tail calls" has been added to the 4.14-stable tree gregkh
2018-01-29 12:21 ` [PATCH stable 4.14 0/6] BPF stable patches Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180128233647.21154-4-daniel@iogearbox.net \
    --to=daniel@iogearbox.net \
    --cc=ast@kernel.org \
    --cc=edumazet@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).