From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (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 AEC7928852E for ; Mon, 6 Jul 2026 20:00:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783368059; cv=none; b=BHJ9gOwrFJpsluMUDsZHb60FFqQfx80yFIPK65pn1Z38XfW4eZWrJXMI/XnwLFhDGsvGmAJK9nwa81JN1yeAnta0109HpH2aOPVb4dcyOuLPJchkxBDSK8CMEGzpcqLYRppmJVuhcYsdIxFkZVZgoR9iv6YzWk29qLmTsUIC7b4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783368059; c=relaxed/simple; bh=Bn4Wn0GSYZIZgIEZ5ntKigY1VQrjvtTEoGxji+iVLx8=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=LQZ6yAwYT5lgkn9tmXcG7/DQUX6GqJowaqmwri2a2YoEl0mCUBLcFrQvj7fAtyBVRbN9PVEiGJIDVK+jzoM/CTelzuUoiELY/+fwumYz18hHK/7eZ/1OG5xKXvZXJF6f/mt9IZTLh75gqXHmM39X6jwe7g7B1VywQlWIaG1/QTw= 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=HiSwyHYX; arc=none smtp.client-ip=209.85.216.42 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="HiSwyHYX" Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-38759bcd877so446789a91.2 for ; Mon, 06 Jul 2026 13:00:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783368058; x=1783972858; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=VIf+zohqeDaZywcmZWeYMtyc4MEDifAz/egCRkrh6AM=; b=HiSwyHYXuXpCTq21Ed9uLQF2gfbf80+jtXt78BOXXvwjEWDjx6ulzU1zCNWvT3Pkut Y2na8agDKhmivMiVJa8MdV2BDLdW1wfBHmwuGNh/K49HVPvBdiVX5xuFhbIJCON7jM/P PH5J+TN7sD2UJSGqjcVlB0/hLN6VyfFHZ5NeBu6J3IGW6D2o7us0DAnHTZn+qRqztdQh nAZKcwglPbcQZSO95lZW4zlFIj4eG4Z1RcYvNjcQNhfoyHhVlUkA4aln1omwu00MH3Cm iIs5H2YKZvt3T2fEe2mCywK1m/eD2aIGEPnKt3pw3KuPebIrX2A4jqlSl8ouzaK30nLR pCQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783368058; x=1783972858; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VIf+zohqeDaZywcmZWeYMtyc4MEDifAz/egCRkrh6AM=; b=QVvelEzFvugEEfA5B2uRRzn2xmJpDoEfWcMHDiWyJAqmcqEPg6R2HYqUxBf930LepX UaJz9nV749mwqYo6z54V2ZAL5w0PrO80X/1pZU4TMclz8tVwnBSGCdXM5k6L8HEpscQG 5vt6L5MDU0ElgfTCr4UoFIe9/Y27bM3Hn5Bc8iwH9qHjZveeSrKiP1LytwJ5ZAUvxJMi jGwtmypHQ1o0VB199qSNeq0qwWntZNx7FhXz5bz3DWDpngD7oFHCSHvLeJGQRte8Bam7 VuPKRDGAbx1xHWUaQvKyvMz9nxS0IYdyjEiBPhPADImr4fAQ3bQZ0b4UwkfHCFiTupuM c2SA== X-Forwarded-Encrypted: i=1; AHgh+Rp3EDRi9fsqRQtSRPIdsT9jb8w9thwA4qngdnjizE+bs0gDEjJNJrgPeNJFtrtdigrpmlIDULucb5LW11Y=@vger.kernel.org X-Gm-Message-State: AOJu0YyQurw99MNhYzc0B9ml3Cvr9/AgpT+aFgVAEe1fe4rGotYVQ5gR RjPxzgPVLMnxPhl27ATSICXFUPGX3uDVvJ4YyDihY59tEUSBkA3WxPeQ X-Gm-Gg: AfdE7cnA9UkspH5MNoThCQlvfL6EECo4odCOYtBm2PLXzp52h4YJi5hMpwSjkSAkNeF DCukuoh+yr4bn1MMhdpBc1Yfx4l8Zd+qNC8SNPKM41nOUS3UftPnFfSwwE5Om4+ak6CMLgk7IRL OpyB3MYlVzuRtS38m5+sXK1DXMccUZuDKcrDOSkebOAk8vYCqAYggorjRshoGeAOp8uxXtSCM/j wF3wr/+F0T6LQ5JjwhmZYiW9/foQcWqvOw0GmtbML5C32t64Z55hTctl3ah2WTE+Zqj9setrPkg i+lGaSEVQ/Jjvv2g3/sSq0f+1yP3ixoG0F3qhSE0g2HQysz1AamlyhSHCUtNi6pL8xMY2iU3sR+ OJSWAISZt2KlhwmIB/rsgORkkLxYLALtxDcKl/dhMxjY1OZa0NKjyfWaf8SM+Syvch/skGk11rm D0QRl7Ax7C1nq1jC7KzKAInkosHQFTLXVsa35sMaY+i6LvxPRLRbDOYrtCFy3zvjhutVQO0Q== X-Received: by 2002:a17:90b:1d43:b0:380:540:d499 with SMTP id 98e67ed59e1d1-38754ea7328mr2054607a91.6.1783368058145; Mon, 06 Jul 2026 13:00:58 -0700 (PDT) Received: from ?IPv6:2a03:83e0:115c:1:612f:7084:be32:532a? ([2620:10d:c090:500::1:55b9]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-311561dd3a1sm19197214eec.22.2026.07.06.13.00.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 13:00:57 -0700 (PDT) Message-ID: <559673fc207097ecd08f1d7e9f684fe1e9f2a581.camel@gmail.com> Subject: Re: [PATCH bpf] bpf: Reject negative const offsets for buffer pointers From: Eduard Zingerman To: Sun Jian , bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, 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, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Date: Mon, 06 Jul 2026 13:00:54 -0700 In-Reply-To: <20260703035137.109608-1-sun.jian.kdev@gmail.com> References: <20260703035137.109608-1-sun.jian.kdev@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.60.1 (3.60.1-1.fc44) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Thu, 2026-07-02 at 20:51 -0700, Sun Jian wrote: > The verifier rejects variable offsets for PTR_TO_TP_BUFFER and PTR_TO_BUF > accesses, but it currently accepts a constant negative offset produced by > pointer arithmetic. > > For example, a raw tracepoint writable program can load ctx[0] as a > PTR_TO_TP_BUFFER, move it by -8, and then read from the adjusted pointer. > The register is still tracked as tp_buffer(imm=3D-8), but the access is > before the tracepoint writable buffer base and should be rejected. > > Check the signed effective buffer offset before updating max_tp_access or > other buffer max access accounting. Reject negative effective offsets and > use the checked end offset for max access accounting. > > Add a verifier test that rejects a raw tracepoint writable program using = a > negative constant offset. > > Fixes: 9df1c28bb752 ("bpf: add writable context for raw tracepoints") > Signed-off-by: Sun Jian > --- The commit 9df1c28bb752 ("bpf: add writable context for raw tracepoints") delays the tracepoint buffer access to the attach time: int bpf_probe_register(struct bpf_raw_event_map *btp, struct bpf_raw_tp= _link *link) { ... if (prog->aux->max_tp_access > btp->writable_size) return -EINVAL; =20 ... } Called from syscall.c:bpf_raw_tp_link_attach(). Please modify the test case such that it exercises the attachment logic. Also, please keep selftests in a separate patch and make use of the full 100 characters line width limit. pw-bot: cr.