From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from zg8tmtyylji0my4xnjeumjiw.icoremail.net (zg8tmtyylji0my4xnjeumjiw.icoremail.net [162.243.161.220]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A01453AFB1B; Tue, 23 Jun 2026 06:11:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.243.161.220 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782195119; cv=none; b=j5qeKBfrgIlH0gTe0Iw+Zvtq5z1bbhH+/8qhHm4QOOXtr+69lrDfuy2ykWPkTyxyhUdt2gJypgOpHhPcsiL+duwIsJsnqD8eoV35ZqSv9xfk3uwsiiMdfgo/4XfqCwMqwYW2cCjPR587wfUTESnXuKBdSOov7WSzfi30Ij+FR9Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782195119; c=relaxed/simple; bh=SFE+n92nV/aiYiKgiiJg3UHjDXNx07v+CPPydxAikXg=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=bJdvJVH5gIT+/yGCJc9OCngjbap/wN/8Tc9B3EemTM22go2hU2w+pVtotCQlY0nLrW7LFrfwnJ0uEFHu5IpZRaZQvxnmx72qQlmgupKOmmfDef3y/0dqeU18+ER3eIBIhY66RFiVcBJgZkaRoaZe5fiRXQivhdo2DhvYM8LKqKQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mails.tsinghua.edu.cn; spf=pass smtp.mailfrom=mails.tsinghua.edu.cn; dkim=pass (1024-bit key) header.d=mails.tsinghua.edu.cn header.i=@mails.tsinghua.edu.cn header.b=MiucgvSS; arc=none smtp.client-ip=162.243.161.220 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mails.tsinghua.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mails.tsinghua.edu.cn Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mails.tsinghua.edu.cn header.i=@mails.tsinghua.edu.cn header.b="MiucgvSS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mails.tsinghua.edu.cn; s=dkim; h=Received:From:To:Cc:Subject: Date:Message-Id:MIME-Version:Content-Transfer-Encoding; bh=pCJbk muJfju09ou2x2V+w0+SSqTTN4WWo/jzMYeHGtI=; b=MiucgvSS+sJFuvJkMqovg 0ANLa6GP9veLyWC98gz4o4uk3qNk8UkBeTekM67fUJxVrLL22CWJuYqeX1fQK1sm AtR5wncR6f/Mlfp+7gTTiEQmn/RXYrlkCFS0vDi9951Zky4c9Pk2nAv1FCUz8GLM A99RkkZKJgFF0VW65rN8oo= Received: from c9a6c405b3f2.. (unknown [202.112.238.121]) by web4 (Coremail) with SMTP id ywQGZQAXKJ1_Izpqkgx3Ag--.57670S2; Tue, 23 Jun 2026 14:11:22 +0800 (CST) From: Yiyang Chen To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi Cc: Yiyang Chen , John Fastabend , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Shuah Khan , Viktor Malik , Leon Hwang , Dave Marchevsky , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v4 0/2] bpf: Reject offset refcount acquire arguments Date: Tue, 23 Jun 2026 06:11:08 +0000 Message-Id: X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:ywQGZQAXKJ1_Izpqkgx3Ag--.57670S2 X-Coremail-Antispam: 1UD129KBjvJXoW7WrW8GFyDCr4UJFyrCw4UArb_yoW8Kw17p3 yrXr15trn7tryxCrZavw1UCryrCan5CrWFkF1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eled as returning a refcounted allocation base, but it currently accepts PTR_TO_BTF_ID | MEM_ALLOC arguments whose offset already points at an embedded graph node returned from a list or rbtree operation. At runtime the kfunc starts from the supplied pointer and adds the type's refcount offset. With a graph-node pointer, that starts from base + node_off, while the verifier treats the returned pointer as the allocation base. Reject non-zero fixed-offset arguments to keep the runtime operation and the verifier model aligned. Programs that pop graph nodes can still acquire a reference after normalizing the node pointer with container_of(). Patch 1 handles the zero fixed-offset requirement in the existing check_func_arg_reg_off() / __check_ptr_off_reg() path without consuming a bpf_type_flag bit. Patch 2 adds a rejected direct list-node case. Changes from v3: - Add Eduard's Acked-by to patch 1. - Drop the redundant rbtree selftest case; the list case exercises the same refcount-acquire fixed-offset rejection path. - Trim the selftest commit message and remove the selftest Fixes tag. Changes from v2: - Avoid adding a new bpf_type_flag bit. - Carry the refcount-acquire zero fixed-offset requirement with an internal check_func_arg_reg_off() parameter. Changes from v1: - Move zero fixed-offset enforcement into check_func_arg_reg_off() / __check_ptr_off_reg(), as suggested by Eduard. - Drop the positive container_of() selftest case. - Remove the stale bpf_obj_drop() after bpf_list_push_front(), since the pushed reference is consumed even when the verifier explores the error branch. - Rebase to bpf-next master a975094bf98c. v3: https://lore.kernel.org/bpf/cover.1781979133.git.chenyy23@mails.tsinghua.edu.cn/ v2: https://lore.kernel.org/bpf/cover.1781963957.git.chenyy23@mails.tsinghua.edu.cn/ v1: https://lore.kernel.org/bpf/cover.1781852308.git.chenyy23@mails.tsinghua.edu.cn/ Yiyang Chen (2): bpf: Reject offset refcount acquire arguments selftests/bpf: Cover refcount acquire node offsets kernel/bpf/verifier.c | 32 +++++++++++------ .../bpf/progs/refcounted_kptr_fail.c | 34 +++++++++++++++++++ 2 files changed, 56 insertions(+), 10 deletions(-) base-commit: a975094bf98ca97be9146f9d3b5681a6f9cf5ce3 -- 2.34.1