Parcourir la source

[arp] Increase robustness of ARP discarder

Take ownership from the ARP cache at the start of arp_destroy(), to
ensure that no code path can lead to arp_destroy() being re-entered.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown il y a 11 ans
Parent
révision
885384faf3
1 fichiers modifiés avec 10 ajouts et 7 suppressions
  1. 10
    7
      src/net/arp.c

+ 10
- 7
src/net/arp.c Voir le fichier

@@ -180,13 +180,16 @@ static void arp_destroy ( struct arp_entry *arp, int rc ) {
180 180
 	struct net_device *netdev = arp->netdev;
181 181
 	struct net_protocol *net_protocol = arp->net_protocol;
182 182
 	struct io_buffer *iobuf;
183
-	struct io_buffer *tmp;
183
+
184
+	/* Take ownership from cache */
185
+	list_del ( &arp->list );
184 186
 
185 187
 	/* Stop timer */
186 188
 	stop_timer ( &arp->timer );
187 189
 
188 190
 	/* Discard any outstanding I/O buffers */
189
-	list_for_each_entry_safe ( iobuf, tmp, &arp->tx_queue, list ) {
191
+	while ( ( iobuf = list_first_entry ( &arp->tx_queue, struct io_buffer,
192
+					     list ) ) != NULL ) {
190 193
 		DBGC2 ( arp, "ARP %p %s %s %s discarding deferred packet: "
191 194
 			"%s\n", arp, netdev->name, net_protocol->name,
192 195
 			net_protocol->ntoa ( arp->net_dest ), strerror ( rc ) );
@@ -198,8 +201,7 @@ static void arp_destroy ( struct arp_entry *arp, int rc ) {
198 201
 	       net_protocol->name, net_protocol->ntoa ( arp->net_dest ),
199 202
 	       strerror ( rc ) );
200 203
 
201
-	/* Remove from cache and drop reference */
202
-	list_del ( &arp->list );
204
+	/* Drop remaining reference */
203 205
 	ref_put ( &arp->refcnt );
204 206
 }
205 207
 
@@ -518,12 +520,13 @@ static unsigned int arp_discard ( void ) {
518 520
 	struct arp_entry *arp;
519 521
 
520 522
 	/* Drop oldest cache entry, if any */
521
-	list_for_each_entry_reverse ( arp, &arp_entries, list ) {
523
+	arp = list_last_entry ( &arp_entries, struct arp_entry, list );
524
+	if ( arp ) {
522 525
 		arp_destroy ( arp, -ENOBUFS );
523 526
 		return 1;
527
+	} else {
528
+		return 0;
524 529
 	}
525
-
526
-	return 0;
527 530
 }
528 531
 
529 532
 /** ARP cache discarder

Chargement…
Annuler
Enregistrer