OpenFastPath / ofp

OpenFastPath project
BSD 3-Clause "New" or "Revised" License
349 stars 126 forks source link

recv returns trash data if eth frame was expanded #166

Open tolikheha opened 7 years ago

tolikheha commented 7 years ago

If ethernet frame was less than minimum ethernet frame size and was extended, recv will return trash data. In linux ethernet frames often bigger that minimum, as linux use timestamps by default. But in Windows packets often comes without timestamps, and could be situation when frame should be extended. For example, if someone decided to send 1byte (telnet?), we will have 14(eth)+20(ip)+20(tcp)+1(payload) = 55 bytes frame. It will be expanded, and ofp will receive 60bytes frame. And than ofp will just drop headers and recv will return rest of packet.

tolikheha commented 7 years ago

As possible solution:

diff --git a/src/ofp_tcp_input.c b/src/ofp_tcp_input.c
index 79466bb..26c648a 100644
--- a/src/ofp_tcp_input.c
+++ b/src/ofp_tcp_input.c
@@ -1733,6 +1733,11 @@ ofp_tcp_do_segment(odp_packet_t m, struct ofp_tcphdr *th, struct socket *so,
                                            newsize, so, NULL))
                                                so->so_rcv.sb_flags &= ~SB_AUTOSIZE;
                                odp_packet_pull_head(m, drop_hdrlen);   /* delayed header drop */
+
+                               todrop = odp_packet_len(m) - tlen;
+                               if (todrop > 0)
+                                       odp_packet_pull_tail(m, todrop);
+
                                ofp_sbappendstream_locked(&so->so_rcv, m);
                        }
                        /* NB: sorwakeup_locked() does an implicit unlock. */
@@ -2787,6 +2792,11 @@ dodata:                                                  /* XXX */
            TCPS_HAVERCVDFIN(tp->t_state) == 0) {
                tcp_seq save_start = th->th_seq;
                odp_packet_pull_head(m, drop_hdrlen);   /* delayed header drop */
+
+               todrop = odp_packet_len(m) - tlen;
+               if (todrop > 0)
+                       odp_packet_pull_tail(m, todrop);
+
                /*
                 * Insert segment which includes th into TCP reassembly queue
                 * with control block tp.  Set thflags to whether reassembly now
sovu commented 6 years ago

Hi,

Anyone who wants to contribute to the OpenFastPath Foundation needs to sign the contribution agreement. http://www.openfastpath.org/downloads/OpenFastPath_ContributionAgreement.pdf See http://www.openfastpath.org/index.php/about-us/

To submit patches see: http://www.openfastpath.org/index.php/service/getinvolved/ Mailing List and Patches Chapters.

BR, Sorin OpenFastPath Maintainer