Commit d0fde795 authored by David S. Miller's avatar David S. Miller

xfrm_user: Stop using NLA_PUT*().

These macros contain a hidden goto, and are thus extremely error
prone and make code hard to audit.
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 72331bc0
...@@ -756,40 +756,50 @@ static int copy_to_user_state_extra(struct xfrm_state *x, ...@@ -756,40 +756,50 @@ static int copy_to_user_state_extra(struct xfrm_state *x,
{ {
copy_to_user_state(x, p); copy_to_user_state(x, p);
if (x->coaddr) if (x->coaddr &&
NLA_PUT(skb, XFRMA_COADDR, sizeof(*x->coaddr), x->coaddr); nla_put(skb, XFRMA_COADDR, sizeof(*x->coaddr), x->coaddr))
goto nla_put_failure;
if (x->lastused) if (x->lastused &&
NLA_PUT_U64(skb, XFRMA_LASTUSED, x->lastused); nla_put_u64(skb, XFRMA_LASTUSED, x->lastused))
goto nla_put_failure;
if (x->aead) if (x->aead &&
NLA_PUT(skb, XFRMA_ALG_AEAD, aead_len(x->aead), x->aead); nla_put(skb, XFRMA_ALG_AEAD, aead_len(x->aead), x->aead))
if (x->aalg) { goto nla_put_failure;
if (copy_to_user_auth(x->aalg, skb))
goto nla_put_failure;
NLA_PUT(skb, XFRMA_ALG_AUTH_TRUNC, if (x->aalg &&
xfrm_alg_auth_len(x->aalg), x->aalg); (copy_to_user_auth(x->aalg, skb) ||
} nla_put(skb, XFRMA_ALG_AUTH_TRUNC,
if (x->ealg) xfrm_alg_auth_len(x->aalg), x->aalg)))
NLA_PUT(skb, XFRMA_ALG_CRYPT, xfrm_alg_len(x->ealg), x->ealg); goto nla_put_failure;
if (x->calg)
NLA_PUT(skb, XFRMA_ALG_COMP, sizeof(*(x->calg)), x->calg);
if (x->encap) if (x->ealg &&
NLA_PUT(skb, XFRMA_ENCAP, sizeof(*x->encap), x->encap); nla_put(skb, XFRMA_ALG_CRYPT, xfrm_alg_len(x->ealg), x->ealg))
goto nla_put_failure;
if (x->tfcpad) if (x->calg &&
NLA_PUT_U32(skb, XFRMA_TFCPAD, x->tfcpad); nla_put(skb, XFRMA_ALG_COMP, sizeof(*(x->calg)), x->calg))
goto nla_put_failure;
if (x->encap &&
nla_put(skb, XFRMA_ENCAP, sizeof(*x->encap), x->encap))
goto nla_put_failure;
if (x->tfcpad &&
nla_put_u32(skb, XFRMA_TFCPAD, x->tfcpad))
goto nla_put_failure;
if (xfrm_mark_put(skb, &x->mark)) if (xfrm_mark_put(skb, &x->mark))
goto nla_put_failure; goto nla_put_failure;
if (x->replay_esn) if (x->replay_esn &&
NLA_PUT(skb, XFRMA_REPLAY_ESN_VAL, nla_put(skb, XFRMA_REPLAY_ESN_VAL,
xfrm_replay_state_esn_len(x->replay_esn), x->replay_esn); xfrm_replay_state_esn_len(x->replay_esn),
x->replay_esn))
goto nla_put_failure;
if (x->security && copy_sec_ctx(x->security, skb) < 0) if (x->security && copy_sec_ctx(x->security, skb))
goto nla_put_failure; goto nla_put_failure;
return 0; return 0;
...@@ -912,8 +922,9 @@ static int build_spdinfo(struct sk_buff *skb, struct net *net, ...@@ -912,8 +922,9 @@ static int build_spdinfo(struct sk_buff *skb, struct net *net,
sph.spdhcnt = si.spdhcnt; sph.spdhcnt = si.spdhcnt;
sph.spdhmcnt = si.spdhmcnt; sph.spdhmcnt = si.spdhmcnt;
NLA_PUT(skb, XFRMA_SPD_INFO, sizeof(spc), &spc); if (nla_put(skb, XFRMA_SPD_INFO, sizeof(spc), &spc) ||
NLA_PUT(skb, XFRMA_SPD_HINFO, sizeof(sph), &sph); nla_put(skb, XFRMA_SPD_HINFO, sizeof(sph), &sph))
goto nla_put_failure;
return nlmsg_end(skb, nlh); return nlmsg_end(skb, nlh);
...@@ -967,8 +978,9 @@ static int build_sadinfo(struct sk_buff *skb, struct net *net, ...@@ -967,8 +978,9 @@ static int build_sadinfo(struct sk_buff *skb, struct net *net,
sh.sadhmcnt = si.sadhmcnt; sh.sadhmcnt = si.sadhmcnt;
sh.sadhcnt = si.sadhcnt; sh.sadhcnt = si.sadhcnt;
NLA_PUT_U32(skb, XFRMA_SAD_CNT, si.sadcnt); if (nla_put_u32(skb, XFRMA_SAD_CNT, si.sadcnt) ||
NLA_PUT(skb, XFRMA_SAD_HINFO, sizeof(sh), &sh); nla_put(skb, XFRMA_SAD_HINFO, sizeof(sh), &sh))
goto nla_put_failure;
return nlmsg_end(skb, nlh); return nlmsg_end(skb, nlh);
...@@ -1690,21 +1702,27 @@ static int build_aevent(struct sk_buff *skb, struct xfrm_state *x, const struct ...@@ -1690,21 +1702,27 @@ static int build_aevent(struct sk_buff *skb, struct xfrm_state *x, const struct
id->reqid = x->props.reqid; id->reqid = x->props.reqid;
id->flags = c->data.aevent; id->flags = c->data.aevent;
if (x->replay_esn) if (x->replay_esn) {
NLA_PUT(skb, XFRMA_REPLAY_ESN_VAL, if (nla_put(skb, XFRMA_REPLAY_ESN_VAL,
xfrm_replay_state_esn_len(x->replay_esn), xfrm_replay_state_esn_len(x->replay_esn),
x->replay_esn); x->replay_esn))
else goto nla_put_failure;
NLA_PUT(skb, XFRMA_REPLAY_VAL, sizeof(x->replay), &x->replay); } else {
if (nla_put(skb, XFRMA_REPLAY_VAL, sizeof(x->replay),
NLA_PUT(skb, XFRMA_LTIME_VAL, sizeof(x->curlft), &x->curlft); &x->replay))
goto nla_put_failure;
}
if (nla_put(skb, XFRMA_LTIME_VAL, sizeof(x->curlft), &x->curlft))
goto nla_put_failure;
if (id->flags & XFRM_AE_RTHR) if ((id->flags & XFRM_AE_RTHR) &&
NLA_PUT_U32(skb, XFRMA_REPLAY_THRESH, x->replay_maxdiff); nla_put_u32(skb, XFRMA_REPLAY_THRESH, x->replay_maxdiff))
goto nla_put_failure;
if (id->flags & XFRM_AE_ETHR) if ((id->flags & XFRM_AE_ETHR) &&
NLA_PUT_U32(skb, XFRMA_ETIMER_THRESH, nla_put_u32(skb, XFRMA_ETIMER_THRESH,
x->replay_maxage * 10 / HZ); x->replay_maxage * 10 / HZ))
goto nla_put_failure;
if (xfrm_mark_put(skb, &x->mark)) if (xfrm_mark_put(skb, &x->mark))
goto nla_put_failure; goto nla_put_failure;
...@@ -2835,8 +2853,9 @@ static int build_report(struct sk_buff *skb, u8 proto, ...@@ -2835,8 +2853,9 @@ static int build_report(struct sk_buff *skb, u8 proto,
ur->proto = proto; ur->proto = proto;
memcpy(&ur->sel, sel, sizeof(ur->sel)); memcpy(&ur->sel, sel, sizeof(ur->sel));
if (addr) if (addr &&
NLA_PUT(skb, XFRMA_COADDR, sizeof(*addr), addr); nla_put(skb, XFRMA_COADDR, sizeof(*addr), addr))
goto nla_put_failure;
return nlmsg_end(skb, nlh); return nlmsg_end(skb, nlh);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment