Skip to content

Commit

Permalink
xfrm: add extack to xfrm_new_ae and xfrm_replay_verify_len
Browse files Browse the repository at this point in the history
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
  • Loading branch information
Sabrina Dubroca authored and Steffen Klassert committed Nov 25, 2022
1 parent 880e475 commit 643bc1a
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions net/xfrm/xfrm_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,8 @@ static int attach_aead(struct xfrm_state *x, struct nlattr *rta,
}

static inline int xfrm_replay_verify_len(struct xfrm_replay_state_esn *replay_esn,
struct nlattr *rp)
struct nlattr *rp,
struct netlink_ext_ack *extack)
{
struct xfrm_replay_state_esn *up;
unsigned int ulen;
Expand All @@ -528,13 +529,25 @@ static inline int xfrm_replay_verify_len(struct xfrm_replay_state_esn *replay_es

/* Check the overall length and the internal bitmap length to avoid
* potential overflow. */
if (nla_len(rp) < (int)ulen ||
xfrm_replay_state_esn_len(replay_esn) != ulen ||
replay_esn->bmp_len != up->bmp_len)
if (nla_len(rp) < (int)ulen) {
NL_SET_ERR_MSG(extack, "ESN attribute is too short");
return -EINVAL;
}

if (up->replay_window > up->bmp_len * sizeof(__u32) * 8)
if (xfrm_replay_state_esn_len(replay_esn) != ulen) {
NL_SET_ERR_MSG(extack, "New ESN size doesn't match the existing SA's ESN size");
return -EINVAL;
}

if (replay_esn->bmp_len != up->bmp_len) {
NL_SET_ERR_MSG(extack, "New ESN bitmap size doesn't match the existing SA's ESN bitmap");
return -EINVAL;
}

if (up->replay_window > up->bmp_len * sizeof(__u32) * 8) {
NL_SET_ERR_MSG(extack, "ESN replay window is longer than the bitmap");
return -EINVAL;
}

return 0;
}
Expand Down Expand Up @@ -2433,23 +2446,29 @@ static int xfrm_new_ae(struct sk_buff *skb, struct nlmsghdr *nlh,
struct nlattr *et = attrs[XFRMA_ETIMER_THRESH];
struct nlattr *rt = attrs[XFRMA_REPLAY_THRESH];

if (!lt && !rp && !re && !et && !rt)
if (!lt && !rp && !re && !et && !rt) {
NL_SET_ERR_MSG(extack, "Missing required attribute for AE");
return err;
}

/* pedantic mode - thou shalt sayeth replaceth */
if (!(nlh->nlmsg_flags&NLM_F_REPLACE))
if (!(nlh->nlmsg_flags & NLM_F_REPLACE)) {
NL_SET_ERR_MSG(extack, "NLM_F_REPLACE flag is required");
return err;
}

mark = xfrm_mark_get(attrs, &m);

x = xfrm_state_lookup(net, mark, &p->sa_id.daddr, p->sa_id.spi, p->sa_id.proto, p->sa_id.family);
if (x == NULL)
return -ESRCH;

if (x->km.state != XFRM_STATE_VALID)
if (x->km.state != XFRM_STATE_VALID) {
NL_SET_ERR_MSG(extack, "SA must be in VALID state");
goto out;
}

err = xfrm_replay_verify_len(x->replay_esn, re);
err = xfrm_replay_verify_len(x->replay_esn, re, extack);
if (err)
goto out;

Expand Down

0 comments on commit 643bc1a

Please sign in to comment.