Explorar el Código

[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 hace 13 años
padre
commit
17f09dfe03
Se han modificado 1 ficheros con 3 adiciones y 1 borrados
  1. 3
    1
      src/net/retry.c

+ 3
- 1
src/net/retry.c Ver fichero

@@ -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
 /**

Loading…
Cancelar
Guardar