From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C024231D372 for ; Mon, 20 Jul 2026 18:58:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784573896; cv=none; b=OZF8qf837c2o5Z9OY/6i7ryFspUJ/vtyyOOMPHux7WZjfRK2lbvaGt+f7MY6wIUWizC9tASSq7tek4FHb+eUU5V9IsmNeVLsg30WpOo5Qv2bFDyLh7hiwEkjKJs5yJX2IUXOOmlk/5vFvITv1pUKAhKsDXyw/dGs3GJ7fUCExe8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784573896; c=relaxed/simple; bh=eMgTGw8wrTt0RInOc+uENx4fWyxGJ4zX701Lv6w7LfI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=pHLc2v0PZMLvqKH7F2O+bH57/VOqIWdXFkQybttGkmZLtCCOucsVuzHPEVDG02q4DGG4H62RJL3YB2EI6i6e8z4p2+Il/rSnBZxOOKLqlhtIZWPgM7XSkSY9H75X9aA+Ju3xCSx8Eu1w0s06Ltn7QAIfyIAGf+33jB2ILQu/aag= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JseSykWn; arc=none smtp.client-ip=209.85.214.182 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.b="JseSykWn" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2ceaf8a1265so103106055ad.2 for ; Mon, 20 Jul 2026 11:58:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784573894; x=1785178694; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=EUhJ3DQnkMITZG1aHb7WqoIrpGY+mCsbkAev63KsSzg=; b=JseSykWnQEbL9VNHG/JeFVk4GQrH5oPSkhuNksL7MzZYtCyomCmp+za+G4cUxVKEoy qwYyMBGgjK3XsnJajq5cr177cH6/ma41+ArA2yckiGPRljm10n8KN1OEEiEUYO9QxW9s XTM997IyM42GB6GFvNjgvyCD7yLPqkgWClBuNXSRB122MkbRBPH3m7Mho24r1PN/n97r hkonbXZcXNwpGcqtF95yLG+FUxFZddlBvfMdNohltecxGkJ+1saLbFIxYRJqFztvMH+0 1Enm8/tT7TO0W1uVHUFHKlcC3V7SZtNWcoW6bYd0+p4aNPzqPqfjVRtaBeAnJIw1Qirn sLAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784573894; x=1785178694; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=EUhJ3DQnkMITZG1aHb7WqoIrpGY+mCsbkAev63KsSzg=; b=skv9n8iW4VYfwWLktjObKE+39O05DIYEuFCf9l2xqhyzsZR+dRZ7NO254YiV8Rb5xM FXupFfGGpcOW2cQjHr0Oo9lSj4pj8EUUktEQL68rjf+2WkkhN1phLMIADVcEv6PoYjlM LaG8c+nUYRalRcCI5ekrQMODtdfVjd95MQNhLLf8QbtvfmDgS57h+4VGFfsZoanTCCvN p9eOk819aXkGWhSwnPGDtzdUAb0yQr4UwS9TCR/u8jMIxyZuvjx86VpFuvaUIQyGRgTa HaCdj+B6zEMfeWrAIC5jNbvigUSG40nhLQ54Hj4ERkMb8Wdh3bXIs0491/azRsNb5t8C ge5Q== X-Forwarded-Encrypted: i=1; AHgh+RorWj0i4y9IgkBIk8KNFc0StoBcRMI6zFs+tfYT4pnMtLvw10/tdO5+abI0N9aGGoDNiKcgoqFtnTrZKvQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzhuFgu9h9TMF6m5YgvbWjq6FvtOUCC4Is84G8osuSsowjz/xg8 nm4yWcW+tf10DBwZxDqkStH9GJHuXIcR1AcDqHoIPYL+CiZ9mNp05NS9 X-Gm-Gg: AR+sD10LrXnJ55knwLMgD61UqNhjUzcN35bvWLyI5bmpbjK/byLJ/151ZmluvQ1l9o+ eUyEGoLDdWPtaD32WhyRgu5A/0qQ/8EPcHdkAJaxFjp0e77HTmnQse5HzI8zlDTly66/CnAFPs8 pvDFyMA0zt56qKDCErx+OsAe73LxKVjqdfDoQDs3QwwoqL2M+nN7mpTRNlg4Gu9L/FqOwkOnu9I cBkdTxjU3PAjnSFmo26odc7Wv2xaliDC/yrZDp5aO4bG5pF2UFwLQP6YLYi6n8t3NA2PHascW/Y n+1UylsEx0nm50DXtHWr7sK7GtsQ0refvjTzYO51gBTwhoqaWTvmNGTqVhRgnlASVDGrinPfNQO glyPnaRhXyyWEiu27PmwNdrH2Zvnlu6/GI+D+hIcUdeHW78ExbWzZGy7dM+rEduan7cY6nX6MUO JbSMg2TSkFbHomg3d90Ew= X-Received: by 2002:a17:903:13c6:b0:2ce:b096:e517 with SMTP id d9443c01a7336-2cf3489548bmr165934705ad.5.1784573894122; Mon, 20 Jul 2026 11:58:14 -0700 (PDT) Received: from [192.168.1.77] ([50.47.108.115]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cf347166e6sm61259355ad.59.2026.07.20.11.58.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 20 Jul 2026 11:58:13 -0700 (PDT) Message-ID: <505a58d4-e585-4cb7-a21f-80a721f5c452@gmail.com> Date: Mon, 20 Jul 2026 11:58:13 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH bpf v4 4/4] bpf, cgroup: Fix storage null-ptr-deref after replacing prog To: Pu Lehui , bpf@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Yonghong Song , Song Liu , Jiri Olsa , Emil Tsalapatis , Pu Lehui References: <20260720134547.1289964-1-pulehui@huaweicloud.com> <20260720134547.1289964-5-pulehui@huaweicloud.com> Content-Language: en-US From: Amery Hung In-Reply-To: <20260720134547.1289964-5-pulehui@huaweicloud.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 7/20/26 6:45 AM, Pu Lehui wrote: > From: Pu Lehui > > Syzkaller reported a storage null-ptr-deref issue after replacing prog. > This occurs in the following scenario: > 1. prog A, an empty prog, is attached to a cgrp. > 2. prog B uses BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE and calls the > bpf_get_local_storage helper. > 3. link_update is called to replace prog A with prog B. > > The reason is that __cgroup_bpf_replace fails to alloc and assign the > required cgrp storage for the incoming replacement prog. Consequently, > the new prog inherits an uninit storage, leading to null-ptr-deref panic > when kick the new prog. > > Fix this by properly allocating the storage and comparing the old and > new storage pointers. If the storage changed, fallback to > update_effective_progs which performs a RCU-safe update of the entire > array. If the storage remains unchanged, we can safely retain the > fast-path in-place update. > > Additionally, handle the error path in __cgroup_bpf_attach strictly. > Although it is rare for update_effective_progs to fail in this context, > proper rollbacks for storage and flags are added for code rigor. > > Fixes: 0c991ebc8c69 ("bpf: Implement bpf_prog replacement for an active bpf_cgroup_link") > Signed-off-by: Pu Lehui Reviewed-by: Amery Hung [...]