Skip to content

Commit cd8ae32

Browse files
qsnklassert
authored andcommitted
xfrm: xfrm_alloc_spi shouldn't use 0 as SPI
x->id.spi == 0 means "no SPI assigned", but since commit 94f3980 ("xfrm: Duplicate SPI Handling"), we now create states and add them to the byspi list with this value. __xfrm_state_delete doesn't remove those states from the byspi list, since they shouldn't be there, and this shows up as a UAF the next time we go through the byspi list. Reported-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=a25ee9d20d31e483ba7b Fixes: 94f3980 ("xfrm: Duplicate SPI Handling") Signed-off-by: Sabrina Dubroca <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent 52565a9 commit cd8ae32

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

net/xfrm/xfrm_state.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,6 +2583,8 @@ int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high,
25832583

25842584
for (h = 0; h < range; h++) {
25852585
u32 spi = (low == high) ? low : get_random_u32_inclusive(low, high);
2586+
if (spi == 0)
2587+
goto next;
25862588
newspi = htonl(spi);
25872589

25882590
spin_lock_bh(&net->xfrm.xfrm_state_lock);
@@ -2598,6 +2600,7 @@ int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high,
25982600
xfrm_state_put(x0);
25992601
spin_unlock_bh(&net->xfrm.xfrm_state_lock);
26002602

2603+
next:
26012604
if (signal_pending(current)) {
26022605
err = -ERESTARTSYS;
26032606
goto unlock;

0 commit comments

Comments
 (0)