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=1796385144; b=z8jDqtmYS39Uk7rHUhC4uFGaGnoK4ZdePLDyFdOmbfMilfq0BN286b0GAj5w8+PPE+XK zpPh/+cTlvd1oRzhJy5K0bbKAX1JabBPbkNJxmb11t0SRE2PrbkFieMj99cUgCeUCeyTl B78BC+pZlnuYm3C6TD5eB2+1EsV9nsE5ueitjRqUeyMxNZcnZwvTi684pXTxIWn9nLGzm sV1qaH3cFB6Fn7UKS/tdpBYezy8muzyCandqF7t15esHJgrEGYRiMq3UdGMzWw4ODa6jw I46qDaqZ3+pp7kYmeeqEAaxuFsaIUA6k3oGvF/fZQX54b8c6hb0J4pmwNPsvvFXjwYw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385144; 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=lW9f3ezVX6bijxRmSpl+wB+VtWQQHRnoEPlZwi/AXak=; b=5U4EwdcrZ9PU0L+TthXGhY5c5bB+sBgzVTSyea9R8n50fyqPhttJrwZo3c/XFfJ+UwuR fmfLMlWGXAfL6H7aokqiwXELIi3bzjlgKv3U0/EYEYuA42HkZt0Ymb8GNFCqRSg/Chgqq YN4nNuOIJTU3Oc5Nl/SAppm8BZmUZrfEyvHQNasW21UZMhMtuY6spYZTg8Tlrd/Vde0vq o5srb4w3IAyB2JTn+ze2je+3np95FTpXYXiymTg1YvAnopa2pTJeYLOlReNpdlo6W8Ld3 +zcIQEZmSD59EParGXhgkCdC2OirwPM3I3RES9FtmGu1xziLvy+tgCpVY6c+TWEyYNg== 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=2J+NWCKB; 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 A1F41606A322; Fri, 4 Dec 2026 11:52:24 +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=2J+NWCKB Received: by smtp.kernel.org (Postfix) with ESMTPSA id ADC6B1F000C2; Fri, 4 Dec 2026 11:52:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385144; bh=lW9f3ezVX6bijxRmSpl+wB+VtWQQHRnoEPlZwi/AXak=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=2J+NWCKBwKOx1iZblwIFi5jDNmNG3/U7FxDwtChY/8b86VPULOMZ94LhG3sMJ+AlL zJwpXhhddMekc7q48LY1Q/nbBtBkPv65ImrW74W4cI3+E6JzX3tNugYrD2I1hnxhgJ hO9aE7UQeQlOFdcFkvNNQyGU5ry7m8E+usfKyjcI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Josef Bacik , Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.6 0436/1167] bpf: Follow the head if an skb is written from a slice Date: Fri, 4 Dec 2026 18:57:43 +0900 Message-ID: <20261204100713.373788071@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@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 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Josef Bacik [ Upstream commit 1c19f2b3b2f3b55c8017092257634cb8229b7d97 ] The source of bpf_dynptr_write() may be a slice of the skb which is written to, that is a pointer into its head. bpf_dynptr_copy() does it by itself for a copy inside of one skb, if the source is linear and the destination is not. __bpf_skb_store_bytes() and __bpf_skb_meta_store_bytes() make the skb writable first. If that reallocates the head, the source points to the old one, and freed memory is copied into the packet. The offsets in the head do not change when it is reallocated here. Move the source along with the head. Fixes: 2012c867c800 ("bpf: verifier: Accept dynptr mem as mem in helpers") Fixes: f38499ff45f5 ("bpf: Unclone skb head on bpf_dynptr_write to skb metadata") Signed-off-by: Josef Bacik Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261017230950.802052-14-alexei.starovoitov@gmail.com [ sashal: dropped the __bpf_skb_meta_store_bytes() hunk since that function doesn't exist here, so only the bpf_skb_store_bytes() call site is changed to use the new helper. ] Signed-off-by: Sasha Levin --- net/core/filter.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/net/core/filter.c b/net/core/filter.c index 356bf50afabea..93c87a0d0d7eb 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -1708,6 +1708,24 @@ static inline void bpf_pull_mac_rcsum(struct sk_buff *skb) skb_postpull_rcsum(skb, skb_mac_header(skb), skb->mac_len); } +/* + * The source of a write through a dynptr may be a slice of the same skb. + * Making the skb writable can move its head: follow the move. + */ +static int bpf_try_make_writable_from(struct sk_buff *skb, u32 write_len, + const void **from) +{ + const void *head = skb->head; + bool in_head = *from >= head && + *from < (const void *)skb_end_pointer(skb); + int err; + + err = bpf_try_make_writable(skb, write_len); + if (!err && in_head) + *from = skb->head + (*from - head); + return err; +} + BPF_CALL_5(bpf_skb_store_bytes, struct sk_buff *, skb, u32, offset, const void *, from, u32, len, u64, flags) { @@ -1717,7 +1735,7 @@ BPF_CALL_5(bpf_skb_store_bytes, struct sk_buff *, skb, u32, offset, return -EINVAL; if (unlikely(offset > INT_MAX)) return -EFAULT; - if (unlikely(bpf_try_make_writable(skb, offset + len))) + if (unlikely(bpf_try_make_writable_from(skb, offset + len, &from))) return -EFAULT; ptr = skb->data + offset; -- 2.53.0