Received: by 10.223.176.5 with SMTP id f5csp1146926wra; Fri, 2 Feb 2018 12:01:59 -0800 (PST) X-Google-Smtp-Source: AH8x224Lu8sovZpwEUjPdkqQigZChrEpU9U/ZYAPJwur44DkMljclsraAizc5iBb1ZhM5m5MAvTw X-Received: by 10.99.126.71 with SMTP id o7mr13433024pgn.450.1517601718918; Fri, 02 Feb 2018 12:01:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517601718; cv=none; d=google.com; s=arc-20160816; b=W2sZCUg3bGr5zbkOUUMsv8paKgOZB0sP8tRcnn0xRcrjWElfb1ai8rsyaLJpLTSS40 +/XNABOJE1iPjQqtQ+hupSOImZ7vaTO5VbUf0jRjcmkicsYM9IACfifVXO7EjXKhp68c dBUnntCOGw2tia7E8h7KoIAx663rgeT3O54Wg6qwpbrli4hHiU7E/bBDHgYnUux9j4Xf EEYlZmPAt0x69YqBid3ANvg0/eep63hpVVzgD8zUtsL/4jDnn4SABaqbGE1p/ql8d0Io KPnoEQq2kG4iuh4Q7Wnnn2NwmefUNAa7vkzI+yeSEt1KyjtcpSxoiY7TStu0UKCxK/PM IJpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=uccpZixSY6+G46tcKeRaUk6mpW6ToZIAP7rt8cxkvmI=; b=pdFoJa0TdCD0djUmed3exfpf45w6ZhSVZ9w2vVp0RtNioQdy0RdRj6yfWbyspIbTdg BQWcf2TgRn6hXFACSdUpYkYxjF4dXLUuU84aCxBXXmNzs86A8vmb2pBlnJWNSc18LmRH B+3AMkOaX+TFcebYpdlMJmiDa2eab2lxWXR/fwWC0B53Ye/0FF99QLIZXz0deNFgz/pE EXGi/lRX/U8JZBmQrHn3wfNup9sSX4CL5rBKPb+RlO5pTUVgMVg9UdIVfCtbFla0B1JP dBPRGl2FzJGtXId+E1ozQtscv900zclo+kAeAuU116Wusks3YtaVSEGZWaASxlL16BBF rrzg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r2-v6si2409788pli.324.2018.02.02.12.01.43; Fri, 02 Feb 2018 12:01:58 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754561AbeBBSbJ (ORCPT + 99 others); Fri, 2 Feb 2018 13:31:09 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:34804 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752201AbeBBRAi (ORCPT ); Fri, 2 Feb 2018 12:00:38 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 94068DF5; Fri, 2 Feb 2018 17:00:36 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+48340bb518e88849e2e3@syzkaller.appspotmail.com, Alexei Starovoitov , Daniel Borkmann Subject: [PATCH 4.4 09/67] bpf: fix 32-bit divide by zero Date: Fri, 2 Feb 2018 17:57:38 +0100 Message-Id: <20180202140816.287771547@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140815.091718203@linuxfoundation.org> References: <20180202140815.091718203@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexei Starovoitov [ upstream commit 68fda450a7df51cff9e5a4d4a4d9d0d5f2589153 ] due to some JITs doing if (src_reg == 0) check in 64-bit mode for div/mod operations mask upper 32-bits of src register before doing the check Fixes: 622582786c9e ("net: filter: x86: internal BPF JIT") Fixes: 7a12b5031c6b ("sparc64: Add eBPF JIT.") Reported-by: syzbot+48340bb518e88849e2e3@syzkaller.appspotmail.com Signed-off-by: Alexei Starovoitov Signed-off-by: Daniel Borkmann Signed-off-by: Greg Kroah-Hartman --- kernel/bpf/verifier.c | 18 ++++++++++++++++++ net/core/filter.c | 4 ++++ 2 files changed, 22 insertions(+) --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -2248,6 +2248,24 @@ static int fixup_bpf_calls(struct verifi int i, cnt, delta = 0; for (i = 0; i < insn_cnt; i++, insn++) { + if (insn->code == (BPF_ALU | BPF_MOD | BPF_X) || + insn->code == (BPF_ALU | BPF_DIV | BPF_X)) { + /* due to JIT bugs clear upper 32-bits of src register + * before div/mod operation + */ + insn_buf[0] = BPF_MOV32_REG(insn->src_reg, insn->src_reg); + insn_buf[1] = *insn; + cnt = 2; + new_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt); + if (!new_prog) + return -ENOMEM; + + delta += cnt - 1; + env->prog = prog = new_prog; + insn = new_prog->insnsi + i + delta; + continue; + } + if (insn->code != (BPF_JMP | BPF_CALL)) continue; --- a/net/core/filter.c +++ b/net/core/filter.c @@ -430,6 +430,10 @@ do_pass: convert_bpf_extensions(fp, &insn)) break; + if (fp->code == (BPF_ALU | BPF_DIV | BPF_X) || + fp->code == (BPF_ALU | BPF_MOD | BPF_X)) + *insn++ = BPF_MOV32_REG(BPF_REG_X, BPF_REG_X); + *insn = BPF_RAW_INSN(fp->code, BPF_REG_A, BPF_REG_X, 0, fp->k); break;