Archive-only list for patches
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	patches@lists.linux.dev, Alexei Starovoitov <ast@kernel.org>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.1 0055/1059] bpf: Require BPF_LWT_REROUTE when an lwt_in prog changes the protocol
Date: Fri,  4 Dec 2026 18:53:06 +0900	[thread overview]
Message-ID: <20261204100645.503572802@linuxfoundation.org> (raw)
In-Reply-To: <20261204100643.980430235@linuxfoundation.org>

6.1-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Alexei Starovoitov <ast@kernel.org>

[ Upstream commit d9618a6196953718f7470de5d2e84121bed063f7 ]

When an lwt_in prog returns BPF_OK, bpf_input() calls orig_input(), the
input handler of the route. This handler is for one IP version and needs a
dst of the same family. But BPF_LWT_ENCAP_IP lets the prog push a header of
the other IP version and thus change skb->protocol. Then the handler reads
and changes a header of the other IP version. The push of an SRH also
replaces the dst, because seg6_lookup_nexthop() puts an rt6_info into the
skb. Then ip_forward() uses the rt6_info as a struct rtable.

Drop the skb with -EINVAL when skb->protocol changes, as bpf_xmit() does.
Drop it also when the family of the dst changes, because skb->protocol does
not always show this change. Today no such skb leaves as the prog made it.
A prog works as before if it returns BPF_LWT_REROUTE, or if it pushes an
SRH on an IPv6 route.

The commit in the first Fixes tag lets a prog change skb->protocol. The
commit in the second tag adds the check to bpf_xmit() only.

Fixes: 52f278774e79 ("bpf: implement BPF_LWT_ENCAP_IP mode in bpf_lwt_push_encap")
Fixes: 3bd0b15281af ("bpf: add handling of BPF_LWT_REROUTE to lwt_bpf.c")
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://patch.msgid.link/20261101190535.1454146-24-alexei.starovoitov@gmail.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 net/core/lwt_bpf.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/net/core/lwt_bpf.c b/net/core/lwt_bpf.c
index fde1b4a2f4aac..87fae6fdeeba8 100644
--- a/net/core/lwt_bpf.c
+++ b/net/core/lwt_bpf.c
@@ -157,6 +157,16 @@ static int bpf_input(struct sk_buff *skb)
 			bpf_lwt_reset_cb(skb, proto);
 		if (ret == BPF_LWT_REROUTE)
 			return bpf_lwt_input_reroute(skb);
