From nobody Sat Feb 7 20:58:15 2026 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 AC52D274B40 for ; Sun, 4 Jan 2026 16:25:01 +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=1767543903; cv=none; b=cj1IlzkYYh9CI2IkL2ItS/AFQn7UtqGI+DaF+bl+BVhvHpei9FO/m7k1VhLnWJdTVpoRPUjZeCuoydFv8x4nP7fnkcNwL/aSO2taTZRpIMDYSfE++J1rYu8RqQaO+jtYvImckmLSZ4virtK4Az2XOMCgLqgWB5CkJK7kv+e0NEo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767543903; c=relaxed/simple; bh=j7cR8+ufxEC6b3PZjjtmQAAcUCXybtKLeeEyN+Kt9zs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EDHjuvyxqadXjyvNGVGY4hRW9TSnY0AiCtGaE7DYUufvoEoEbKt2yTQrEpfWHkA244oUF3D9rq14uNQSTLb7BsyOYePKiRkwdYJ4BYbB41EtytZUEUpxN8AMuiMFTD7d/qEwNY8vn0hp4FXi/VNu5JuD6Pz5krsouP7OcnN6UC0= 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=wqGYwy3r; 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="wqGYwy3r" 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=1767543899; 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=CvUp10h0Mn9exzUZ/n1dBrd2YDkqgmgwZbLLzqYBLM4=; b=wqGYwy3rPPwjUgcwc+Zk72fRwu9rJHd4cpXwPFYdXQyo3aLdr2BFjuogY9pVKKvMo27hRB MJoMlLw7LAHxkey1r+/58EPUG5f81OtXgLn0IPa8CtwgPehxf7xadVLLtvI06qmcLb0YRz Ett+KwBbweZPn8l+dQiGwaC6Q4/vKc4= From: KaFai Wan To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, hawk@kernel.org, shuah@kernel.org, aleksander.lobakin@intel.com, toke@redhat.com, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: KaFai Wan , Yinhao Hu , Kaiyan Mei , Dongliang Mu Subject: [PATCH bpf-next 1/2] bpf, test_run: Fix user-memory-access vulnerability for LIVE_FRAMES Date: Mon, 5 Jan 2026 00:23:49 +0800 Message-ID: <20260104162350.347403-2-kafai.wan@linux.dev> In-Reply-To: <20260104162350.347403-1-kafai.wan@linux.dev> References: <20260104162350.347403-1-kafai.wan@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" When testing XDP programs with LIVE_FRAMES mode, if the metalen is set to >=3D (XDP_PACKET_HEADROOM - sizeof(struct xdp_frame)), there won't be enough space for the xdp_frame conversion in xdp_update_frame_from_buff(). Additionally, the xdp_frame structure may be filled with user-provided data, which can lead to a memory access vulnerability when converting to skb. This fix reverts to the original version and ensures data_hard_start correctly points to the xdp_frame structure, eliminating the security risk. Reported-by: Yinhao Hu Reported-by: Kaiyan Mei Reviewed-by: Dongliang Mu Fixes: 294635a8165a ("bpf, test_run: fix &xdp_frame misplacement for LIVE_F= RAMES") Signed-off-by: KaFai Wan --- net/bpf/test_run.c | 23 +++++++++---------- .../bpf/prog_tests/xdp_do_redirect.c | 6 ++--- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c index 655efac6f133..00234eba7c76 100644 --- a/net/bpf/test_run.c +++ b/net/bpf/test_run.c @@ -90,11 +90,9 @@ static bool bpf_test_timer_continue(struct bpf_test_time= r *t, int iterations, struct xdp_page_head { struct xdp_buff orig_ctx; struct xdp_buff ctx; - union { - /* ::data_hard_start starts here */ - DECLARE_FLEX_ARRAY(struct xdp_frame, frame); - DECLARE_FLEX_ARRAY(u8, data); - }; + /* ::data_hard_start starts here */ + struct xdp_frame frame; + DECLARE_FLEX_ARRAY(u8, data); }; =20 struct xdp_test_data { @@ -131,10 +129,11 @@ static void xdp_test_run_init_page(netmem_ref netmem,= void *arg) frm_len =3D orig_ctx->data_end - orig_ctx->data_meta; meta_len =3D orig_ctx->data - orig_ctx->data_meta; headroom -=3D meta_len; + headroom +=3D sizeof(head->frame); =20 new_ctx =3D &head->ctx; - frm =3D head->frame; - data =3D head->data; + frm =3D &head->frame; + data =3D frm; memcpy(data + headroom, orig_ctx->data_meta, frm_len); =20 xdp_init_buff(new_ctx, TEST_XDP_FRAME_SIZE, &xdp->rxq); @@ -215,8 +214,8 @@ static bool frame_was_changed(const struct xdp_page_hea= d *head) * i.e. has the highest chances to be overwritten. If those two are * untouched, it's most likely safe to skip the context reset. */ - return head->frame->data !=3D head->orig_ctx.data || - head->frame->flags !=3D head->orig_ctx.flags; + return head->frame.data !=3D head->orig_ctx.data || + head->frame.flags !=3D head->orig_ctx.flags; } =20 static bool ctx_was_changed(struct xdp_page_head *head) @@ -234,8 +233,8 @@ static void reset_ctx(struct xdp_page_head *head) head->ctx.data =3D head->orig_ctx.data; head->ctx.data_meta =3D head->orig_ctx.data_meta; head->ctx.data_end =3D head->orig_ctx.data_end; - xdp_update_frame_from_buff(&head->ctx, head->frame); - head->frame->mem_type =3D head->orig_ctx.rxq->mem.type; + xdp_update_frame_from_buff(&head->ctx, &head->frame); + head->frame.mem_type =3D head->orig_ctx.rxq->mem.type; } =20 static int xdp_recv_frames(struct xdp_frame **frames, int nframes, @@ -301,7 +300,7 @@ static int xdp_test_run_batch(struct xdp_test_data *xdp= , struct bpf_prog *prog, head =3D phys_to_virt(page_to_phys(page)); reset_ctx(head); ctx =3D &head->ctx; - frm =3D head->frame; + frm =3D &head->frame; xdp->frame_cnt++; =20 act =3D bpf_prog_run_xdp(prog, ctx); diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c b/too= ls/testing/selftests/bpf/prog_tests/xdp_do_redirect.c index dd34b0cc4b4e..f7615c265e6e 100644 --- a/tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c +++ b/tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c @@ -59,12 +59,12 @@ static int attach_tc_prog(struct bpf_tc_hook *hook, int= fd) =20 /* The maximum permissible size is: PAGE_SIZE - sizeof(struct xdp_page_hea= d) - * SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) - XDP_PACKET_HEADROOM = =3D - * 3408 bytes for 64-byte cacheline and 3216 for 256-byte one. + * 3368 bytes for 64-byte cacheline and 3216 for 256-byte one. */ #if defined(__s390x__) -#define MAX_PKT_SIZE 3216 +#define MAX_PKT_SIZE 3176 #else -#define MAX_PKT_SIZE 3408 +#define MAX_PKT_SIZE 3368 #endif =20 #define PAGE_SIZE_4K 4096 --=20 2.43.0