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
 	uint32_t seq;
900
 	uint32_t seq;
901
 	uint32_t ack;
901
 	uint32_t ack;
902
 	uint32_t win;
902
 	uint32_t win;
903
+	uint32_t ts_recent;
903
 	unsigned int flags;
904
 	unsigned int flags;
904
 	size_t len;
905
 	size_t len;
905
 	int rc;
906
 	int rc;
941
 	flags = tcphdr->flags;
942
 	flags = tcphdr->flags;
942
 	tcp_rx_opts ( tcp, ( ( ( void * ) tcphdr ) + sizeof ( *tcphdr ) ),
943
 	tcp_rx_opts ( tcp, ( ( ( void * ) tcphdr ) + sizeof ( *tcphdr ) ),
943
 		      ( hlen - sizeof ( *tcphdr ) ), &options );
944
 		      ( hlen - sizeof ( *tcphdr ) ), &options );
945
+	ts_recent = ( options.tsopt ?
946
+		      ntohl ( options.tsopt->tsval ) : tcp->ts_recent );
944
 	iob_pull ( iobuf, hlen );
947
 	iob_pull ( iobuf, hlen );
945
 	len = iob_len ( iobuf );
948
 	len = iob_len ( iobuf );
946
 
949
 
981
 	}
984
 	}
982
 
985
 
983
 	/* Handle new data, if any */
986
 	/* Handle new data, if any */
984
-	tcp_rx_data ( tcp, seq, iobuf );
987
+	tcp_rx_data ( tcp, seq, iob_disown ( iobuf ) );
985
 	seq += len;
988
 	seq += len;
986
 
989
 
987
 	/* Handle FIN, if present */
990
 	/* Handle FIN, if present */
990
 		seq++;
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
 	/* Dump out any state change as a result of the received packet */
1000
 	/* Dump out any state change as a result of the received packet */
998
 	tcp_dump_state ( tcp );
1001
 	tcp_dump_state ( tcp );

Loading…
Cancel
Save