+		/*
+		 * orig_input() is for the old protocol only, see bpf_xmit().
+		 * It also needs a dst of the old family. BPF_LWT_ENCAP_SEG6
+		 * puts an IPv6 dst into the skb.
+		 */
+		if (skb->protocol != proto ||
+		    skb_dst(skb)->ops->family != dst->ops->family) {
+			kfree_skb(skb);
+			return -EINVAL;
+		}
 	}
 
 	if (unlikely(!dst->lwtstate->orig_input)) {
-- 
2.53.0




  parent reply	other threads:[~2026-12-04 10:20 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  9:52 [PATCH 6.1 0000/1059] 6.1.194-rc1 review Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0001/1059] RDMA/erdma: Use IRQ-safe XArray helpers for QP and CQ tables Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0002/1059] netfilter: nft_ct: expectation timeouts are passed in milliseconds Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0003/1059] netfilter: nft_ct: move custom expectation support to helper Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0004/1059] mm/khugepaged: preserve dirty bits when collapsing PTE-mapped THPs Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0005/1059] drm/amdgpu: Check cs flags Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0006/1059] bpf: Drop inet_conn_established from lsm sleepable hooks Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0007/1059] mm: page_alloc: remove ALLOC_NON_BLOCK from ALLOC_RESERVES Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0008/1059] irqchip/sifive-plic: Avoid signed shift in interrupt enable mask Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0009/1059] fs: aio: reject partial mremap to avoid Null-pointer-dereference error Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0010/1059] Revert "SUNRPC: svcauth_gss: enforce krb5 token minimum length" Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0011/1059] Revert "SUNRPC: Convert unwrap_priv_data() to use xdr_stream" Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0012/1059] SUNRPC: svcauth_gss: enforce krb5 token minimum length Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0013/1059] mm/ksm: simplify break_ksm() to not rely on VM_FAULT_WRITE Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0014/1059] mm/ksm: fix KSM COW breaking with userfaultfd-wp via FAULT_FLAG_UNSHARE Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0015/1059] mm/ksm: fix userfaultfd protection during merge and unmerge Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0016/1059] udf: validate VAT inode size for old VAT format Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0017/1059] udf: validate vat20->lengthHeader and VAT inode size in udf_load_vat() Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0018/1059] io_uring: enable toggle of iowait usage when waiting on CQEs Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0019/1059] io_uring: fail soft links on negative IOU_COMPLETE results Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0020/1059] io_uring/rw: fail soft links on IOPOLL short or error IO Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0021/1059] io_uring/rsrc: keep the old file when a file update fails Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0022/1059] Input: destroy force-feedback device on input unregistration Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0023/1059] staging: media: atomisp: use array3_size() for overflow-safe allocation Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0024/1059] fs/9p: switch vfsmount to use v9fs_get_new_inode Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0025/1059] fs/9p: rework qid2ino logic Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0026/1059] 9p: skip intermediate directory entry name copy in p9dirent_read() Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0027/1059] xfrm: zero-initialise km_event in the replay-notify path Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0028/1059] batman-adv: avoid WARN_ON for orig_ifinfo allocation failure Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0029/1059] wifi: ath9k_htc: start ANI when an AP interface begins to beacon Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0030/1059] scsi: aic7xxx: Fix REQUEST SENSE allocation length on big-endian hosts Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0031/1059] scsi: aha1542: Remove unneeded scsi_dma_unmap() call Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0032/1059] wifi: ath10k: Stop unanswered temperature reads Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0033/1059] seg6: fix transport header for inner IPv4 with IP options Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0034/1059] gpio: omap: Propagate runtime PM failures in probe and request Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0035/1059] btrfs: verity: propagate orphan insertion errors when enabling verity Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0036/1059] btrfs: scrub: fix lost wakeup and hang when cancelling a scrub that is finishing Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0037/1059] btrfs: zoned: fix double free of bitmaps on clone failure Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0038/1059] ptp: drain virtual clock sysfs operations before unregistering children Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0039/1059] ptp: unwind partially completed virtual clock creation Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0040/1059] ptp: prevent possible ABBA deadlock in ptp_clock_freerun() Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0041/1059] ptp: vclock: propagate physical clock sampling errors Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0042/1059] ptp: vclock: serialize extended samples with counter updates Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0043/1059] scsi: target: Validate REGISTER AND MOVE TransportID length Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0044/1059] tipc: reject attaching bearer of different media to the same occupied device Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0045/1059] spi: pic32-sqi: fail transfer when the BD ring is exhausted Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0046/1059] bpf: Dont let bpf_skb_adjust_room() raise gso_size to GSO_BY_FRAGS Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0047/1059] bpf: Reject non-IPv6 packets in BPF_LWT_ENCAP_SEG6 Greg Kroah-Hartman
2026-12-04  9:52 ` [PATCH 6.1 0048/1059] bpf: Limit the SRH length in bpf_lwt_seg6_adjust_srh() Greg Kroah-Hartman
2026-12-04  9:53 ` [PATCH 6.1 0049/1059] bpf: Dont look for the SRH again in the End.BPF helpers Greg Kroah-Hartman
2026-12-04  9:53 ` [PATCH 6.1 0050/1059] bpf: Move the MAC header in bpf_lwt_seg6_adjust_srh() Greg Kroah-Hartman
2026-12-04  9:53 ` [PATCH 6.1 0051/1059] bpf: Dont leave a stale MAC header in bpf_lwt_push_ip_encap() Greg Kroah-Hartman
2026-12-04  9:53 ` [PATCH 6.1 0052/1059] ipv4: Unmask upper DSCP bits in input route lookup Greg Kroah-Hartman
2026-12-04  9:53 ` [PATCH 6.1 0053/1059] ipv4: Convert ip_route_input_noref() to dscp_t Greg Kroah-Hartman
2026-12-04  9:53 ` [PATCH 6.1 0054/1059] bpf: Reset skb->cb after an lwt prog pushes an IP header Greg Kroah-Hartman
2026-12-04  9:53 ` Greg Kroah-Hartman [this message]
2026-12-04  9:53 ` [PATCH 6.1 0056/1059] bpf: Move the transport header with the moved headers Greg Kroah-Hartman
2026-12-04  9:53 ` [PATCH 6.1 0057/1059] bpf: Check the offset in bpf_skb_generic_{push,pop}() Greg Kroah-Hartman
2026-12-04  9:53 ` [PATCH 6.1 0058/1059] spi: Fix ACPI SPI resources using relative path Greg Kroah-Hartman
2026-12-04  9:53 ` [PATCH 6.1 0059/1059] spi: acpi: only look up the IRQ of confirmed SPI devices Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204100645.503572802@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=ast@kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox