From patchwork Fri Sep 21 17:10:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Stringer X-Patchwork-Id: 973327 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="po3u0u3n"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42H0VR3tyNz9sCS for ; Sat, 22 Sep 2018 03:10:55 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390829AbeIUXAl (ORCPT ); Fri, 21 Sep 2018 19:00:41 -0400 Received: from mail-yb1-f196.google.com ([209.85.219.196]:43057 "EHLO mail-yb1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390788AbeIUXAl (ORCPT ); Fri, 21 Sep 2018 19:00:41 -0400 Received: by mail-yb1-f196.google.com with SMTP id w80-v6so5712542ybe.10 for ; Fri, 21 Sep 2018 10:10:53 -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=FNq2oLHKUmqg+Zy7nlHKOncZEHJDaRhgOfXV4iUVVEQ=; b=po3u0u3nWRS5TknWSEx6Un7OES4ehAh8NHzdMuOnG8nXvdi7VLZeYoQB1utZP/dxm2 8mfIeWyD16gZS3qNJvKccorAiGpg/ZaMIQZZMBzLfiwFNYjl6BKnpnZ9b0hNlYvGLWXM AqqajcFhmTm+rONC0WxB4vVdKV6l3wJKWGGQ/lJTCkMlo9QX0KJpK+2sYlVgk6l+Gedf pjyGXlmjyyYY3rn7NOGwkdICrNw3+edmAOdUgzZBirDQOOfy6AzgyjaE1kuLyX9piaSH G0AwZM/mNVB7QJyOWVfW7KDdxAY1HVqbfziq6IS8KzTfdqc98Y4fvjxMaF2prvPB9x/j dOPA== 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=FNq2oLHKUmqg+Zy7nlHKOncZEHJDaRhgOfXV4iUVVEQ=; b=aIFDcaxWd7OyFOICjRbgPyClAw2snuiJB6bTj0k4zBvHV5VnLqhyqE4giGHNgch08P fuBGGoX0byUad0RPbn4LtwAiLqiv/hh6DAx96L3lUe1YhBEi0jqv2rBhYmTnes72gapr o+dsRjWFifgbXi8JfI76r6a5+QnBYpyGm1PLQbRJA/aDZyqOgq6+h7M03oYSoMGpixSJ YDxHjK5xfn87IUDY2oTsHGN0vIemrFvOPN7PmU248jBNoUcJfhoUM2wUAdwKbt0RIl+N uhT0hnZEG1TyF4kf4lwLgAhHeFiz5xOQuhqawAOVGPH2GOKb6znDKRuaqRmb1TFj+nyN 8TKA== X-Gm-Message-State: APzg51AJf5r9WfOLBS2oC22LDcJSJ/PujU/zVOKahke3Up3FtDK26RzY KwCE5iC8bCgbuAEbXX3rLTM= X-Google-Smtp-Source: ANB0VdZz0kaZ5EIcmeIdrnlkD8zZ3WjzFb7UyFX+zLrUVgEoprKVP1B9TvUGDIpc8uIIDzOGb85NFA== X-Received: by 2002:a25:8806:: with SMTP id c6-v6mr21622751ybl.12.1537549852395; Fri, 21 Sep 2018 10:10:52 -0700 (PDT) Received: from localhost.localdomain ([99.0.85.34]) by smtp.gmail.com with ESMTPSA id h10-v6sm9930972ywa.35.2018.09.21.10.10.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Sep 2018 10:10:51 -0700 (PDT) From: Joe Stringer To: ast@kernel.org Cc: netdev@vger.kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, tgraf@suug.ch, kafai@fb.com, nitin.hande@gmail.com, mauricio.vasquez@polito.it Subject: [PATCHv2 bpf-next 02/11] bpf: Simplify ptr_min_max_vals adjustment Date: Fri, 21 Sep 2018 10:10:34 -0700 Message-Id: <20180921171043.20823-3-joe@wand.net.nz> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180921171043.20823-1-joe@wand.net.nz> References: <20180921171043.20823-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 62ce45d9c558..a889398ba43d 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -2667,20 +2667,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 67c412d19c09..ceb55a9f3da9 100644 --- a/tools/testing/selftests/bpf/test_verifier.c +++ b/tools/testing/selftests/bpf/test_verifier.c @@ -3637,7 +3637,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, }, @@ -4780,7 +4780,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 }, @@ -4801,7 +4801,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 }, @@ -4822,7 +4822,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 }, @@ -7137,7 +7137,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, }, { @@ -8811,7 +8811,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, }, @@ -8830,7 +8830,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, },