Skip to content

Commit

Permalink
xfrm_user: uncoditionally validate esn replay attribute struct
Browse files Browse the repository at this point in the history
The sanity test added in ecd7918 can be bypassed, validation
only occurs if XFRM_STATE_ESN flag is set, but rest of code doesn't care
and just checks if the attribute itself is present.

So always validate.  Alternative is to reject if we have the attribute
without the flag but that would change abi.

Reported-by: [email protected]
Cc: Mathias Krause <[email protected]>
Fixes: ecd7918 ("xfrm_user: ensure user supplied esn replay window is valid")
Fixes: d8647b7 ("xfrm: Add user interface for esn and big anti-replay windows")
Signed-off-by: Florian Westphal <[email protected]>
Signed-off-by: Steffen Klassert <[email protected]>
  • Loading branch information
Florian Westphal authored and klassert committed Feb 13, 2018
1 parent 2471c98 commit d97ca5d
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions net/xfrm/xfrm_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,17 @@ static inline int verify_replay(struct xfrm_usersa_info *p,
struct nlattr *rt = attrs[XFRMA_REPLAY_ESN_VAL];
struct xfrm_replay_state_esn *rs;

if (p->flags & XFRM_STATE_ESN) {
if (!rt)
return -EINVAL;
if (!rt)
return (p->flags & XFRM_STATE_ESN) ? -EINVAL : 0;

rs = nla_data(rt);
rs = nla_data(rt);

if (rs->bmp_len > XFRMA_REPLAY_ESN_MAX / sizeof(rs->bmp[0]) / 8)
return -EINVAL;

if (nla_len(rt) < (int)xfrm_replay_state_esn_len(rs) &&
nla_len(rt) != sizeof(*rs))
return -EINVAL;
}
if (rs->bmp_len > XFRMA_REPLAY_ESN_MAX / sizeof(rs->bmp[0]) / 8)
return -EINVAL;

if (!rt)
return 0;
if (nla_len(rt) < (int)xfrm_replay_state_esn_len(rs) &&
nla_len(rt) != sizeof(*rs))
return -EINVAL;

/* As only ESP and AH support ESN feature. */
if ((p->id.proto != IPPROTO_ESP) && (p->id.proto != IPPROTO_AH))
Expand Down

0 comments on commit d97ca5d

Please sign in to comment.