xfrm: Introduce direction attribute for SA
Subsystems (4)
v12 cover xfrm: Introduce direction attribute for SA
Hi,
Inspired by the upcoming IP-TFS patch set, and confusions experienced in the past due to lack of direction attribute on SAs, add a new direction "dir" attribute. It aims to streamline the SA configuration process and enhance the clarity of existing SA attributes.
This patch set introduces the 'dir' attribute to SA, aka xfrm_state, ('in' for input or 'out' for output). Alsp add validations of existing direction-specific SA attributes during configuration and in the data path lookup.
This change would not affect any existing use case or way of configuring SA. You will notice improvements when the new 'dir' attribute is set.
Antony Antony (4):
xfrm: Add Direction to the SA in or out
xfrm: Add dir validation to "out" data path lookup
xfrm: Add dir validation to "in" data path lookup
xfrm: Restrict SA direction attribute to specific netlink message
types
Documentation/networking/xfrm_proc.rst | 6 + include/net/xfrm.h | 1 + include/uapi/linux/snmp.h | 2 + include/uapi/linux/xfrm.h | 6 + net/ipv6/xfrm6_input.c | 7 ++ net/xfrm/xfrm_compat.c | 7 +- net/xfrm/xfrm_device.c | 6 + net/xfrm/xfrm_input.c | 11 ++ net/xfrm/xfrm_policy.c | 6 + net/xfrm/xfrm_proc.c | 2 + net/xfrm/xfrm_replay.c | 3 +- net/xfrm/xfrm_state.c | 5 + net/xfrm/xfrm_user.c | 149 ++++++++++++++++++++++++- 13 files changed, 202 insertions(+), 9 deletions(-)
--
2.30.2
PATCH v12 1/4 xfrm: Add Direction to the SA in or out
This patch introduces the 'dir' attribute, 'in' or 'out', to the xfrm_state, SA, enhancing usability by delineating the scope of values based on direction. An input SA will restrict values pertinent to input, effectively segregating them from output-related values.
And an output SA will restrict attributes for output. This change aims to streamline the configuration process and improve the overall consistency of SA attributes during configuration.
This feature sets the groundwork for future patches, including the upcoming IP-TFS patch.
---v11->v12:
- fix typo in error messge for flag ICMP
v10->v11:
- set dir out for acquire state
- allow output state with ESN to set replay-window 0
- change XFRMA_SA_DIR using NLA_POLICY_RANGE()
- replace verify_sa_dir() with refactored code.
v9->v10:
- add more direction specific validations XFRM_STATE_NOPMTUDISC, XFRM_SA_XFLAG_DONT_ENCAP_DSCP XFRMA_MTIMER_THRESH
- refactor validations into a fuction.
- add dir to ALLOCSPI to support strongSwan updating SPI to "in" state
v8->v9:
- add validation XFRM_STATE_ICMP not allowed on OUT SA.
v7->v8:
- add extra validation check on replay window and seq
- XFRM_MSG_UPDSA old and new SA should match "dir"
v6->v7:
- add replay-window check non-esn 0 and ESN 1.
- remove :XFRMA_SA_DIR only allowed with HW OFFLOAD
v5->v6:
- XFRMA_SA_DIR only allowed with HW OFFLOAD
v4->v5:
- add details to commit message
v3->v4:
- improve HW OFFLOAD DIR check add the other direction
v2->v3:
- delete redundant XFRM_SA_DIR_USE
- use u8 for "dir"
- fix HW OFFLOAD DIR check
v1->v2:
- use .strict_start_type in struct nla_policy xfrma_policy
- delete redundant XFRM_SA_DIR_MAX enum
--- include/net/xfrm.h | 1 + include/uapi/linux/xfrm.h | 6 ++ net/xfrm/xfrm_compat.c | 7 ++- net/xfrm/xfrm_device.c | 6 ++ net/xfrm/xfrm_replay.c | 3 +- net/xfrm/xfrm_state.c | 5 ++ net/xfrm/xfrm_user.c | 125 ++++++++++++++++++++++++++++++++++++-- 7 files changed, 144 insertions(+), 9 deletions(-)
include/net/xfrm.h +1 -0
@@ -291,6 +291,7 @@ struct xfrm_state {/* Private data of this transformer, format is opaque, * interpreted by xfrm_type methods. */ void *data; +u8 dir; };static inline struct net *xs_net (struct xfrm_state *x)
include/uapi/linux/xfrm.h +6 -0
@@ -141,6 +141,11 @@ enum {XFRM_POLICY_MAX =3 }; +enum xfrm_sa_dir { +XFRM_SA_DIR_IN =1 , +XFRM_SA_DIR_OUT =2 +}; +enum {XFRM_SHARE_ANY ,/* No limitations */ XFRM_SHARE_SESSION ,/* For this session only */
@@ -315,6 +320,7 @@ enum xfrm_attr_type_t {XFRMA_SET_MARK_MASK ,/* __u32 */ XFRMA_IF_ID ,/* __u32 */ XFRMA_MTIMER_THRESH ,/* __u32 in seconds for input SA */ +XFRMA_SA_DIR ,/* __u8 */ __XFRMA_MAX#define XFRMA_OUTPUT_MARK XFRMA_SET_MARK/* Compatibility */
net/xfrm/xfrm_compat.c +5 -2
@@ -98,6 +98,7 @@ static const int compat_msg_min[XFRM_NR_MSGTYPES] = { };static const struct nla_policy compat_policy[XFRMA_MAX +1 ] = { + [XFRMA_UNSPEC ] = { .strict_start_type =XFRMA_SA_DIR }, [XFRMA_SA ] = { .len =XMSGSIZE (compat_xfrm_usersa_info)}, [XFRMA_POLICY ] = { .len =XMSGSIZE (compat_xfrm_userpolicy_info)}, [XFRMA_LASTUSED ] = { .type =NLA_U64 },
@@ -129,6 +130,7 @@ static const struct nla_policy compat_policy[XFRMA_MAX+1] = { [XFRMA_SET_MARK_MASK] = { .type = NLA_U32 }, [XFRMA_IF_ID] = { .type = NLA_U32 }, [XFRMA_MTIMER_THRESH] = { .type = NLA_U32 }, + [XFRMA_SA_DIR] = NLA_POLICY_RANGE(NLA_U8, XFRM_SA_DIR_IN, XFRM_SA_DIR_OUT), }; static struct nlmsghdr *xfrm_nlmsg_put_compat(struct sk_buff *skb,
@@ -277,9 +279,10 @@ static int xfrm_xlate64_attr(struct sk_buff *dst, const struct nlattr *src)case XFRMA_SET_MARK_MASK :case XFRMA_IF_ID :case XFRMA_MTIMER_THRESH : +case XFRMA_SA_DIR :return xfrm_nla_cpy (dst, src,nla_len (src));default : -BUILD_BUG_ON (XFRMA_MAX !=XFRMA_MTIMER_THRESH ); +BUILD_BUG_ON (XFRMA_MAX !=XFRMA_SA_DIR );pr_warn_once ("unsupported nla_type %d\n" , src->nla_type);return -EOPNOTSUPP ; }
@@ -434,7 +437,7 @@ static int xfrm_xlate32_attr(void *dst, const struct nlattr *nla,int err;if (type >XFRMA_MAX ) { -BUILD_BUG_ON (XFRMA_MAX !=XFRMA_MTIMER_THRESH ); +BUILD_BUG_ON (XFRMA_MAX !=XFRMA_SA_DIR );NL_SET_ERR_MSG (extack,"Bad attribute" );return -EOPNOTSUPP ; }
net/xfrm/xfrm_device.c +6 -0
@@ -253,6 +253,12 @@ int xfrm_dev_state_add(struct net *net, struct xfrm_state *x,return -EINVAL ; } +if ((xuo->flags &XFRM_OFFLOAD_INBOUND && x->dir ==XFRM_SA_DIR_OUT ) || + (!(xuo->flags &XFRM_OFFLOAD_INBOUND ) && x->dir ==XFRM_SA_DIR_IN )) { +NL_SET_ERR_MSG (extack,"Mismatched SA and offload direction" ); +return -EINVAL ; + } + is_packet_offload = xuo->flags &XFRM_OFFLOAD_PACKET ;/* We don't yet support UDP encapsulation and TFC padding. */
net/xfrm/xfrm_replay.c +2 -1
@@ -778,7 +778,8 @@ int xfrm_init_replay(struct xfrm_state *x, struct netlink_ext_ack *extack) }if (x->props.flags &XFRM_STATE_ESN ) { -if (replay_esn->replay_window ==0 ) { +if (replay_esn->replay_window ==0 && + (!x->dir || x->dir ==XFRM_SA_DIR_IN )) {NL_SET_ERR_MSG (extack,"ESN replay window must be > 0" );return -EINVAL ; }
net/xfrm/xfrm_state.c +5 -0
@@ -1292,6 +1292,7 @@ xfrm_state_find(const xfrm_address_t *daddr, const xfrm_address_t *saddr,if (km_query (x, tmpl, pol) ==0 ) {spin_lock_bh (&net->xfrm.xfrm_state_lock); x->km.state =XFRM_STATE_ACQ ; + x->dir =XFRM_SA_DIR_OUT ;list_add (&x->km.all, &net->xfrm.state_all); XFRM_STATE_INSERT(bydst, &x->bydst, net->xfrm.state_bydst + h,
@@ -1744,6 +1745,7 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig, x->lastused = orig->lastused; x->new_mapping =0 ; x->new_mapping_sport =0 ; + x->dir = orig->dir;return x;
@@ -1857,6 +1859,9 @@ int xfrm_state_update(struct xfrm_state *x)if (!x1) goto out; +if (x1->dir != x->dir) + goto out; +if (xfrm_state_kern (x1)) { to_put = x1; err = -EEXIST ;
net/xfrm/xfrm_user.c +119 -6
216 lines not on this page · raw message
--
2.30.2
Re: [PATCH ipsec-next v12 1/4] xfrm: Add Direction to the SA in or out
net/xfrm/xfrm_state.c xfrm_state_find(const xfrm_address_t *daddr, const xfrm_address_t *saddr, · line 1295
Quoted 9 lines · Antony Antony
net/xfrm/xfrm_state.c +1
-0@@ -1292,6 +1292,7 @@ xfrm_state_find(const xfrm_address_t *daddr, const xfrm_address_t *saddr,if (km_query (x, tmpl, pol) ==0 ) {spin_lock_bh (&net->xfrm.xfrm_state_lock); x->km.state =XFRM_STATE_ACQ ; + x->dir =XFRM_SA_DIR_OUT ;
Would that make updates fail if userspace isn't setting SA_DIR afterwards?
Quoted 4 lines
net/xfrm/xfrm_user.c +0
-0
[...]
net/xfrm/xfrm_user.c static int verify_newsa_info(struct xfrm_usersa_info *p, · line 203
Quoted 5 lines
net/xfrm/xfrm_user.c +1
-0@@ -176,6 +200,7 @@ static int verify_newsa_info(struct xfrm_usersa_info *p, struct netlink_ext_ack *extack) {int err; +u8 sa_dir = attrs[XFRMA_SA_DIR ] ?nla_get_u8 (attrs[XFRMA_SA_DIR ]) :0 ;
nit: extra ' ' after '?', only one is needed.
Quoted 6 lines
net/xfrm/xfrm_user.c +2
-0@@ -358,6 +383,64 @@ static int verify_newsa_info(struct xfrm_usersa_info *p, err = -EINVAL ; goto out; } + +if (sa_dir ==XFRM_SA_DIR_OUT ) {
net/xfrm/xfrm_user.c static int verify_newsa_info(struct xfrm_usersa_info *p, · line 397
Quoted 10 lines
net/xfrm/xfrm_user.c +10
-0+NL_SET_ERR_MSG (extack, +"MTIMER_THRESH attribute should not be set on output SA" ); + err = -EINVAL ; + goto out; + } + } + +if (sa_dir ==XFRM_SA_DIR_OUT ) { +if (p->flags &XFRM_STATE_DECAP_DSCP ) { +NL_SET_ERR_MSG (extack,"Flag NDECAP_DSCP should not be set for output SA" );
That typo in the error string is still here (extra N in flag name).
Signature · 1 line
Sabrina
Re: [PATCH ipsec-next v12 1/4] xfrm: Add Direction to the SA in or out
Quoted 13 lines · Sabrina Dubroca via Devel
net/xfrm/xfrm_state.c xfrm_state_find(const xfrm_address_t *daddr, const xfrm_address_t *saddr, · line 1295
Quoted 9 lines · Antony Antony
net/xfrm/xfrm_state.c +1
-0@@ -1292,6 +1292,7 @@ xfrm_state_find(const xfrm_address_t *daddr, const xfrm_address_t *saddr,if (km_query (x, tmpl, pol) ==0 ) {spin_lock_bh (&net->xfrm.xfrm_state_lock); x->km.state =XFRM_STATE_ACQ ; + x->dir =XFRM_SA_DIR_OUT ;Would that make updates fail if userspace isn't setting
SA_DIRafterwards?
Not in typical, operation of IKE daemons. I haven't update acquire state. I don't think iproute2 supports that.
UPDSA is called for input where there is no acquire; acquire is for output. For output SA, added using NEWSA, will find the output acquire and delete it if p->seq matches. It won't update.
May be some other userspace update acquire? I extend the code to accomodate this possible case, in v13.
Quoted 5 lines
Quoted 4 lines
net/xfrm/xfrm_user.c +0
-0[...]
Quoted 7 lines
net/xfrm/xfrm_user.c static int verify_newsa_info(struct xfrm_usersa_info *p, · line 203
Quoted 5 lines
net/xfrm/xfrm_user.c +1
-0@@ -176,6 +200,7 @@ static int verify_newsa_info(struct xfrm_usersa_info *p, struct netlink_ext_ack *extack) {int err; +u8 sa_dir = attrs[XFRMA_SA_DIR ] ?nla_get_u8 (attrs[XFRMA_SA_DIR ]) :0 ;nit: extra ' ' after '?', only one is needed.
fixed.
Quoted 11 lines
Quoted 11 lines
net/xfrm/xfrm_user.c +6
-0@@ -358,6 +383,64 @@ static int verify_newsa_info(structxfrm_usersa_info *p, err = -EINVAL ; goto out; } + +if (sa_dir ==XFRM_SA_DIR_OUT ) { +NL_SET_ERR_MSG (extack, +"MTIMER_THRESH attribute should not be set on output SA" ); + err = -EINVAL ; + goto out;
Quoted 8 lines
net/xfrm/xfrm_user.c static int verify_newsa_info(struct xfrm_usersa_info *p, · line 397
Quoted 6 lines
net/xfrm/xfrm_user.c +6
-0+ } + } + +if (sa_dir ==XFRM_SA_DIR_OUT ) { +if (p->flags &XFRM_STATE_DECAP_DSCP ) { +NL_SET_ERR_MSG (extack,"Flag NDECAP_DSCP should not be set for output SA" );That typo in the error string is still here (extra N in flag name).
sorry.Fixed. I will send v13 soon.
-antony
PATCH v12 2/4 xfrm: Add dir validation to "out" data path lookup
In reply to Antony AntonyIntroduces validation for the x->dir attribute within the XFRM output data lookup path. If the configured direction does not match the expected direction, output, increment the XfrmOutStateDirError counter and drop the packet to ensure data integrity and correct flow handling.
grep -vw 0 /proc/net/xfrm_stat
XfrmOutPolError 1
XfrmOutStateDirError 1
---
v11 -> 12
- added add documentation xfrm_proc.rst
v10 -> 11
- rename error s/XfrmOutDirError/XfrmOutStateDirError/
- fix possible dereferencing of x reported by Smatch
--- Documentation/networking/xfrm_proc.rst | 3 +++ include/uapi/linux/snmp.h | 1 + net/xfrm/xfrm_policy.c | 6 ++++++ net/xfrm/xfrm_proc.c | 1 + 4 files changed, 11 insertions(+)
Documentation/networking/xfrm_proc.rst +3 -0
@@ -111,3 +111,6 @@ XfrmOutPolError: XfrmOutStateInvalid: State is invalid, perhaps expired + +XfrmOutStateDirError: + State direction output mismatched with lookup path direction
include/uapi/linux/snmp.h +1 -0
@@ -337,6 +337,7 @@ enumLINUX_MIB_XFRMFWDHDRERROR ,/* XfrmFwdHdrError*/ LINUX_MIB_XFRMOUTSTATEINVALID ,/* XfrmOutStateInvalid */ LINUX_MIB_XFRMACQUIREERROR ,/* XfrmAcquireError */ +LINUX_MIB_XFRMOUTSTATEDIRERROR ,/* XfrmOutStateDirError */ __LINUX_MIB_XFRMMAX };
net/xfrm/xfrm_policy.c +6 -0
@@ -2489,6 +2489,12 @@ xfrm_tmpl_resolve_one(struct xfrm_policy *policy, const struct flowi *fl, x =xfrm_state_find (remote, local, fl, tmpl, policy, &error, family, policy->if_id); +if (x && x->dir && x->dir !=XFRM_SA_DIR_OUT ) { +XFRM_INC_STATS (net,LINUX_MIB_XFRMOUTSTATEDIRERROR ); +xfrm_state_put (x); + error = -EINVAL ; + goto fail; + }if (x && x->km.state ==XFRM_STATE_VALID ) { xfrm[nx++] = x;
net/xfrm/xfrm_proc.c +1 -0
@@ -41,6 +41,7 @@ static const struct snmp_mib xfrm_mib_list[] = {SNMP_MIB_ITEM ("XfrmFwdHdrError" ,LINUX_MIB_XFRMFWDHDRERROR ),SNMP_MIB_ITEM ("XfrmOutStateInvalid" ,LINUX_MIB_XFRMOUTSTATEINVALID ),SNMP_MIB_ITEM ("XfrmAcquireError" ,LINUX_MIB_XFRMACQUIREERROR ), +SNMP_MIB_ITEM ("XfrmOutStateDirError" ,LINUX_MIB_XFRMOUTSTATEDIRERROR ), SNMP_MIB_SENTINEL };
--
2.30.2
PATCH v12 3/4 xfrm: Add dir validation to "in" data path lookup
In reply to Antony AntonyIntroduces validation for the x->dir attribute within the XFRM input data lookup path. If the configured direction does not match the expected direction, input, increment the XfrmInStateDirError counter and drop the packet to ensure data integrity and correct flow handling.
grep -vw 0 /proc/net/xfrm_stat
XfrmInStateDirError 1
---
v11 -> 12
- add documentation to xfrm_proc.rst
v10->v11
- rename error s/XfrmInDirError/XfrmInStateDirError/
--- Documentation/networking/xfrm_proc.rst | 3 +++ include/uapi/linux/snmp.h | 1 + net/ipv6/xfrm6_input.c | 7 +++++++ net/xfrm/xfrm_input.c | 11 +++++++++++ net/xfrm/xfrm_proc.c | 1 + 5 files changed, 23 insertions(+)
Documentation/networking/xfrm_proc.rst +3 -0
@@ -73,6 +73,9 @@ XfrmAcquireError: XfrmFwdHdrError: Forward routing of a packet is not allowed +XfrmInStateDirError: + State direction input mismatched with lookup path direction + Outbound errors ~~~~~~~~~~~~~~~ XfrmOutError:
include/uapi/linux/snmp.h +1 -0
@@ -338,6 +338,7 @@ enumLINUX_MIB_XFRMOUTSTATEINVALID ,/* XfrmOutStateInvalid */ LINUX_MIB_XFRMACQUIREERROR ,/* XfrmAcquireError */ LINUX_MIB_XFRMOUTSTATEDIRERROR ,/* XfrmOutStateDirError */ +LINUX_MIB_XFRMINSTATEDIRERROR ,/* XfrmInStateDirError */ __LINUX_MIB_XFRMMAX };
net/ipv6/xfrm6_input.c +7 -0
@@ -266,6 +266,13 @@ int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr,if (!x)continue ; +if (unlikely (x->dir && x->dir !=XFRM_SA_DIR_IN )) { +XFRM_INC_STATS (net,LINUX_MIB_XFRMINSTATEDIRERROR ); +xfrm_state_put (x); + x =NULL ; +continue ; + } +spin_lock (&x->lock); if ((!i || (x->props.flags & XFRM_STATE_WILDRECV)) &&
net/xfrm/xfrm_input.c +11 -0
@@ -466,6 +466,11 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)if (encap_type <0 || (xo && xo->flags &XFRM_GRO )) { x =xfrm_input_state (skb); +if (unlikely (x->dir && x->dir !=XFRM_SA_DIR_IN )) { +XFRM_INC_STATS (net,LINUX_MIB_XFRMINSTATEDIRERROR ); + goto drop; + } +if (unlikely (x->km.state !=XFRM_STATE_VALID )) {if (x->km.state ==XFRM_STATE_ACQ )XFRM_INC_STATS (net,LINUX_MIB_XFRMACQUIREERROR );
@@ -571,6 +576,12 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) goto drop; } +if (unlikely (x->dir && x->dir !=XFRM_SA_DIR_IN )) { +XFRM_INC_STATS (net,LINUX_MIB_XFRMINSTATEDIRERROR ); +xfrm_state_put (x); + goto drop; + } + skb->mark =xfrm_smark_get (skb->mark, x); sp->xvec[sp->len++] = x;
net/xfrm/xfrm_proc.c +1 -0
@@ -42,6 +42,7 @@ static const struct snmp_mib xfrm_mib_list[] = {SNMP_MIB_ITEM ("XfrmOutStateInvalid" ,LINUX_MIB_XFRMOUTSTATEINVALID ),SNMP_MIB_ITEM ("XfrmAcquireError" ,LINUX_MIB_XFRMACQUIREERROR ),SNMP_MIB_ITEM ("XfrmOutStateDirError" ,LINUX_MIB_XFRMOUTSTATEDIRERROR ), +SNMP_MIB_ITEM ("XfrmInStateDirError" ,LINUX_MIB_XFRMINSTATEDIRERROR ), SNMP_MIB_SENTINEL };
--
2.30.2
Re: [PATCH ipsec-next v12 3/4] xfrm: Add dir validation to "in" data path lookup
Le 23/04/2024 à 14:50, Antony Antony a écrit :
Quoted 28 lines
Introduces validation for the
x->dirattribute within the XFRM input data lookup path. If the configured direction does not match the expected direction, input, increment the XfrmInStateDirError counter and drop the packet to ensure data integrity and correct flow handling.grep -vw 0
/proc/net/xfrm_stat
XfrmInStateDirError 1Signed-off-by Antony Antony <[email protected]>---
v11 -> 12
- add documentation toxfrm_proc.rst
v10->v11
- rename error s/XfrmInDirError/XfrmInStateDirError/--- Documentation/networking/xfrm_proc.rst | 3 +++ include/uapi/linux/snmp.h | 1 + net/ipv6/xfrm6_input.c | 7 +++++++ net/xfrm/xfrm_input.c | 11 +++++++++++ net/xfrm/xfrm_proc.c | 1 + 5 files changed, 23 insertions(+)Documentation/networking/xfrm_proc.rst +0
-0
Documentation/networking/xfrm_proc.rst XfrmAcquireError: · line 77
Quoted 5 lines
Documentation/networking/xfrm_proc.rst +2
-0@@ -73,6 +73,9 @@ XfrmAcquireError: XfrmFwdHdrError: Forward routing of a packet is not allowed +XfrmInStateDirError: + State direction input mismatched with lookup path direction
It's a bit confusing because when this error occurs, the state direction is not 'input'.
This statistic is under 'Inbound errors', so may something like this is enough:
'State direction is output.'
Regards,
Nicolas
Re: [PATCH ipsec-next v12 3/4] xfrm: Add dir validation to "in" data path lookup
Quoted 32 lines · Nicolas Dichtel
Le 23/04/2024 à 14:50, Antony Antony a écrit :
Quoted 31 lines
Introduces validation for the
x->dirattribute within the XFRM input data lookup path. If the configured direction does not match the expected direction, input, increment the XfrmInStateDirError counter and drop the packet to ensure data integrity and correct flow handling.grep -vw 0
/proc/net/xfrm_stat
XfrmInStateDirError 1Signed-off-by Antony Antony <[email protected]>---
v11 -> 12
- add documentation toxfrm_proc.rst
v10->v11
- rename error s/XfrmInDirError/XfrmInStateDirError/--- Documentation/networking/xfrm_proc.rst | 3 +++ include/uapi/linux/snmp.h | 1 + net/ipv6/xfrm6_input.c | 7 +++++++ net/xfrm/xfrm_input.c | 11 +++++++++++ net/xfrm/xfrm_proc.c | 1 + 5 files changed, 23 insertions(+)Documentation/networking/xfrm_proc.rst +0
-0@@ -73,6 +73,9 @@ XfrmAcquireError: XfrmFwdHdrError: Forward routing of a packet is not allowed
Quoted 4 lines
Documentation/networking/xfrm_proc.rst XfrmAcquireError: · line 77
Quoted 2 lines
Documentation/networking/xfrm_proc.rst +2
-0+XfrmInStateDirError: + State direction input mismatched with lookup path directionIt's a bit confusing because when this error occurs, the state direction is not 'input'.
Agree.
Quoted 2 lines
This statistic is under 'Inbound errors', so may something like this is enough:
'State direction is output.'
Maybe something like:
State direction mismatch (lookup found an output state on the input path, expected input or no direction)
It's a bit verbose, but I think those extra details would help users understand what went wrong.
Signature · 1 line
Sabrina
Re: [PATCH ipsec-next v12 3/4] xfrm: Add dir validation to "in" data path lookup
Le 24/04/2024 à 10:40, Sabrina Dubroca a écrit :
[snip]
Quoted 18 lines
Quoted 8 lines
Quoted 8 lines
Documentation/networking/xfrm_proc.rst +0
-0@@ -73,6 +73,9 @@ XfrmAcquireError: XfrmFwdHdrError: Forward routing of a packet is not allowedQuoted 4 lines
Documentation/networking/xfrm_proc.rst XfrmAcquireError: · line 77
Quoted 2 lines
Documentation/networking/xfrm_proc.rst +2
-0+XfrmInStateDirError: + State direction input mismatched with lookup path directionIt's a bit confusing because when this error occurs, the state direction is not 'input'.
Agree.
Quoted 2 lines
This statistic is under 'Inbound errors', so may something like this is enough:
'State direction is output.'
Quoted 7 lines
Maybe something like:
State direction mismatch (lookup found an output state on the input path, expected input or no direction)
It's a bit verbose, but I think those extra details would help users understand what went wrong.
Sure, it's ok for me.
Re: [PATCH ipsec-next v12 3/4] xfrm: Add dir validation to "in" data path lookup
Quoted 23 lines · Nicolas Dichtel via Devel
Le 24/04/2024 à 10:40, Sabrina Dubroca a écrit :
[snip]Quoted 21 lines
Quoted 8 lines
Quoted 8 lines
Documentation/networking/xfrm_proc.rst +0
-0@@ -73,6 +73,9 @@ XfrmAcquireError: XfrmFwdHdrError: Forward routing of a packet is not allowedQuoted 4 lines
Documentation/networking/xfrm_proc.rst XfrmAcquireError: · line 77
Quoted 2 lines
Documentation/networking/xfrm_proc.rst +2
-0+XfrmInStateDirError: + State direction input mismatched with lookup path directionIt's a bit confusing because when this error occurs, the state direction is not 'input'.
Agree.
Quoted 2 lines
This statistic is under 'Inbound errors', so may something like this is enough:
'State direction is output.'Maybe something like:
State direction mismatch (lookup found an output state on the input path, expected input or no direction)
This is better. Fixed in v13.
Quoted 5 lines
Quoted 4 lines
It's a bit verbose, but I think those extra details would help users understand what went wrong.
Sure, it's ok for me.
thanks,
-antony
PATCH v12 4/4 xfrm: Restrict SA direction attribute to specific netlink message types
In reply to Antony AntonyReject the usage of the SA_DIR attribute in xfrm netlink messages when it's not applicable. This ensures that SA_DIR is only accepted for certain message types (NEWSA, UPDSA, and ALLOCSPI)
---
v11 -> 12
- fix spd look up. This broke xfrm_policy.sh tests
--- net/xfrm/xfrm_user.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
net/xfrm/xfrm_user.c +24 -0
@@ -3200,6 +3200,24 @@ static const struct xfrm_link { [XFRM_MSG_GETDEFAULT - XFRM_MSG_BASE] = { .doit = xfrm_get_default }, }; +static int xfrm_reject_unused (int type,struct nlattr **attrs, +struct netlink_ext_ack *extack) +{ +if (attrs[XFRMA_SA_DIR ]) { +switch (type) { +case XFRM_MSG_NEWSA : +case XFRM_MSG_UPDSA : +case XFRM_MSG_ALLOCSPI : +break ; +default : +NL_SET_ERR_MSG (extack,"Invalid attribute SA_DIR" ); +return -EINVAL ; + } + } + +return 0 ; +} +static int xfrm_user_rcv_msg (struct sk_buff *skb,struct nlmsghdr *nlh,struct netlink_ext_ack *extack) {
@@ -3259,6 +3277,12 @@ static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh,if (err <0 ) goto err; +if (!link->nla_pol || link->nla_pol == xfrma_policy) { + err =xfrm_reject_unused ((type +XFRM_MSG_BASE ), attrs, extack); +if (err <0 ) + goto err; + } +if (link->doit ==NULL ) { err = -EINVAL ; goto err;
--
2.30.2
Steffen Klassert
maintainerRe: [PATCH ipsec-next v12 4/4] xfrm: Restrict SA direction attribute to specific netlink message types
Quoted 17 lines · Antony Antony
Reject the usage of the
SA_DIRattribute in xfrm netlink messages when it's not applicable. This ensures thatSA_DIRis only accepted for certain message types (NEWSA, UPDSA, and ALLOCSPI)Signed-off-by Antony Antony <[email protected]>---
v11 -> 12
- fix spd look up. This brokexfrm_policy.shtests--- net/xfrm/xfrm_user.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)net/xfrm/xfrm_user.c +0
-0
net/xfrm/xfrm_user.c static const struct xfrm_link { · line 3204
Quoted 5 lines
net/xfrm/xfrm_user.c +2
-0@@ -3200,6 +3200,24 @@ static const struct xfrm_link { [XFRM_MSG_GETDEFAULT - XFRM_MSG_BASE] = { .doit = xfrm_get_default }, }; +static int xfrm_reject_unused (int type,struct nlattr **attrs, +struct netlink_ext_ack *extack)
Maybe call that function xfrm_reject_unused_attr to make it clear what is unused here?
Re: [PATCH ipsec-next v12 4/4] xfrm: Restrict SA direction attribute to specific netlink message types
Quoted 21 lines · Steffen Klassert via Devel
Quoted 20 lines · Antony Antony
Reject the usage of the
SA_DIRattribute in xfrm netlink messages when it's not applicable. This ensures thatSA_DIRis only accepted for certain message types (NEWSA, UPDSA, and ALLOCSPI)Signed-off-by Antony Antony <[email protected]>---
v11 -> 12
- fix spd look up. This brokexfrm_policy.shtests--- net/xfrm/xfrm_user.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)net/xfrm/xfrm_user.c +0
-0@@ -3200,6 +3200,24 @@ static const struct xfrm_link { [XFRM_MSG_GETDEFAULT - XFRM_MSG_BASE] = { .doit = xfrm_get_default }, };
Quoted 5 lines
net/xfrm/xfrm_user.c static const struct xfrm_link { · line 3204
Quoted 2 lines
net/xfrm/xfrm_user.c +2
-0+static int xfrm_reject_unused (int type,struct nlattr **attrs, +struct netlink_ext_ack *extack)Maybe call that function
xfrm_reject_unused_attrto make it clear what is unused here?
good idea. Fixed in v13