From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796380497; b=mMvEmJG81XZoabqPtihopV6s1aWU8jZLzapI2aEn93to5g1bg/40rev0V6mHU8lYpzZI wRiFPqzFwNiltOR8oKSU2y2QZ8zVmnIGyfYCn/ylzkXTuwsCNF+gjkPsYEPdFdd1RfyOy v+hfmOX4rc0E1TZcN6fWxj3hOIR0+3c8u+Yq00R9q2Rs6/Sw3I0jDIIiS5c2aGacVsIka 2iLPzNXfvxFovX71eW4LRGvwbFOeHI5Uf8e/a9HZ6aEDTOH2Cx9MbSYm2LXkprQKbr4aG 62UEUc2PEH9THt//qY/hJPb0zGEOjzvDfpGET1pt/FUTtOrxAjcQ1kE+AmZfPnAhoWA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380497; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=68V/DCslrO0YAPPWw7T15U53hHvCAA8pCqjPGQBUmFg=; b=b3kqKgy8eADf0I0SE0rZLCAsXJ888KR3E72U8eXjir6AbjoJGJNv/ortcNp78tKfXt84 AgkNifS+SqGzRHNnt74NCVerufkoI21nkTZlUwVVuBCbkB3vuUs3S+FdxrQFJc9ht3DDp SAO+siDxPOTNcZP/OL8uQJLlI8VUpPS4lOUb5LnWoXEIGOpkf+OSb6ONGqLh4Tv9thw2c dKMoPHL9HWgBDWctxIEKzbkuEQgegKRWxU4o0oKAlWQvN+uWf2SiTP/LHiluLnngaDX3S TghE+0tPsb5dQYEYcEgO9dT9DpChNhwdOWJ0Mva2aU7/HAi4cfazmrYQB76NRjyYBIA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=RRi6ZHJc; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19678606A680; Fri, 4 Dec 2026 10:34:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=RRi6ZHJc Received: by smtp.kernel.org (Postfix) with ESMTPSA id 860B71F000C2; Fri, 4 Dec 2026 10:34:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380497; bh=68V/DCslrO0YAPPWw7T15U53hHvCAA8pCqjPGQBUmFg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=RRi6ZHJcyjgA0bqPDrZe1rq3yI9OmyTVe3bfzhoWtRyJdus0m56EB+W2pn3v1BGoI kaitlDB14teQ0+Rhy0LUSkgfxeHOAApCANJ7bX8yvlZspMoAqt/wEfGr425EtyQBYW eqWIWc07735t9/Klo+aQRzoa2AOGY7Y4PbGNZSBY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexei Starovoitov , Sasha Levin Subject: [PATCH 7.3 298/742] bpf: Fix slices behind the end of an XDP packet Date: Fri, 4 Dec 2026 19:02:42 +0900 Message-ID: <20261204100642.953743420@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexei Starovoitov [ Upstream commit 2fc7a1733992e28d4c89f57e2c237b85b236d83c ] A dynptr keeps the size that the packet had at bpf_dynptr_from_xdp(). When the packet has shrunk since, bpf_dynptr_slice() takes the error of bpf_xdp_pointer() for "not linear" and copies from the frags. A linear packet has none, its skb_shared_info is what the buffer held before. Return NULL. Don't look at the frags of a linear packet for a length of 0 at its end either. Fixes: 66e3a13e7c2c ("bpf: Add bpf_dynptr_slice and bpf_dynptr_slice_rdwr") Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261125032938.670542-41-alexei.starovoitov@gmail.com Signed-off-by: Sasha Levin --- kernel/bpf/helpers.c | 4 +++- net/core/filter.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index 42d6b22edfcdf..991d03fede8c2 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -3092,7 +3093,8 @@ __bpf_kfunc void *bpf_dynptr_slice(const struct bpf_dynptr *p, u64 offset, if (!IS_ERR_OR_NULL(xdp_ptr)) return xdp_ptr; - if (!buffer__nullable) + /* the packet may be shorter than it was for bpf_dynptr_from_xdp() */ + if (!buffer__nullable || ptr->offset + offset + len > xdp_get_buff_len(ptr->data)) return NULL; bpf_xdp_copy_buf(ptr->data, ptr->offset + offset, buffer__nullable, len, false); return buffer__nullable; diff --git a/net/core/filter.c b/net/core/filter.c index 9f0cfb0b52357..22246ec8f0c68 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -4332,7 +4332,7 @@ void *bpf_xdp_pointer(struct xdp_buff *xdp, u32 offset, u32 len) if (unlikely(offset + len > xdp_get_buff_len(xdp))) return ERR_PTR(-EINVAL); - if (likely(offset < size)) /* linear area */ + if (likely(offset < size || !xdp_buff_has_frags(xdp))) /* linear area */ goto out; sinfo = xdp_get_shared_info_from_buff(xdp); -- 2.53.0