mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] firewire: net: Fix fragmented datagram reassembly
@ 2026-07-07 15:04 Ruoyu Wang
  2026-07-13 11:21 ` Takashi Sakamoto
  0 siblings, 1 reply; 2+ messages in thread
From: Ruoyu Wang @ 2026-07-07 15:04 UTC (permalink / raw)
  To: o-takashi; +Cc: fenlason, stefanr, linux1394-devel, linux-kernel, Ruoyu Wang

fwnet_frag_new() keeps a sorted list of received fragments for a partial
datagram. When a new fragment is adjacent to an existing fragment, the
code checks whether the new fragment also closes the gap to the next or
previous list entry.

Those neighbor lookups currently assume that the current fragment always
has a real next or previous fragment. At a list edge, the next or
previous entry is the list head, not a struct fwnet_fragment_info.

The gap checks also compare against the old edge of the current fragment
instead of the edge after adding the new fragment. As a result, a
fragment that bridges two existing ranges may leave two adjacent ranges
unmerged, so fwnet_pd_is_complete() can miss a complete datagram.

Check for the list head before looking up the neighboring fragment, and
compare the neighbor against the new fragment's far edge when deciding
whether to merge all three ranges.

This issue was found by a static analysis checker and confirmed by
manual source review.

Fixes: c76acec6d551 ("firewire: add IPv4 support")
Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>
---
 drivers/firewire/net.c | 39 +++++++++++++++++++++------------------
 1 file changed, 21 insertions(+), 18 deletions(-)

diff --git a/drivers/firewire/net.c b/drivers/firewire/net.c
index e5361f4f8bbd9..961f1a0460257 100644
--- a/drivers/firewire/net.c
+++ b/drivers/firewire/net.c
@@ -297,31 +297,34 @@ static struct fwnet_fragment_info *fwnet_frag_new(
 		if (fi->offset + fi->len == offset) {
 			/* The new fragment can be tacked on to the end */
 			/* Did the new fragment plug a hole? */
-			fi2 = list_entry(fi->fi_link.next,
-					 struct fwnet_fragment_info, fi_link);
-			if (fi->offset + fi->len == fi2->offset) {
-				/* glue fragments together */
-				fi->len += len + fi2->len;
-				list_del(&fi2->fi_link);
-				kfree(fi2);
-			} else {
-				fi->len += len;
+			if (!list_is_last(&fi->fi_link, &pd->fi_list)) {
+				fi2 = list_next_entry(fi, fi_link);
+				if (offset + len == fi2->offset) {
+					/* glue fragments together */
+					fi->len += len + fi2->len;
+					list_del(&fi2->fi_link);
+					kfree(fi2);
+
+					return fi;
+				}
 			}
+			fi->len += len;
 
 			return fi;
 		}
 		if (offset + len == fi->offset) {
 			/* The new fragment can be tacked on to the beginning */
 			/* Did the new fragment plug a hole? */
-			fi2 = list_entry(fi->fi_link.prev,
-					 struct fwnet_fragment_info, fi_link);
-			if (fi2->offset + fi2->len == fi->offset) {
-				/* glue fragments together */
-				fi2->len += fi->len + len;
-				list_del(&fi->fi_link);
-				kfree(fi);
-
-				return fi2;
+			if (!list_is_first(&fi->fi_link, &pd->fi_list)) {
+				fi2 = list_prev_entry(fi, fi_link);
+				if (fi2->offset + fi2->len == offset) {
+					/* glue fragments together */
+					fi2->len += fi->len + len;
+					list_del(&fi->fi_link);
+					kfree(fi);
+
+					return fi2;
+				}
 			}
 			fi->offset = offset;
 			fi->len += len;
-- 
2.51.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] firewire: net: Fix fragmented datagram reassembly
  2026-07-07 15:04 [PATCH] firewire: net: Fix fragmented datagram reassembly Ruoyu Wang
@ 2026-07-13 11:21 ` Takashi Sakamoto
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Sakamoto @ 2026-07-13 11:21 UTC (permalink / raw)
  To: Ruoyu Wang; +Cc: fenlason, stefanr, linux1394-devel, linux-kernel

Hi,

On Tue, Jul 07, 2026 at 11:04:54PM +0800, Ruoyu Wang wrote:
> fwnet_frag_new() keeps a sorted list of received fragments for a partial
> datagram. When a new fragment is adjacent to an existing fragment, the
> code checks whether the new fragment also closes the gap to the next or
> previous list entry.
> 
> Those neighbor lookups currently assume that the current fragment always
> has a real next or previous fragment. At a list edge, the next or
> previous entry is the list head, not a struct fwnet_fragment_info.
> 
> The gap checks also compare against the old edge of the current fragment
> instead of the edge after adding the new fragment. As a result, a
> fragment that bridges two existing ranges may leave two adjacent ranges
> unmerged, so fwnet_pd_is_complete() can miss a complete datagram.
> 
> Check for the list head before looking up the neighboring fragment, and
> compare the neighbor against the new fragment's far edge when deciding
> whether to merge all three ranges.
> 
> This issue was found by a static analysis checker and confirmed by
> manual source review.
> 
> Fixes: c76acec6d551 ("firewire: add IPv4 support")
> Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>
> ---
>  drivers/firewire/net.c | 39 +++++++++++++++++++++------------------
>  1 file changed, 21 insertions(+), 18 deletions(-)

Applied to for-linus branch.


Thanks

Takashi Sakamoto

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-13 11:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-07 15:04 [PATCH] firewire: net: Fix fragmented datagram reassembly Ruoyu Wang
2026-07-13 11:21 ` Takashi Sakamoto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®