mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Christian Melki <christian.melki@t2data.com>
To: barebox@lists.infradead.org
Subject: [PATCH] net.c: Don't forget about the first fragment.
Date: Tue,  4 Jul 2023 19:55:35 +0200	[thread overview]
Message-ID: <20230704175535.1183448-1-christian.melki@t2data.com> (raw)

It's possible to request very large messages using
the current code base. F.ex. UDP datagrams with the tftp client.
The tftp servers will happily reply with fragmented IP frames.
All these frame parts need to be dropped as BB currently doesn't
do fragment reassembly.

The current check was for fragment offsets only (0x1fff).
But the first frame has fragment offset 0 and would slip through
this check. That could result in a seemingly OK frame
for the tftp client, but with broken data.

Add check for the MF (More Fragments) flag. Should cover the
first packet too.

Signed-off-by: Christian Melki <christian.melki@t2data.com>
---
 net/net.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/net/net.c b/net/net.c
index 19161d2e82..b842041d59 100644
--- a/net/net.c
+++ b/net/net.c
@@ -678,7 +678,12 @@ static int net_handle_ip(struct eth_device *edev, unsigned char *pkt, int len)
 	if ((ip->hl_v & 0xf0) != 0x40)
 		goto bad;
 
-	if (ip->frag_off & htons(0x1fff)) /* Can't deal w/ fragments */
+	/* Can't deal w/ fragments.
+	 * Ether a fragment offset (13 bits), or
+	 * MF (More Fragments) from frag. flags (3 bits).
+	 * MF - because first fragment has fragment offset 0
+	 */
+	if (ip->frag_off & htons(0x3fff)) 
 		goto bad;
 	if (!net_checksum_ok((unsigned char *)ip, sizeof(struct iphdr)))
 		goto bad;
-- 
2.34.1




             reply	other threads:[~2023-07-04 17:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-04 17:55 Christian Melki [this message]
2023-07-28  6:37 ` Sascha Hauer

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=20230704175535.1183448-1-christian.melki@t2data.com \
    --to=christian.melki@t2data.com \
    --cc=barebox@lists.infradead.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