aboutsummaryrefslogtreecommitdiffstats
path: root/net/xfrm
diff options
context:
space:
mode:
authorFan Du <fan.du@windriver.com>2013-12-16 05:47:49 -0500
committerSteffen Klassert <steffen.klassert@secunet.com>2013-12-16 06:54:02 -0500
commit776e9dd90ca223b82166eb2835389493b5914cba (patch)
tree565d2ac3f67fe6fa88e789fe94ac5cf9ee3a3d4b /net/xfrm
parentea9884b3acf3311c8a11db67bfab21773f6f82ba (diff)
xfrm: export verify_userspi_info for pkfey and netlink interface
In order to check against valid IPcomp spi range, export verify_userspi_info for both pfkey and netlink interface. Signed-off-by: Fan Du <fan.du@windriver.com> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
Diffstat (limited to 'net/xfrm')
-rw-r--r--net/xfrm/xfrm_state.c24
-rw-r--r--net/xfrm/xfrm_user.c25
2 files changed, 25 insertions, 24 deletions
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}
1490EXPORT_SYMBOL(xfrm_get_acqseq); 1490EXPORT_SYMBOL(xfrm_get_acqseq);
1491 1491
1492int 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}
1514EXPORT_SYMBOL(verify_spi_info);
1515
1492int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high) 1516int 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
1082static 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
1105static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh, 1082static 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