Browse Source

[tcp] Fix potential use-after-free when accessing timestamp option

Reported-by: Piotr Jaroszyński <p.jaroszynski@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 14 years ago
parent
commit
68c2f07f15
1 changed files with 7 additions and 4 deletions
  1. 7
    4
      src/net/tcp.c

+ 7
- 4
src/net/tcp.c View File

@@ -900,6 +900,7 @@ static int tcp_rx ( struct io_buffer *iobuf,
900 900
 	uint32_t seq;
901 901
 	uint32_t ack;
902 902
 	uint32_t win;
903
+	uint32_t ts_recent;
903 904
 	unsigned int flags;
904 905
 	size_t len;
905 906
 	int rc;
@@ -941,6 +942,8 @@ static int tcp_rx ( struct io_buffer *iobuf,
941 942
 	flags = tcphdr->flags;
942 943
 	tcp_rx_opts ( tcp, ( ( ( void * ) tcphdr ) + sizeof ( *tcphdr ) ),
943 944
 		      ( hlen - sizeof ( *tcphdr ) ), &options );
945
+	ts_recent = ( options.tsopt ?
946
+		      ntohl ( options.tsopt->tsval ) : tcp->ts_recent );
944 947
 	iob_pull ( iobuf, hlen );
945 948
 	len = iob_len ( iobuf );
946 949
 
@@ -981,7 +984,7 @@ static int tcp_rx ( struct io_buffer *iobuf,
981 984
 	}
982 985
 
983 986
 	/* Handle new data, if any */
984
-	tcp_rx_data ( tcp, seq, iobuf );
987
+	tcp_rx_data ( tcp, seq, iob_disown ( iobuf ) );
985 988
 	seq += len;
986 989
 
987 990
 	/* Handle FIN, if present */
@@ -990,9 +993,9 @@ static int tcp_rx ( struct io_buffer *iobuf,
990 993
 		seq++;
991 994
 	}
992 995
 
993
-	/* Update timestamp, if present and applicable */
994
-	if ( ( seq == tcp->rcv_ack ) && options.tsopt )
995
-		tcp->ts_recent = ntohl ( options.tsopt->tsval );
996
+	/* Update timestamp, if applicable */
997
+	if ( seq == tcp->rcv_ack )
998
+		tcp->ts_recent = ts_recent;
996 999
 
997 1000
 	/* Dump out any state change as a result of the received packet */
998 1001
 	tcp_dump_state ( tcp );

Loading…
Cancel
Save