Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1989597imu; Fri, 14 Dec 2018 04:09:19 -0800 (PST) X-Google-Smtp-Source: AFSGD/VpBVp5EJs9MXNkQZUqZr98UyrOKQkbL1xRCrmsMKs+YTb+evqtU4PvxRDbKfNP2CFI3QlO X-Received: by 2002:a17:902:7588:: with SMTP id j8mr2646717pll.215.1544789359081; Fri, 14 Dec 2018 04:09:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544789359; cv=none; d=google.com; s=arc-20160816; b=FHSL1YDCqH6E9+7EsfwUVxkyZkf8S8/6+X5Jd4S0rABeBirmTgsXkOwZqFTKhGPleT tIXuo2XdKT0m5IPpZHPTHiAecVOfbqS9nV8ttbRbJu/i4nKeeGsMB1GrUnHC8BpfXjnD zIDjgf279E8fdYXDbpUeseHs5s2QT1n7HGqr1/JS8mL5wMej8s3n1VP4cl2HwM1YU1zK 43uIYR5GCaZaY6F1OZZ+OD28myzlvfrkqFmMIHZ0btfTCIol2Z2sHxtIjLWmub+K0Mtf 3cB4QFk3yK5e596FYz1I95BVAS1VlxZ7sJ/PQLk09TTTAoFkg7xummXn9231WHW96iGl do6g== 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=JzbGVpr0ksHeW2gL6yN0Dgmj9HOBatA8u9Nuj8Uko7k=; b=cYCe9h3pb537+/gwyXgisqjTucaeoGlyLXBnzUig8CNbmmYlxjZtxTWLcv0icuy+Q6 Cwb7Pr5SDL7rqFYJVExMkSAlPfD5pUsLwQUu26p/VeBXwnlYpuTYE5EbqjNMd8Umrwsp +zPgavywSZ2dvhCVKRca/lg921y9ns1KbqsbNGlR5HiJQ5OHgkP0A7PuZ5aOniTD+zUF EFB1AjWYrZzUY5Pv8K1O1J7ywai7upkkpN4QGWGX5QpjebLWW8RISVtVu/rcr1zpWUrM /WDy0UuGSo3shUVQLHNNXpxS1LqhKjH2zK2OHzyAr1E0UlShyqPkPVCMMCfnh85ynFGE XA3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=H4FjlRL1; 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 k7si3900507pgm.462.2018.12.14.04.09.01; Fri, 14 Dec 2018 04:09:19 -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; dkim=pass header.i=@kernel.org header.s=default header.b=H4FjlRL1; 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 S1731130AbeLNMH3 (ORCPT + 99 others); Fri, 14 Dec 2018 07:07:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:52674 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730158AbeLNMH0 (ORCPT ); Fri, 14 Dec 2018 07:07:26 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 AFDEB2147D; Fri, 14 Dec 2018 12:07:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544789245; bh=6+WBP6JLgm7pO2DIRdO+66i/jbAbwpcIB5nQJXNWutE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H4FjlRL1x+Uf2sDGESuvfTSWiexsHrhjevPIj9S0etj0RYI1HaVeVtAiQXMHTEMvr 4oCNGk0dXwktmYW+r3kIq3tNRs0Lmm6LTwlpQGshoXlqsI1K9DGYgqhQFw9A6qepud o0yKHA6YxNU5xYVJEuQtAnhFROngTGMwIXlOYpkE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+4fc427c7af994b0948be@syzkaller.appspotmail.com, Edward Cree , Yonghong Song , Alexei Starovoitov Subject: [PATCH 4.19 142/142] bpf: fix off-by-one error in adjust_subprog_starts Date: Fri, 14 Dec 2018 13:00:27 +0100 Message-Id: <20181214115752.714813088@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181214115747.053633987@linuxfoundation.org> References: <20181214115747.053633987@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Edward Cree commit afd594240806acc138cf696c09f2f4829d55d02f upstream. When patching in a new sequence for the first insn of a subprog, the start of that subprog does not change (it's the first insn of the sequence), so adjust_subprog_starts should check start <= off (rather than < off). Also added a test to test_verifier.c (it's essentially the syz reproducer). Fixes: cc8b0b92a169 ("bpf: introduce function calls (function boundaries)") Reported-by: syzbot+4fc427c7af994b0948be@syzkaller.appspotmail.com Signed-off-by: Edward Cree Acked-by: Yonghong Song Signed-off-by: Alexei Starovoitov Signed-off-by: Greg Kroah-Hartman --- kernel/bpf/verifier.c | 2 +- tools/testing/selftests/bpf/test_verifier.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -5283,7 +5283,7 @@ static void adjust_subprog_starts(struct return; /* NOTE: fake 'exit' subprog should be updated as well. */ for (i = 0; i <= env->subprog_cnt; i++) { - if (env->subprog_info[i].start < off) + if (env->subprog_info[i].start <= off) continue; env->subprog_info[i].start += len - 1; } --- a/tools/testing/selftests/bpf/test_verifier.c +++ b/tools/testing/selftests/bpf/test_verifier.c @@ -12511,6 +12511,25 @@ static struct bpf_test tests[] = { .prog_type = BPF_PROG_TYPE_SCHED_CLS, .result = ACCEPT, }, + { + "calls: ctx read at start of subprog", + .insns = { + BPF_MOV64_REG(BPF_REG_6, BPF_REG_1), + BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 1, 0, 5), + BPF_JMP_REG(BPF_JSGT, BPF_REG_0, BPF_REG_0, 0), + BPF_MOV64_REG(BPF_REG_1, BPF_REG_6), + BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 1, 0, 2), + BPF_MOV64_REG(BPF_REG_1, BPF_REG_0), + BPF_EXIT_INSN(), + BPF_LDX_MEM(BPF_B, BPF_REG_9, BPF_REG_1, 0), + BPF_MOV64_IMM(BPF_REG_0, 0), + BPF_EXIT_INSN(), + }, + .prog_type = BPF_PROG_TYPE_SOCKET_FILTER, + .errstr_unpriv = "function calls to other bpf functions are allowed for root only", + .result_unpriv = REJECT, + .result = ACCEPT, + }, }; static int probe_filter_length(const struct bpf_insn *fp)