From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (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 9D6443B1ED0 for ; Tue, 16 Jun 2026 09:31:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781602286; cv=none; b=lDJL9FSlbpWo/ovU6ZfoREYRToP99lDdQ7ue1NiX7DwZPB4POciPYcX6uHmasv9r9c+KwKq2T9KnWsziVJZM4IU4MDB5MkxXkxj71KO/pX3tT2GRcokKUf22SDJYineoWYnRrqR9iDQ1G2Rt3CkANUGz55XtbBDdylzLMQQgPj8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781602286; c=relaxed/simple; bh=W9h2vOBocmHv8yyrIINbKPNLrEdNr/MHz6FXnnLhIHs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=mlWq2CXwYZdwKUe5gcvlwedfzXzUJPbcvx+12UjCyNxnjYHOP6TZYH0x3lwfQyuIJpZVsd8Z+JQMUlvla8HuJghsDHrHWDMFmyDOFSuPoxRqQ95F2MAWb78r5dLch2H6DJO9CFsiL1fw5bexLQw16vqHQKguFODHUCwtkgb1Foo= 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=VPZGHktG; arc=none smtp.client-ip=209.85.216.43 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="VPZGHktG" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-36b95eb4bb4so2721834a91.3 for ; Tue, 16 Jun 2026 02:31:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781602285; x=1782207085; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ub/HkQc7hVDHHCyEiXac763qR/8PT/efz8C9QeD8xAU=; b=VPZGHktG+D3GfGjxuEa5dEoeuKRF90HZPl7OlmzuAZCfBLnfslBYLWtY9Vh2RWitgP pY2hWCVyajpytDVM1BUjN+iqc4R9Ngh9dDX7D7I/uWIaNoBW77JWuBJIeZE5SjW6xrPj BYx9qWM9CHd3C/iSXNmmWjWxvAc8W5wkrryDFfK6IztIjyHMZi7Oi7JwZDbwauu62B5M iq3Uo7JqGVGqMK1k9mC0567m+Hvqfb/UssKX4GmZXu4AK3q2wInqx+dnyXXV3BlSDxuv r6WEXqUGvDIZIW5K1WEZPViCyRXwOEDEvOAHdPD5LHkctmJlaiXIYTGJYX77MnHyB8Zu awRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781602285; x=1782207085; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ub/HkQc7hVDHHCyEiXac763qR/8PT/efz8C9QeD8xAU=; b=KENQBjQsxl/653hkfwapQzoKSYvKuDaTJ0Dh/S8/teTjg9uHLEzAzeQN9RLJH2G6N4 5kOnbcOsOiXiVmp98rq7GT2O4XFzAuKtiLv7KXzfgsvK3KkuHBszW9tBgjtuOwpmSmUS oST/qP3g3os/4ytODUx6/YQysoU6JMRwigm08oc/fIbE6MyuXoNWOdfZ+GOnIlefAIrr Hq+mHvg1luylJfPHulUZHOBvn5Mds5s1A/OfnMihQqpqsi+ZFITLZK/eqJQsSTtbFdRK NE3bb+O912DfNto7Nnzmq3rPxo1OdgDbvSUDEYkZyXiSfyoyXVuI9d59bnpVuUCrj5Lq mH8g== X-Forwarded-Encrypted: i=1; AFNElJ93d9bajxLaMmyPal5ZDtI4XXWHLANFuBXmKLzTqc07B4JRLsPdlmEfPVDTNjJJ2qAb8wRyNTbQUdmP+8A=@vger.kernel.org X-Gm-Message-State: AOJu0YwXK8tmvUPRuNRRxY6o8hFwj5GoP4vwe0/WxONmBJszY+ouYpsx cMEhzaSga4HMou/Z2CRJAEDzlznzbQousbPumGT5Ha8N3N3rH5ezda3g X-Gm-Gg: Acq92OFSE23abgRcxdZUKxpm+EbVlfHLkkeabpx5bIsMSeUjoqrn1ypkmnz7r/PYk1t yyj4V7jgEZKzxyKohGHV+TcDUoY4LSgnUBJH4UmlMALVwIgP5s2BXknmhlIDYbiw2wVG9pKyGny AeoeMaXwtgnbnCIB9YNFS9kCkaGSMmcnB6M787Uv36HZpC8VA4lJsoASLGEMQELRjJpHH8zJyKr xmvenncQ5YYiTPnfUV6nLX5/kW3FbkM/02ggfOgFrrGp/c2LMXOleCuypxW54BsAJ8jAgyQVJva ogpvzDBT9/h+tpd5z/ViCPRp16b0HkdvkyitqG5RxXtsVNrrpb0EOcoh9QHFMOJGPvTTxnu2BDG 4r186Z6BsIPiRJGCq4EwFbdmvpvW1ygojLBQtJCFWKJKEUqz8ZKQ3N6CdTEzcRcaWiF3IKqt8Hg K02xeXLbvz9PN0J5OzVCgC648zFrf0QWn3FNKrdqEpW2BOsLO8liVa1lYN4iPvueY= X-Received: by 2002:a17:902:c952:b0:2c2:dadd:940 with SMTP id d9443c01a7336-2c69a0d46dcmr28361895ad.2.1781602284852; Tue, 16 Jun 2026 02:31:24 -0700 (PDT) Received: from localhost.localdomain ([2a12:a304:100::209f]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c42f7c6c52sm127329545ad.22.2026.06.16.02.31.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jun 2026 02:31:24 -0700 (PDT) From: Sun Jian To: bpf@vger.kernel.org Cc: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, memxor@gmail.com, song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, shuah@kernel.org, hawk@kernel.org, john.fastabend@gmail.com, sdf@fomichev.me, toke@redhat.com, lorenzo@kernel.org, paul.chaignon@gmail.com Subject: [PATCH bpf v2 0/2] Fix partial copy of non-linear test_run output Date: Tue, 16 Jun 2026 17:31:01 +0800 Message-ID: <20260616093103.471444-1-sun.jian.kdev@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit When BPF_PROG_TEST_RUN returns non-linear output and userspace provides a short data_out buffer, bpf_test_finish() can return -ENOSPC before copying the packet prefix or updating data_size_out. Fix this by deriving the linear copy length from the packet layout rather than from the already-clamped copy_size. Add selftest coverage for both non-linear skb and XDP frags paths. --- Changes in v2: * Fix the Fixes tag to point to the commit that introduced the shared non-linear copy-out logic. * Drop skb-specific wording from the fix commit. * Move the selftest from skb_load_bytes.c to prog_run_opts.c. * Add XDP frags coverage in addition to non-linear skb coverage. v1: https://lore.kernel.org/bpf/20260615073856.152479-1-sun.jian.kdev@gmail.com/ Tested with: ./test_progs -t prog_run_opts -v ./test_progs -t skb_load_bytes -v ./test_progs -t xdp_pull_data -v Sun Jian (2): bpf: Fix partial copy of non-linear test_run output selftests/bpf: Cover partial copy of non-linear test_run output net/bpf/test_run.c | 11 ++- .../selftests/bpf/prog_tests/prog_run_opts.c | 72 +++++++++++++++++++ .../selftests/bpf/progs/test_pkt_access.c | 12 ++++ 3 files changed, 88 insertions(+), 7 deletions(-) Range-diff: 1: 3691b07aa440 ! 1: e5a0c426d4cb bpf: Fix partial copy of non-linear skb test_run output @@ Metadata Author: Sun Jian ## Commit message ## - bpf: Fix partial copy of non-linear skb test_run output + bpf: Fix partial copy of non-linear test_run output - For non-linear skbs, bpf_test_finish() derives the linear head copy - length from copy_size - frag_size. This only matches the skb head length - when copy_size is the full packet size. + For non-linear test_run output, bpf_test_finish() derives the linear + data copy length from copy_size - frag_size. This only matches the + linear data length when copy_size is the full packet size. When userspace provides a short data_out buffer, copy_size is clamped to that buffer size. If copy_size is smaller than frag_size, the computed length becomes negative and bpf_test_finish() returns -ENOSPC before copying the packet prefix or updating data_size_out. - Compute the linear head length from the skb layout instead, and clamp the - head copy length to copy_size. This preserves the expected partial-copy - semantics: return -ENOSPC, copy the packet prefix that fits in data_out, - and report the full packet length through data_size_out. + Compute the linear data length from the packet layout instead, and clamp + the linear copy length to copy_size. This preserves the expected + partial-copy semantics: return -ENOSPC, copy the packet prefix that fits + in data_out, and report the full packet length through data_size_out. - Fixes: 838baa351cee ("bpf: Craft non-linear skbs in BPF_PROG_TEST_RUN") + Fixes: 7855e0db150ad ("bpf: test_run: add xdp_shared_info pointer in bpf_test_finish signature") Signed-off-by: Sun Jian ## net/bpf/test_run.c ## 2: 663847520f0b < -: ------------ selftests/bpf: Cover partial copy of non-linear skb test_run output -: ------------ > 2: 680506532d97 selftests/bpf: Cover partial copy of non-linear test_run output -- 2.43.0