mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Aleksander Morgado <aleksander@aleksander.es>
To: s.hauer@pengutronix.de
Cc: barebox@lists.infradead.org,
	Aleksander Morgado <aleksander@aleksander.es>
Subject: [PATCH v2 06/16] ratp: fix data presence check
Date: Wed, 21 Jun 2017 21:13:13 +0200	[thread overview]
Message-ID: <20170621191323.18191-7-aleksander@aleksander.es> (raw)
In-Reply-To: <20170621191323.18191-1-aleksander@aleksander.es>

Looking at the "data length" and SO flag isn't enough to declare a
packet with or without data, because SYN flagged packets will also use
the "data length" field to define MDL.

So, improve the check to match against SYN|RST|FIN flagged packets,
which can never have data.

This commit fixed a segfault in barebox when an unexpected SYN packet
was sent in the middle of a connection; barebox thought the packet had
data because the "data length" in the SYN packet was different than 0.

Signed-off-by: Aleksander Morgado <aleksander@aleksander.es>
---
 lib/ratp.c             | 4 ++--
 scripts/remote/ratp.py | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/ratp.c b/lib/ratp.c
index d3c252047..c946bea1a 100644
--- a/lib/ratp.c
+++ b/lib/ratp.c
@@ -165,7 +165,7 @@ static bool ratp_has_data(struct ratp_header *hdr)
 {
 	if (hdr->control & RATP_CONTROL_SO)
 		return 1;
-	if (hdr->data_length)
+	if (!(hdr->control & (RATP_CONTROL_SYN | RATP_CONTROL_RST | RATP_CONTROL_FIN)) && hdr->data_length)
 		return 1;
 	return 0;
 }
@@ -1338,7 +1338,7 @@ static int ratp_behaviour_i1(struct ratp_internal *ri, void *pkt)
 	struct ratp_header *hdr = pkt;
 	uint8_t control = 0;
 
-	if (!hdr->data_length && !(hdr->control & RATP_CONTROL_SO))
+	if (!ratp_has_data (hdr))
 		return 1;
 
 	pr_vdebug("%s **received** %d\n", __func__, hdr->data_length);
diff --git a/scripts/remote/ratp.py b/scripts/remote/ratp.py
index 079fb871a..a41d2e8a3 100644
--- a/scripts/remote/ratp.py
+++ b/scripts/remote/ratp.py
@@ -525,7 +525,7 @@ class RatpConnection(object):
             # Our fin was lost, rely on retransmission
             return False
 
-        if r.length or r.c_so:
+        if (r.length and not r.c_syn and not r.c_rst and not r.c_fin) or r.c_so:
             self._retrans = None
             s = RatpPacket(flags='RA')
             s.c_sn = r.c_an
@@ -596,7 +596,7 @@ class RatpConnection(object):
         if r.c_so:
             self._r_sn = r.c_sn
             self._rx_buf.append(chr(r.length))
-        elif r.length:
+        elif r.length and not r.c_syn and not r.c_rst and not r.c_fin:
             self._r_sn = r.c_sn
             self._rx_buf.append(r.payload)
         else:
-- 
2.13.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2017-06-21 19:14 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-21 19:13 [PATCH v2 00/16] RATP logic fixes and improvements Aleksander Morgado
2017-06-21 19:13 ` [PATCH v2 01/16] ratp: add missing transition to SYN-RECEIVED in behavior B Aleksander Morgado
2017-06-21 19:13 ` [PATCH v2 02/16] ratp: avoid unnecessary variable initializations Aleksander Morgado
2017-06-21 19:13 ` [PATCH v2 03/16] ratp: send missing RST in behavior C2 Aleksander Morgado
2017-06-21 19:13 ` [PATCH v2 04/16] ratp: add missing RST flag in behavior G Aleksander Morgado
2017-06-21 19:13 ` [PATCH v2 05/16] ratp: completely ignore RST flagged packets " Aleksander Morgado
2017-06-21 19:13 ` Aleksander Morgado [this message]
2017-06-21 19:13 ` [PATCH v2 07/16] ratp: fix single byte sending flagged with SO Aleksander Morgado
2017-06-21 19:13 ` [PATCH v2 08/16] ratp: remove bogus data checks in behavior C2 Aleksander Morgado
2017-06-21 19:13 ` [PATCH v2 09/16] ratp: remove FIXME comment: FIN always requires ACK Aleksander Morgado
2017-06-21 19:13 ` [PATCH v2 10/16] ratp: fix sending ACKs without data Aleksander Morgado
2017-06-21 19:13 ` [PATCH v2 11/16] ratp: consolidate ratp_sn_expected() and ratp_an_expected() Aleksander Morgado
2017-06-21 19:13 ` [PATCH v2 12/16] ratp: prefer using ratp_send_ack() in behaviour I1 Aleksander Morgado
2017-06-21 19:13 ` [PATCH v2 13/16] ratp: send initial data in behaviour B if any pending Aleksander Morgado
2017-06-21 19:13 ` [PATCH v2 14/16] ratp: don't ignore data that may arrive in behaviour H1 Aleksander Morgado
2017-06-21 19:13 ` [PATCH v2 15/16] ratp: consolidate setting the next AN or SN flags Aleksander Morgado
2017-06-21 19:13 ` [PATCH v2 16/16] ratp: user close may happen in SYN-RECEIVED state Aleksander Morgado
2017-06-23 11:37 ` [PATCH v2 00/16] RATP logic fixes and improvements 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=20170621191323.18191-7-aleksander@aleksander.es \
    --to=aleksander@aleksander.es \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /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