Skip to content

Commit

Permalink
xfrm: notify default policy on update
Browse files Browse the repository at this point in the history
[ Upstream commit 88d0adb ]

This configuration knob is very sensible, it should be notified when
changing.

Fixes: 2d151d3 ("xfrm: Add possibility to set the default to block if we have no policy")
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
NicolasDichtel authored and gregkh committed May 25, 2022
1 parent 20fd28d commit 9856c3a
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions net/xfrm/xfrm_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -1914,6 +1914,36 @@ static struct sk_buff *xfrm_policy_netlink(struct sk_buff *in_skb,
return skb;
}

static int xfrm_notify_userpolicy(struct net *net)
{
struct xfrm_userpolicy_default *up;
int len = NLMSG_ALIGN(sizeof(*up));
struct nlmsghdr *nlh;
struct sk_buff *skb;

skb = nlmsg_new(len, GFP_ATOMIC);
if (skb == NULL)
return -ENOMEM;

nlh = nlmsg_put(skb, 0, 0, XFRM_MSG_GETDEFAULT, sizeof(*up), 0);
if (nlh == NULL) {
kfree_skb(skb);
return -EMSGSIZE;
}

up = nlmsg_data(nlh);
up->in = net->xfrm.policy_default & XFRM_POL_DEFAULT_IN ?
XFRM_USERPOLICY_BLOCK : XFRM_USERPOLICY_ACCEPT;
up->fwd = net->xfrm.policy_default & XFRM_POL_DEFAULT_FWD ?
XFRM_USERPOLICY_BLOCK : XFRM_USERPOLICY_ACCEPT;
up->out = net->xfrm.policy_default & XFRM_POL_DEFAULT_OUT ?
XFRM_USERPOLICY_BLOCK : XFRM_USERPOLICY_ACCEPT;

nlmsg_end(skb, nlh);

return xfrm_nlmsg_multicast(net, skb, 0, XFRMNLGRP_POLICY);
}

static int xfrm_set_default(struct sk_buff *skb, struct nlmsghdr *nlh,
struct nlattr **attrs)
{
Expand All @@ -1937,6 +1967,7 @@ static int xfrm_set_default(struct sk_buff *skb, struct nlmsghdr *nlh,

rt_genid_bump_all(net);

xfrm_notify_userpolicy(net);
return 0;
}

Expand Down

0 comments on commit 9856c3a

Please sign in to comment.