Skip to content

Commit 84770d1

Browse files
committed
Merge tag 'ipsec-2023-03-15' of git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec
Steffen Klassert says: ==================== pull request (net): ipsec 2023-03-15 1) Fix an information leak when dumping algos and encap. From Herbert Xu 2) Allow transport-mode states with AF_UNSPEC selector to allow for nested transport-mode states. From Herbert Xu. * tag 'ipsec-2023-03-15' of git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec: xfrm: Allow transport-mode states with AF_UNSPEC selector xfrm: Zero padding when dumping algos and encap ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents c782c7f + c276a70 commit 84770d1

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

net/xfrm/xfrm_state.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2815,11 +2815,6 @@ int __xfrm_init_state(struct xfrm_state *x, bool init_replay, bool offload,
28152815
goto error;
28162816
}
28172817

2818-
if (!(inner_mode->flags & XFRM_MODE_FLAG_TUNNEL)) {
2819-
NL_SET_ERR_MSG(extack, "Only tunnel modes can accommodate an AF_UNSPEC selector");
2820-
goto error;
2821-
}
2822-
28232818
x->inner_mode = *inner_mode;
28242819

28252820
if (x->props.family == AF_INET)

net/xfrm/xfrm_user.c

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,9 @@ static int copy_to_user_aead(struct xfrm_algo_aead *aead, struct sk_buff *skb)
10121012
return -EMSGSIZE;
10131013

10141014
ap = nla_data(nla);
1015-
memcpy(ap, aead, sizeof(*aead));
1015+
strscpy_pad(ap->alg_name, aead->alg_name, sizeof(ap->alg_name));
1016+
ap->alg_key_len = aead->alg_key_len;
1017+
ap->alg_icv_len = aead->alg_icv_len;
10161018

10171019
if (redact_secret && aead->alg_key_len)
10181020
memset(ap->alg_key, 0, (aead->alg_key_len + 7) / 8);
@@ -1032,7 +1034,8 @@ static int copy_to_user_ealg(struct xfrm_algo *ealg, struct sk_buff *skb)
10321034
return -EMSGSIZE;
10331035

10341036
ap = nla_data(nla);
1035-
memcpy(ap, ealg, sizeof(*ealg));
1037+
strscpy_pad(ap->alg_name, ealg->alg_name, sizeof(ap->alg_name));
1038+
ap->alg_key_len = ealg->alg_key_len;
10361039

10371040
if (redact_secret && ealg->alg_key_len)
10381041
memset(ap->alg_key, 0, (ealg->alg_key_len + 7) / 8);
@@ -1043,6 +1046,40 @@ static int copy_to_user_ealg(struct xfrm_algo *ealg, struct sk_buff *skb)
10431046
return 0;
10441047
}
10451048

1049+
static int copy_to_user_calg(struct xfrm_algo *calg, struct sk_buff *skb)
1050+
{
1051+
struct nlattr *nla = nla_reserve(skb, XFRMA_ALG_COMP, sizeof(*calg));
1052+
struct xfrm_algo *ap;
1053+
1054+
if (!nla)
1055+
return -EMSGSIZE;
1056+
1057+
ap = nla_data(nla);
1058+
strscpy_pad(ap->alg_name, calg->alg_name, sizeof(ap->alg_name));
1059+
ap->alg_key_len = 0;
1060+
1061+
return 0;
1062+
}
1063+
1064+
static int copy_to_user_encap(struct xfrm_encap_tmpl *ep, struct sk_buff *skb)
1065+
{
1066+
struct nlattr *nla = nla_reserve(skb, XFRMA_ENCAP, sizeof(*ep));
1067+
struct xfrm_encap_tmpl *uep;
1068+
1069+
if (!nla)
1070+
return -EMSGSIZE;
1071+
1072+
uep = nla_data(nla);
1073+
memset(uep, 0, sizeof(*uep));
1074+
1075+
uep->encap_type = ep->encap_type;
1076+
uep->encap_sport = ep->encap_sport;
1077+
uep->encap_dport = ep->encap_dport;
1078+
uep->encap_oa = ep->encap_oa;
1079+
1080+
return 0;
1081+
}
1082+
10461083
static int xfrm_smark_put(struct sk_buff *skb, struct xfrm_mark *m)
10471084
{
10481085
int ret = 0;
@@ -1098,12 +1135,12 @@ static int copy_to_user_state_extra(struct xfrm_state *x,
10981135
goto out;
10991136
}
11001137
if (x->calg) {
1101-
ret = nla_put(skb, XFRMA_ALG_COMP, sizeof(*(x->calg)), x->calg);
1138+
ret = copy_to_user_calg(x->calg, skb);
11021139
if (ret)
11031140
goto out;
11041141
}
11051142
if (x->encap) {
1106-
ret = nla_put(skb, XFRMA_ENCAP, sizeof(*x->encap), x->encap);
1143+
ret = copy_to_user_encap(x->encap, skb);
11071144
if (ret)
11081145
goto out;
11091146
}

0 commit comments

Comments
 (0)