From patchwork Tue Oct 2 20:35:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Stringer X-Patchwork-Id: 978015 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=wand.net.nz Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Kj+KFaK4"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42PrWr5YCWz9s7T for ; Wed, 3 Oct 2018 06:35:52 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727471AbeJCDU7 (ORCPT ); Tue, 2 Oct 2018 23:20:59 -0400 Received: from mail-yw1-f65.google.com ([209.85.161.65]:44998 "EHLO mail-yw1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727379AbeJCDU7 (ORCPT ); Tue, 2 Oct 2018 23:20:59 -0400 Received: by mail-yw1-f65.google.com with SMTP id s73-v6so1342803ywg.11 for ; Tue, 02 Oct 2018 13:35:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=CxGU+WZePbCRyBdWomq3eMkEWtR8FRwQmoKJgm30qzE=; b=Kj+KFaK48oAQTdSUMVe52wOqbzlIfxR18iWui4sA29IcbRpMoRXIeog3HDnbXVd3z0 KXd4iC1Y+YDi0MivxbfQi5qJWA3PiGITCCDMYLJ8rhhumGAmJax3PSft8OKJiVXjc+bf 6DQrhkzchbQ82rvk2n1nMV9G6eMfDanSuNbTnFfErep+tNg5wVx7V8xWw8xPbC+md6yk AA4exDKE2vZQTtZzLJSawvC392odgp6YVB9VTSs9/SDvvGUePd/x8yeUqJAA0WkTRF9z x+3VFyD8flqO7kg45XtmXc9HJfx3a1BetLPQK3bUp25PtLrb/jrFjVJP+3R6vi4ts5Vu 8fyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=CxGU+WZePbCRyBdWomq3eMkEWtR8FRwQmoKJgm30qzE=; b=CW6UUdEvf1t4Pa//VfAg/h977Q14aUVZUhY4N4/Zzmh+Ex9m6bVohKliyNb2d/feYX tFllGQKzVesgHUfWJrkzqy/wQkGKuh0/ITMaHEccAIepRVB6Bhs3gQ2N9O19oeFnF5HE /dJ8VZKr1z4OFs4aRZiql9USRNrWnnuNE417c2/h37BAA6Sy8Ea877JORT1J0YgD/S/g XnmT5ZkNtih+zxz1UTXcJYFDhTDTdDE6JxWGRhC52dxZ7HvrICmeVnfzw/3aqH02FaAl vvBXpHGrRpBPDa4+knYjIoicwCgR8U5H3EzVCp32swZl6OTaD67pUzz9uDlUdYY4W5pa rmxQ== X-Gm-Message-State: ABuFfog1DGmT5G03qkE7A3P5fu/Brz17wAGtnTStr7O9ILYHEhrOtPfi +dTez/+pr4/Ndq67bsSVw0Q= X-Google-Smtp-Source: ACcGV63xjR+ZmYA5X4/gx8lp8YXJR2uGfa+68fxvJ7haIiV+79jEU50U5Ytu6zy/Vv2hb+BewGQqpw== X-Received: by 2002:a81:3856:: with SMTP id f83-v6mr9264463ywa.81.1538512549509; Tue, 02 Oct 2018 13:35:49 -0700 (PDT) Received: from localhost.localdomain ([99.0.85.34]) by smtp.gmail.com with ESMTPSA id o131-v6sm4555361ywb.107.2018.10.02.13.35.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Oct 2018 13:35:49 -0700 (PDT) From: Joe Stringer To: daniel@iogearbox.net Cc: netdev@vger.kernel.org, ast@kernel.org, john.fastabend@gmail.com, tgraf@suug.ch, kafai@fb.com, nitin.hande@gmail.com, mauricio.vasquez@polito.it Subject: [PATCHv4 bpf-next 03/13] bpf: Reuse canonical string formatter for ctx errs Date: Tue, 2 Oct 2018 13:35:31 -0700 Message-Id: <20181002203541.26599-4-joe@wand.net.nz> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181002203541.26599-1-joe@wand.net.nz> References: <20181002203541.26599-1-joe@wand.net.nz> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The array "reg_type_str" provides canonical formatting of register types, however a couple of places would previously check whether a register represented the context and write the name "context" directly. An upcoming commit will add another pointer type to these statements, so to provide more accurate error messages in the verifier, update these error messages to use "reg_type_str" instead. Signed-off-by: Joe Stringer --- v4: New patch. --- kernel/bpf/verifier.c | 7 +++---- tools/testing/selftests/bpf/test_verifier.c | 10 +++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index abf567200574..8b4e70eeced2 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -1763,8 +1763,7 @@ static int check_xadd(struct bpf_verifier_env *env, int insn_idx, struct bpf_ins if (is_ctx_reg(env, insn->dst_reg) || is_pkt_reg(env, insn->dst_reg)) { verbose(env, "BPF_XADD stores into R%d %s is not allowed\n", - insn->dst_reg, is_ctx_reg(env, insn->dst_reg) ? - "context" : "packet"); + insn->dst_reg, reg_type_str[insn->dst_reg]); return -EACCES; } @@ -4871,8 +4870,8 @@ static int do_check(struct bpf_verifier_env *env) return err; if (is_ctx_reg(env, insn->dst_reg)) { - verbose(env, "BPF_ST stores into R%d context is not allowed\n", - insn->dst_reg); + verbose(env, "BPF_ST stores into R%d %s is not allowed\n", + insn->dst_reg, reg_type_str[insn->dst_reg]); return -EACCES; } diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c index a90be44f61e0..6e0b3f148cdb 100644 --- a/tools/testing/selftests/bpf/test_verifier.c +++ b/tools/testing/selftests/bpf/test_verifier.c @@ -3276,7 +3276,7 @@ static struct bpf_test tests[] = { BPF_ST_MEM(BPF_DW, BPF_REG_1, offsetof(struct __sk_buff, mark), 0), BPF_EXIT_INSN(), }, - .errstr = "BPF_ST stores into R1 context is not allowed", + .errstr = "BPF_ST stores into R1 inv is not allowed", .result = REJECT, .prog_type = BPF_PROG_TYPE_SCHED_CLS, }, @@ -3288,7 +3288,7 @@ static struct bpf_test tests[] = { BPF_REG_0, offsetof(struct __sk_buff, mark), 0), BPF_EXIT_INSN(), }, - .errstr = "BPF_XADD stores into R1 context is not allowed", + .errstr = "BPF_XADD stores into R1 inv is not allowed", .result = REJECT, .prog_type = BPF_PROG_TYPE_SCHED_CLS, }, @@ -5266,7 +5266,7 @@ static struct bpf_test tests[] = { .errstr_unpriv = "R2 leaks addr into mem", .result_unpriv = REJECT, .result = REJECT, - .errstr = "BPF_XADD stores into R1 context is not allowed", + .errstr = "BPF_XADD stores into R1 inv is not allowed", }, { "leak pointer into ctx 2", @@ -5281,7 +5281,7 @@ static struct bpf_test tests[] = { .errstr_unpriv = "R10 leaks addr into mem", .result_unpriv = REJECT, .result = REJECT, - .errstr = "BPF_XADD stores into R1 context is not allowed", + .errstr = "BPF_XADD stores into R1 inv is not allowed", }, { "leak pointer into ctx 3", @@ -12230,7 +12230,7 @@ static struct bpf_test tests[] = { BPF_EXIT_INSN(), }, .result = REJECT, - .errstr = "BPF_XADD stores into R2 packet", + .errstr = "BPF_XADD stores into R2 ctx", .prog_type = BPF_PROG_TYPE_XDP, }, {