From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (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 904112750ED for ; Wed, 8 Jul 2026 04:07:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783483677; cv=none; b=F8WxCoue+ZLOynaE0nGL8XrhtSDuIf2q5rej4jeey8nZU/AjXkDG6BOpfBuJQsJRDkaIK2RIh1dbWOpO0P8uMZu44e3Z9qLxMgJp4U/neMJKFIP1RJqu6qk6pvDc7Vx9yNI5KfWBWrtLbS+x03NtSvPppx+K6byUqK5VFzO7HoY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783483677; c=relaxed/simple; bh=FzKeTeF8JA+KsfuZhglVYUhLx5S0Q2O5ea+96KMWWzY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QbT95wlx2Ak/vhjGDEIM+l28coV83BPc1Ux0CHEdaIyJbbxq6do5sct8biRz+nEhm/TjnSxDieI0KsSOvW6bzMOPThfIWsb3c8Dhgr5iPfZbZMHIkqrLGzx3NM7J511s3sPWWc4MKa+DJxbYFAD3FWqVWtLb3ZIlEysLeR8KOsw= 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=CgtJHMDc; arc=none smtp.client-ip=209.85.216.48 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="CgtJHMDc" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-3810c5d691bso189034a91.1 for ; Tue, 07 Jul 2026 21:07:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783483676; x=1784088476; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=VGJwch6uaoT+4VIjlzymTYDaLAmgt0JW6oLszFG1Jaw=; b=CgtJHMDcrFVIvpHnz8B+kqjJ2yXpOBR0aBfeT+aw3IZZCEdBDNXW4Ma2YW2MUejmNx Fy+23++tAMsNhYDU88KQzycAs39i/MCWGbyNX0X3MVRjrJHGUwRW1RAV0N0/SH4dALr9 5895RVTLO4cBfRaoYMAyHHfVr4io6HA3vLiTfZWioRo5DrleRp0mk7b04QmSVNZYs4mR PWqkzO3sAATpi0TIB3OhatI1hyfz29HdLWaVcnfFyN0NqkG1cKtM+kwJ8apBd5hYPYF3 ZNAuOAFKxuBZDQ5JB4L4EgKxbDhk15XGn1AJLLN3ZX94c8dY1QfnmpGnGk1Bi5F6gXJB p6aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783483676; x=1784088476; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=VGJwch6uaoT+4VIjlzymTYDaLAmgt0JW6oLszFG1Jaw=; b=muMtoK4Uz5qVSAdcqXJ5zsbzXgmL1I5uKyHbc1TT28RhLQJ9TdIjU1sXdhm5lQIBce MyOEiVEVjGKc/S8RHjcVE1xdSx+pYeAFqy0gmJ9hs4Gx1es24H6LsyzX9XPz25JBvdOH HQ+kev7kfBrJLjlyi3fPDRse1LoFDSfnsTKQb2ldvFBOXSvBISe6GEhEp4dx51lQzbhz GKPFHPJ2GZYj1ssSAI8u4D/vO2xY/MOxNtly1KehuNpl3Iv0gWOTF5fSBql0iruoukWt JCGI+wRYOb7s/hnM9ILOspojXdLmOvgWPUVr+9mmbVo2Ee3MdtIDkjdgKmGFeTWtIXUu BVKg== X-Forwarded-Encrypted: i=1; AHgh+RrWVxTL1fSrEeEotaPRkpewmDhqFKJkoFpcJwpDl2+dawCGzrRmljR2XRLVClqWiQvlSKsa6bhmV+y7Ncc=@vger.kernel.org X-Gm-Message-State: AOJu0YxPcGE1LFVOxhhvUpx2z+RVb7U6WiGNzfAz36UffyMDIDmWpW/i 0bywrXdRdoHJxDmETZcipJI7fmaN6UwEK4cC+Jnkue+EtCFiTDhsnckN X-Gm-Gg: AfdE7cl5/3le4cJxBQXJ4ReJbh864AqpBL1FikjeqYSf+vbr6WEQE100wp8k1Xp4VLP B6xPW26CNcfG0+K5xmy73/FuTj+Ct9zzm9YODH7Eo13PnXPTsfmdN/dpnBIAlp0ugGl60aZvoGx mdVP+9KPYFlVQmPBby44g9SLiyi71TeZbJkfW+9qCsH9upXI8FZbMzwVEPKbtcBONg2OEe4utwV msrBqdS/EHd5/8wy4fvGRU2GWTbp//BkT6SQ1KHUlw8tHynI3DFNtQmZD6EvvKoDsy9v5vAnHVi GvNl61FNfalfkIklYKQXwmy0zRtOSJKxZUmUg35nMaROW503QixLOpP15B/OX+uy22GAbuLdAzc B3n4cEFq1TvHssS/JbHG+y0cK/P+qDBVzYp8/6qiIpa67dFCbm0IMo7R9p8TxnP81ocYG+eog0K Fes1sTVnRojeLrCvsUMpQQm3En+p3s/Z9VSyhRh0Io5Kt43iPdHzX1wU2TEy41xPg1Lb4Ie9hmT 9PcWZX+HvAdCVQA1dIVE/dKsLc6Sz6vQg== X-Received: by 2002:a17:90b:2f06:b0:381:50ab:1594 with SMTP id 98e67ed59e1d1-3894120590amr862773a91.27.1783483675857; Tue, 07 Jul 2026 21:07:55 -0700 (PDT) Received: from u2404-VMware-Virtual-Platform.tailf6b5e0.ts.net ([24.4.24.156]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-31189cd8234sm4198982eec.9.2026.07.07.21.07.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2026 21:07:55 -0700 (PDT) From: Sun Jian To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org, emil@etsalapatis.com, shuah@kernel.org, mmullins@fb.com, shung-hsi.yu@suse.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Sun Jian Subject: [PATCH bpf v3 2/2] selftests/bpf: Cover negative raw_tp writable buffer offsets Date: Tue, 7 Jul 2026 21:07:15 -0700 Message-ID: <20260708040715.116680-3-sun.jian.kdev@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260708040715.116680-1-sun.jian.kdev@gmail.com> References: <20260708040715.116680-1-sun.jian.kdev@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add raw tracepoint writable coverage for buffer accesses involving negative constant pointer adjustments. The verifier case checks that a negative effective offset is rejected. The attach-time case adds incremental coverage beyond the existing nbd test and the verifier rejection case: it uses a negative var_off and a positive instruction offset whose effective offset remains non-negative. This exercises the checked access_end accounting path and verifies that the resulting max_tp_access is still checked against nbd_send_request's writable size at attach time. Signed-off-by: Sun Jian --- .../raw_tp_writable_reject_nbd_invalid.c | 58 +++++++++++-------- .../bpf/progs/verifier_raw_tp_writable.c | 16 +++++ 2 files changed, 51 insertions(+), 23 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/raw_tp_writable_reject_nbd_invalid.c b/tools/testing/selftests/bpf/prog_tests/raw_tp_writable_reject_nbd_invalid.c index 216b0dfac0fe..efe4cad47b28 100644 --- a/tools/testing/selftests/bpf/prog_tests/raw_tp_writable_reject_nbd_invalid.c +++ b/tools/testing/selftests/bpf/prog_tests/raw_tp_writable_reject_nbd_invalid.c @@ -4,12 +4,31 @@ #include #include "bpf_util.h" -void test_raw_tp_writable_reject_nbd_invalid(void) +static void check_nbd_attach_reject(const char *name, + const struct bpf_insn *program, size_t prog_len) { - __u32 duration = 0; + LIBBPF_OPTS(bpf_prog_load_opts, opts); char error[4096]; - int bpf_fd = -1, tp_fd = -1; + int bpf_fd, tp_fd; + + opts.log_level = 2; + opts.log_buf = error; + opts.log_size = sizeof(error); + + bpf_fd = bpf_prog_load(BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE, NULL, "GPL v2", + program, prog_len, &opts); + if (!ASSERT_GE(bpf_fd, 0, "prog_load")) + return; + + tp_fd = bpf_raw_tracepoint_open("nbd_send_request", bpf_fd); + if (!ASSERT_LT(tp_fd, 0, name)) + close(tp_fd); + + close(bpf_fd); +} +void test_raw_tp_writable_reject_nbd_invalid(void) +{ const struct bpf_insn program[] = { /* r6 is our tp buffer */ BPF_LDX_MEM(BPF_DW, BPF_REG_6, BPF_REG_1, 0), @@ -19,25 +38,18 @@ void test_raw_tp_writable_reject_nbd_invalid(void) BPF_EXIT_INSN(), }; - LIBBPF_OPTS(bpf_prog_load_opts, opts, - .log_level = 2, - .log_buf = error, - .log_size = sizeof(error), - ); - - bpf_fd = bpf_prog_load(BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE, NULL, "GPL v2", - program, ARRAY_SIZE(program), - &opts); - if (CHECK(bpf_fd < 0, "bpf_raw_tracepoint_writable load", - "failed: %d errno %d\n", bpf_fd, errno)) - return; - - tp_fd = bpf_raw_tracepoint_open("nbd_send_request", bpf_fd); - if (CHECK(tp_fd >= 0, "bpf_raw_tracepoint_writable open", - "erroneously succeeded\n")) - goto out_bpffd; + const struct bpf_insn negative_var_off_program[] = { + BPF_LDX_MEM(BPF_DW, BPF_REG_6, BPF_REG_1, 0), + /* make var_off negative, but keep the effective access offset non-negative */ + BPF_ALU64_IMM(BPF_ADD, BPF_REG_6, -8), + /* one byte beyond the end of the nbd_request struct */ + BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_6, + sizeof(struct nbd_request) + 8), + BPF_EXIT_INSN(), + }; - close(tp_fd); -out_bpffd: - close(bpf_fd); + check_nbd_attach_reject("nbd_invalid", program, ARRAY_SIZE(program)); + check_nbd_attach_reject("nbd_invalid_negative_var_off", + negative_var_off_program, + ARRAY_SIZE(negative_var_off_program)); } diff --git a/tools/testing/selftests/bpf/progs/verifier_raw_tp_writable.c b/tools/testing/selftests/bpf/progs/verifier_raw_tp_writable.c index 14a0172e2141..4055a6443bc2 100644 --- a/tools/testing/selftests/bpf/progs/verifier_raw_tp_writable.c +++ b/tools/testing/selftests/bpf/progs/verifier_raw_tp_writable.c @@ -47,4 +47,20 @@ l0_%=: /* shift the buffer pointer to a variable location */\ : __clobber_all); } +SEC("raw_tracepoint.w") +__description("raw_tracepoint_writable: reject negative const offset") +__failure +__msg("invalid negative tracepoint buffer offset") +__naked void tracepoint_writable_reject_negative_const_offset(void) +{ + asm volatile (" \ + r6 = *(u64 *)(r1 + 0); \ + r6 += -8; \ + r0 = *(u64 *)(r6 + 0); \ + exit; \ +" : + : + : __clobber_all); +} + char _license[] SEC("license") = "GPL"; -- 2.43.0