From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) (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 4DCB230BF52 for ; Thu, 25 Jun 2026 21:30:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782423049; cv=none; b=Y0wxkhWKARW6HZCHojZUNDlhNEDY5YGoOIM1wLpYJeYPIA3B3VTZZoYNlfyHDsL2sxpdew38D8xFDyu/NwnVPAlj1x1lkVLuH5mukFBaAEUkT6cL8XaAxEQyMEVhGDTdPXnxk7xy9KHYzMI1fNukBRkdPBGz/WynUZp1DzKjDUE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782423049; c=relaxed/simple; bh=FAfGsS/vKMjiqWjBITTAkt5g8m2FD7Lkq/gg8IRItFc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=EYl30niLRUNpbz4qUlwx0m/7UQP87sXcd4Yn1tuCCM5HyxtGzcXTTc6qEVOpjmv0WckPC5oLSFRk7J8Zr1i8bclDZSD2q/hDYQTMSVh0llGF+NcvhO+TlphquZgknm2ngxN2yeYFON2uAs7gewun9n+v36Iba7oYp7bci4xT8Zc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=OUbTVyQ7; arc=none smtp.client-ip=91.218.175.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="OUbTVyQ7" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1782423035; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FAfGsS/vKMjiqWjBITTAkt5g8m2FD7Lkq/gg8IRItFc=; b=OUbTVyQ7WUf7GxwU7LhYcV1WsTM03Qc636p0aJn/vLvx5d4RJpXee9ZT0EqRdDt4usKmpv +pYwuGaK6qZjb4alX7YIWgj3r6uhxzMYPyEtXaNo0HCLOwKssQdttKLcb4vO6CeQcE1ic/ zq9upf8gTjMB3Du+uHKWkLhyFHr/wE4= Date: Thu, 25 Jun 2026 14:30:17 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH bpf-next v4 1/2] bpf: Reject offset refcount acquire arguments Content-Language: en-GB To: Yiyang Chen , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi Cc: John Fastabend , Martin KaFai Lau , Song Liu , 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 References: <2f894647f56f71838fdddeb97a3e057ed35ea92e.1782192383.git.chenyy23@mails.tsinghua.edu.cn> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Yonghong Song In-Reply-To: <2f894647f56f71838fdddeb97a3e057ed35ea92e.1782192383.git.chenyy23@mails.tsinghua.edu.cn> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 6/22/26 11:11 PM, Yiyang Chen wrote: > bpf_refcount_acquire() increments the refcount at the caller-supplied > pointer plus the refcount field offset, then returns the caller-supplied > pointer unchanged. > > The verifier records the return value as a base pointer to the refcounted > object. > > bpf_list_pop_front() and bpf_rbtree_remove() can return embedded > graph-node pointers as PTR_TO_BTF_ID | MEM_ALLOC with a fixed offset equal > to the node field offset. Passing such a pointer directly to > bpf_refcount_acquire() currently passes the refcounted-kptr type check. > > That makes the runtime operation start from base + node_off while the > verifier models the returned pointer as the object base. > > Require refcount-acquire arguments to have zero fixed offset by carrying > the requirement through check_func_arg_reg_off() to __check_ptr_off_reg(). > Programs can still acquire a refcount from a graph-node-derived pointer > after normalizing it with container_of(). > > Fixes: 7c50b1cb76aca ("bpf: Add bpf_refcount_acquire kfunc") > Signed-off-by: Yiyang Chen > Acked-by: Eduard Zingerman Acked-by: Yonghong Song