Thread View: linux.kernel.netdev
3 messages
3 total messages
Started by Eric Dumazet
Fri, 13 Nov 2026 12:46
[PATCH net 4/5] sctp: use skb_set_transport_header_careful() in sctp_v6_err()
Author: Eric Dumazet
Date: Fri, 13 Nov 2026 12:46
Date: Fri, 13 Nov 2026 12:46
48 lines
10244 bytes
10244 bytes
skb->transport_header is a 16-bit offset from skb->head, and U16_MAX is
reserved as the "not set" value. skb_set_transport_header() silently
truncates an offset that does not fit.
sctp_v6_err() stores @offset, computed by icmpv6_notify() from the
extension headers of the packet embedded in an ICMPv6 error. Should
the value be truncated, sctp_err_lookup() would read the SCTP header
at the wrong place.
Since commit 3744b0964d52 ("ipv6: Implement limits on extension header
parsing") a single chain is bounded to IP6_MAX_EXT_HDRS_CNT headers
(24576 bytes), so this needs a large skb->data - skb->head on top of it,
for instance after several nested decapsulations, each of them possibly
pulling its own extension header chain, since @offset is relative to
the IPv6 header embedded in the ICMPv6 error. No reproducer was written,
this is hardening.
Use skb_set_transport_header_careful() and ignore the ICMPv6 error if
the offset can not be stored. Do this before changing the network
header, so that nothing has to be restored on failure.
Fixes: 1a37e412a022 ("net: Use 16bits for *_headers fields of struct skbuff")
Cc: stable@vger.kernel.org
Signed-off-by: Eric Dumazet <edumazet@kernel.org>
---
net/sctp/ipv6.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
index 97390569c4bd..ad5c951efdf0 100644
--- a/net/sctp/ipv6.c
+++ b/net/sctp/ipv6.c
@@ -170,8 +170,11 @@ static int sctp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
/* Fix up skb to look at the embedded net header. */
saveip = skb->network_header;
savesctp = skb->transport_header;
+ if (unlikely(!skb_set_transport_header_careful(skb, offset))) {
+ __ICMP6_INC_STATS(net, __in6_dev_get(skb->dev), ICMP6_MIB_INERRORS);
+ return -EINVAL;
+ }
skb_reset_network_header(skb);
- skb_set_transport_header(skb, offset);
sk = sctp_err_lookup(net, AF_INET6, skb, sctp_hdr(skb), &asoc, &transport);
/* Put back, the original pointers. */
skb->network_header = saveip;
--
2.53.0
Re: [PATCH net 4/5] sctp: use skb_set_transport_header_careful() in sctp_v6_err()
Author: netdev-bot+sashiko
Date: Mon, 16 Nov 2026 15:47
Date: Mon, 16 Nov 2026 15:47
89 lines
11745 bytes
11745 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] The main part of this concern is fixed later in the series.
--
sctp: use skb_set_transport_header_careful() in sctp_v6_err()
sctp_v6_err() now stores the ICMPv6 inner transport offset with
skb_set_transport_header_careful(). If the offset does not fit in the
16-bit skb->transport_header field, the ICMPv6 error is ignored. Before,
the offset was silently truncated and sctp_err_lookup() read the SCTP
header from the wrong place.
> diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
> index 97390569c4bdc..ad5c951efdf06 100644
> --- a/net/sctp/ipv6.c
> +++ b/net/sctp/ipv6.c
> @@ -170,8 +170,11 @@ static int sctp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
> /* Fix up skb to look at the embedded net header. */
> saveip = skb->network_header;
> savesctp = skb->transport_header;
> + if (unlikely(!skb_set_transport_header_careful(skb, offset))) {
> + __ICMP6_INC_STATS(net, __in6_dev_get(skb->dev), ICMP6_MIB_INERRORS);
> + return -EINVAL;
> + }
> skb_reset_network_header(skb);
> - skb_set_transport_header(skb, offset);
> sk = sctp_err_lookup(net, AF_INET6, skb, sctp_hdr(skb), &asoc, &transport);
[Severity: Medium]
This covers native SCTP. Can the SCTP-over-UDPv6 handler in the same file
still hand a wrapped transport header to sctp_err_lookup()?
sctp_udp_v6_err() is installed as encap_err_lookup. It still does an
unchecked 16-bit add:
net/sctp/ipv6.c:sctp_udp_v6_err() {
...
skb->transport_header += sizeof(struct udphdr);
sk = sctp_err_lookup(net, AF_INET6, skb, sctp_hdr(skb), &asoc, &t);
...
}
A later patch in this series ("udp: use skb_set_transport_header_careful()
in __udp6_lib_err_encap()") makes __udp6_lib_err_encap() store the UDP
header offset carefully. That check only makes sure the UDP header offset
itself fits and is not U16_MAX, so transport_header can still be as high
as 0xFFFE when sctp_udp_v6_err() runs.
For a UDP header offset between 0xFFF7 and 0xFFFE, adding 8 gives a bad
value:
- 0xFFF7 becomes 0xFFFF, the "not set" value. With CONFIG_DEBUG_NET this
trips the DEBUG_NET_WARN_ON_ONCE() in skb_transport_header().
- 0xFFF8 to 0xFFFE wrap to 0..6, so sctp_hdr(skb) points at
skb->head + 0..6.
In the wrapped case, sctp_err_lookup() reads vtag from the wrong bytes.
sctp_v6_from_skb(), called through af->from_skb, also reads sh->source and
sh->dest from there for the association lookup. When vtag == 0, the INIT
chunk is read with skb_header_pointer() at a negative
skb_transport_offset().
The commit message says "Should the value be truncated, sctp_err_lookup()
would read the SCTP header at the wrong place". Would it make sense to
also check, before the += in sctp_udp_v6_err(), that transport_header +
sizeof(struct udphdr) fits in 16 bits and is not U16_MAX? Another option
is for __udp6_lib_err_encap() to reserve room for the payload header.
This needs the same large skb->data - skb->head precondition the series
describes, and there is no reproducer.
> /* Put back, the original pointers. */
> skb->network_header = saveip;
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113124625.4010206-1-edumazet%40kernel.org
Re: [PATCH net 4/5] sctp: use skb_set_transport_header_careful() in sctp_v6_err()
Author: Xin Long
Date: Mon, 16 Nov 2026 19:20
Date: Mon, 16 Nov 2026 19:20
113 lines
16337 bytes
16337 bytes
On Mon, Nov 16, 2026 at 10:47 AM <netdev-bot+sashiko@kernel.org> wrote:
>
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider.
>
> Critical: 0 · High: 0 · Medium: 1 · Low: 0
>
> If you believe none of the issues are legitimate, please reply to each
> issue of Medium severity or higher and explain why the AI is wrong.
> If any of them are legitimate and you plan to respin, please let patchwork
> know by including "pw-bot: cr" as a separate line at the end of your reply
> (one such reply per series is enough).
>
> - [Medium] The main part of this concern is fixed later in the series.
>
> --
>
> sctp: use skb_set_transport_header_careful() in sctp_v6_err()
>
> sctp_v6_err() now stores the ICMPv6 inner transport offset with
> skb_set_transport_header_careful(). If the offset does not fit in the
> 16-bit skb->transport_header field, the ICMPv6 error is ignored. Before,
> the offset was silently truncated and sctp_err_lookup() read the SCTP
> header from the wrong place.
>
> > diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
> > index 97390569c4bdc..ad5c951efdf06 100644
> > --- a/net/sctp/ipv6.c
> > +++ b/net/sctp/ipv6.c
> > @@ -170,8 +170,11 @@ static int sctp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
> > /* Fix up skb to look at the embedded net header. */
> > saveip = skb->network_header;
> > savesctp = skb->transport_header;
> > + if (unlikely(!skb_set_transport_header_careful(skb, offset))) {
> > + __ICMP6_INC_STATS(net, __in6_dev_get(skb->dev), ICMP6_MIB_INERRORS);
> > + return -EINVAL;
> > + }
> > skb_reset_network_header(skb);
> > - skb_set_transport_header(skb, offset);
> > sk = sctp_err_lookup(net, AF_INET6, skb, sctp_hdr(skb), &asoc, &transport);
>
> [Severity: Medium]
>
> This covers native SCTP. Can the SCTP-over-UDPv6 handler in the same file
> still hand a wrapped transport header to sctp_err_lookup()?
>
> sctp_udp_v6_err() is installed as encap_err_lookup. It still does an
> unchecked 16-bit add:
>
> net/sctp/ipv6.c:sctp_udp_v6_err() {
> ...
> skb->transport_header += sizeof(struct udphdr);
> sk = sctp_err_lookup(net, AF_INET6, skb, sctp_hdr(skb), &asoc, &t);
> ...
> }
>
> A later patch in this series ("udp: use skb_set_transport_header_careful()
> in __udp6_lib_err_encap()") makes __udp6_lib_err_encap() store the UDP
> header offset carefully. That check only makes sure the UDP header offset
> itself fits and is not U16_MAX, so transport_header can still be as high
> as 0xFFFE when sctp_udp_v6_err() runs.
>
> For a UDP header offset between 0xFFF7 and 0xFFFE, adding 8 gives a bad
> value:
>
> - 0xFFF7 becomes 0xFFFF, the "not set" value. With CONFIG_DEBUG_NET this
> trips the DEBUG_NET_WARN_ON_ONCE() in skb_transport_header().
> - 0xFFF8 to 0xFFFE wrap to 0..6, so sctp_hdr(skb) points at
> skb->head + 0..6.
>
> In the wrapped case, sctp_err_lookup() reads vtag from the wrong bytes.
> sctp_v6_from_skb(), called through af->from_skb, also reads sh->source and
> sh->dest from there for the association lookup. When vtag == 0, the INIT
> chunk is read with skb_header_pointer() at a negative
> skb_transport_offset().
>
> The commit message says "Should the value be truncated, sctp_err_lookup()
> would read the SCTP header at the wrong place". Would it make sense to
> also check, before the += in sctp_udp_v6_err(), that transport_header +
> sizeof(struct udphdr) fits in 16 bits and is not U16_MAX? Another option
> is for __udp6_lib_err_encap() to reserve room for the payload header.
>
> This needs the same large skb->data - skb->head precondition the series
> describes, and there is no reproducer.
>
> > /* Put back, the original pointers. */
> > skb->network_header = saveip;
>
> --
> Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113124625.4010206-1-edumazet%40kernel.org
The new skb->transport_header is used by sctp_hdr(skb) in af->from_skb()
in sctp_err_lookup(). I think it's better to avoid changing
skb->transport_header by passing sctphdr to af->from_skb(), which also
makes code cleaner.
Hi Eric, you can either continue with the idea, or discard this patch and
leave it to me.
Thanks.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads