From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-177.mta0.migadu.com (out-177.mta0.migadu.com [91.218.175.177]) (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 7A5813630AE; Fri, 12 Jun 2026 13:10:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781269834; cv=none; b=HKFHvUTdRw2ODH8YYA0qhKp37QSQ1QcnxeV8pXyKjFlgzfd/KsAT7JQBbhXhY9GIzVMJAPLdK8Lp4tznoq1VpxHS0/Qtorf++qRtMblmlhz2WV4NupboxAfvyzI8AJzdxiLUsiEBn0Beb3tYO2SbRW3OvrXQLtszCnmP1PMOi8s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781269834; c=relaxed/simple; bh=T7WTtQncrx2W3vrD+NN+RSar96YHpVnJWI0UZ09CLNs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NPSQ8D3ijyGODx3qr5KhofUjL2a3DOG8zqlSk55mIbU8Dj46629bYAajtHUzUdKkuAXSEKfW1szHMM784t+anBmhPEv0Lu+rV5r2A+jE4XQqRPzIpvGUqr250LB4xzFMGPt+c9AtjEIN71Z1vYmOPGp9uU2peRJEtxoQrmD1tMg= 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=kihALc21; arc=none smtp.client-ip=91.218.175.177 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="kihALc21" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1781269830; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9osiR+wejlHOHqtIIsmuWrRyuWCJR1wPh5cgThKEz9s=; b=kihALc21ZRiXlB+TvdergDkP8Bo9HrAsUk1ttjT9aR++pOCDMw1bIhxM/XSZTSwa3up/zx ICHjlUa/kCnxRqw4v4MVBr+9DVteS4FQn/B2D3XKUWh/iIRyZ8/L8zJiya3vcEXXSB8eyw WE6IvtRDW2bPdSFUObM8f7LBEHrcKnQ= From: Jiayuan Chen To: bpf@vger.kernel.org Cc: Weiming Shi , Xiang Mei , Xinyu Ma , Jiayuan Chen , Emil Tsalapatis , Daniel Borkmann , John Fastabend , Stanislav Fomichev , Martin KaFai Lau , Alexei Starovoitov , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Song Liu , Yonghong Song , Jiri Olsa , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jakub Sitnicki , Shuah Khan , Jesper Dangaard Brouer , Sechang Lim , Ihor Solodrai , Cong Wang , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v3 3/7] bpf, sockmap: zero-initialize pages allocated in bpf_msg_push_data Date: Fri, 12 Jun 2026 21:07:47 +0800 Message-ID: <20260612130919.299124-4-jiayuan.chen@linux.dev> In-Reply-To: <20260612130919.299124-1-jiayuan.chen@linux.dev> References: <20260612130919.299124-1-jiayuan.chen@linux.dev> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT From: Weiming Shi bpf_msg_push_data() allocates pages via alloc_pages() without __GFP_ZERO. In the non-copy path, the entire page of uninitialized heap content is added directly to the sk_msg scatterlist, which is then transmitted over TCP to userspace via tcp_bpf_push(). In the copy path, a gap of len bytes between the front and back memcpy regions is similarly left uninitialized. This leads to a kernel heap information leak: stale page content including kernel pointers from the direct-map and vmemmap regions is transmitted to userspace, which can be used to defeat KASLR. Add __GFP_ZERO to the alloc_pages() call to ensure the allocated page is always zeroed before it enters the scatterlist. Link: https://lore.kernel.org/all/20260424155913.A19FDC19425@smtp.kernel.org Fixes: 6fff607e2f14 ("bpf: sk_msg program helper bpf_msg_push_data") Tested-by: Xiang Mei Tested-by: Xinyu Ma Reviewed-by: Jiayuan Chen Reviewed-by: Emil Tsalapatis Signed-off-by: Weiming Shi Signed-off-by: Jiayuan Chen --- net/core/filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/core/filter.c b/net/core/filter.c index 3e555f276ba80..6e345ca65ca14 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -2832,7 +2832,7 @@ BPF_CALL_4(bpf_msg_push_data, struct sk_msg *, msg, u32, start, if (unlikely(copy + len < copy)) return -EINVAL; - page = alloc_pages(__GFP_NOWARN | GFP_ATOMIC | __GFP_COMP, + page = alloc_pages(__GFP_NOWARN | GFP_ATOMIC | __GFP_COMP | __GFP_ZERO, get_order(copy + len)); if (unlikely(!page)) return -ENOMEM; -- 2.43.0