Received: by 2002:ab2:69cc:0:b0:1fd:c486:4f03 with SMTP id n12csp520743lqp; Tue, 11 Jun 2024 11:01:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVM+kThc1g7FvEdWosbC8o9Z4e1EEYEvwQ883pPXjrd2LFDNYEFeeCkbukRHXR6Jv2SRWYxDU7OVhYxB+S2qVw5EQjO99ZyM/pNHFyd9Q== X-Google-Smtp-Source: AGHT+IHhtCLuKiY4YDKgMKDAzG2eUQrTfSEgQW98IJKqbveCFPhzEixz8tX7XumnP51+3M9TJX4c X-Received: by 2002:a25:ab70:0:b0:dfa:7e09:21c4 with SMTP id 3f1490d57ef6-dfaf64e7511mr14462772276.3.1718128878672; Tue, 11 Jun 2024 11:01:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718128878; cv=pass; d=google.com; s=arc-20160816; b=bAocs86BpOzD/Atg6EbnyUJ5WHruevIntrbYLxghGJMpdOEEh6d35kfT6aGeFzF0aM vEj1h8g61XUeYn/gqFmAwRzzS0hFaRw9Yogr3KiqGkpx/HSnGrwqZmh9VA3+YS22F8+Q V5lH/sHmZez8pvIq4cp4vEXnjPjDPAkQxqx6B36qfsibWyUSbRwfQYhR36wjT4VgyJBR Xv6fQut3JM6RkVu8mZApLWLe9R6Q5So5thH0fC05TCJ8FubJF23oUz/YMsZ4K42+GTF1 lqDK1Oin5VWOPoEtRBmSwflDiIheD6E1HsNfWWWpRURRWi4KgFeUTDSg9Kn9YuwnI7mm 0kdg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:feedback-id :dkim-signature:dkim-signature; bh=3TsTy4miANTIONNoIvT1RtaTHJWrsau+L4RJ3v/4SRY=; fh=G0XgjGphR4jmpNrMMhiPyPmMawFamg9MbdEdug6sGVU=; b=Ufn60BXo0dimQfGgf0TtZI4uCBT9++9YxaH6vrBlKVtX7aGG7R0Rh3oQKVkLMS16UA DJFe/tv/AvsLrisYDSbQ3oL+laX6NK6Q0SJUIyKvB4YkGRIjusdlfwotEX23dlEDIf5J gnjeGCwRmPyyGLLCb2O8JPT1HgvEhJC0XwFtoK24lLWgLbaoAx1ZYzslVCucTap57yxk bSfGZgCsZTNVwDdPYlWufXMNt0jtOPQqbANb62ZxrWK7ZzoaD1s91ne7Ptfqk/zCUP/T dfnvlL6oel4tGkeGXK/eV7RepWYaEuyvro6Q5GvDe3T6FdDQNqmgKO+Eiy+Ad3IIQDCo CV2A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm3 header.b=kvXB5kpZ; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=kHrnGfVd; arc=pass (i=1 spf=pass spfdomain=dxuuu.xyz dkim=pass dkdomain=dxuuu.xyz dkim=pass dkdomain=messagingengine.com); spf=pass (google.com: domain of linux-kernel+bounces-210383-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210383-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-4415769c40csi4346881cf.345.2024.06.11.11.01.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 11:01:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-210383-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=@dxuuu.xyz header.s=fm3 header.b=kvXB5kpZ; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=kHrnGfVd; arc=pass (i=1 spf=pass spfdomain=dxuuu.xyz dkim=pass dkdomain=dxuuu.xyz dkim=pass dkdomain=messagingengine.com); spf=pass (google.com: domain of linux-kernel+bounces-210383-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-210383-linux.lists.archive=gmail.com@vger.kernel.org" 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 4C14D1C23314 for ; Tue, 11 Jun 2024 18:01:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 43BDD5BAF0; Tue, 11 Jun 2024 18:01:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="kvXB5kpZ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="kHrnGfVd" Received: from fout4-smtp.messagingengine.com (fout4-smtp.messagingengine.com [103.168.172.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 481991CD06; Tue, 11 Jun 2024 18:01:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718128870; cv=none; b=VRIFj20N3pGIau7RblRiEKcGQqlyH8ogqBiPZ4NmbgDZYZgUrl9jmI3db8hzlvMoY62cma0AvIAby/OPbu9UmVH30pgADTK9pjn4gbqJ7HBRO6K5I/NNQwyVpk0HJM85KzsQZuWhH8Qt8n0GPT/bdhcg+6c7VvvwkTa487Wpi1E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718128870; c=relaxed/simple; bh=8QWtb6pcKPnWcVLg2JzrAry10KmxCU8luPjLBJwvgjM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tsWr/8hIsmZgzXUu/LI/9ZymOOl6ioGzPIGhdQHKG5AEoThOqVCFrmCOLEnGp/10I5Jike+Iz+nBR6l29mzkeP9pGbQT10JrJjF5latqOh2zJ98lV/ZxGxNfkQSHfwlu6CPNcSbiXCTVvpsMoHbLmWx2B+/1OewJU6giACxyZho= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz; spf=pass smtp.mailfrom=dxuuu.xyz; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b=kvXB5kpZ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=kHrnGfVd; arc=none smtp.client-ip=103.168.172.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dxuuu.xyz Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id 42EF61380087; Tue, 11 Jun 2024 14:01:07 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Tue, 11 Jun 2024 14:01:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1718128867; x=1718215267; bh=3TsTy4miANTIONNoIvT1RtaTHJWrsau+L4RJ3v/4SRY=; b= kvXB5kpZt5ftlNR+NOZR2zGB46PyiXp4NYl/4hlvTr4JkKAl7g/d9Gf/xaS09Sbd 2q+bUizUBO+r9l31TNHh24BNa0tsKtsdKUfp3Q6TavlOb6bADTioee7wCt6rqzYI YuQ2wcErEU79wY1uNWM02UVeu7djV0XWLZBj5FzDco5kDjhdJGOzh8ZmJYhg4SSq uz+TRzWlmhMMQzYKclUcxd1lPCX+Y0kexOQlQnPJLgrr3j8nhCdA5/AD2BnnFQk8 zYAoxIBCWHAJuaUUFP1TW8kK6RoLahxK1qw94NBXHY+cETka+0yoMoLW4mfgtGwn gbM+uKOoe/JGQkAyzmJ94g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1718128867; x= 1718215267; bh=3TsTy4miANTIONNoIvT1RtaTHJWrsau+L4RJ3v/4SRY=; b=k HrnGfVd8lxcs207atytWSbFMwCys3wj1s8VJDOV3q3dIIR5NXVlzVCTxBAk3dChc ZRYXcuhHLdAbHtTDq6zl8/vc2xQQtpBVEtezY+YWxvMXB4LG8KqWM6ycgj6tVXvq aeSqRIfqhQ2lKdMGrI5Fu+npXmi5bTilQeBUgUZZiIBrv+l67Tw4PNK6TIFwKvyy tCfKzGiKqkkv/+WDQoYlxP39desrRUeYIz0TTS98++pwdLf+2YafR8K/028YWVm0 iCAZX9FJW0N9Qga+LC6Y2ibhSSA1ZvPgnntcjDCnrvaGjLGr4GJY0T+ocSh8y5ze 5eoSXL5G4Ym16cYYwCMiQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfeduvddguddujecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enfghrlhcuvffnffculdejtddmnecujfgurhepfffhvfevuffkfhggtggugfgjsehtkefs tddttdejnecuhfhrohhmpeffrghnihgvlhcuighuuceougiguhesugiguhhuuhdrgiihii eqnecuggftrfgrthhtvghrnheptdfgueeuueekieekgfeiueekffelteekkeekgeegffev tddvjeeuheeuueelfeetnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepugiguhesugiguhhuuhdrgiihii X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 11 Jun 2024 14:01:05 -0400 (EDT) Date: Tue, 11 Jun 2024 12:01:03 -0600 From: Daniel Xu To: Alexei Starovoitov Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Jiri Olsa , Quentin Monnet , Alan Maguire , Arnaldo Carvalho de Melo , Eddy Z , John Fastabend , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf , LKML , Kernel Team Subject: Re: [PATCH bpf-next v4 08/12] bpf: verifier: Relax caller requirements for kfunc projection type args Message-ID: <3ys25qg63cfuxjclqjlagsasvp5bpu6oqzjeia32kg2seistbv@5t24bsw5jtij> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Mon, Jun 10, 2024 at 11:30:31AM GMT, Alexei Starovoitov wrote: > On Sat, Jun 8, 2024 at 2:16 PM Daniel Xu wrote: > > > > Currently, if a kfunc accepts a projection type as an argument (eg > > struct __sk_buff *), the caller must exactly provide exactly the same > > type with provable provenance. > > > > However in practice, kfuncs that accept projection types _must_ cast to > > the underlying type before use b/c projection type layouts are > > completely made up. Thus, it is ok to relax the verifier rules around > > implicit conversions. > > > > We will use this functionality in the next commit when we align kfuncs > > to user-facing types. > > > > Signed-off-by: Daniel Xu > > --- > > kernel/bpf/verifier.c | 10 +++++++++- > > 1 file changed, 9 insertions(+), 1 deletion(-) > > > > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > > index 81a3d2ced78d..0808beca3837 100644 > > --- a/kernel/bpf/verifier.c > > +++ b/kernel/bpf/verifier.c > > @@ -11257,6 +11257,8 @@ static int process_kf_arg_ptr_to_btf_id(struct bpf_verifier_env *env, > > bool strict_type_match = false; > > const struct btf *reg_btf; > > const char *reg_ref_tname; > > + bool taking_projection; > > + bool struct_same; > > u32 reg_ref_id; > > > > if (base_type(reg->type) == PTR_TO_BTF_ID) { > > @@ -11300,7 +11302,13 @@ static int process_kf_arg_ptr_to_btf_id(struct bpf_verifier_env *env, > > > > reg_ref_t = btf_type_skip_modifiers(reg_btf, reg_ref_id, ®_ref_id); > > reg_ref_tname = btf_name_by_offset(reg_btf, reg_ref_t->name_off); > > - if (!btf_struct_ids_match(&env->log, reg_btf, reg_ref_id, reg->off, meta->btf, ref_id, strict_type_match)) { > > + struct_same = btf_struct_ids_match(&env->log, reg_btf, reg_ref_id, reg->off, meta->btf, ref_id, strict_type_match); > > + /* If kfunc is accepting a projection type (ie. __sk_buff), it cannot > > + * actually use it -- it must cast to the underlying type. So we allow > > + * caller to pass in the underlying type. > > + */ > > + taking_projection = !strcmp(ref_tname, "__sk_buff") && !strcmp(reg_ref_tname, "sk_buff"); > > xdp_md/buff probably as well? > > And with that share the code with btf_is_prog_ctx_type() ? Ack - will do.