* [PATCH nf] Revert "netfilter: conntrack: fix bug in for_each_sctp_chunk"
@ 2023-01-26 1:35 Florian Westphal
2023-01-26 9:02 ` Sriram Yagnaraman
0 siblings, 1 reply; 2+ messages in thread
From: Florian Westphal @ 2023-01-26 1:35 UTC (permalink / raw)
To: netfilter-devel; +Cc: Florian Westphal
There is no bug. If sch->length == 0, this would result in an infinite
loop, but first caller, do_basic_checks(), errors out in this case.
After this change, packets with bogus zero-length chunks are no longer
detected as invalid, so revert & add comment wrt. 0 length check.
Fixes: 98ee00774525 ("netfilter: conntrack: fix bug in for_each_sctp_chunk")
Signed-off-by: Florian Westphal <fw@strlen.de>
---
It might be a good idea to merge do_basic_checks and sctp_error
to avoid future patches adding for_each_sctp_chunk() earlier in the
pipeline.
net/netfilter/nf_conntrack_proto_sctp.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/net/netfilter/nf_conntrack_proto_sctp.c b/net/netfilter/nf_conntrack_proto_sctp.c
index 945dd40e7077..2f4459478750 100644
--- a/net/netfilter/nf_conntrack_proto_sctp.c
+++ b/net/netfilter/nf_conntrack_proto_sctp.c
@@ -142,10 +142,11 @@ static void sctp_print_conntrack(struct seq_file *s, struct nf_conn *ct)
}
#endif
+/* do_basic_checks ensures sch->length > 0, do not use before */
#define for_each_sctp_chunk(skb, sch, _sch, offset, dataoff, count) \
for ((offset) = (dataoff) + sizeof(struct sctphdr), (count) = 0; \
- ((sch) = skb_header_pointer((skb), (offset), sizeof(_sch), &(_sch))) && \
- (sch)->length; \
+ (offset) < (skb)->len && \
+ ((sch) = skb_header_pointer((skb), (offset), sizeof(_sch), &(_sch))); \
(offset) += (ntohs((sch)->length) + 3) & ~3, (count)++)
/* Some validity checks to make sure the chunks are fine */
--
2.39.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* RE: [PATCH nf] Revert "netfilter: conntrack: fix bug in for_each_sctp_chunk"
2023-01-26 1:35 [PATCH nf] Revert "netfilter: conntrack: fix bug in for_each_sctp_chunk" Florian Westphal
@ 2023-01-26 9:02 ` Sriram Yagnaraman
0 siblings, 0 replies; 2+ messages in thread
From: Sriram Yagnaraman @ 2023-01-26 9:02 UTC (permalink / raw)
To: Florian Westphal, netfilter-devel
> -----Original Message-----
> From: Florian Westphal <fw@strlen.de>
> Sent: Thursday, 26 January 2023 02:35
> To: netfilter-devel@vger.kernel.org
> Cc: Florian Westphal <fw@strlen.de>
> Subject: [PATCH nf] Revert "netfilter: conntrack: fix bug in
> for_each_sctp_chunk"
>
> There is no bug. If sch->length == 0, this would result in an infinite loop, but
> first caller, do_basic_checks(), errors out in this case.
>
Ah yes, perhaps your comment was for [1], where for_each_sctp_chunk() is used only once in nf_conntrack_sctp_packet(), and I didn't check for (sch)->length.
The (sch)->length check in do_basic_checks() was almost invisible to me :(
[1] https://patchwork.ozlabs.org/project/netfilter-devel/patch/20230111094640.24663-1-sriram.yagnaraman@est.tech/
> After this change, packets with bogus zero-length chunks are no longer
> detected as invalid, so revert & add comment wrt. 0 length check.
>
> Fixes: 98ee00774525 ("netfilter: conntrack: fix bug in for_each_sctp_chunk")
> Signed-off-by: Florian Westphal <fw@strlen.de>
> ---
> It might be a good idea to merge do_basic_checks and sctp_error to avoid
> future patches adding for_each_sctp_chunk() earlier in the pipeline.
>
> net/netfilter/nf_conntrack_proto_sctp.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/net/netfilter/nf_conntrack_proto_sctp.c
> b/net/netfilter/nf_conntrack_proto_sctp.c
> index 945dd40e7077..2f4459478750 100644
> --- a/net/netfilter/nf_conntrack_proto_sctp.c
> +++ b/net/netfilter/nf_conntrack_proto_sctp.c
> @@ -142,10 +142,11 @@ static void sctp_print_conntrack(struct seq_file *s,
> struct nf_conn *ct) } #endif
>
> +/* do_basic_checks ensures sch->length > 0, do not use before */
> #define for_each_sctp_chunk(skb, sch, _sch, offset, dataoff, count) \
> for ((offset) = (dataoff) + sizeof(struct sctphdr), (count) = 0; \
> - ((sch) = skb_header_pointer((skb), (offset), sizeof(_sch), &(_sch))) &&
> \
> - (sch)->length; \
> + (offset) < (skb)->len && \
> + ((sch) = skb_header_pointer((skb), (offset), sizeof(_sch), &(_sch)));
> \
> (offset) += (ntohs((sch)->length) + 3) & ~3, (count)++)
>
> /* Some validity checks to make sure the chunks are fine */
> --
> 2.39.1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-01-26 9:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-26 1:35 [PATCH nf] Revert "netfilter: conntrack: fix bug in for_each_sctp_chunk" Florian Westphal
2023-01-26 9:02 ` Sriram Yagnaraman
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.