Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp2644460lqo; Mon, 20 May 2024 11:44:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXa0G7wFx6rYraEeQxrqFeXfA8yNQ6gldJomJi2KOVyp5D5etb4lbBeFGlTFMs/CoCyjvmW5ZLHt17FvNWuVKbxVFeNVprngiB58IqksQ== X-Google-Smtp-Source: AGHT+IHbJUqPKYrMITKBcGqNFb2niwfnifk/2X0wl/fZ5dryfN9kvhF/pmHP8sXWadU2cRc27hmE X-Received: by 2002:a05:6512:34c9:b0:51d:7d4a:5e6e with SMTP id 2adb3069b0e04-5220fa71c80mr16819625e87.3.1716230674054; Mon, 20 May 2024 11:44:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716230674; cv=pass; d=google.com; s=arc-20160816; b=c+rcS/nLu7v4tJaVe0tQ3aILA5L7MW2xBTPyw7P8qwpQ0QZKCbaM4GbXuoFSmw5TiS Zy92LrZaoNxjd+nsZF8UERxtigKMkYc562kxmw7YLtoh+ymGXVRL7uA6f4Z6bXWnT8P5 eX6G93X/4YbFiHSyD+u2W2N1hYxJCncPzG9PoWPsnH8CdMHouDv3Qrl+rzyiSLN9YHL1 heFAhzragGDt+EAyXU7ZeeLsdOHaGK0ilpWcvidXXEM9LWCos8OCB67WrwioXiWP3dgy 8nOpO2GXzexByqvK/ryTU4ch3OgnZyRI6ngmrdCo3cyfI6gOmV9DbOJRtaCAN6cWftBQ +aFQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=KUBLBSrsQ9qU9W/MCb1o7PdEzonP2nGcujZe+jtBzUg=; fh=1R2c02sZW2T+v2huYUOvIY00/LjDWf9xt3InHP8oaog=; b=gHuc1aagpzl86CmDeBiCrui8wOWIPIs+WzK5Rz8hDrntcZMKeDCTksk/7MtNu/69xq S/vKgJIQUURd2GNxe/XmMuR+eL2M6XcDJ8gpahNKVyvWDmajD/NbVj+XDNMT1l97YGeQ 9+TPKq23EJW39DeZFhwNFNpmT6g5OhIvdMbfWlACQ7lTLx8KuM9lCbWAA1XfkKtHUFg7 VrWzddUxBlmM5oNzN4xTI607nNawti7zOR6xD7kaW6bbOwDQXXHof01jYPe7tRSHhMpO FlN4z+IlxDuvkakBAGulbw4hLLst/sFrkKXHiF4/jFYLOG1D15yKPbiLStsJyO/ePAfP U3HQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google09082023 header.b=CHmfj0dG; arc=pass (i=1 spf=pass spfdomain=cloudflare.com dkim=pass dkdomain=cloudflare.com dmarc=pass fromdomain=cloudflare.com); spf=pass (google.com: domain of linux-kernel+bounces-184076-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-184076-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17c008b4si1305083666b.888.2024.05.20.11.44.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 11:44:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-184076-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google09082023 header.b=CHmfj0dG; arc=pass (i=1 spf=pass spfdomain=cloudflare.com dkim=pass dkdomain=cloudflare.com dmarc=pass fromdomain=cloudflare.com); spf=pass (google.com: domain of linux-kernel+bounces-184076-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-184076-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 9C9BB1F221FD for ; Mon, 20 May 2024 18:44:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4C39E1384AC; Mon, 20 May 2024 18:44:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="CHmfj0dG" Received: from mail-yw1-f171.google.com (mail-yw1-f171.google.com [209.85.128.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C20B0138496 for ; Mon, 20 May 2024 18:44:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716230668; cv=none; b=NfPK/42dAtk8Hl6yRBfBsYOsVM1HW5GX7rK1S4J18OVFeMzeJZttWh6f7u018fppw3kOfi7xhTu9VAPtpmEGFxJYeAWmMV8Daef5pX665bKlASYMZ9sZsODMyqMvU0XeM7Rp9iJVbxLLL/YsbspyT2A5w/Yz1odeqKCJjDCtZSc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716230668; c=relaxed/simple; bh=YrF+BGB8KkA20GPMWSqiSRn6DYf3paXMT8yMVBT+jSc=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=nYvPKld9OtKoEbZD56lX7yGzTsTTs+bw+O3jVOgBC4O9mMzkax2CuKyIbLvAYrQPN+QNnPATAfJaBvbzU4oasptcf5IqzB/KhSa1BRBy0yi6VCESfCgkujF1DzXJw9HwA1sY2jMmRIGannwXZ+yj1bjCYpEBwyU6dLEip/qGusw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=cloudflare.com; spf=pass smtp.mailfrom=cloudflare.com; dkim=pass (2048-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b=CHmfj0dG; arc=none smtp.client-ip=209.85.128.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=cloudflare.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cloudflare.com Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-61be613d903so30499827b3.0 for ; Mon, 20 May 2024 11:44:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google09082023; t=1716230666; x=1716835466; darn=vger.kernel.org; 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=KUBLBSrsQ9qU9W/MCb1o7PdEzonP2nGcujZe+jtBzUg=; b=CHmfj0dG/dfHB5J5tRmNRw5zHNb1PTbyhUAqVvw8YouKRqPhXz+rYB5655qI/wMgfC PWmk0Y3NjrJtgpdJ3/mluq2W1lPj9q6Adz3azKRgR1xsqaZLi5yP4BlvrRBw3awXwVkG XgqZTfE9wV91CEPPDPdhjnewVy6c7KvPtcf6jSklNR39A/PNhH4J8Kv1ET29O1sr+2wE x9C2JRxYZIKLOPvPtfOlRIJE8mik6uRI+5RgcAfRjY7lS3wvBTHN8DzvDnFy9R66NAXB 6Uwz7nEfvhCT0Xmpm0C9zwcqarBe8Rrguf16uI2tkXaYd8yERIFXv8bwFhK+GGTHc8iB 0rLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716230666; x=1716835466; 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=KUBLBSrsQ9qU9W/MCb1o7PdEzonP2nGcujZe+jtBzUg=; b=c/uDy95eGSMdlZH/I6J2vR8V57v727oTftpqfijlqBC5sDyaGbWTG3fS8MBAliuNs2 4u+m3hE8DDsRTvzn050LBILYEsmznahzcjh07J/Qgu8e+TIOXGGUSFCA+ctZ0DJwwMVz KZVYuZ6je/4kKrLYSjuHYAoaLiyVJmcr4JoFv0QXobPeAqR8GbGZ2P5VQOEbG0jzmbvj eIOXjPsFrah842u1BYa1D1h8yeky8xruUOXiPBahJrJsDlHOwtvL4z1BiQSZwqmzl1ls OS6f8oQiFpzNk+UDahPaC0j7HMS+XtB5wciUHlPcZqnrbiMa4SJn1Txb5H7aZaq/aSf/ eI8w== X-Forwarded-Encrypted: i=1; AJvYcCXriarT5zzB2ncihvYPMYCtnRHla5bmFdCZPpgfS5UKKHzTQqU5NDz5areqMLxnZSdGybTNd3umB1uS3yopTUBSxPYYjBwIbus+Iwhs X-Gm-Message-State: AOJu0YweD0Micz1NCxuXllq/ZlXVrU7vzq4RZWJ4InxIbsezlJpiXAnj NVEN0jxqKQM1Hf8gXdYSfPF5eKNlj3oTIKANrxBK1jopz02CV5c2IXPIcE+QOHaC55FBWx61Kpa tZJlWIiGXnLvDKXdqI4atlsD9I4Q/WlZuUEFbIt4+CDQoH1LBylA= X-Received: by 2002:a0d:e297:0:b0:627:77fe:d00f with SMTP id 00721157ae682-62777ff81f8mr127465407b3.6.1716230665752; Mon, 20 May 2024 11:44:25 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: In-Reply-To: From: Ivan Babrou Date: Mon, 20 May 2024 11:44:14 -0700 Message-ID: Subject: Re: bpftool does not print full names with LLVM 17 and newer To: Alexei Starovoitov Cc: bpf , kernel-team , linux-kernel , clang-built-linux Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, May 17, 2024 at 4:33=E2=80=AFPM Alexei Starovoitov wrote: > > On Fri, May 17, 2024 at 2:51=E2=80=AFPM Ivan Babrou = wrote: > > > > Hello, > > > > We recently bumped LLVM used for bpftool compilation from 15 to 18 and > > our alerting system notified us about some unknown bpf programs. It > > turns out, the names were truncated to 15 chars, whereas before they > > were longer. > > > > After some investigation, I was able to see that the following code: > > > > diff --git a/src/common.c b/src/common.c > > index 958e92a..ac38506 100644 > > --- a/src/common.c > > +++ b/src/common.c > > @@ -435,7 +435,9 @@ void get_prog_full_name(const struct > > bpf_prog_info *prog_info, int prog_fd, > > if (!prog_btf) > > goto copy_name; > > > > + printf("[0] finfo.type_id =3D %x\n", finfo.type_id); > > func_type =3D btf__type_by_id(prog_btf, finfo.type_id); > > + printf("[1] finfo.type_id =3D %x\n", finfo.type_id); > > if (!func_type || !btf_is_func(func_type)) > > goto copy_name; > > > > When ran under gdb, shows: > > > > (gdb) b common.c:439 > > Breakpoint 1 at 0x16859: file common.c, line 439. > > > > (gdb) r > > 3403: tracing [0] finfo.type_id =3D 0 > > > > Breakpoint 1, get_prog_full_name (prog_info=3D0x7fffffffe160, > > prog_fd=3D3, name_buff=3D0x7fffffffe030 "", buff_len=3D128) at common.c= :439 > > 439 func_type =3D btf__type_by_id(prog_btf, finfo.type_id); > > (gdb) print finfo > > $1 =3D {insn_off =3D 0, type_id =3D 1547} > > > > > > Notice that finfo.type_id is printed as zero, but in gdb it is in fact = 1547. > > > > Disassembly difference looks like this: > > > > - 8b 75 cc mov -0x34(%rbp),%esi > > - e8 47 8d 02 00 call 3f5b0 > > + 31 f6 xor %esi,%esi > > + e8 a9 8c 02 00 call 3f510 > > > > This can be avoided if one removes "const" during finfo initialization: > > > > const struct bpf_func_info finfo =3D {}; > > > > This seems like a pretty annoying miscompilation, and hopefully > > there's a way to make clang complain about this loudly, but that's > > outside of my expertise. There might be other places like this that we > > just haven't noticed yet. > > > > I can send a patch to fix this particular issue, but I'm hoping for a > > more comprehensive approach from people who know better. > > Wow. Great catch. Please send a patch to fix bpftool and, > I agree, llvm should be warning about such footgun, > but the way ptr_to_u64() is written is probably silencing it. > We probably should drop 'const' from it: > static inline __u64 ptr_to_u64(const void *ptr) > > and maybe add a flavor of ptr_to_u64 with extra check > that the arg doesn't have a const modifier. > __builtin_types_compatible_p(typeof(ptr), void *) > should do the trick. In bpftool there's just two call sites that are unhappy if I remove "const" in the arguments: * this problematic one * "GPL" literal passed I'll send the patch to drop "const" from the struct initialization today or tomorrow (it works great in our internal build), but I'll leave the bigger change to you. There seem to be many places in libbpf and I'm far from being a C expert to drive this change. I managed to bisect clang to find the commit that introduced the change: * https://github.com/llvm/llvm-project/commit/0b2d5b967d98 I also mentioned the commit author and they have some ideas about UBSAN catching this (it doesn't in the current state): * https://mastodon.ivan.computer/@mastodon/112465898861074834