diff options
-rw-r--r-- | include/net/xfrm.h | 1 | ||||
-rw-r--r-- | net/key/af_key.c | 6 | ||||
-rw-r--r-- | net/xfrm/xfrm_state.c | 24 | ||||
-rw-r--r-- | net/xfrm/xfrm_user.c | 25 |
4 files changed, 32 insertions, 24 deletions
diff --git a/include/net/xfrm.h b/include/net/xfrm.h index 59f5d0a6c7f8..b7635ef4d436 100644 --- a/include/net/xfrm.h +++ b/include/net/xfrm.h | |||
@@ -1563,6 +1563,7 @@ struct xfrm_policy *xfrm_policy_byid(struct net *net, u32 mark, u8, int dir, | |||
1563 | u32 id, int delete, int *err); | 1563 | u32 id, int delete, int *err); |
1564 | int xfrm_policy_flush(struct net *net, u8 type, struct xfrm_audit *audit_info); | 1564 | int xfrm_policy_flush(struct net *net, u8 type, struct xfrm_audit *audit_info); |
1565 | u32 xfrm_get_acqseq(void); | 1565 | u32 xfrm_get_acqseq(void); |
1566 | int verify_spi_info(u8 proto, u32 min, u32 max); | ||
1566 | int xfrm_alloc_spi(struct xfrm_state *x, u32 minspi, u32 maxspi); | 1567 | int xfrm_alloc_spi(struct xfrm_state *x, u32 minspi, u32 maxspi); |
1567 | struct xfrm_state *xfrm_find_acq(struct net *net, const struct xfrm_mark *mark, | 1568 | struct xfrm_state *xfrm_find_acq(struct net *net, const struct xfrm_mark *mark, |
1568 | u8 mode, u32 reqid, u8 proto, | 1569 | u8 mode, u32 reqid, u8 proto, |
diff --git a/net/key/af_key.c b/net/key/af_key.c index 5beabd8ba772..1a04c1329362 100644 --- a/net/key/af_key.c +++ b/net/key/af_key.c | |||
@@ -1340,6 +1340,12 @@ static int pfkey_getspi(struct sock *sk, struct sk_buff *skb, const struct sadb_ | |||
1340 | max_spi = range->sadb_spirange_max; | 1340 | max_spi = range->sadb_spirange_max; |
1341 | } | 1341 | } |
1342 | 1342 | ||
1343 | err = verify_spi_info(x->id.proto, min_spi, max_spi); | ||
1344 | if (err) { | ||
1345 | xfrm_state_put(x); | ||
1346 | return err; | ||
1347 | } | ||
1348 | |||
1343 | err = xfrm_alloc_spi(x, min_spi, max_spi); | 1349 | err = xfrm_alloc_spi(x, min_spi, max_spi); |
1344 | resp_skb = err ? ERR_PTR(err) : pfkey_xfrm_state2msg(x); | 1350 | resp_skb = err ? ERR_PTR(err) : pfkey_xfrm_state2msg(x); |
1345 | 1351 | ||
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c index e845066547c4..a62c25ea3631 100644 --- a/net/xfrm/xfrm_state.c +++ b/net/xfrm/xfrm_state.c | |||
@@ -1489,6 +1489,30 @@ u32 xfrm_get_acqseq(void) | |||
1489 | } | 1489 | } |
1490 | EXPORT_SYMBOL(xfrm_get_acqseq); | 1490 | EXPORT_SYMBOL(xfrm_get_acqseq); |
1491 | 1491 | ||
1492 | int verify_spi_info(u8 proto, u32 min, u32 max) | ||
1493 | { | ||
1494 | switch (proto) { | ||
1495 | case IPPROTO_AH: | ||
1496 | case IPPROTO_ESP: | ||
1497 | break; | ||
1498 | |||
1499 | case IPPROTO_COMP: | ||
1500 | /* IPCOMP spi is 16-bits. */ | ||
1501 | if (max >= 0x10000) | ||
1502 | return -EINVAL; | ||
1503 | break; | ||
1504 | |||
1505 | default: | ||
1506 | return -EINVAL; | ||
1507 | } | ||
1508 | |||
1509 | if (min > max) | ||
1510 | return -EINVAL; | ||
1511 | |||
1512 | return 0; | ||
1513 | } | ||
1514 | EXPORT_SYMBOL(verify_spi_info); | ||
1515 | |||
1492 | int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high) | 1516 | int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high) |
1493 | { | 1517 | { |
1494 | struct net *net = xs_net(x); | 1518 | struct net *net = xs_net(x); |
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c index 4027c4266a87..97681a390402 100644 --- a/net/xfrm/xfrm_user.c +++ b/net/xfrm/xfrm_user.c | |||
@@ -1079,29 +1079,6 @@ out_noput: | |||
1079 | return err; | 1079 | return err; |
1080 | } | 1080 | } |
1081 | 1081 | ||
1082 | static int verify_userspi_info(struct xfrm_userspi_info *p) | ||
1083 | { | ||
1084 | switch (p->info.id.proto) { | ||
1085 | case IPPROTO_AH: | ||
1086 | case IPPROTO_ESP: | ||
1087 | break; | ||
1088 | |||
1089 | case IPPROTO_COMP: | ||
1090 | /* IPCOMP spi is 16-bits. */ | ||
1091 | if (p->max >= 0x10000) | ||
1092 | return -EINVAL; | ||
1093 | break; | ||
1094 | |||
1095 | default: | ||
1096 | return -EINVAL; | ||
1097 | } | ||
1098 | |||
1099 | if (p->min > p->max) | ||
1100 | return -EINVAL; | ||
1101 | |||
1102 | return 0; | ||
1103 | } | ||
1104 | |||
1105 | static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh, | 1082 | static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh, |
1106 | struct nlattr **attrs) | 1083 | struct nlattr **attrs) |
1107 | { | 1084 | { |
@@ -1116,7 +1093,7 @@ static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh, | |||
1116 | struct xfrm_mark m; | 1093 | struct xfrm_mark m; |
1117 | 1094 | ||
1118 | p = nlmsg_data(nlh); | 1095 | p = nlmsg_data(nlh); |
1119 | err = verify_userspi_info(p); | 1096 | err = verify_spi_info(p->info.id.proto, p->min, p->max); |
1120 | if (err) | 1097 | if (err) |
1121 | goto out_noput; | 1098 | goto out_noput; |
1122 | 1099 | ||