Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp3766678pxb; Fri, 4 Feb 2022 16:22:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJyrm8ID0tre1eOVOt6mxYqZByFoJQ4Om4yiP4efyO1zGUoa8G8OHpyBk4vUFBTKcF0Mr3hL X-Received: by 2002:aa7:d650:: with SMTP id v16mr1844258edr.444.1644020537322; Fri, 04 Feb 2022 16:22:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644020537; cv=none; d=google.com; s=arc-20160816; b=AmOkAu0B99keCLYrTDEqWRuoS+ulWZgfHAlncjHmkoFEwDlng+n6QjJ/qDXpmxPprP NCckUEMvpqShkEuludgdBGfdlW2n/V0Ss1QYiw/At6buRgUJX11cmFocOTSN+DQUN4z9 ba8a1EZgpsXj3ymv8dY7hglRTeK0SY3OUuVpKKwlh1PpBQxzT7sW3AxbZTReTakWnpI2 ipihFW3nmNNM1Qkynr3ZgUYde6t8d2tK6QQv1XYSDb74O7XANqH6C3uI1kNZlbkf3hw4 rnV3hNaUkBPjd0IEjGraJuj7VPgy28M32orjP+jIi3ZgJ90LmLOjFpSHkMHN/rlc6jPn fuvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature:dkim-filter; bh=saUwzlBmQw7hsfFOi/x4+4YXpypfM/v+QZi+szh+Erk=; b=e0fX3rgKEuBak7yz/EmzxFLqGk/GIDiOhaG2D2moXIqr121we1D5VWZNwaUFSx6/5N F4LDnwoMEJL9Q0SCvUXliOsEa4oB2n396xs5U6lSum+/3o91HCyfREujJbJtqdpvnQea px2PiV68n+VuTpadd9PK7aXkYYTMXNGY2IWGtuul/jiZodzB1Bb4gQ4cHl48i1nyP0Ld AZd4nioYFe68Y79yHjplsgqNUbXWJ4WMOPmqGnSrdOYjAEYfo3Am2jVFvW3+/j6dKO21 p0DuFpDlCyq6C9jx3p5Hl2s9jNxoIF6SCnxoClxWvHP4tEJ2nuRlMArcQnj1XTr6HXnI /Bng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=g8MLyghp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w20si2375841eje.135.2022.02.04.16.21.52; Fri, 04 Feb 2022 16:22:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=g8MLyghp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243437AbiBBSap (ORCPT + 99 others); Wed, 2 Feb 2022 13:30:45 -0500 Received: from linux.microsoft.com ([13.77.154.182]:56588 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346674AbiBBSam (ORCPT ); Wed, 2 Feb 2022 13:30:42 -0500 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by linux.microsoft.com (Postfix) with ESMTPSA id 69D1A20B8010; Wed, 2 Feb 2022 10:30:42 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 69D1A20B8010 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1643826642; bh=saUwzlBmQw7hsfFOi/x4+4YXpypfM/v+QZi+szh+Erk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=g8MLyghpydSh+CK2jMQTSrXhsn//Y0c3uHtI/JQefyjy58xhROhlmQrjZM3kM1tH8 Nj59sVqulm+8CNGgUfF6SansldHxSUlzRcQnXiMNvPphufNatgsCGLsO0Eun7REomJ CukH/nVDGQmitpfRzs2XB7JW37cWN7xMluwbQgns= Received: by mail-pj1-f41.google.com with SMTP id y5-20020a17090aca8500b001b8127e3d3aso315718pjt.3; Wed, 02 Feb 2022 10:30:42 -0800 (PST) X-Gm-Message-State: AOAM531ItDtPZosOnTrlddhw/opomMedyzjlj+LjZizRYJrxZcCddJiZ qqoZwIvszodGZILnfKOeApRbqHWhYuRzhOcgUSk= X-Received: by 2002:a17:90b:4c92:: with SMTP id my18mr9483017pjb.15.1643826641822; Wed, 02 Feb 2022 10:30:41 -0800 (PST) MIME-Version: 1.0 References: <20211210172034.13614-1-mcroce@linux.microsoft.com> <177da568-8410-36d6-5f95-c5792ba47d62@fb.com> In-Reply-To: From: Matteo Croce Date: Wed, 2 Feb 2022 19:30:05 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH bpf-next] bpf: limit bpf_core_types_are_compat() recursion To: Alexei Starovoitov Cc: Yonghong Song , bpf , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jan 29, 2022 at 2:11 AM Alexei Starovoitov wrote: > > On Fri, Jan 28, 2022 at 4:36 PM Matteo Croce wrote: > > > > On Fri, Jan 28, 2022 at 9:09 PM Alexei Starovoitov > > wrote: > > > > > > On Fri, Jan 28, 2022 at 10:51 AM Matteo Croce > > > wrote: > > > > > > > > On Fri, Jan 28, 2022 at 6:31 AM Alexei Starovoitov > > > > wrote: > > > > > > > > > > On Mon, Dec 20, 2021 at 10:34 PM Yonghong Song wrote: > > > > > > > > > > > > > > > > > > https://reviews.llvm.org/D116063 improved the error message as below > > > > > > to make it a little bit more evident what is the problem: > > > > > > > > > > > > $ clang -target bpf -O2 -g -c bug.c > > > > > > > > > > > > fatal error: error in backend: SubroutineType not supported for > > > > > > BTF_TYPE_ID_REMOTE reloc > > > > > > > > > > Hi Matteo, > > > > > > > > > > Are you still working on a test? > > > > > What's a timeline to repost the patch set? > > > > > > > > > > Thanks! > > > > > > > > Hi Alexei, > > > > > > > > The change itself is ready, I'm just stuck at writing a test which > > > > will effectively calls __bpf_core_types_are_compat() with some > > > > recursion. > > > > I guess that I have to generate a BTF_KIND_FUNC_PROTO type somehow, so > > > > __bpf_core_types_are_compat() is called again to check the prototipe > > > > arguments type. > > > > I tried with these two, with no luck: > > > > > > > > // 1 > > > > typedef int (*func_proto_typedef)(struct sk_buff *); > > > > bpf_core_type_exists(func_proto_typedef); > > > > > > > > // 2 > > > > void func_proto(int, unsigned int); > > > > bpf_core_type_id_kernel(func_proto); > > > > > > > > Which is a simple way to generate a BTF_KIND_FUNC_PROTO BTF field? > > > > > > What do you mean 'no luck'? > > > Have you tried what progs/test_core_reloc_type_id.c is doing? > > > typedef int (*func_proto_typedef)(long); > > > bpf_core_type_id_kernel(func_proto_typedef); > > > > > > Without macros: > > > typedef int (*func_proto_typedef)(long); > > > > > > int test() { > > > return __builtin_btf_type_id(*(typeof(func_proto_typedef) *)0, 1); > > > } > > > int test2() { > > > return __builtin_preserve_type_info(*(typeof(func_proto_typedef) *)0, 0); > > > } > > > > > > > > > compiles fine and generates relos. > > > > Yes, I tried that one. > > We reach bpf_core_apply_relo_insn() but not bpf_core_spec_match(), > > since cands->len is 0. > > > > [ 16.424821] bpf_core_apply_relo_insn:1202 cands->len: 0 > > > > That's a very simple raw_tracepoint/sys_enter program: > > Did you forget to attach it ? > > If it's doing bpf_core_type_id_kernel(func_proto_typedef) > then, of course, cands->len will be zero. > You need to add this typedef to bpf_testmod first. > Then use two typedef flavors: func_proto_typedef___match > and func_proto_typedef___doesnt_match > with matching and mismatching prototypes, so > both can call into bpf_core_types_are_compat() and > return different results. > Then build on top to test recursion. Hi, I'm able to trigger __bpf_core_types_are_compat() recursion now. What do you think to generate also a prototype which needs 3 recursion calls, thus invalid, and check that it returns error? e.g. typedef int (*func_proto_typedef)(long); typedef int (*func_proto_typedef___of)(func_proto_typedef); func_proto_typedef funcp = NULL; func_proto_typedef___of funcp_of = NULL; this gives: [ 190.875387] bpf_core_apply_relo_insn:1200 cands->len: 3 [ 190.875435] __bpf_core_types_are_compat:6798 level: 2 [ 190.875479] __bpf_core_types_are_compat:6798 level: 1 [ 190.875506] bpf_core_types_are_compat:6896: ret: 0 [ 190.875541] __bpf_core_types_are_compat:6798 level: 2 [ 190.875570] __bpf_core_types_are_compat:6798 level: 1 [ 190.875599] bpf_core_types_are_compat:6896: ret: 0 [ 190.875629] __bpf_core_types_are_compat:6798 level: 2 [ 190.875659] __bpf_core_types_are_compat:6798 level: 1 [ 190.875686] bpf_core_types_are_compat:6896: ret: -22 failed to open and/or load BPF object -- per aspera ad upstream