Skip to content

Commit 1137b5e

Browse files
herbertxklassert
authored andcommitted
ipsec: Fix aborted xfrm policy dump crash
An independent security researcher, Mohamed Ghannam, has reported this vulnerability to Beyond Security's SecuriTeam Secure Disclosure program. The xfrm_dump_policy_done function expects xfrm_dump_policy to have been called at least once or it will crash. This can be triggered if a dump fails because the target socket's receive buffer is full. This patch fixes it by using the cb->start mechanism to ensure that the initialisation is always done regardless of the buffer situation. Fixes: 12a169e ("ipsec: Put dumpers on the dump list") Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
1 parent 10a7ef3 commit 1137b5e

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

Diff for: net/xfrm/xfrm_user.c

+15-10
Original file line numberDiff line numberDiff line change
@@ -1693,32 +1693,34 @@ static int dump_one_policy(struct xfrm_policy *xp, int dir, int count, void *ptr
16931693

16941694
static int xfrm_dump_policy_done(struct netlink_callback *cb)
16951695
{
1696-
struct xfrm_policy_walk *walk = (struct xfrm_policy_walk *) &cb->args[1];
1696+
struct xfrm_policy_walk *walk = (struct xfrm_policy_walk *)cb->args;
16971697
struct net *net = sock_net(cb->skb->sk);
16981698

16991699
xfrm_policy_walk_done(walk, net);
17001700
return 0;
17011701
}
17021702

1703+
static int xfrm_dump_policy_start(struct netlink_callback *cb)
1704+
{
1705+
struct xfrm_policy_walk *walk = (struct xfrm_policy_walk *)cb->args;
1706+
1707+
BUILD_BUG_ON(sizeof(*walk) > sizeof(cb->args));
1708+
1709+
xfrm_policy_walk_init(walk, XFRM_POLICY_TYPE_ANY);
1710+
return 0;
1711+
}
1712+
17031713
static int xfrm_dump_policy(struct sk_buff *skb, struct netlink_callback *cb)
17041714
{
17051715
struct net *net = sock_net(skb->sk);
1706-
struct xfrm_policy_walk *walk = (struct xfrm_policy_walk *) &cb->args[1];
1716+
struct xfrm_policy_walk *walk = (struct xfrm_policy_walk *)cb->args;
17071717
struct xfrm_dump_info info;
17081718

1709-
BUILD_BUG_ON(sizeof(struct xfrm_policy_walk) >
1710-
sizeof(cb->args) - sizeof(cb->args[0]));
1711-
17121719
info.in_skb = cb->skb;
17131720
info.out_skb = skb;
17141721
info.nlmsg_seq = cb->nlh->nlmsg_seq;
17151722
info.nlmsg_flags = NLM_F_MULTI;
17161723

1717-
if (!cb->args[0]) {
1718-
cb->args[0] = 1;
1719-
xfrm_policy_walk_init(walk, XFRM_POLICY_TYPE_ANY);
1720-
}
1721-
17221724
(void) xfrm_policy_walk(net, walk, dump_one_policy, &info);
17231725

17241726
return skb->len;
@@ -2474,6 +2476,7 @@ static const struct nla_policy xfrma_spd_policy[XFRMA_SPD_MAX+1] = {
24742476

24752477
static const struct xfrm_link {
24762478
int (*doit)(struct sk_buff *, struct nlmsghdr *, struct nlattr **);
2479+
int (*start)(struct netlink_callback *);
24772480
int (*dump)(struct sk_buff *, struct netlink_callback *);
24782481
int (*done)(struct netlink_callback *);
24792482
const struct nla_policy *nla_pol;
@@ -2487,6 +2490,7 @@ static const struct xfrm_link {
24872490
[XFRM_MSG_NEWPOLICY - XFRM_MSG_BASE] = { .doit = xfrm_add_policy },
24882491
[XFRM_MSG_DELPOLICY - XFRM_MSG_BASE] = { .doit = xfrm_get_policy },
24892492
[XFRM_MSG_GETPOLICY - XFRM_MSG_BASE] = { .doit = xfrm_get_policy,
2493+
.start = xfrm_dump_policy_start,
24902494
.dump = xfrm_dump_policy,
24912495
.done = xfrm_dump_policy_done },
24922496
[XFRM_MSG_ALLOCSPI - XFRM_MSG_BASE] = { .doit = xfrm_alloc_userspi },
@@ -2539,6 +2543,7 @@ static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh,
25392543

25402544
{
25412545
struct netlink_dump_control c = {
2546+
.start = link->start,
25422547
.dump = link->dump,
25432548
.done = link->done,
25442549
};

0 commit comments

Comments
 (0)