From patchwork Wed May 9 21:07:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Stringer X-Patchwork-Id: 911186 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="ouqbL62r"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40h87j4GmJz9s3D for ; Thu, 10 May 2018 07:07:29 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965569AbeEIVH1 (ORCPT ); Wed, 9 May 2018 17:07:27 -0400 Received: from mail-ot0-f196.google.com ([74.125.82.196]:44531 "EHLO mail-ot0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964849AbeEIVHZ (ORCPT ); Wed, 9 May 2018 17:07:25 -0400 Received: by mail-ot0-f196.google.com with SMTP id g7-v6so41784777otj.11 for ; Wed, 09 May 2018 14:07:25 -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=eYEm4Yjfy/HAL370LdhYTmCCugsSZfz0fbUSG4Mw84g=; b=ouqbL62rykrWoGltu1MEUX1C3QEnHiQdvIj8uS6p2cXql7rM8g6BXWqUHMkMd5HA/1 yceU187eteSr92z32eH05Oirc4eStqbuodj4b3LcgeKRLVxVjXl/Vtr/DGoiegZSgq2o 6ZoKAkEQ4FeE/PPVm+KvdNMAjTNMGBN777r8EkclEjV/blKdbuFb3LCKM22dd3A8x3NF ifx3Q1WU0WTyYQ2JsvYN718kxOVWIDqe5uY8kt0Uwc0i/Pq2jtm1phNgcCxLXyqqjKBz 7GX/TVuaNyT/er32TqtHhS3sZ7ucdFHRTuiqXDWfU07lJSzrofPmAJngfdC4iuwC9HHM OJIA== 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=eYEm4Yjfy/HAL370LdhYTmCCugsSZfz0fbUSG4Mw84g=; b=MnfUQQfSSlNXg71fDjZKtfWPCTOt6oJl2v6S2ctGlei8ph6s0q8TMqiVs59RyKu8ZF /T0u+hXQLJY69P5wWmn5W9DgZACU+GTK+j6bxDU0xNQ0XRqjilLKSLr6xwPj5NHk0Bs7 pacUjDcGIFx7Z0NJmruzajQC1dmuKHO0btNhfWKLe0oa4JhIz18spv4JIjP8TA3NggcH ssxVn/jrXV/rXgGYAuGc/XrwkCtS/iLV/Lppuzupp+rYjEluLmtPyoOaJw2etm0zmilN H2bPxupcdBki4k0cvhGMY9HyNPmPrMOkaDYPbBYd8QFp5xREHi5pvGRwPoZnmQ0govex AHEQ== X-Gm-Message-State: ALKqPwefXmskyjZ3RSymDg6Vdx2hqaXdT/gTtHP/cHx4YeuT2mZ/OWpN JrGgYIaCuU+mwyfbKsLUHiQ= X-Google-Smtp-Source: AB8JxZpiDoLX8GwWyicPfjVEeb1t1wQR/60tbaDqeJ4UMROizLgu+JRFReKpqIanho526YR3hka+eQ== X-Received: by 2002:a9d:2b5c:: with SMTP id f28-v6mr6282449otd.317.1525900044803; Wed, 09 May 2018 14:07:24 -0700 (PDT) Received: from allosaurus.lan ([99.0.85.34]) by smtp.gmail.com with ESMTPSA id h125-v6sm13612921oic.54.2018.05.09.14.07.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 May 2018 14:07:24 -0700 (PDT) From: Joe Stringer To: daniel@iogearbox.net Cc: netdev@vger.kernel.org, ast@kernel.org, john.fastabend@gmail.com, kafai@fb.com Subject: [RFC bpf-next 02/11] bpf: Simplify ptr_min_max_vals adjustment Date: Wed, 9 May 2018 14:07:00 -0700 Message-Id: <20180509210709.7201-3-joe@wand.net.nz> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180509210709.7201-1-joe@wand.net.nz> References: <20180509210709.7201-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 --- 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 f40e089c3893..a32b560072d7 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -2602,20 +2602,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 275b4570b5b8..53439f40e1de 100644 --- a/tools/testing/selftests/bpf/test_verifier.c +++ b/tools/testing/selftests/bpf/test_verifier.c @@ -3497,7 +3497,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, }, @@ -4525,7 +4525,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 }, @@ -4546,7 +4546,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 }, @@ -4567,7 +4567,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 }, @@ -6864,7 +6864,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, }, { @@ -8538,7 +8538,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, }, @@ -8557,7 +8557,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, },