From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 202E7C33CAA for ; Tue, 21 Jan 2020 12:05:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E033C217F4 for ; Tue, 21 Jan 2020 12:05:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579608326; bh=yVgRYe+9GyBgRwrh264lI4FWyLkEJf7A7KAYA5vpI1o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=j+1GbduAwuzqoqQ3PXBsd6LdRWFJ0t5MsZ8ZkeG8yHitkPR9BS7aohT7XEkW9GhER AQSPZtyS357AUgd9jWBLEkXkoje8NUPO51Ju95LWZ35b3kgeayxBQVxpoDnrCPJmxd OdFvmETxz7LLMzZ/Et1wnezfs4vZJsSHujeUNsMI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729409AbgAUMFZ convert rfc822-to-8bit (ORCPT ); Tue, 21 Jan 2020 07:05:25 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:57230 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728829AbgAUMFY (ORCPT ); Tue, 21 Jan 2020 07:05:24 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-262-4K2eQSvsOyquuIyY_KWYkA-1; Tue, 21 Jan 2020 07:05:20 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5B91318C35A1; Tue, 21 Jan 2020 12:05:18 +0000 (UTC) Received: from krava.redhat.com (unknown [10.43.17.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 09AC05C28D; Tue, 21 Jan 2020 12:05:15 +0000 (UTC) From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann Cc: John Fastabend , netdev@vger.kernel.org, bpf@vger.kernel.org, Andrii Nakryiko , Yonghong Song , Martin KaFai Lau , Jakub Kicinski , David Miller , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= Subject: [PATCH 1/6] bpf: Allow ctx access for pointers to scalar Date: Tue, 21 Jan 2020 13:05:07 +0100 Message-Id: <20200121120512.758929-2-jolsa@kernel.org> In-Reply-To: <20200121120512.758929-1-jolsa@kernel.org> References: <20200121120512.758929-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: 4K2eQSvsOyquuIyY_KWYkA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kernel.org Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: 8BIT Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When accessing the context we allow access to arguments with scalar type and pointer to struct. But we omit pointer to scalar type, which is the case for many functions and same case as when accessing scalar. Adding the check if the pointer is to scalar type and allow it. Acked-by: John Fastabend Signed-off-by: Jiri Olsa --- kernel/bpf/btf.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 832b5d7fd892..207ae554e0ce 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -3668,7 +3668,7 @@ bool btf_ctx_access(int off, int size, enum bpf_access_type type, const struct bpf_prog *prog, struct bpf_insn_access_aux *info) { - const struct btf_type *t = prog->aux->attach_func_proto; + const struct btf_type *tp, *t = prog->aux->attach_func_proto; struct bpf_prog *tgt_prog = prog->aux->linked_prog; struct btf *btf = bpf_prog_get_target_btf(prog); const char *tname = prog->aux->attach_func_name; @@ -3730,6 +3730,17 @@ bool btf_ctx_access(int off, int size, enum bpf_access_type type, */ return true; + tp = btf_type_by_id(btf, t->type); + /* skip modifiers */ + while (btf_type_is_modifier(tp)) + tp = btf_type_by_id(btf, tp->type); + + if (btf_type_is_int(tp) || btf_type_is_enum(tp)) + /* This is a pointer scalar. + * It is the same as scalar from the verifier safety pov. + */ + return true; + /* this is a pointer to another type */ info->reg_type = PTR_TO_BTF_ID; -- 2.24.1