Received: by 2002:ab2:68c1:0:b0:1fd:9a81:d0e4 with SMTP id e1csp242946lqp; Sat, 8 Jun 2024 14:21:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVG4BS+1Ls1jxtPq+c7lkPuSRQqeKHBvz4oIbh3jrMzQVoMTdZZCIq7MvJBn9GVQwBGjmBXWlILe/c73sCCTmhAn3zX7VWwF8ECWbzKnQ== X-Google-Smtp-Source: AGHT+IHy2p8OO8bSMVYz/0Cei4NNHeSho4BOv53c0AMvvcyfsu29a9ME5x+Nq6c3klYm0cPs7KgU X-Received: by 2002:a17:90a:c87:b0:2bd:7e38:798e with SMTP id 98e67ed59e1d1-2c2bcc0ba89mr5101718a91.28.1717881697664; Sat, 08 Jun 2024 14:21:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717881697; cv=pass; d=google.com; s=arc-20160816; b=V+AWfofnBDylWOdvCGJcGTlbEVAr6xdUfKuN/MqHiQbN9DmCP1NyMBx1NdaaWoKaWB JNt1k51RxWiY9Lb1J5p+QXYYy20OSCGncppW6yYykKIVCMQPU0ojLO9UvDk/KSedvIkM hrBo91fIDy2vsmuseGD9dQQ2mMIhuMj32N6V03FelzY3wyXYhwjGD3OuVe4SQyXunG8f lKQE6tr56DEDjihpke4m7Tv8Qnn85092LJaWUe72HtOp1HnDlNlj2z2mspki7n3Tl3hv mXwQJjo4ZzCv73h/SqIuEdmSI8z5VbfndXmEe/WT6b+4SRYLyERyF2Ohe0MzkxBccaV/ CKMA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:feedback-id:dkim-signature:dkim-signature; bh=Jpevwhj99iE9aQa9agLdQ7m/XajfHuUGhGYbM7gqMgk=; fh=2FZHBRXxTIPNqMIjNyFweujFtaeVJlm0MOF2qOq2VGM=; b=cIp/seO68DDw0W32wSnlfkg58PBwx741LEHsC8DfSPjQ6VAa06mrLnrHepdW5qKHkw tIiVscv5PyZxwUPcavk+/R/k3DF4j8eibbIsS4FfN3Auc3i5sUbOmMM1DAB2RgB8GyPr y1TSHNC+btOJH5eBv/glQNjTiDePcn8SXw+9Csx25TKVMNP5MNI3cktvwYbUttk1N+dn 6SwuOtFb9y7yZkXVAxANZsBQbTa/4QXBc22yNpKd0IYaTop28XfjF5Zr/p1HGm1jYKej i9VCqrud2VKWzBn5YvKhr7N7TOpdot1eLdTa+pvz12404RCeBUD+0ghKSGF7k/qib6eu cn4w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm3 header.b=k2Mr+Pym; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=bOo9mEU6; 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-207199-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207199-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2c2806d1b76si4533463a91.146.2024.06.08.14.21.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Jun 2024 14:21:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-207199-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm3 header.b=k2Mr+Pym; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=bOo9mEU6; 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-207199-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-207199-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id C370FB2224D for ; Sat, 8 Jun 2024 21:19:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A527155897; Sat, 8 Jun 2024 21:16:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="k2Mr+Pym"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="bOo9mEU6" Received: from wfhigh8-smtp.messagingengine.com (wfhigh8-smtp.messagingengine.com [64.147.123.159]) (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 3E87F15EA2; Sat, 8 Jun 2024 21:16:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.159 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717881413; cv=none; b=RXqr4e3eJYElIGopSMvSbIdj1UK9ORTqHezCnBeEukN0/drfP3CjtPHUDQHbszUb5+F4zIKHSLL6oVpdoPxSfg3pW+SKABDyN27QRhibT0E63pclBHBu0qFymtnQxz4GfIRHz8bRZda12/xYzkBRkkfAsobIEHeTIBUEQpvu0KM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717881413; c=relaxed/simple; bh=oZVk7OcZLn78TEsK/Tv+mE4vVgftTWhMblLRODMmDdE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CzWn5xi6xmZ+bIpKLS9hOfelWVZdpPaKwkRH5bwso/FYNGkGoepuc9zRlQQkINFz/MfbUaAhgSXDdsBFbLfANgVs6doUlpdWCxzmfLJ3HeMJyzKMB2QGQENeWXMYOPK44EsQvjqFhsUmjwBAkx38fkapJNI4sGrQSS2iMehRx7Q= 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=k2Mr+Pym; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=bOo9mEU6; arc=none smtp.client-ip=64.147.123.159 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 compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.west.internal (Postfix) with ESMTP id 4F59C180008D; Sat, 8 Jun 2024 17:16:50 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Sat, 08 Jun 2024 17:16:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding: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=1717881409; x= 1717967809; bh=Jpevwhj99iE9aQa9agLdQ7m/XajfHuUGhGYbM7gqMgk=; b=k 2Mr+PymiEGt+rrLrv1TuwO+gPXjnShkOooz3dpCCf4kZLZWUz6CYQO71qJPEiXkf BHZo72zxleukCoqdOqKYD/NKKC9GBp9kp4WEtBsr2MqPcZcPglfYecqHoF8tMg9N vbi1rBmBTXBkirlw/nshEb0Z1JtlvXuxS8v2D+va4AuPlAbmr2LHMVBZgc+6KnKu HfNDfQf8WDNmGjjZo+itPOXkn1lPRR16D3Dp5TJxtMvE1bIvVjCUr8c8DPz0QqSD 8tDod3a8/pTWlT23WQsTjQsFnd5DHVbNfs+ieDqL+oIK+uRjR4IQQdX3iPP86Gbc BibuVHvDPNg/WeHng6O1w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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=1717881409; x= 1717967809; bh=Jpevwhj99iE9aQa9agLdQ7m/XajfHuUGhGYbM7gqMgk=; b=b Oo9mEU6cy3tAuqJTT29ct5LDjAjHqcY1Ursoc6ujLcQW6vjUH+srowEovwbjU8if zb3/0zwmh7YN2HWxXrZIwqwqDt1yewqKWBi5e3EXOqmZmdUdjuvqYRUaA3b/ILi8 cW1qqin+BITe4Tivvy5bvxcEk2RZUjCgWen0F2Mafi9rxPTQ+r3NTYzd6XWCzOQj HwVyibMkq+Vjt6vZssRaAzDe18PeXOM/ojSQ5zKzFIspcRRo+Z4eT2oaHrtL9886 J5cVuEZIUCKam145ndUenALTaanGD3X43rZUC98ATFXG/wk+BRqOaPgFwKVqYrAL eBJLbbnfqt2BCn3FF0O7w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfedtgedgleegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdljedtmdenucfjughrpefhvf evufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeffrghnihgvlhcuighuuceo ugiguhesugiguhhuuhdrgiihiieqnecuggftrfgrthhtvghrnhepgfefgfegjefhudeike dvueetffelieefuedvhfehjeeljeejkefgffeghfdttdetnecuvehluhhsthgvrhfuihii vgeptdenucfrrghrrghmpehmrghilhhfrhhomhepugiguhesugiguhhuuhdrgiihii X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 8 Jun 2024 17:16:48 -0400 (EDT) From: Daniel Xu To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, olsajiri@gmail.com, quentin@isovalent.com, alan.maguire@oracle.com, acme@kernel.org, eddyz87@gmail.com Cc: john.fastabend@gmail.com, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: [PATCH bpf-next v4 08/12] bpf: verifier: Relax caller requirements for kfunc projection type args Date: Sat, 8 Jun 2024 15:16:04 -0600 Message-ID: X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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"); + if (!taking_projection && !struct_same) { verbose(env, "kernel function %s args#%d expected pointer to %s %s but R%d has a pointer to %s %s\n", meta->func_name, argno, btf_type_str(ref_t), ref_tname, argno + 1, btf_type_str(reg_ref_t), reg_ref_tname); -- 2.44.0