pull request (net-next): ipsec-next 2021-08-27
Subsystems (3)
Steffen Klassert
maintainer1) Remove an unneeded extra variable in esp4 esp_ssg_unref. From Corey Minyard.
2) Add a configuration option to change the default behaviour to block traffic if there is no matching policy. Joint work with Christian Langrock and Antony Antony.
3) Fix a shift-out-of-bounce bug reported from syzbot. From Pavel Skripkin.
Please pull or let me know if there are problems.
Thanks!
The following changes since commit c18e9405d46aa08bb4b55a35ee9bcc66ef3e89e0:
Merge branch 's390-next' (2021-07-20 06:23:50 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec-next.git master
for you to fetch changes up to 5d8dbb7fb82b8661c16d496644b931c0e2e3a12e:
net: xfrm: fix shift-out-of-bounce (2021-07-29 08:04:10 +0200)
----------------------------------------------------------------
Corey Minyard (1):
ipsec: Remove unneeded extra variable in esp4 esp_ssg_unref()
Pavel Skripkin (1):
net: xfrm: fix shift-out-of-bounce
Steffen Klassert (1):
xfrm: Add possibility to set the default to block if we have no policy
include/net/netns/xfrm.h | 7 ++++++ include/net/xfrm.h | 36 +++++++++++++++++++++++++----- include/uapi/linux/xfrm.h | 11 +++++++++ net/ipv4/esp4.c | 4 +--- net/xfrm/xfrm_policy.c | 16 +++++++++++++ net/xfrm/xfrm_user.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 122 insertions(+), 9 deletions(-)
Steffen Klassert
maintainerPATCH 1/3 ipsec: Remove unneeded extra variable in esp4 esp_ssg_unref()
From: Corey Minyard <[email protected]>
It's assigned twice, but only used to calculate the size of the structure it points to. Just remove it and take a sizeof the actual structure.
--- net/ipv4/esp4.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
net/ipv4/esp4.c +1 -3
@@ -97,7 +97,6 @@ static inline struct scatterlist *esp_req_sg(struct crypto_aead *aead,static void esp_ssg_unref (struct xfrm_state *x,void *tmp) { -struct esp_output_extra *extra =esp_tmp_extra (tmp);struct crypto_aead *aead = x->data;int extralen =0 ;u8 *iv;
@@ -105,9 +104,8 @@ static void esp_ssg_unref(struct xfrm_state *x, void *tmp)struct scatterlist *sg;if (x->props.flags &XFRM_STATE_ESN ) - extralen +=sizeof (*extra); + extralen +=sizeof (struct esp_output_extra ); - extra =esp_tmp_extra (tmp); iv =esp_tmp_iv (aead, tmp, extralen); req =esp_tmp_req (aead, iv);
Signature · 1 line
2.25.1
Steffen Klassert
maintainerPATCH 2/3 xfrm: Add possibility to set the default to block if we have no policy
In reply to Steffen KlassertAs the default we assume the traffic to pass, if we have no matching IPsec policy. With this patch, we have a possibility to change this default from allow to block. It can be configured via netlink. Each direction (input/output/forward) can be configured separately. With the default to block configuered, we need allow policies for all packet flows we accept. We do not use default policy lookup for the loopback device.
v1->v2
- fix compiling when XFRM is disabled
- Reported-by: kernel test robot <[email protected]>
--- include/net/netns/xfrm.h | 7 ++++++ include/net/xfrm.h | 36 ++++++++++++++++++++++----- include/uapi/linux/xfrm.h | 10 ++++++++ net/xfrm/xfrm_policy.c | 16 ++++++++++++ net/xfrm/xfrm_user.c | 52 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 115 insertions(+), 6 deletions(-)
include/net/netns/xfrm.h +7 -0
@@ -65,6 +65,13 @@ struct netns_xfrm {u32 sysctl_aevent_rseqth;int sysctl_larval_drop;u32 sysctl_acq_expires; + +u8 policy_default; +#define XFRM_POL_DEFAULT_IN 1 +#define XFRM_POL_DEFAULT_OUT 2 +#define XFRM_POL_DEFAULT_FWD 4 +#define XFRM_POL_DEFAULT_MASK 7 +#ifdef CONFIG_SYSCTL struct ctl_table_header *sysctl_hdr;#endif
include/net/xfrm.h +30 -6
@@ -1075,6 +1075,22 @@ xfrm_state_addr_cmp(const struct xfrm_tmpl *tmpl, const struct xfrm_state *x, un }#ifdef CONFIG_XFRM +static inline bool +xfrm_default_allow (struct net *net,int dir) +{ +u8 def = net->xfrm.policy_default; + +switch (dir) { +case XFRM_POLICY_IN : +return def &XFRM_POL_DEFAULT_IN ? false : true; +case XFRM_POLICY_OUT : +return def &XFRM_POL_DEFAULT_OUT ? false : true; +case XFRM_POLICY_FWD : +return def &XFRM_POL_DEFAULT_FWD ? false : true; + } +return false; +} +int __xfrm_policy_check (struct sock *,int dir,struct sk_buff *skb,unsigned short family);
@@ -1088,9 +1104,13 @@ static inline int __xfrm_policy_check2(struct sock *sk, int dir,if (sk && sk->sk_policy[XFRM_POLICY_IN ])return __xfrm_policy_check (sk, ndir, skb, family); -return (!net->xfrm.policy_count[dir] && !secpath_exists (skb)) || - (skb_dst (skb) && (skb_dst (skb)->flags &DST_NOPOLICY )) || -__xfrm_policy_check (sk, ndir, skb, family); +if (xfrm_default_allow (net, dir)) +return (!net->xfrm.policy_count[dir] && !secpath_exists (skb)) || + (skb_dst (skb) && (skb_dst (skb)->flags &DST_NOPOLICY )) || +__xfrm_policy_check (sk, ndir, skb, family); +else +return (skb_dst (skb) && (skb_dst (skb)->flags &DST_NOPOLICY )) || +__xfrm_policy_check (sk, ndir, skb, family); }static inline int xfrm_policy_check (struct sock *sk,int dir,struct sk_buff *skb,unsigned short family)
@@ -1142,9 +1162,13 @@ static inline int xfrm_route_forward(struct sk_buff *skb, unsigned short family) {struct net *net =dev_net (skb->dev); -return !net->xfrm.policy_count[XFRM_POLICY_OUT ] || - (skb_dst (skb)->flags &DST_NOXFRM ) || -__xfrm_route_forward (skb, family); +if (xfrm_default_allow (net,XFRM_POLICY_FWD )) +return !net->xfrm.policy_count[XFRM_POLICY_OUT ] || + (skb_dst (skb)->flags &DST_NOXFRM ) || +__xfrm_route_forward (skb, family); +else +return (skb_dst (skb)->flags &DST_NOXFRM ) || +__xfrm_route_forward (skb, family); }static inline int xfrm4_route_forward (struct sk_buff *skb)
include/uapi/linux/xfrm.h +10 -0
@@ -213,6 +213,11 @@ enum { XFRM_MSG_GETSPDINFO,#define XFRM_MSG_GETSPDINFO XFRM_MSG_GETSPDINFO + XFRM_MSG_SETDEFAULT, +#define XFRM_MSG_SETDEFAULT XFRM_MSG_SETDEFAULT + XFRM_MSG_GETDEFAULT, +#define XFRM_MSG_GETDEFAULT XFRM_MSG_GETDEFAULT + XFRM_MSG_MAPPING,#define XFRM_MSG_MAPPING XFRM_MSG_MAPPING __XFRM_MSG_MAX
@@ -508,6 +513,11 @@ struct xfrm_user_offload {#define XFRM_OFFLOAD_IPV6 1#define XFRM_OFFLOAD_INBOUND 2 +struct xfrm_userpolicy_default { +__u8 dirmask; +__u8 action; +}; +#ifndef __KERNEL__/* backwards compatibility for userspace */ #define XFRMGRP_ACQUIRE 1
net/xfrm/xfrm_policy.c +16 -0
@@ -3165,6 +3165,11 @@ struct dst_entry *xfrm_lookup_with_ifid(struct net *net,return dst; nopol: +if (!(dst_orig->dev->flags &IFF_LOOPBACK ) && + !xfrm_default_allow (net, dir)) { + err = -EPERM ; + goto error; + }if (!(flags &XFRM_LOOKUP_ICMP )) { dst = dst_orig; goto ok;
@@ -3553,6 +3558,11 @@ int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb, }if (!pol) { +if (!xfrm_default_allow (net, dir)) { +XFRM_INC_STATS (net,LINUX_MIB_XFRMINNOPOLS ); +return 0 ; + } +if (sp &&secpath_has_nontransport (sp,0 , &xerr_idx)) {xfrm_secpath_reject (xerr_idx, skb, &fl);XFRM_INC_STATS (net,LINUX_MIB_XFRMINNOPOLS );
@@ -3607,6 +3617,12 @@ int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb, tpp[ti++] = &pols[pi]->xfrm_vec[i]; } xfrm_nr = ti; + +if (!xfrm_default_allow (net, dir) && !xfrm_nr) { +XFRM_INC_STATS (net,LINUX_MIB_XFRMINNOSTATES ); + goto reject; + } +if (npols >1 ) {xfrm_tmpl_sort (stp, tpp, xfrm_nr, family); tpp = stp;
net/xfrm/xfrm_user.c +52 -0
70 lines not on this page · raw message
Signature · 1 line
2.25.1
Steffen Klassert
maintainerPATCH 3/3 net: xfrm: fix shift-out-of-bounce
In reply to Steffen KlassertFrom: Pavel Skripkin <[email protected]>
We need to check up->dirmask to avoid shift-out-of-bounce bug, since up->dirmask comes from userspace.
Also, added XFRM_USERPOLICY_DIRMASK_MAX constant to uapi to inform user-space that up->dirmask has maximum possible value
--- include/uapi/linux/xfrm.h | 1 + net/xfrm/xfrm_user.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-)
include/uapi/linux/xfrm.h +1 -0
@@ -514,6 +514,7 @@ struct xfrm_user_offload {#define XFRM_OFFLOAD_INBOUND 2struct xfrm_userpolicy_default { +#define XFRM_USERPOLICY_DIRMASK_MAX (sizeof(__u8) * 8)__u8 dirmask;__u8 action; };
net/xfrm/xfrm_user.c +6 -1
@@ -1966,9 +1966,14 @@ static int xfrm_set_default(struct sk_buff *skb, struct nlmsghdr *nlh, {struct net *net =sock_net (skb->sk);struct xfrm_userpolicy_default *up =nlmsg_data (nlh); -u8 dirmask = (1 << up->dirmask) &XFRM_POL_DEFAULT_MASK ; +u8 dirmask;u8 old_default = net->xfrm.policy_default; +if (up->dirmask >=XFRM_USERPOLICY_DIRMASK_MAX ) +return -EINVAL ; + + dirmask = (1 << up->dirmask) &XFRM_POL_DEFAULT_MASK ; + net->xfrm.policy_default = (old_default & (0xff ^ dirmask)) | (up->action << up->dirmask);
Signature · 1 line
2.25.1
This pull request was applied to netdev/net-next.git (refs/heads/master):
Hello:
This pull request was applied to netdev/net-next.git (refs/heads/master):
Quoted 8 lines · On Fri, 27 Aug 2021 09:50:12 +0200 you wrote:
1) Remove an unneeded extra variable in esp4
esp_ssg_unref. From Corey Minyard.2) Add a configuration option to change the default behaviour to block traffic if there is no matching policy. Joint work with Christian Langrock and Antony Antony.
[...]
Here is the summary with links:
- pull request (net-next): ipsec-next 2021-08-27
https://git.kernel.org/netdev/net-next/c/fe50893aa86e - [2/3] xfrm: Add possibility to set the default to block if we have no policy https://git.kernel.org/netdev/net-next/c/2d151d39073a - [3/3] net: xfrm: fix shift-out-of-bounce https://git.kernel.org/netdev/net-next/c/5d8dbb7fb82b
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html