Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796061162; b=YBiEtpbPtAov5fkYGxDOHlq4NFdPJ40C/MT5fco02UWqZ6M7BE0VEJ0ztfJuVxhgQhTh R1BfSbXYgwbBvj5IX5usn+Dsrg2zDpmSKrmfucpPBMjqgFpsqHk6c+wblhgUsZuogdrF/ BiKiqAJO7mXvtkXrn+EPhhwlZuAMvc7kJi6A9u49P9ERM8WB0dehW2y7GgmWLg0ml9smO df9MA1hIKO1NGdbBQ00Z93t8hIaBfZgwVI+qKJFo0J0C453LSSYV6nLkmm6EJSiQoTQE9 5NBXxHwn8h0vL0iqasbC2uWdjW3+XRFe/v5k4U/5Q04sQHlwuXVRQqN5st2pO3Dchfg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796061162; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=+sp/faC6iZ3Fg/3RqTykFmckQk27IcS1oK1Krqth4ws=; b=SgROnjPvPI4T90smKpjLtEEJPyhs23uwO0AlifmFhneSmXO/p4K3PoG7VLRuBs8YUA4o Jnj7WyLvJ7w8KmFz8szoz2XLGiA5dAQFmiWMfJU0xDU6CH1zT0vy0EXAHdIFGzEv6+6Xt 2BLpMBwinbjOvB2aj//QcCgRY6WDz9TuNAzak6q/l5eZSiamcUyNMnmXO/YF2BLK4f5FZ FW1G6BBlWNOxk8+aZBO5qYBH2zQ0H0T8hoCkCOx+iPa4lX5zem8OuniT3m8iJiIck6/mV Rp5fPQnPHyABjIPFzixDEFGOn60Cyzo4B8UAll+RPbkQzvWie9AlgNWMvya+8EKjCxw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=cWFj9BVs; arc=none smtp.remote-ip=209.85.221.45 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87AE0606A31C for ; Mon, 30 Nov 2026 17:52:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 87AE0606A31C 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=cWFj9BVs Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-4c3f0acc1easo1193758f8f.0 for ; Mon, 30 Nov 2026 09:52:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796061161; x=1796665961; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=+sp/faC6iZ3Fg/3RqTykFmckQk27IcS1oK1Krqth4ws=; b=cWFj9BVs3elEOAOIMYIwydiGDT3zpVOiKIqvn5rhRJahhnNHW7M7I6hRdunGkUcC8e XSeVdg+XkDIWlKMLHqjnSHiQ/2HFvrhISq0kYXgfN+3kfsv5cNaXn2ZiLHl4MI6aQYQ+ kewGIpR+p51j4unYwG5sc0CSrf5/wZaDw35uHPLErAxc564AgJJ9z07Qo4B/EF+bdWp0 h8bAZuE0ps4KVONyCaGspI82TXQyXnbpwUFm1hvd5s5tOYKJCV4LPs0E0NrjpULKu4F2 pKGS2DA+DInN8tEFaVvrWbhxhvQkxADlzXpziViUeBY97zKa6zTBEBh1IeVHZW98xFhf /PBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796061161; x=1796665961; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=+sp/faC6iZ3Fg/3RqTykFmckQk27IcS1oK1Krqth4ws=; b=jOv2ytnw2adx8iJWjArLTEAAu9C/IRv9ROp7hiloLnCA+z5kwh5PXmNW6615Tg07Mt 1Po0PZA2hd9v6cBvDZfctMN9hgefgzeBz+MslviG3DJT90vAaP4uoaYLRZjnbrup2yDz wiWhXd0xx1RxJKdNlax73PXDDNCWIfeMCZEhEH3pYndmPJUXjXZALNqrPPUmyL3t+bAY hyhrN1qhrGMEMExUnIXXLKRN49vlZwsJfPzra0dbqV0FNL2X76AUeZtQJh/A5YDYke2L Ohr/J/+eiNoZFnC385Hm3Rb6paS+7AZnhEIxlgPGGcLfzm+8Y5AlyKKeKDHC6iF0yOB+ +m6g== X-Forwarded-Encrypted: i=1; AL+hErEOi2fmGCxLv+9qI1WXbNh7M/VvFuxTMNdDY0kK1wIMO3+pBEC3TUIrpWm/g75wYP+mti4=@vger.kernel.org X-Gm-Message-State: APuU4Z93b9WRHFSKDpYkcG9L9Tkpj5YgIc/Cfa2k7F6aC1O/u/vN0F8i FVSJN2Bnqt9OzXYhJsbQI0ZqSLOhZiW8JNGyViyl6AB9V/eBSJYxPzVN X-Gm-Gg: AZFdTZfJ/1rLyVr1tznBQzcdUNInnm69eMi7QevSNDrFR435NiqjJk6lR5bll2mkeis wyr+z8/+012A1RY626BDDxZVuoPEaW+7ny2aCeZlikuAR5bXNr5NO266jEMJls15lrNhhwg+jJu MbKmjh/Lx/BPX8Dnqs39hWFSAFqrwUYKe9l5pAeDMdjz5mKQ7Ro2AMeVIGfqdnKtE2SRa2rjI2b oY++74MD/n0TjEtMIkygbyzMOi4b6AHzrmx0EZwBppslpg758idtRpvZeA96sGrs0Iz4KmdNF8l hBN/Mz/+LIxMyyMFWyUnY0so/3beBLOS0p2LMCsacmp0kzAAj5cuTquaiTg+hYP3irbWGd74ZAC q8HwTQ3TIPhKuUcO4s0lA2J3vd95LrfONH4PVx5165KtnvxRFzRwn+LMjfgtzJtJACZW6hrMyil WS52dndEagKHyojMlINurGJ6knI2dlXBC7TO9rawTOATEZBZDoX7gPtM/cxIVscG+bZIxfwTayc MqsE+V11e/Db1GXIXlU1E+90JwmwS4x9ReUCo+bxx6eM1acEFCIGplU8VrUHKYLIUX5fkKixbSZ hNGW21+GuzUkx9m96kC2MxfBSAkyuvNqgsgJWrPtxzpVCLs= X-Received: by 2002:a05:6000:2903:b0:48e:d40:a87c with SMTP id ffacd0b85a97d-4aa579a8cabmr86598755f8f.16.1796061160821; Mon, 30 Nov 2026 09:52:40 -0800 (PST) Received: from localhost.localdomain ([2a04:ee41:4:b2de:1ac0:4dff:fe0f:3782]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab9cf005f2sm55159452f8f.45.2026.11.30.09.52.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 09:52:40 -0800 (PST) From: Anton Protopopov To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Alan Maguire , John Fastabend , bpf@vger.kernel.org Cc: Anton Protopopov Subject: [PATCH v2 bpf-next 2/5] resolve_btfids: Tag the functions that return ERR_PTR() Date: Mon, 30 Nov 2026 18:04:19 +0000 Message-ID: <20261130180425.150703-3-a.s.protopopov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261130180425.150703-1-a.s.protopopov@gmail.com> References: <20261130180425.150703-1-a.s.protopopov@gmail.com> X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit A function that returns ERR_PTR(-EINVAL) fails in the same way as one that returns -EINVAL. Its callers check the pointer with IS_ERR() and get the error with PTR_ERR(). But resolve_btfids looks only at the functions that return an integer. Look at the functions that return a pointer too. A pointer has 8 bytes and its errors are sign extended as for a function that returns long. NULL is not listed: a program that returns 0 lets the trampoline call the function. The verifier checks all 64 bits of the return value of a program on such a function and requires the JIT for it, as for a function that returns long. Signed-off-by: Anton Protopopov --- tools/bpf/resolve_btfids/fmodret.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/bpf/resolve_btfids/fmodret.c b/tools/bpf/resolve_btfids/fmodret.c index 34085d944718..daf08a4b0204 100644 --- a/tools/bpf/resolve_btfids/fmodret.c +++ b/tools/bpf/resolve_btfids/fmodret.c @@ -29,8 +29,8 @@ /* More than any arch has argument registers */ #define MAX_PARAMS 16 -/* Return the size of the integer which FUNC returns, or 0 */ -static __u32 int_return_size(const struct btf *btf, const struct btf_type *func) +/* Return the size of the integer or of the pointer which FUNC returns, or 0 */ +static __u32 return_size(const struct btf *btf, const struct btf_type *func) { const struct btf_type *t = btf__type_by_id(btf, func->type); int ret = t->type ? btf__resolve_type(btf, t->type) : -1; @@ -38,6 +38,8 @@ static __u32 int_return_size(const struct btf *btf, const struct btf_type *func) if (ret < 0) return 0; t = btf__type_by_id(btf, ret); + if (btf_is_ptr(t)) + return 8; return btf_is_int(t) || btf_is_any_enum(t) ? t->size : 0; } @@ -160,7 +162,8 @@ static int cmp_error(const void *va, const void *vb) /* * Write the tag for a function which returns SIZE bytes, and in them one of the * NR VALUES of the return value register. For ASYNC see means_failure(). In 8 - * bytes an error is sign extended. + * bytes an error is sign extended, as in ERR_PTR(). NULL is 0: no program can + * return it instead of the function. * Return false if there is nothing to tag. * * The machine code cannot tell the -EPERM of a permission check from the -1 of a @@ -338,7 +341,7 @@ int fmodret_tag(Elf *elf, struct btf *btf, const char *deny_path, int verbose) if (!btf_is_func(t)) continue; nr_funcs++; - size = int_return_size(btf, t); + size = return_size(btf, t); if ((size != 4 && size != 8) || !fits_trampoline(btf, t)) continue; /* Skip functions which take or return BPF objects */ -- 2.43.0