xfrm: Check for esn buffer len in xfrm_new_ae

In xfrm_new_ae() we may overwrite the allocated esn replay state
buffer with a wrong size. So check that the new size matches the
original allocated size and return an error if this is not the case.

Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by Steffen Klassert and committed by David S. Miller e2b19125 af2f464e

+21
+21
net/xfrm/xfrm_user.c
··· 360 360 return 0; 361 361 } 362 362 363 + static inline int xfrm_replay_verify_len(struct xfrm_replay_state_esn *replay_esn, 364 + struct nlattr *rp) 365 + { 366 + struct xfrm_replay_state_esn *up; 367 + 368 + if (!replay_esn || !rp) 369 + return 0; 370 + 371 + up = nla_data(rp); 372 + 373 + if (xfrm_replay_state_esn_len(replay_esn) != 374 + xfrm_replay_state_esn_len(up)) 375 + return -EINVAL; 376 + 377 + return 0; 378 + } 379 + 363 380 static int xfrm_alloc_replay_state_esn(struct xfrm_replay_state_esn **replay_esn, 364 381 struct xfrm_replay_state_esn **preplay_esn, 365 382 struct nlattr *rta) ··· 1781 1764 return -ESRCH; 1782 1765 1783 1766 if (x->km.state != XFRM_STATE_VALID) 1767 + goto out; 1768 + 1769 + err = xfrm_replay_verify_len(x->replay_esn, rp); 1770 + if (err) 1784 1771 goto out; 1785 1772 1786 1773 spin_lock_bh(&x->lock);