All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steffen Klassert <steffen.klassert@secunet.com>
To: David Miller <davem@davemloft.net>, Jakub Kicinski <kuba@kernel.org>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
	Steffen Klassert <steffen.klassert@secunet.com>,
	<netdev@vger.kernel.org>
Subject: [PATCH 09/24] xfrm: add extack to verify_policy_type
Date: Sun, 2 Oct 2022 10:16:57 +0200	[thread overview]
Message-ID: <20221002081712.757515-10-steffen.klassert@secunet.com> (raw)
In-Reply-To: <20221002081712.757515-1-steffen.klassert@secunet.com>

From: Sabrina Dubroca <sd@queasysnail.net>

Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 net/xfrm/xfrm_user.c | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index 0042b77337bd..0f2a2aa1e289 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -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_us
 
 	copy_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;
 
-- 
2.25.1


  parent reply	other threads:[~2022-10-02  8:34 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-02  8:16 [PATCH 0/24] pull request (net-next): ipsec-next 2022-10-02 Steffen Klassert
2022-10-02  8:16 ` [PATCH 01/24] selftests/net: Refactor xfrm_fill_key() to use array of structs Steffen Klassert
2022-10-03  7:10   ` patchwork-bot+netdevbpf
2022-10-02  8:16 ` [PATCH 02/24] xfrm: Drop unused argument Steffen Klassert
2022-10-02  8:16 ` [PATCH 03/24] net: allow storing xfrm interface metadata in metadata_dst Steffen Klassert
2022-10-02  8:16 ` [PATCH 04/24] xfrm: interface: support collect metadata mode Steffen Klassert
2022-10-02  8:16 ` [PATCH 05/24] xfrm: lwtunnel: add lwtunnel support for xfrm interfaces in collect_md mode Steffen Klassert
2022-10-02  8:16 ` [PATCH 06/24] xfrm: propagate extack to all netlink doit handlers Steffen Klassert
2022-10-02  8:16 ` [PATCH 07/24] xfrm: add extack support to verify_newpolicy_info Steffen Klassert
2022-10-02  8:16 ` [PATCH 08/24] xfrm: add extack to verify_policy_dir Steffen Klassert
2022-10-02  8:16 ` Steffen Klassert [this message]
2022-10-02  8:16 ` [PATCH 10/24] xfrm: add extack to validate_tmpl Steffen Klassert
2022-10-02  8:16 ` [PATCH 11/24] xfrm: add extack to verify_sec_ctx_len Steffen Klassert
2022-10-02  8:17 ` [PATCH 12/24] xfrm: add extack support to verify_newsa_info Steffen Klassert
2022-10-02  8:17 ` [PATCH 13/24] xfrm: add extack to verify_replay Steffen Klassert
2022-10-02  8:17 ` [PATCH 14/24] xfrm: add extack to verify_one_alg, verify_auth_trunc, verify_aead Steffen Klassert
2022-10-02  8:17 ` [PATCH 15/24] xfrm: add extack support to xfrm_dev_state_add Steffen Klassert
2022-10-02  8:17 ` [PATCH 16/24] xfrm: add extack to attach_* Steffen Klassert
2022-10-02  8:17 ` [PATCH 17/24] xfrm: add extack to __xfrm_init_state Steffen Klassert
2022-10-02  8:17 ` [PATCH 18/24] xfrm: add extack support to xfrm_init_replay Steffen Klassert
2022-10-02  8:17 ` [PATCH 19/24] xfrm: pass extack down to xfrm_type ->init_state Steffen Klassert
2022-10-02  8:17 ` [PATCH 20/24] xfrm: ah: add extack to ah_init_state, ah6_init_state Steffen Klassert
2022-10-02  8:17 ` [PATCH 21/24] xfrm: esp: add extack to esp_init_state, esp6_init_state Steffen Klassert
2022-10-02  8:17 ` [PATCH 22/24] xfrm: tunnel: add extack to ipip_init_state, xfrm6_tunnel_init_state Steffen Klassert
2022-10-02  8:17 ` [PATCH 23/24] xfrm: ipcomp: add extack to ipcomp{4,6}_init_state Steffen Klassert
2022-10-02  8:17 ` [PATCH 24/24] xfrm: mip6: add extack to mip6_destopt_init_state, mip6_rthdr_init_state Steffen Klassert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221002081712.757515-10-steffen.klassert@secunet.com \
    --to=steffen.klassert@secunet.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.