Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: Prevent use after free in netif_napi_set_irq_locked()

The cpu_rmap_put() will call kfree() when the last reference is dropped
so it could result in a use after free when we dereference the same
pointer the next line. Move the cpu_rmap_put() after the dereference.

Fixes: bd7c00605ee0 ("net: move aRFS rmap management and CPU affinity to core")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Link: https://patch.msgid.link/5a9c53a4-5487-4b8c-9ffa-d8e5343aaaaf@stanley.mountain
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Dan Carpenter and committed by
Jakub Kicinski
f252f23a b9564ca3

+1 -1
+1 -1
net/core/dev.c
··· 7072 7072 put_rmap: 7073 7073 #ifdef CONFIG_RFS_ACCEL 7074 7074 if (napi->dev->rx_cpu_rmap_auto) { 7075 - cpu_rmap_put(napi->dev->rx_cpu_rmap); 7076 7075 napi->dev->rx_cpu_rmap->obj[napi->napi_rmap_idx] = NULL; 7076 + cpu_rmap_put(napi->dev->rx_cpu_rmap); 7077 7077 napi->napi_rmap_idx = -1; 7078 7078 } 7079 7079 #endif