Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp786940lql; Mon, 11 Mar 2024 18:52:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUXJfyk72U6dzATR613+LaJ6GfZ2H9gavRrgZHdQAZQORPUmZXznr1KQiQJz56V8qhW1yARZUw1NnHCGpJfi6aWe2B1VT6hOGRDaQivDA== X-Google-Smtp-Source: AGHT+IE/8tySRPhNngZDq59QOFiwR0HmCzRCEr2M8Y+DRAmxHl4lg4dE06nfW582vvhCDVIgnLVq X-Received: by 2002:a05:622a:1115:b0:42e:f036:d9d1 with SMTP id e21-20020a05622a111500b0042ef036d9d1mr2189809qty.12.1710208320194; Mon, 11 Mar 2024 18:52:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710208320; cv=pass; d=google.com; s=arc-20160816; b=wFJ1AD5BOfVEhBLC1Jx+WsiEMg+1JuMuj8cP1YjBFsBCZtsKg65/7OSv69lwvTLV1m iDCP9bPsSeDVG0ALCc3FNPzYTX0oAH1mnPX6qdcky0HgFWsbL7xYokiL8MEGOoY09qk8 0o6jyEs6rxcp9aFd9PAcdxHed+3OxGob3lGypIpACu1eChitdCY4QMeuOy/oqd80WfNo kntnxEzATD1B4MGiq7R3IHpZh4Bf7pxicXaT+TGq6+XFBsYrU31HLAxWffeOOVJ0KoNQ vt9tGHIutyy9248vJl5j3cstSZRt6sET9FV9V/P98JwWUxR70wO5dknBTUBM6fqyc6Cd 1pqQ== 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=aKvBVych6YCWus4gRNHRR8iBtRNOaryODuyFk+IiwIg=; fh=86fPk91BxWUx0TibW3QyjgmnLqbovjGv7pt+nEAN6R4=; b=xIX1q60JiAMlD6Rrqsn+UEM5zX8956b8ZkWAt84Q9e4AhwylUzNNFj3DVuuyalNYvY vcUUyA47siWB/48eMk94kg1CP/Avwa6Y+lenVhFyszB+Eolte5iscsAX1NRjjPe/Qza8 ttJ6otxZAhugXcwsdgYxXMIGjo9zRGvXLFvQ6XwpWEy5Z5rISf/TAD528szcvsnflcbh YKH5CgepzfFFEJSDwO7ySiX9qkOLMr0dIjIBnwEXH/OLV5Co5Om4UI+hPDooyaeaH+o/ 0DIHgTfkK2Bj3MhXetGI0o2ntaMeSuGrS1tPOAG+Rtzh4G0c1YoyQ1FyZFTKvg/3NGgU eZNQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=X+aNpiql; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-99745-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99745-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id b3-20020ac85bc3000000b0042f5160c808si1523836qtb.628.2024.03.11.18.52.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 18:52:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-99745-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=X+aNpiql; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-99745-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99745-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id B16631C2122C for ; Tue, 12 Mar 2024 01:51:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3A67F6FB2; Tue, 12 Mar 2024 01:51:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="X+aNpiql" Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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 B2EF11842; Tue, 12 Mar 2024 01:51:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710208305; cv=none; b=NCleHHT8yM8RMALE1pxk2D1d2uYWv5cMhIt2rmGhbkZooBw4+JDbG+7CtrBr+ZDXH6O3NE9bQmCAcsYcgk5sj8MtTIdMVeEp8d9pArZytWrUA8FxyVPtAgdIagkO1eBTBiyBZWYQMCFDi+lIYocRRQ7dQWeCL2AFujEJzmBhVOU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710208305; c=relaxed/simple; bh=ArRWAWBpJ3etLudFkCPT+4Xfr92xcoH1FAZA3SWgHRw=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=SsQuyO5noBeFxxbL54bbWASVq4KfQ6afIIHyEqRNB/b21oPRAdPopmPVGEJ3ezXzW8wc3ENEJz7aTGXxEETnLpLLaW/zj/UvwkOpibbVIho/hCxdo9+AL+2j0MoPbYuvrGLhHPw9TY1ixpPoGQJ/4S+zeusju4wA9I+DApvpkYo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=X+aNpiql; arc=none smtp.client-ip=209.85.221.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-33e6aca1ca9so4852836f8f.2; Mon, 11 Mar 2024 18:51:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710208302; x=1710813102; 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=aKvBVych6YCWus4gRNHRR8iBtRNOaryODuyFk+IiwIg=; b=X+aNpiqlfNLa15xtiizq7yUkjhhQo4D8wSaenGLmpd+ev87vyCI2kxuCeMDYdoKRVe KPchzNkC3myzkZfIm3FIpxZokp4q0ReLKupbcTDHrSzZfByzl/2APvc+ZCDjLiKZiKWp 214mT4iWxeNyqlbfzs7a1JZk/ONNApUzoSDABYHiRbz0HIutVwGzwizR5u43ue+VBdnO pJSWmoTSAdQyvPuelIac5XIc6gD3DWX4XsKzk3vDySlQXro6f4spNtn2Raa4UUBRBze8 Uv/X7n37vtP+njUwtIwKY5g3xxthPLYmTAnbyv7w5rBFVoDFfxvkuZY84iIWw6o5pLIo SGDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710208302; x=1710813102; 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=aKvBVych6YCWus4gRNHRR8iBtRNOaryODuyFk+IiwIg=; b=u8ASxJILzAqdp1WWcwvux3KMCm8wF6l0mKskSDnFYwPEpg8rXntAEalwve3M0LW5xd FFrDBdWmtIDESRRS2ojQQvR8qLiJ/ozDMIYYXaTr9Dy4uC3d4rdclt/bsEwXmIeJRC88 g7jvO+1wfRx9ouhH4vRULl1++GpjsaJ8nNpsTAc4So9WQzLU7TwRVD+5Iyjq3+nRiMcn O+dwMl0l5BysXqihIbmD5sIyXFdaE6lo7hDbD6vYiWL3Ltt1BJF2lFUqk3nNRVkgF/Pq bap0S6UMh2LuYCh6xE+27JcliUPgEv9zg8wnF6J9zahSLSmfdl4u8C7v7vzRqKvfLLAd d8ng== X-Forwarded-Encrypted: i=1; AJvYcCWha1hYlnBiTgL6iFwhKHpP+CutqMxriFR0fkFo5XC8edxEaH3I06Dd/LkhT3mE3qVQa7C+0LHvNkp6iU3wkizRmJkz3Nu6uNQJFSu9mUW9qIb9qZAdxzS0+0Bzcm3T2YF3nenIVroAPsDElOoF/51Hh/rF1AT8ImYTwD1718xJDKUs1ESPv+T5gokiNf8JHhjC8AwsZbrcP1u2dCnrfup2aIPGBq2QaG+J/dR8WBh2UW9TpU0SuTcEWvikKooJNpslCKOFfYiHbO1sr5yit5Crh+rWLuj6jp1E/g== X-Gm-Message-State: AOJu0YxtVb9s8WT3ZS+6mtGJUhht/J1hrYJ1V1uRl1Mf0ipmIa/jX1jk V2gXL8s8ENYLDpiI3t3maZvRU+sV7ijSlZjuHZFL9PxVDqxmRCqba5CvQjddjq4G/ej/hBN4lX7 tXHrPVxEfg6m7NupwLtC6wncljXQ= X-Received: by 2002:adf:ea06:0:b0:33e:48f9:169d with SMTP id q6-20020adfea06000000b0033e48f9169dmr403840wrm.31.1710208301974; Mon, 11 Mar 2024 18:51:41 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240311093526.1010158-1-dongmenglong.8@bytedance.com> <20240311093526.1010158-6-dongmenglong.8@bytedance.com> In-Reply-To: <20240311093526.1010158-6-dongmenglong.8@bytedance.com> From: Alexei Starovoitov Date: Mon, 11 Mar 2024 18:51:30 -0700 Message-ID: Subject: Re: [PATCH bpf-next v2 5/9] bpf: verifier: add btf to the function args of bpf_check_attach_target To: Menglong Dong Cc: Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Eddy Z , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , "David S. Miller" , David Ahern , Dave Hansen , X86 ML , Steven Rostedt , Mathieu Desnoyers , Quentin Monnet , bpf , linux-arm-kernel , LKML , linux-riscv , linux-s390 , Network Development , linux-trace-kernel@vger.kernel.org, "open list:KERNEL SELFTEST FRAMEWORK" , linux-stm32@st-md-mailman.stormreply.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Mar 11, 2024 at 2:35=E2=80=AFAM Menglong Dong wrote: > > Add target btf to the function args of bpf_check_attach_target(), then > the caller can specify the btf to check. > > Signed-off-by: Menglong Dong > --- > include/linux/bpf_verifier.h | 1 + > kernel/bpf/syscall.c | 6 ++++-- > kernel/bpf/trampoline.c | 1 + > kernel/bpf/verifier.c | 8 +++++--- > 4 files changed, 11 insertions(+), 5 deletions(-) > > diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h > index 4b0f6600e499..6cb20efcfac3 100644 > --- a/include/linux/bpf_verifier.h > +++ b/include/linux/bpf_verifier.h > @@ -811,6 +811,7 @@ static inline void bpf_trampoline_unpack_key(u64 key,= u32 *obj_id, u32 *btf_id) > int bpf_check_attach_target(struct bpf_verifier_log *log, > const struct bpf_prog *prog, > const struct bpf_prog *tgt_prog, > + struct btf *btf, > u32 btf_id, > struct bpf_attach_target_info *tgt_info); > void bpf_free_kfunc_btf_tab(struct bpf_kfunc_btf_tab *tab); > diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c > index d1cd645ef9ac..6128c3131141 100644 > --- a/kernel/bpf/syscall.c > +++ b/kernel/bpf/syscall.c > @@ -3401,9 +3401,11 @@ static int bpf_tracing_prog_attach(struct bpf_prog= *prog, > * need a new trampoline and a check for compatibility > */ > struct bpf_attach_target_info tgt_info =3D {}; > + struct btf *btf; > > - err =3D bpf_check_attach_target(NULL, prog, tgt_prog, btf= _id, > - &tgt_info); > + btf =3D tgt_prog ? tgt_prog->aux->btf : prog->aux->attach= _btf; I think it's better to keep this bit inside bpf_check_attach_target(), since a lot of other code in there is working with if (tgt_prog) ... so if the caller messes up passing tgt_prog->aux->btf with tgt_prog the bug will be difficult to debug. > + err =3D bpf_check_attach_target(NULL, prog, tgt_prog, btf= , > + btf_id, &tgt_info);