Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp6427858rwd; Mon, 5 Jun 2023 18:40:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6pD2APvBP3fBTHCNNimCmZrYG445nqlQDZXG+0Wm1f3RxfE9o7+YkT1VxxVY2oJTf/8TO+ X-Received: by 2002:ac8:7d96:0:b0:3f7:df68:7b12 with SMTP id c22-20020ac87d96000000b003f7df687b12mr670873qtd.43.1686015631990; Mon, 05 Jun 2023 18:40:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686015631; cv=none; d=google.com; s=arc-20160816; b=ccK39QCmAmduFIfb45hsM5rlTKZPeKc6Q/IHY6Qo6YTWOMXBZ8A7zFpx5C1m0Oe+Ul R5//OddZRcqxFN8C+JY5sW03It86TIhN4o3HIWs785k8B2HZpoBYQUNVM0vw/tMAOMj1 hU+AuaOcaWikjhOdEfD+gjtWSD/ws6PPT0DgIOXTWdE3nJhWYj2RWB3lA9t520u0MPxE AjNB3mGnQjInsx/2m3uIT4MFelfZutEDrRlFn4lBQou1zbEoWVz166E0gZKNNsuzRLtg MrHfYDXMaLorp5maxhb5I7x/v7vLFPRj8Dc+Rz/GWMpMmjWcPruvmDGncRErYU1KKpV5 jrKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=nKXeYLBgNZsLD/+IxPwyyN63h/BVDg7LwOnNrEDBze0=; b=WIg4DIjRzsaVvIEu51EcjPcbSoS1DMGlg0r7hLG4UDv4cgt34HEvGRLo19DzTCHh6f UhrYcbpowTAxLh6bxUGYrkeH2CsnX/xkmgEVhH1BLtwwxwEfduR5BSq6tsX61iZLMYE8 jl36KlmmwPC66T+ZeG5B3y3zirI6FIOIXdpXkE2gz0CgvObMKSeKj8b7kjPdRk2TUH85 z/uwocmh3+28VzB/0P0lOaCDX9GJeiCtVWOzSJ42Am8a3uRulGvyob45oGCcheyO6lH+ lUjzo3roCAojkCWXY5/L5i14rWkmYSsjHOVVIgHOYTBUOXMIzC0J/ypJEMmglit5QkX6 64dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=seM8DoJu; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 19-20020ac85753000000b003f52eb1a5cesi5378976qtx.632.2023.06.05.18.40.17; Mon, 05 Jun 2023 18:40:31 -0700 (PDT) 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=@gmail.com header.s=20221208 header.b=seM8DoJu; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232584AbjFFBcO (ORCPT + 99 others); Mon, 5 Jun 2023 21:32:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230349AbjFFBcM (ORCPT ); Mon, 5 Jun 2023 21:32:12 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B070DC; Mon, 5 Jun 2023 18:32:10 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-4f624daccd1so2742078e87.0; Mon, 05 Jun 2023 18:32:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686015129; x=1688607129; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=nKXeYLBgNZsLD/+IxPwyyN63h/BVDg7LwOnNrEDBze0=; b=seM8DoJuA+l2/qluDMFHOqVY2TU0LJEsce5E3zY3BfHXHqYaAoQIn0CcRJVxEiYkeX ueig2x+BcON7b3hxf82SBc6l8PbMtq4dUUcKED2ECulGGEw8YTmbReZY5raJxynbLWYH J9JeYjQuOEvrKBuDThQR39KCrrrmOCQSwS492duLcJ/KfwdyKnVK2MqZaLe2qCpWlreh ATkJkwBLHbj51yPzGh1iKBuit1jUH4WrNFzJ8d/tHdPVOvbrSvBkuBk5fBD/5hjx7tZB hvNmbxkl4kAJgOqDogjNztOz6Dw1NyYjYumFZpe26RxkMpJWsTkFj25n9Bjoa3LU72b6 okpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686015129; x=1688607129; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nKXeYLBgNZsLD/+IxPwyyN63h/BVDg7LwOnNrEDBze0=; b=kjLxcs+WiVJ4dyorV4B7lzSHbAoY6fRqHbjjxckuXrK3oQp8eSok6pW0Uz3uGe9mtP qjN5+QApp/K+6WPTbmLM7momAYHvtiKgKIfNisiZmjC3Go4BejfiBsdSeiKqV1LLULEM Q0c1wzqMr+RZfFHYemargTdqZFNLjK3g8YlGrxoL+MIqTZA+9DEExhrMZicH9rcLaIi7 bbfd0kAAauhXG9PjKKoCO5TYEAEBTdWDDcobBOWZvkIQswzRZoyHpxc2ESKh8WHnadJ8 qk1JugnZyhauyKwihYzy5J14WSFmXHwB1bntLqGUJuNLn8+DXgqI9T0uM8CEQ4HrDK21 +cqg== X-Gm-Message-State: AC+VfDwj9PTr0O+75yhITU9cfaaaxNeKZUi0mmFGMsUxpdYTpN4DgCyJ b8MQskKdrJx69XC502zxX+j2ROPEBbAyCip10b4= X-Received: by 2002:a2e:7219:0:b0:2b1:c389:c424 with SMTP id n25-20020a2e7219000000b002b1c389c424mr648772ljc.12.1686015128552; Mon, 05 Jun 2023 18:32:08 -0700 (PDT) MIME-Version: 1.0 References: <20230605164955.GA1977@templeofstupid.com> <20230606004139.GE1977@templeofstupid.com> In-Reply-To: <20230606004139.GE1977@templeofstupid.com> From: Alexei Starovoitov Date: Mon, 5 Jun 2023 18:31:57 -0700 Message-ID: Subject: Re: [PATCH bpf] bpf: search_bpf_extables should search subprogram extables To: Krister Johansen Cc: bpf , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , Nathan Chancellor , Nick Desaulniers , Tom Rix , LKML , Network Development , clang-built-linux , stable Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 5, 2023 at 5:46=E2=80=AFPM Krister Johansen wrote: > > On Mon, Jun 05, 2023 at 04:30:29PM -0700, Alexei Starovoitov wrote: > > On Mon, Jun 5, 2023 at 9:50=E2=80=AFAM Krister Johansen wrote: > > > + if (!aux->func[i]->aux->num_exentries || > > > + aux->func[i]->aux->extable =3D=3D NULL) > > > + continue; > > > + e =3D search_extable(aux->func[i]->aux->extab= le, > > > + aux->func[i]->aux->num_exentries, addr); > > > + } > > > + } > > > > something odd here. > > We do bpf_prog_kallsyms_add(func[i]); for each subprog. > > So bpf_prog_ksym_find() in search_bpf_extables() > > should be finding ksym and extable of the subprog > > and not the main prog. > > The bug is probably elsewhere. > > I have a kdump (or more) of this bug so if there's additional state > you'd like me to share, let me know. Please convert the test into selftest. Then everyone will be able to reproduce easily and it will serve us later to make sure we don't regress. > With your comments in mind, I took > another look at the ksym fields in the aux structs. I have this in the > main program: > > ksym =3D { > start =3D 18446744072638420852, > end =3D 18446744072638423040, > name =3D <...> > lnode =3D { > next =3D 0xffff88d9c1065168, > prev =3D 0xffff88da91609168 > }, > tnode =3D { > node =3D {{ > __rb_parent_color =3D 18446613068361611640, > rb_right =3D 0xffff88da91609178, > rb_left =3D 0xffff88d9f0c5a578 > }, { > __rb_parent_color =3D 18446613068361611664, > rb_right =3D 0xffff88da91609190, > rb_left =3D 0xffff88d9f0c5a590 > }} > }, > prog =3D true > }, > > and this in the func[0] subprogram: > > ksym =3D { > start =3D 18446744072638420852, > end =3D 18446744072638423040, > name =3D <...> > lnode =3D { > next =3D 0xffff88da91609168, > prev =3D 0xffffffff981f8990 > }, > tnode =3D { > node =3D {{ > __rb_parent_color =3D 18446613068361606520, > rb_right =3D 0x0, > rb_left =3D 0x0 > }, { > __rb_parent_color =3D 18446613068361606544, > rb_right =3D 0x0, > rb_left =3D 0x0 > }} > }, > prog =3D true > }, > > That sure looks like func[0] is a leaf in the rbtree and the main > program is an intermediate node with leaves. If that's the case, then > bpf_prog_ksym_find may have found the main program instead of the > subprogram. In that case, do you think it's better to skip the main > program's call to bpf_prog_ksym_set_addr() if it has subprograms instead > of searching for subprograms if the main program is found? I see. Looks like we're doing double bpf_prog_kallsyms_add(). First in in jit_subprogs(): for (i =3D 0; i < env->subprog_cnt; i++) { bpf_prog_lock_ro(func[i]); bpf_prog_kallsyms_add(func[i]); } and then again: bpf_prog_kallsyms_add(prog); in bpf_prog_load(). because func[0] is the main prog. We are also doing double bpf_prog_lock_ro() for main prog, but that's not causing harm. The fix is probably just this: diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 1e38584d497c..89266dac9c12 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -17633,7 +17633,7 @@ static int jit_subprogs(struct bpf_verifier_env *en= v) /* finally lock prog and jit images for all functions and * populate kallsysm */ - for (i =3D 0; i < env->subprog_cnt; i++) { + for (i =3D 1; i < env->subprog_cnt; i++) { bpf_prog_lock_ro(func[i]); bpf_prog_kallsyms_add(func[i]); }