Bläddra i källkod

[retry] Fix potential use-after-free in timer_expired()

timer->refcnt is allowed to be NULL, in which case the timer's
expired() method may end up freeing the timer object.

Discovered using valgrind.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 år sedan
förälder
incheckning
17f09dfe03
1 ändrade filer med 3 tillägg och 1 borttagningar
  1. 3
    1
      src/net/retry.c

+ 3
- 1
src/net/retry.c Visa fil

@@ -148,6 +148,7 @@ void stop_timer ( struct retry_timer *timer ) {
148 148
  * @v timer		Retry timer
149 149
  */
150 150
 static void timer_expired ( struct retry_timer *timer ) {
151
+	struct refcnt *refcnt = timer->refcnt;
151 152
 	int fail;
152 153
 
153 154
 	/* Stop timer without performing RTT calculations */
@@ -169,8 +170,9 @@ static void timer_expired ( struct retry_timer *timer ) {
169 170
 
170 171
 	/* Call expiry callback */
171 172
 	timer->expired ( timer, fail );
173
+	/* If refcnt is NULL, then timer may already have been freed */
172 174
 
173
-	ref_put ( timer->refcnt );
175
+	ref_put ( refcnt );
174 176
 }
175 177
 
176 178
 /**

Laddar…
Avbryt
Spara