xfrm: start adding netlink extack support
Subsystems (3)
cover xfrm: start adding netlink extack support
XFRM states and policies are complex objects, and there are many reasons why the kernel can reject userspace's request to create one. This series makes it a bit clearer by providing extended ack messages for policy creation.
A few other operations that reuse the same helper functions are also getting partial extack support in this series. More patches will follow to complete extack support, in particular for state creation.
Note: The policy->share attribute seems to be entirely ignored in the kernel outside of checking its value in verify_newpolicy_info(). There are some (very) old comments in copy_from_user_policy and copy_to_user_policy suggesting that it should at least be copied to/from userspace. I don't know what it was intended for.
Sabrina Dubroca (6):
xfrm: propagate extack to all netlink doit handlers
xfrm: add extack support to verify_newpolicy_info
xfrm: add extack to verify_policy_dir
xfrm: add extack to verify_policy_type
xfrm: add extack to validate_tmpl
xfrm: add extack to verify_sec_ctx_len
net/xfrm/xfrm_user.c | 163 +++++++++++++++++++++++++++---------------- 1 file changed, 103 insertions(+), 60 deletions(-)
Signature · 1 line
2.37.2
PATCH 1/6 xfrm: propagate extack to all netlink doit handlers
xfrm_user_rcv_msg() already handles extack, we just need to pass it down.
--- net/xfrm/xfrm_user.c | 56 +++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 22 deletions(-)
net/xfrm/xfrm_user.c +34 -22
@@ -678,7 +678,7 @@ static struct xfrm_state *xfrm_state_construct(struct net *net, }static int xfrm_add_sa (struct sk_buff *skb,struct nlmsghdr *nlh, -struct nlattr **attrs) +struct nlattr **attrs,struct netlink_ext_ack *extack) {struct net *net =sock_net (skb->sk);struct xfrm_usersa_info *p =nlmsg_data (nlh);
@@ -757,7 +757,7 @@ static struct xfrm_state *xfrm_user_state_lookup(struct net *net, }static int xfrm_del_sa (struct sk_buff *skb,struct nlmsghdr *nlh, -struct nlattr **attrs) +struct nlattr **attrs,struct netlink_ext_ack *extack) {struct net *net =sock_net (skb->sk);struct xfrm_state *x;
@@ -1254,7 +1254,8 @@ static int build_spdinfo(struct sk_buff *skb, struct net *net, }static int xfrm_set_spdinfo (struct sk_buff *skb,struct nlmsghdr *nlh, -struct nlattr **attrs) +struct nlattr **attrs, +struct netlink_ext_ack *extack) {struct net *net =sock_net (skb->sk);struct xfrmu_spdhthresh *thresh4 =NULL ;
@@ -1299,7 +1300,8 @@ static int xfrm_set_spdinfo(struct sk_buff *skb, struct nlmsghdr *nlh, }static int xfrm_get_spdinfo (struct sk_buff *skb,struct nlmsghdr *nlh, -struct nlattr **attrs) +struct nlattr **attrs, +struct netlink_ext_ack *extack) {struct net *net =sock_net (skb->sk);struct sk_buff *r_skb;
@@ -1358,7 +1360,8 @@ static int build_sadinfo(struct sk_buff *skb, struct net *net, }static int xfrm_get_sadinfo (struct sk_buff *skb,struct nlmsghdr *nlh, -struct nlattr **attrs) +struct nlattr **attrs, +struct netlink_ext_ack *extack) {struct net *net =sock_net (skb->sk);struct sk_buff *r_skb;
@@ -1378,7 +1381,7 @@ static int xfrm_get_sadinfo(struct sk_buff *skb, struct nlmsghdr *nlh, }static int xfrm_get_sa (struct sk_buff *skb,struct nlmsghdr *nlh, -struct nlattr **attrs) +struct nlattr **attrs,struct netlink_ext_ack *extack) {struct net *net =sock_net (skb->sk);struct xfrm_usersa_id *p =nlmsg_data (nlh);
@@ -1402,7 +1405,8 @@ static int xfrm_get_sa(struct sk_buff *skb, struct nlmsghdr *nlh, }static int xfrm_alloc_userspi (struct sk_buff *skb,struct nlmsghdr *nlh, -struct nlattr **attrs) +struct nlattr **attrs, +struct netlink_ext_ack *extack) {struct net *net =sock_net (skb->sk);struct xfrm_state *x;
@@ -1754,7 +1758,8 @@ static struct xfrm_policy *xfrm_policy_construct(struct net *net, struct xfrm_us }static int xfrm_add_policy (struct sk_buff *skb,struct nlmsghdr *nlh, -struct nlattr **attrs) +struct nlattr **attrs, +struct netlink_ext_ack *extack) {struct net *net =sock_net (skb->sk);struct xfrm_userpolicy_info *p =nlmsg_data (nlh);
@@ -2015,7 +2020,7 @@ static bool xfrm_userpolicy_is_valid(__u8 policy) }static int xfrm_set_default (struct sk_buff *skb,struct nlmsghdr *nlh, -struct nlattr **attrs) +struct nlattr **attrs,struct netlink_ext_ack *extack) {struct net *net =sock_net (skb->sk);struct xfrm_userpolicy_default *up =nlmsg_data (nlh);
@@ -2036,7 +2041,7 @@ static int xfrm_set_default(struct sk_buff *skb, struct nlmsghdr *nlh, }static int xfrm_get_default (struct sk_buff *skb,struct nlmsghdr *nlh, -struct nlattr **attrs) +struct nlattr **attrs,struct netlink_ext_ack *extack) {struct sk_buff *r_skb;struct nlmsghdr *r_nlh;
@@ -2066,7 +2071,8 @@ static int xfrm_get_default(struct sk_buff *skb, struct nlmsghdr *nlh, }static int xfrm_get_policy (struct sk_buff *skb,struct nlmsghdr *nlh, -struct nlattr **attrs) +struct nlattr **attrs, +struct netlink_ext_ack *extack) {struct net *net =sock_net (skb->sk);struct xfrm_policy *xp;
@@ -2149,7 +2155,8 @@ static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh, }static int xfrm_flush_sa (struct sk_buff *skb,struct nlmsghdr *nlh, -struct nlattr **attrs) +struct nlattr **attrs, +struct netlink_ext_ack *extack) {struct net *net =sock_net (skb->sk);struct km_event c;
@@ -2249,7 +2256,7 @@ static int build_aevent(struct sk_buff *skb, struct xfrm_state *x, const struct }static int xfrm_get_ae (struct sk_buff *skb,struct nlmsghdr *nlh, -struct nlattr **attrs) +struct nlattr **attrs,struct netlink_ext_ack *extack) {struct net *net =sock_net (skb->sk);struct xfrm_state *x;
@@ -2293,7 +2300,7 @@ static int xfrm_get_ae(struct sk_buff *skb, struct nlmsghdr *nlh, }static int xfrm_new_ae (struct sk_buff *skb,struct nlmsghdr *nlh, -struct nlattr **attrs) +struct nlattr **attrs,struct netlink_ext_ack *extack) {struct net *net =sock_net (skb->sk);struct xfrm_state *x;
@@ -2344,7 +2351,8 @@ static int xfrm_new_ae(struct sk_buff *skb, struct nlmsghdr *nlh, }static int xfrm_flush_policy (struct sk_buff *skb,struct nlmsghdr *nlh, -struct nlattr **attrs) +struct nlattr **attrs, +struct netlink_ext_ack *extack) {struct net *net =sock_net (skb->sk);struct km_event c;
@@ -2372,7 +2380,8 @@ static int xfrm_flush_policy(struct sk_buff *skb, struct nlmsghdr *nlh, }static int xfrm_add_pol_expire (struct sk_buff *skb,struct nlmsghdr *nlh, -struct nlattr **attrs) +struct nlattr **attrs, +struct netlink_ext_ack *extack) {struct net *net =sock_net (skb->sk);struct xfrm_policy *xp;
@@ -2438,7 +2447,8 @@ static int xfrm_add_pol_expire(struct sk_buff *skb, struct nlmsghdr *nlh, }static int xfrm_add_sa_expire (struct sk_buff *skb,struct nlmsghdr *nlh, -struct nlattr **attrs) +struct nlattr **attrs, +struct netlink_ext_ack *extack) {struct net *net =sock_net (skb->sk);struct xfrm_state *x;
@@ -2472,7 +2482,8 @@ static int xfrm_add_sa_expire(struct sk_buff *skb, struct nlmsghdr *nlh, }static int xfrm_add_acquire (struct sk_buff *skb,struct nlmsghdr *nlh, -struct nlattr **attrs) +struct nlattr **attrs, +struct netlink_ext_ack *extack) {struct net *net =sock_net (skb->sk);struct xfrm_policy *xp;
@@ -2577,7 +2588,7 @@ static int copy_from_user_migrate(struct xfrm_migrate *ma, }static int xfrm_do_migrate (struct sk_buff *skb,struct nlmsghdr *nlh, -struct nlattr **attrs) +struct nlattr **attrs,struct netlink_ext_ack *extack) {struct xfrm_userpolicy_id *pi =nlmsg_data (nlh);struct xfrm_migrate m[XFRM_MAX_DEPTH ];
@@ -2623,7 +2634,7 @@ static int xfrm_do_migrate(struct sk_buff *skb, struct nlmsghdr *nlh, }#else static int xfrm_do_migrate (struct sk_buff *skb,struct nlmsghdr *nlh, -struct nlattr **attrs) +struct nlattr **attrs,struct netlink_ext_ack *extack) {return -ENOPROTOOPT ; }
@@ -2819,7 +2830,8 @@ static const struct nla_policy xfrma_spd_policy[XFRMA_SPD_MAX+1] = { }; static const struct xfrm_link { - int (*doit)(struct sk_buff *, struct nlmsghdr *, struct nlattr **); + int (*doit)(struct sk_buff *, struct nlmsghdr *, struct nlattr **, + struct netlink_ext_ack *); int (*start)(struct netlink_callback *); int (*dump)(struct sk_buff *, struct netlink_callback *); int (*done)(struct netlink_callback *);
@@ -2921,7 +2933,7 @@ static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, goto err; } - err = link->doit (skb, nlh, attrs); + err = link->doit (skb, nlh, attrs, extack);/* We need to free skb allocated in xfrm_alloc_compat() before * returning from this function, because consume_skb() won't take
Signature · 1 line
2.37.2
PATCH 2/6 xfrm: add extack support to verify_newpolicy_info
In reply to Sabrina Dubroca--- net/xfrm/xfrm_user.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-)
net/xfrm/xfrm_user.c +18 -7
@@ -1512,7 +1512,8 @@ static int verify_policy_type(u8 type)return 0 ; } -static int verify_newpolicy_info (struct xfrm_userpolicy_info *p) +static int verify_newpolicy_info (struct xfrm_userpolicy_info *p, +struct netlink_ext_ack *extack) {int ret;
@@ -1524,6 +1525,7 @@ static int verify_newpolicy_info(struct xfrm_userpolicy_info *p)break ;default : +NL_SET_ERR_MSG (extack,"Invalid policy share" );return -EINVAL ; }
@@ -1533,35 +1535,44 @@ static int verify_newpolicy_info(struct xfrm_userpolicy_info *p)break ;default : +NL_SET_ERR_MSG (extack,"Invalid policy action" );return -EINVAL ; }switch (p->sel.family) {case AF_INET : -if (p->sel.prefixlen_d >32 || p->sel.prefixlen_s >32 ) +if (p->sel.prefixlen_d >32 || p->sel.prefixlen_s >32 ) { +NL_SET_ERR_MSG (extack,"Invalid prefix length in selector (must be <= 32 for IPv4)" );return -EINVAL ; + }break ;case AF_INET6 :#if IS_ENABLED (CONFIG_IPV6 ) -if (p->sel.prefixlen_d >128 || p->sel.prefixlen_s >128 ) +if (p->sel.prefixlen_d >128 || p->sel.prefixlen_s >128 ) { +NL_SET_ERR_MSG (extack,"Invalid prefix length in selector (must be <= 128 for IPv6)" );return -EINVAL ; + }break ;#else +NL_SET_ERR_MSG (extack,"IPv6 support disabled" );return -EAFNOSUPPORT ;#endif default : +NL_SET_ERR_MSG (extack,"Invalid selector family" );return -EINVAL ; } ret =verify_policy_dir (p->dir);if (ret)return ret; -if (p->index && (xfrm_policy_id2dir (p->index) != p->dir)) +if (p->index && (xfrm_policy_id2dir (p->index) != p->dir)) { +NL_SET_ERR_MSG (extack,"Policy index doesn't match direction" );return -EINVAL ; + }return 0 ; }
@@ -1768,7 +1779,7 @@ static int xfrm_add_policy(struct sk_buff *skb, struct nlmsghdr *nlh,int err;int excl; - err =verify_newpolicy_info (p); + err =verify_newpolicy_info (p, extack);if (err)return err; err =verify_sec_ctx_len (attrs);
@@ -2501,7 +2512,7 @@ static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh,xfrm_mark_get (attrs, &mark); - err =verify_newpolicy_info (&ua->policy); + err =verify_newpolicy_info (&ua->policy, extack);if (err) goto free_state; err =verify_sec_ctx_len (attrs);
@@ -3284,7 +3295,7 @@ static struct xfrm_policy *xfrm_compile_policy(struct sock *sk, int opt, *dir = -EINVAL ;if (len <sizeof (*p) || -verify_newpolicy_info (p)) +verify_newpolicy_info (p,NULL ))return NULL ; nr = ((len -sizeof (*p)) /sizeof (*ut));
Signature · 1 line
2.37.2
PATCH 3/6 xfrm: add extack to verify_policy_dir
In reply to Sabrina Dubroca--- net/xfrm/xfrm_user.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
net/xfrm/xfrm_user.c +5 -4
@@ -1481,7 +1481,7 @@ static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh,return err; } -static int verify_policy_dir (u8 dir) +static int verify_policy_dir (u8 dir,struct netlink_ext_ack *extack) {switch (dir) {case XFRM_POLICY_IN :
@@ -1490,6 +1490,7 @@ static int verify_policy_dir(u8 dir)break ;default : +NL_SET_ERR_MSG (extack,"Invalid policy direction" );return -EINVAL ; }
@@ -1566,7 +1567,7 @@ static int verify_newpolicy_info(struct xfrm_userpolicy_info *p,return -EINVAL ; } - ret =verify_policy_dir (p->dir); + ret =verify_policy_dir (p->dir, extack);if (ret)return ret;if (p->index && (xfrm_policy_id2dir (p->index) != p->dir)) {
@@ -2102,7 +2103,7 @@ static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh,if (err)return err; - err =verify_policy_dir (p->dir); + err =verify_policy_dir (p->dir, extack);if (err)return err;
@@ -2407,7 +2408,7 @@ static int xfrm_add_pol_expire(struct sk_buff *skb, struct nlmsghdr *nlh,if (err)return err; - err =verify_policy_dir (p->dir); + err =verify_policy_dir (p->dir, extack);if (err)return err;
Signature · 1 line
2.37.2
PATCH 4/6 xfrm: add extack to verify_policy_type
In reply to Sabrina Dubroca--- net/xfrm/xfrm_user.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-)
net/xfrm/xfrm_user.c +17 -11
@@ -1497,7 +1497,7 @@ static int verify_policy_dir(u8 dir, struct netlink_ext_ack *extack)return 0 ; } -static int verify_policy_type (u8 type) +static int verify_policy_type (u8 type,struct netlink_ext_ack *extack) {switch (type) {case XFRM_POLICY_TYPE_MAIN :
@@ -1507,6 +1507,7 @@ static int verify_policy_type(u8 type)break ;default : +NL_SET_ERR_MSG (extack,"Invalid policy type" );return -EINVAL ; }
@@ -1688,7 +1689,8 @@ static int copy_from_user_tmpl(struct xfrm_policy *pol, struct nlattr **attrs)return 0 ; } -static int copy_from_user_policy_type (u8 *tp,struct nlattr **attrs) +static int copy_from_user_policy_type (u8 *tp,struct nlattr **attrs, +struct netlink_ext_ack *extack) {struct nlattr *rt = attrs[XFRMA_POLICY_TYPE ];struct xfrm_userpolicy_type *upt;
@@ -1700,7 +1702,7 @@ static int copy_from_user_policy_type(u8 *tp, struct nlattr **attrs) type = upt->type; } - err =verify_policy_type (type); + err =verify_policy_type (type, extack);if (err)return err;
@@ -1735,7 +1737,11 @@ static void copy_to_user_policy(struct xfrm_policy *xp, struct xfrm_userpolicy_i p->share =XFRM_SHARE_ANY ;/* XXX xp->share */ } -static struct xfrm_policy *xfrm_policy_construct (struct net *net,struct xfrm_userpolicy_info *p,struct nlattr **attrs,int *errp) +static struct xfrm_policy *xfrm_policy_construct (struct net *net, +struct xfrm_userpolicy_info *p, +struct nlattr **attrs, +int *errp, +struct netlink_ext_ack *extack) {struct xfrm_policy *xp =xfrm_policy_alloc (net,GFP_KERNEL );int err;
@@ -1747,7 +1753,7 @@ static struct xfrm_policy *xfrm_policy_construct(struct net *net, struct xfrm_uscopy_from_user_policy (xp, p); - err =copy_from_user_policy_type (&xp->type, attrs); + err =copy_from_user_policy_type (&xp->type, attrs, extack);if (err) goto error;
@@ -1787,7 +1793,7 @@ static int xfrm_add_policy(struct sk_buff *skb, struct nlmsghdr *nlh,if (err)return err; - xp =xfrm_policy_construct (net, p, attrs, &err); + xp =xfrm_policy_construct (net, p, attrs, &err, extack);if (!xp)return err;
@@ -2099,7 +2105,7 @@ static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh, p =nlmsg_data (nlh); delete = nlh->nlmsg_type ==XFRM_MSG_DELPOLICY ; - err =copy_from_user_policy_type (&type, attrs); + err =copy_from_user_policy_type (&type, attrs, extack);if (err)return err;
@@ -2371,7 +2377,7 @@ static int xfrm_flush_policy(struct sk_buff *skb, struct nlmsghdr *nlh,u8 type =XFRM_POLICY_TYPE_MAIN ;int err; - err =copy_from_user_policy_type (&type, attrs); + err =copy_from_user_policy_type (&type, attrs, extack);if (err)return err;
@@ -2404,7 +2410,7 @@ static int xfrm_add_pol_expire(struct sk_buff *skb, struct nlmsghdr *nlh,struct xfrm_mark m;u32 if_id =0 ; - err =copy_from_user_policy_type (&type, attrs); + err =copy_from_user_policy_type (&type, attrs, extack);if (err)return err;
@@ -2521,7 +2527,7 @@ static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh, goto free_state;/* build an XP */ - xp =xfrm_policy_construct (net, &ua->policy, attrs, &err); + xp =xfrm_policy_construct (net, &ua->policy, attrs, &err, extack);if (!xp) goto free_state;
@@ -2617,7 +2623,7 @@ static int xfrm_do_migrate(struct sk_buff *skb, struct nlmsghdr *nlh, kmp = attrs[XFRMA_KMADDRESS ] ? &km :NULL ; - err =copy_from_user_policy_type (&type, attrs); + err =copy_from_user_policy_type (&type, attrs, extack);if (err)return err;
Signature · 1 line
2.37.2
PATCH 5/6 xfrm: add extack to validate_tmpl
In reply to Sabrina Dubroca--- net/xfrm/xfrm_user.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-)
net/xfrm/xfrm_user.c +20 -9
@@ -1616,13 +1616,16 @@ static void copy_templates(struct xfrm_policy *xp, struct xfrm_user_tmpl *ut, } } -static int validate_tmpl (int nr,struct xfrm_user_tmpl *ut,u16 family) +static int validate_tmpl (int nr,struct xfrm_user_tmpl *ut,u16 family, +struct netlink_ext_ack *extack) {u16 prev_family;int i; -if (nr >XFRM_MAX_DEPTH ) +if (nr >XFRM_MAX_DEPTH ) { + NL_SET_ERR_MSG(extack, "Template count must be <= XFRM_MAX_DEPTH (" __stringify(XFRM_MAX_DEPTH) ")");return -EINVAL ; + } prev_family = family;
@@ -1642,12 +1645,16 @@ static int validate_tmpl(int nr, struct xfrm_user_tmpl *ut, u16 family)case XFRM_MODE_BEET :break ;default : -if (ut[i].family != prev_family) +if (ut[i].family != prev_family) { +NL_SET_ERR_MSG (extack,"Mode in template doesn't support a family change" );return -EINVAL ; + }break ; } -if (ut[i].mode >=XFRM_MODE_MAX ) +if (ut[i].mode >=XFRM_MODE_MAX ) { + NL_SET_ERR_MSG(extack, "Mode in template must be < XFRM_MODE_MAX (" __stringify(XFRM_MODE_MAX) ")");return -EINVAL ; + } prev_family = ut[i].family;
@@ -1659,17 +1666,21 @@ static int validate_tmpl(int nr, struct xfrm_user_tmpl *ut, u16 family)break ;#endif default : +NL_SET_ERR_MSG (extack,"Invalid family in template" );return -EINVAL ; } -if (!xfrm_id_proto_valid (ut[i].id.proto)) +if (!xfrm_id_proto_valid (ut[i].id.proto)) { +NL_SET_ERR_MSG (extack,"Invalid XFRM protocol in template" );return -EINVAL ; + } }return 0 ; } -static int copy_from_user_tmpl (struct xfrm_policy *pol,struct nlattr **attrs) +static int copy_from_user_tmpl (struct xfrm_policy *pol,struct nlattr **attrs, +struct netlink_ext_ack *extack) {struct nlattr *rt = attrs[XFRMA_TMPL ];
@@ -1680,7 +1691,7 @@ static int copy_from_user_tmpl(struct xfrm_policy *pol, struct nlattr **attrs)int nr =nla_len (rt) /sizeof (*utmpl);int err; - err =validate_tmpl (nr, utmpl, pol->family); + err =validate_tmpl (nr, utmpl, pol->family, extack);if (err)return err;
@@ -1757,7 +1768,7 @@ static struct xfrm_policy *xfrm_policy_construct(struct net *net,if (err) goto error; -if (!(err =copy_from_user_tmpl (xp, attrs))) +if (!(err =copy_from_user_tmpl (xp, attrs, extack))) err =copy_from_user_sec_ctx (xp, attrs);if (err) goto error;
@@ -3306,7 +3317,7 @@ static struct xfrm_policy *xfrm_compile_policy(struct sock *sk, int opt,return NULL ; nr = ((len -sizeof (*p)) /sizeof (*ut)); -if (validate_tmpl (nr, ut, p->sel.family)) +if (validate_tmpl (nr, ut, p->sel.family,NULL ))return NULL ;if (p->dir >XFRM_POLICY_OUT )
Signature · 1 line
2.37.2
PATCH 6/6 xfrm: add extack to verify_sec_ctx_len
In reply to Sabrina Dubroca--- net/xfrm/xfrm_user.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
net/xfrm/xfrm_user.c +9 -7
@@ -102,7 +102,7 @@ static void verify_one_addr(struct nlattr **attrs, enum xfrm_attr_type_t type, *addrp =nla_data (rt); } -static inline int verify_sec_ctx_len (struct nlattr **attrs) +static inline int verify_sec_ctx_len (struct nlattr **attrs,struct netlink_ext_ack *extack) {struct nlattr *rt = attrs[XFRMA_SEC_CTX ];struct xfrm_user_sec_ctx *uctx;
@@ -112,8 +112,10 @@ static inline int verify_sec_ctx_len(struct nlattr **attrs) uctx =nla_data (rt);if (uctx->len >nla_len (rt) || - uctx->len != (sizeof (struct xfrm_user_sec_ctx ) + uctx->ctx_len)) + uctx->len != (sizeof (struct xfrm_user_sec_ctx ) + uctx->ctx_len)) { +NL_SET_ERR_MSG (extack,"Invalid security context length" );return -EINVAL ; + }return 0 ; }
@@ -264,7 +266,7 @@ static int verify_newsa_info(struct xfrm_usersa_info *p, goto out;if ((err =verify_one_alg (attrs,XFRMA_ALG_COMP ))) goto out; -if ((err =verify_sec_ctx_len (attrs))) +if ((err =verify_sec_ctx_len (attrs,NULL ))) goto out;if ((err =verify_replay (p, attrs))) goto out;
@@ -1800,7 +1802,7 @@ static int xfrm_add_policy(struct sk_buff *skb, struct nlmsghdr *nlh, err =verify_newpolicy_info (p, extack);if (err)return err; - err =verify_sec_ctx_len (attrs); + err =verify_sec_ctx_len (attrs, extack);if (err)return err;
@@ -2136,7 +2138,7 @@ static int xfrm_get_policy(struct sk_buff *skb, struct nlmsghdr *nlh,struct nlattr *rt = attrs[XFRMA_SEC_CTX ];struct xfrm_sec_ctx *ctx; - err =verify_sec_ctx_len (attrs); + err =verify_sec_ctx_len (attrs, extack);if (err)return err;
@@ -2441,7 +2443,7 @@ static int xfrm_add_pol_expire(struct sk_buff *skb, struct nlmsghdr *nlh,struct nlattr *rt = attrs[XFRMA_SEC_CTX ];struct xfrm_sec_ctx *ctx; - err =verify_sec_ctx_len (attrs); + err =verify_sec_ctx_len (attrs, extack);if (err)return err;
@@ -2533,7 +2535,7 @@ static int xfrm_add_acquire(struct sk_buff *skb, struct nlmsghdr *nlh, err =verify_newpolicy_info (&ua->policy, extack);if (err) goto free_state; - err =verify_sec_ctx_len (attrs); + err =verify_sec_ctx_len (attrs, extack);if (err) goto free_state;
Signature · 1 line
2.37.2
Steffen Klassert
maintainerQuoted 15 lines · Sabrina Dubroca
XFRM states and policies are complex objects, and there are many reasons why the kernel can reject userspace's request to create one. This series makes it a bit clearer by providing extended ack messages for policy creation.
A few other operations that reuse the same helper functions are also getting partial extack support in this series. More patches will follow to complete extack support, in particular for state creation.
Note: The
policy->shareattribute seems to be entirely ignored in the kernel outside of checking its value inverify_newpolicy_info(). There are some (very) old comments incopy_from_user_policyandcopy_to_user_policysuggesting that it should at least be copied to/from userspace. I don't know what it was intended for.
Quoted 7 lines
Sabrina Dubroca (6):
xfrm: propagate extack to all netlink doit handlers
xfrm: add extack support toverify_newpolicy_info
xfrm: add extack toverify_policy_dir
xfrm: add extack toverify_policy_type
xfrm: add extack tovalidate_tmpl
xfrm: add extack toverify_sec_ctx_len
Series applied, thanks a lot Sabrina!