From patchwork Thu Sep 27 23:26:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Stringer X-Patchwork-Id: 975959 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="mvoJhBNY"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42LrZ34jbzz9s1c for ; Fri, 28 Sep 2018 09:27:23 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728123AbeI1Frw (ORCPT ); Fri, 28 Sep 2018 01:47:52 -0400 Received: from mail-yw1-f68.google.com ([209.85.161.68]:40594 "EHLO mail-yw1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727635AbeI1Frw (ORCPT ); Fri, 28 Sep 2018 01:47:52 -0400 Received: by mail-yw1-f68.google.com with SMTP id z143-v6so1849245ywa.7 for ; Thu, 27 Sep 2018 16:27:07 -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=nYiTeLqzIYnUgMVeQ1tqw8pldup98Tbcdli6hwJf/Rg=; b=mvoJhBNYpiOGP63R9ZY6m+6157gll7XZFHE6gqiy4WZBDkW/LcJR6s4aCQ1MJvmx7u e2z7hLXxPOMjt+aqUCg5lllADUlSf+5tTyCqZroQU2VhMUudkwswRoUeAsUpLnDkU5bi RhZOaTCNKwGROLykuCnNRVTyVyYdM+dl1owiGmiXtJKw6zkhu5lcdGaXeHkBgncRLwMe HA7YA5Lp8mYTkWoY/AFJZM5GSbZDtJoOiIJ1e9MFWmy3IE3R4iHPlukvWcG6NpotMkJl /aw63Giq5/62EFnoLNGcRv/DJ08/k/KQhppCEJu9UsdYlNpB0RDAp8iPPyRkSXnbLtpJ 2Gmg== 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=nYiTeLqzIYnUgMVeQ1tqw8pldup98Tbcdli6hwJf/Rg=; b=t17j03+IgJTE8IzgkEcy/Oae0QIXo0ogLxsbVSNrtMZtFK2w1viK537A6dIX2fUS25 jBl+MkWix4bcbvjlr1Z1NvtnTHrgw+RVM8I1U0MROqBWdMYtJk2iWNDLcJ06jdfQ9Fap 671+lIKxN9NPazoZ9DtTIpQuht3kDldWj0TNosPDclnthGhsf+N7bGo9pybiyMOCfeXl KKt73oIwGgb743+W+BvyfE1NI40PYxHSbqOZP/khtcLTpJp4ISjvpWqkpeEYNkh57o2p kZDC2ipWKpZx1wKsxvK6cvBtlHwdXvAy/UMD9sVLr4lHs3vVpFU8Umsb+LnpLjYsw0rm oqGw== X-Gm-Message-State: ABuFfoi0ACatJopqeNt+mfdAdr1gtNc4bocuDIv4nlhwIPmPlPUBBBM6 eCWNF8mY1dhvmyC8ApBmxmBeeGrG X-Google-Smtp-Source: ACcGV60WOSYuSjMd8GvKVw9aC6C4e68ud2oamAOXAS8UiR3qZHn1vn+htiFG0e3dIjGsSTVMXbou3Q== X-Received: by 2002:a81:7209:: with SMTP id n9-v6mr7368732ywc.277.1538090826708; Thu, 27 Sep 2018 16:27:06 -0700 (PDT) Received: from localhost.localdomain ([99.0.85.34]) by smtp.gmail.com with ESMTPSA id w6-v6sm4810717ywg.3.2018.09.27.16.27.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 16:27:06 -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: [PATCHv3 bpf-next 02/12] bpf: Simplify ptr_min_max_vals adjustment Date: Thu, 27 Sep 2018 16:26:49 -0700 Message-Id: <20180927232659.14348-3-joe@wand.net.nz> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180927232659.14348-1-joe@wand.net.nz> References: <20180927232659.14348-1-joe@wand.net.nz> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org An upcoming commit will add another two pointer types that need very similar behaviour, so generalise this function now. Signed-off-by: Joe Stringer Acked-by: Alexei Starovoitov --- kernel/bpf/verifier.c | 22 ++++++++++----------- tools/testing/selftests/bpf/test_verifier.c | 14 ++++++------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 18347de310ad..87b75efc1dc1 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -2669,20 +2669,18 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env, return -EACCES; } - if (ptr_reg->type == PTR_TO_MAP_VALUE_OR_NULL) { - verbose(env, "R%d pointer arithmetic on PTR_TO_MAP_VALUE_OR_NULL prohibited, null-check it first\n", - dst); - return -EACCES; - } - if (ptr_reg->type == CONST_PTR_TO_MAP) { - verbose(env, "R%d pointer arithmetic on CONST_PTR_TO_MAP prohibited\n", - dst); + switch (ptr_reg->type) { + case PTR_TO_MAP_VALUE_OR_NULL: + verbose(env, "R%d pointer arithmetic on %s prohibited, null-check it first\n", + dst, reg_type_str[ptr_reg->type]); return -EACCES; - } - if (ptr_reg->type == PTR_TO_PACKET_END) { - verbose(env, "R%d pointer arithmetic on PTR_TO_PACKET_END prohibited\n", - dst); + case CONST_PTR_TO_MAP: + case PTR_TO_PACKET_END: + verbose(env, "R%d pointer arithmetic on %s prohibited\n", + dst, reg_type_str[ptr_reg->type]); return -EACCES; + default: + break; } /* In case of 'scalar += pointer', dst_reg inherits pointer type and id. diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c index c7d25f23baf9..a90be44f61e0 100644 --- a/tools/testing/selftests/bpf/test_verifier.c +++ b/tools/testing/selftests/bpf/test_verifier.c @@ -3638,7 +3638,7 @@ static struct bpf_test tests[] = { BPF_MOV64_IMM(BPF_REG_0, 0), BPF_EXIT_INSN(), }, - .errstr = "R3 pointer arithmetic on PTR_TO_PACKET_END", + .errstr = "R3 pointer arithmetic on pkt_end", .result = REJECT, .prog_type = BPF_PROG_TYPE_SCHED_CLS, }, @@ -4896,7 +4896,7 @@ static struct bpf_test tests[] = { BPF_EXIT_INSN(), }, .fixup_map1 = { 4 }, - .errstr = "R4 pointer arithmetic on PTR_TO_MAP_VALUE_OR_NULL", + .errstr = "R4 pointer arithmetic on map_value_or_null", .result = REJECT, .prog_type = BPF_PROG_TYPE_SCHED_CLS }, @@ -4917,7 +4917,7 @@ static struct bpf_test tests[] = { BPF_EXIT_INSN(), }, .fixup_map1 = { 4 }, - .errstr = "R4 pointer arithmetic on PTR_TO_MAP_VALUE_OR_NULL", + .errstr = "R4 pointer arithmetic on map_value_or_null", .result = REJECT, .prog_type = BPF_PROG_TYPE_SCHED_CLS }, @@ -4938,7 +4938,7 @@ static struct bpf_test tests[] = { BPF_EXIT_INSN(), }, .fixup_map1 = { 4 }, - .errstr = "R4 pointer arithmetic on PTR_TO_MAP_VALUE_OR_NULL", + .errstr = "R4 pointer arithmetic on map_value_or_null", .result = REJECT, .prog_type = BPF_PROG_TYPE_SCHED_CLS }, @@ -7253,7 +7253,7 @@ static struct bpf_test tests[] = { BPF_EXIT_INSN(), }, .fixup_map_in_map = { 3 }, - .errstr = "R1 pointer arithmetic on CONST_PTR_TO_MAP prohibited", + .errstr = "R1 pointer arithmetic on map_ptr prohibited", .result = REJECT, }, { @@ -8927,7 +8927,7 @@ static struct bpf_test tests[] = { BPF_MOV64_IMM(BPF_REG_0, 0), BPF_EXIT_INSN(), }, - .errstr = "R3 pointer arithmetic on PTR_TO_PACKET_END", + .errstr = "R3 pointer arithmetic on pkt_end", .result = REJECT, .prog_type = BPF_PROG_TYPE_XDP, }, @@ -8946,7 +8946,7 @@ static struct bpf_test tests[] = { BPF_MOV64_IMM(BPF_REG_0, 0), BPF_EXIT_INSN(), }, - .errstr = "R3 pointer arithmetic on PTR_TO_PACKET_END", + .errstr = "R3 pointer arithmetic on pkt_end", .result = REJECT, .prog_type = BPF_PROG_TYPE_XDP, },