From patchwork Tue Jan 21 15:06:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shigeru Yoshida X-Patchwork-Id: 13946394 X-Patchwork-Delegate: bpf@iogearbox.net Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 4E66F1F4715 for ; Tue, 21 Jan 2025 15:07:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737472030; cv=none; b=NqRKoVbWBClST7uT08UQK/dLzESZwuw+MWbi4rP0HQXaQgWj1M1OQE55KWiM28TjPTUue68nouQIzEO6qeNco/BeVOFH2C4huvYgF7f6w8pNTo40n02HJCOtyjbEwQZ024TEyHt8WRKfa4PPQKUTp+QI8uGeem9cWOHEBMEiny4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737472030; c=relaxed/simple; bh=E4awb02GfOMHu6yIjUy62+GVOVOjQQgO9J5MZBqVA58=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=WZtzR/mEPJhpKA/KZC1NB9B9j78Y4ygwjleHlO7xb6BW6bEaiLOMsjbdnRt5DQqnHgSVXSRWcU31uFFiSmrWWkfKTcYxXkf2YfUExGeu7Ikh/0CPO4SsjoSPOWUdClKeFknpcY9egedwnfLi0g7t0KOAB0FasyjBivuEYD+xseQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Jz+ur9PB; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Jz+ur9PB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737472027; 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; bh=S0A13FjhF2U6qOIcW/juVfvCcYxku+JtO5E2OXUx59g=; b=Jz+ur9PB+tUJ0Yz2oAPrxLPBZpzJqy3PewsJd51DiMCdUDtnfTr2rIohS20uKI9+bv1beC 6Zo/R4MAuGBfTAoG7SIBlQtZ2k/aOajl4o5JXIw0ou+OWht1mEoUdfhTWstAw5I0MeIfSC IST2pKxX50KNskKdc9YFF+x2RrBkAOo= Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-303-3FwZ7jY8OVeIE14nCbnp1Q-1; Tue, 21 Jan 2025 10:07:05 -0500 X-MC-Unique: 3FwZ7jY8OVeIE14nCbnp1Q-1 X-Mimecast-MFC-AGG-ID: 3FwZ7jY8OVeIE14nCbnp1Q Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-2161d5b3eb5so102841375ad.3 for ; Tue, 21 Jan 2025 07:07:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737472025; x=1738076825; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=S0A13FjhF2U6qOIcW/juVfvCcYxku+JtO5E2OXUx59g=; b=d+LcSa7kV+9I+8yBe7OffQOD36DztqedCL29rpaLFx5qPnwWozUt3Es3j4u0m9dC3i yXBF4J4XETbwo5qKv06u1r5It4bLM4xPpwKe40GI3wR9BU8IvZCybPFFxsCsVPdti8+K QgM9Qb/LoSCbpmRC113rXjKNYXbq9kcrNwGZsJ4waqmCWRlAAmrMureJgaPy9De25EzQ 3eYqzDcwynICxerf118PEbMAu72RraLSfcY7lYfiBEfw9uG8nekW9nhiyLbCm1vNHtSV QRvupPrYqUXuWzM3fDeZhmNLsGMgRzoODXNfO2kWVwxw+ZNb2oTFNL49E7D7aeE9oI69 AGBQ== X-Forwarded-Encrypted: i=1; AJvYcCVSe7VFXuoWZM0OpUylFI4C29iNu53kt4hj2tNif0BYuMEqrvEtghwHmZDeNtDQQ/4sX7k=@vger.kernel.org X-Gm-Message-State: AOJu0Yx6YMeKNBLyRxdRQ4v2SXt/wA+/JPTTGtifkshefY4wjeW26eJ2 0aPG528sjkPkcZod4XMcBfhsH81Ubt6dy9RNCCmmYR42uYh6qbCgcC7IKraPIWGqjwaukjP2W0W ZXTsBBJ4i9bjYd6pWAfXy0wTu3gpFHvOmuJkI/zCOeLZOvz8Ejw== X-Gm-Gg: ASbGncvPyNNvp2J/U3G9LU/4dk6lbVcl4XxzdhOxSN1n1y1TNYWG9JJDwPuDscht7Ta sdKLg98KEIR8p7cnVod9PVRjGezJEX8ZoZJ2gZUXsGpn76BAOB6I6QXngpWSg89em6SwaKYBjsL e9L+pZc0zAq4hGJXVmNeSIfKz7MzDrGOIA6iCCb1rawzfPkfecVablHpNmR1MymW4U6E+9YA0uE esVkQamYcnGqcA7IakJp9o5MkTW20TSnvAJMlg/QgsFp1xHby3ULFi84SH2KyF1LAslgfzpAZ8F vXndqaoWsjiUdipzfJJGT4XARmB6+M8rlyM= X-Received: by 2002:a17:902:f60f:b0:215:8270:77e2 with SMTP id d9443c01a7336-21c34cb5bf8mr290507585ad.0.1737472023285; Tue, 21 Jan 2025 07:07:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IFip8Sgzo2DHVqMP4MZArU5I4YQ9MZM/9OeVcTT5mtCY+uCBZ3gqY1GJj53CP0hgom4XvZXlA== X-Received: by 2002:a17:902:f60f:b0:215:8270:77e2 with SMTP id d9443c01a7336-21c34cb5bf8mr290506035ad.0.1737472021406; Tue, 21 Jan 2025 07:07:01 -0800 (PST) Received: from kernel-devel.local (fp6fd8f7a1.knge301.ap.nuro.jp. [111.216.247.161]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2ce9efe3sm79066215ad.20.2025.01.21.07.06.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jan 2025 07:07:00 -0800 (PST) From: Shigeru Yoshida 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 Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, hawk@kernel.org, lorenzo@kernel.org, toke@redhat.com, bpf@vger.kernel.org, netdev@vger.kernel.org, stfomichev@gmail.com, Shigeru Yoshida , syzkaller Subject: [PATCH bpf v2 1/2] bpf, test_run: Fix use-after-free issue in eth_skb_pkt_type() Date: Wed, 22 Jan 2025 00:06:42 +0900 Message-ID: <20250121150643.671650-1-syoshida@redhat.com> X-Mailer: git-send-email 2.48.1 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net KMSAN reported a use-after-free issue in eth_skb_pkt_type()[1]. The cause of the issue was that eth_skb_pkt_type() accessed skb's data that didn't contain an Ethernet header. This occurs when bpf_prog_test_run_xdp() passes an invalid value as the user_data argument to bpf_test_init(). Fix this by returning an error when user_data is less than ETH_HLEN in bpf_test_init(). Additionally, remove the check for "if (user_size > size)" as it is unnecessary. [1] BUG: KMSAN: use-after-free in eth_skb_pkt_type include/linux/etherdevice.h:627 [inline] BUG: KMSAN: use-after-free in eth_type_trans+0x4ee/0x980 net/ethernet/eth.c:165 eth_skb_pkt_type include/linux/etherdevice.h:627 [inline] eth_type_trans+0x4ee/0x980 net/ethernet/eth.c:165 __xdp_build_skb_from_frame+0x5a8/0xa50 net/core/xdp.c:635 xdp_recv_frames net/bpf/test_run.c:272 [inline] xdp_test_run_batch net/bpf/test_run.c:361 [inline] bpf_test_run_xdp_live+0x2954/0x3330 net/bpf/test_run.c:390 bpf_prog_test_run_xdp+0x148e/0x1b10 net/bpf/test_run.c:1318 bpf_prog_test_run+0x5b7/0xa30 kernel/bpf/syscall.c:4371 __sys_bpf+0x6a6/0xe20 kernel/bpf/syscall.c:5777 __do_sys_bpf kernel/bpf/syscall.c:5866 [inline] __se_sys_bpf kernel/bpf/syscall.c:5864 [inline] __x64_sys_bpf+0xa4/0xf0 kernel/bpf/syscall.c:5864 x64_sys_call+0x2ea0/0x3d90 arch/x86/include/generated/asm/syscalls_64.h:322 do_syscall_x64 arch/x86/entry/common.c:52 [inline] do_syscall_64+0xd9/0x1d0 arch/x86/entry/common.c:83 entry_SYSCALL_64_after_hwframe+0x77/0x7f Uninit was created at: free_pages_prepare mm/page_alloc.c:1056 [inline] free_unref_page+0x156/0x1320 mm/page_alloc.c:2657 __free_pages+0xa3/0x1b0 mm/page_alloc.c:4838 bpf_ringbuf_free kernel/bpf/ringbuf.c:226 [inline] ringbuf_map_free+0xff/0x1e0 kernel/bpf/ringbuf.c:235 bpf_map_free kernel/bpf/syscall.c:838 [inline] bpf_map_free_deferred+0x17c/0x310 kernel/bpf/syscall.c:862 process_one_work kernel/workqueue.c:3229 [inline] process_scheduled_works+0xa2b/0x1b60 kernel/workqueue.c:3310 worker_thread+0xedf/0x1550 kernel/workqueue.c:3391 kthread+0x535/0x6b0 kernel/kthread.c:389 ret_from_fork+0x6e/0x90 arch/x86/kernel/process.c:147 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244 CPU: 1 UID: 0 PID: 17276 Comm: syz.1.16450 Not tainted 6.12.0-05490-g9bb88c659673 #8 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-3.fc41 04/01/2014 Fixes: be3d72a2896c ("bpf: move user_size out of bpf_test_init") Reported-by: syzkaller Suggested-by: Martin KaFai Lau Signed-off-by: Shigeru Yoshida --- v2: - Rewrote the code as suggested by Martin. - Fixed the broken tests. v1: - https://lore.kernel.org/all/20241201152735.106681-1-syoshida@redhat.com/ --- net/bpf/test_run.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c index 501ec4249fed..8612023bec60 100644 --- a/net/bpf/test_run.c +++ b/net/bpf/test_run.c @@ -660,12 +660,9 @@ static void *bpf_test_init(const union bpf_attr *kattr, u32 user_size, void __user *data_in = u64_to_user_ptr(kattr->test.data_in); void *data; - if (size < ETH_HLEN || size > PAGE_SIZE - headroom - tailroom) + if (user_size < ETH_HLEN || user_size > PAGE_SIZE - headroom - tailroom) return ERR_PTR(-EINVAL); - if (user_size > size) - return ERR_PTR(-EMSGSIZE); - size = SKB_DATA_ALIGN(size); data = kzalloc(size + headroom + tailroom, GFP_USER); if (!data) From patchwork Tue Jan 21 15:06:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shigeru Yoshida X-Patchwork-Id: 13946395 X-Patchwork-Delegate: bpf@iogearbox.net Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 D2E6A1F4280 for ; Tue, 21 Jan 2025 15:07:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737472044; cv=none; b=bi2Aec0cgd4Gr6HLkftAZNqdkDGcYNtyxmG9RXxA3QuKx5ozhcz0GWQs6cqjBlUva/0n/xFZBBwQWJgbSmNKNmHPsyNfh4lXLkFupNqANHX1+SNpIIQqrigKvRyeU3EVF9+sx6MQM5KlNezmXzqzRoUc0h1qtUk9e/dyMq3rxsY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737472044; c=relaxed/simple; bh=tiZRx3B2HMuqovxcLXfDoQxoFVQ/Mn4COLH9Vv01p5Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XuR26bn0gA6h7Exh4UuTpkoNhWsYZAtpF+Lb3tZycdt/B5+eyI4zBIiGTt0cM7RSSn8Y7sRuYlvdu1kWACPVmrV/0xs98WiG/KtWX1FjCXIgUJ0GX6SIWafu/5Mjn2yayP//9ZAfk7pzvfKMX4v+0r8f0fx7Y0lFCyyAP5rR5uM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=gZGsKlqC; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gZGsKlqC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737472041; 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=DjbE/E9Mq2/nisrHRajqDYH+16MtQm8zpmU3v3KEuJI=; b=gZGsKlqCKa6tSlqafz0r4I1KFjxfvoLrthiazdUR2LrfXZNZfKF/QVvDzb9WHEGxLwk8re 6p4sWstLE5u4u+y3HQGPthEmdv+nlHdwUbNGS3Kk0bLLv5PV8oy0i2buP9NFp0NcpSWYdv qq3+nMTgw5l0BB8b8D1H04CH1x0x0lg= Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-350-ql1KL0eCMPSFNCvDtqPmSA-1; Tue, 21 Jan 2025 10:07:20 -0500 X-MC-Unique: ql1KL0eCMPSFNCvDtqPmSA-1 X-Mimecast-MFC-AGG-ID: ql1KL0eCMPSFNCvDtqPmSA Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-21650d4612eso35129335ad.2 for ; Tue, 21 Jan 2025 07:07:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737472039; x=1738076839; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DjbE/E9Mq2/nisrHRajqDYH+16MtQm8zpmU3v3KEuJI=; b=oLh3ocF/VrsWi2mqSvLivlIOLY7YscVBV1hyJQXeXMP/aP/m/9So2e2G557djuXuLL EmdvecT2d8RcTeY5JO/0/YASt9Vz01OgzR9ATJXhssAza3WJ/LRnkupMzwu4FQiAe5DR dbsRr8JfWm1BJKFcn5ZxSATYimswWBn0BCknjgG1s80usqUwjw1qBEahykLRNhgfwBR7 iONkZqMZXgVt3wA62gLkMj+5RNAOOpcrmuOyEOPZqknddRvJoOco0VKCC5VjN79c9iom nkVt/SGDPTu24+9wNRWzoXgfQ/gK4o0a28MolxeBwLYab93790j5xH3u0S8BucmoR16i hiQQ== X-Forwarded-Encrypted: i=1; AJvYcCUQkp69ACOL/kkO64KTrSGIPg6QB2iuQvVZ0RhpOGYwvmEP2gymNHNpuSy1n9FBFoPy6zM=@vger.kernel.org X-Gm-Message-State: AOJu0Yy95qDzrrsoIJUjOL9nrmVO2zXPeNN/Z+4usxHCgj9HWCRI3+RJ Wm1Q+zW+oQWnPVLZbvGtcsdttnfi4Cbow2jFaBKRt8IkkIR/qYLO1TygjcjxqC7c792NjiKVujg SWQ77IFo7ueR6R5Y7n8orv4Rr/xKZh11rVgndNKXSWhYwyCI7cw== X-Gm-Gg: ASbGncu66cTbhaTpzerDbo3Dcflu3PY7c7WX3qitlHcvDP+0PuHVdSsfTl6gnUla5r0 /OCtEh98Y0SVasQWSfoldgNPWN+ak1seuMD2yzn9uDMs+wThq+ZEpCTdMmrjbcGYumMMuQPRFb0 f7acuEAxiHEMHFVRqwCmk2qs3aFsCuTStb5anqkS8LEzavNJFqsPgjDF80r4X+0THD9CFe8MPkj Q0G80uSDptslPCKo1yfJzKGfmKSzHJJhKySSyVXkKuYS3bvBwB5SA439tNNAZ0oPrSov6Qf8ert 2Wx8R0zUemAnj0KqKVENmL3HHes4P51UOV0= X-Received: by 2002:a17:903:2290:b0:216:5e6e:68cb with SMTP id d9443c01a7336-21c3540d18cmr272622785ad.16.1737472039416; Tue, 21 Jan 2025 07:07:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IGljEPOvi4LdYIJi1m/mh0EvC9Vvtm5uevEGtJyjU6lfXNp5gADbbEg1zX0Q/7CjZDObORDaQ== X-Received: by 2002:a17:903:2290:b0:216:5e6e:68cb with SMTP id d9443c01a7336-21c3540d18cmr272622365ad.16.1737472039096; Tue, 21 Jan 2025 07:07:19 -0800 (PST) Received: from kernel-devel.local (fp6fd8f7a1.knge301.ap.nuro.jp. [111.216.247.161]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2ce9efe3sm79066215ad.20.2025.01.21.07.07.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jan 2025 07:07:18 -0800 (PST) From: Shigeru Yoshida 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 Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, hawk@kernel.org, lorenzo@kernel.org, toke@redhat.com, bpf@vger.kernel.org, netdev@vger.kernel.org, stfomichev@gmail.com, Shigeru Yoshida Subject: [PATCH bpf v2 2/2] selftests/bpf: Adjust data size to have ETH_HLEN Date: Wed, 22 Jan 2025 00:06:43 +0900 Message-ID: <20250121150643.671650-2-syoshida@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250121150643.671650-1-syoshida@redhat.com> References: <20250121150643.671650-1-syoshida@redhat.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net The function bpf_test_init() now returns an error if user_size (.data_size_in) is less than ETH_HLEN, causing the tests to fail. Adjust the data size to ensure it meets the requirement of ETH_HLEN. Signed-off-by: Shigeru Yoshida --- .../testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c | 4 ++-- .../testing/selftests/bpf/prog_tests/xdp_devmap_attach.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c b/tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c index c7f74f068e78..df27535995af 100644 --- a/tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c +++ b/tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c @@ -52,10 +52,10 @@ static void test_xdp_with_cpumap_helpers(void) ASSERT_EQ(info.id, val.bpf_prog.id, "Match program id to cpumap entry prog_id"); /* send a packet to trigger any potential bugs in there */ - char data[10] = {}; + char data[ETH_HLEN] = {}; DECLARE_LIBBPF_OPTS(bpf_test_run_opts, opts, .data_in = &data, - .data_size_in = 10, + .data_size_in = sizeof(data), .flags = BPF_F_TEST_XDP_LIVE_FRAMES, .repeat = 1, ); diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c b/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c index 27ffed17d4be..461ab18705d5 100644 --- a/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c +++ b/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c @@ -23,7 +23,7 @@ static void test_xdp_with_devmap_helpers(void) __u32 len = sizeof(info); int err, dm_fd, dm_fd_redir, map_fd; struct nstoken *nstoken = NULL; - char data[10] = {}; + char data[ETH_HLEN] = {}; __u32 idx = 0; SYS(out_close, "ip netns add %s", TEST_NS); @@ -58,7 +58,7 @@ static void test_xdp_with_devmap_helpers(void) /* send a packet to trigger any potential bugs in there */ DECLARE_LIBBPF_OPTS(bpf_test_run_opts, opts, .data_in = &data, - .data_size_in = 10, + .data_size_in = sizeof(data), .flags = BPF_F_TEST_XDP_LIVE_FRAMES, .repeat = 1, ); @@ -158,7 +158,7 @@ static void test_xdp_with_devmap_helpers_veth(void) struct nstoken *nstoken = NULL; __u32 len = sizeof(info); int err, dm_fd, dm_fd_redir, map_fd, ifindex_dst; - char data[10] = {}; + char data[ETH_HLEN] = {}; __u32 idx = 0; SYS(out_close, "ip netns add %s", TEST_NS); @@ -208,7 +208,7 @@ static void test_xdp_with_devmap_helpers_veth(void) /* send a packet to trigger any potential bugs in there */ DECLARE_LIBBPF_OPTS(bpf_test_run_opts, opts, .data_in = &data, - .data_size_in = 10, + .data_size_in = sizeof(data), .flags = BPF_F_TEST_XDP_LIVE_FRAMES, .repeat = 1, );