Skip to content

Commit 9fcedab

Browse files
qsngregkh
authored andcommitted
xfrm: xfrm_alloc_spi shouldn't use 0 as SPI
[ Upstream commit cd8ae32 ] 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]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 452ad25 commit 9fcedab

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
@@ -2502,6 +2502,8 @@ int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high,
25022502

25032503
for (h = 0; h < range; h++) {
25042504
u32 spi = (low == high) ? low : get_random_u32_inclusive(low, high);
2505+
if (spi == 0)
2506+
goto next;
25052507
newspi = htonl(spi);
25062508

25072509
spin_lock_bh(&net->xfrm.xfrm_state_lock);
@@ -2517,6 +2519,7 @@ int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high,
25172519
xfrm_state_put(x0);
25182520
spin_unlock_bh(&net->xfrm.xfrm_state_lock);
25192521

2522+
next:
25202523
if (signal_pending(current)) {
25212524
err = -ERESTARTSYS;
25222525
goto unlock;

0 commit comments

Comments
 (0)