diff mbox series

[v3] net: xfrm: Amend XFRMA_SEC_CTX nla_policy structure

Message ID 20230630012241.2822225-1-linma@zju.edu.cn (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [v3] net: xfrm: Amend XFRMA_SEC_CTX nla_policy structure | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 23 this patch: 23
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang fail Errors and warnings before: 18 this patch: 18
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 23 this patch: 23
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 23 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Lin Ma June 30, 2023, 1:22 a.m. UTC
According to all consumers code of attrs[XFRMA_SEC_CTX], like

* verify_sec_ctx_len(), convert to xfrm_user_sec_ctx*
* xfrm_state_construct(), call security_xfrm_state_alloc whose prototype
is int security_xfrm_state_alloc(.., struct xfrm_user_sec_ctx *sec_ctx);
* copy_from_user_sec_ctx(), convert to xfrm_user_sec_ctx *
...

It seems that the expected parsing result for XFRMA_SEC_CTX should be
structure xfrm_user_sec_ctx, and the current xfrm_sec_ctx is confusing
and misleading (Luckily, they happen to have same size 8 bytes).

This commit amend the policy structure to xfrm_user_sec_ctx to avoid
ambiguity.

Fixes: cf5cb79f6946 ("[XFRM] netlink: Establish an attribute policy")
Signed-off-by: Lin Ma <linma@zju.edu.cn>
---
V1 -> V2: also amend compat_policy XFRMA_SEC_CTX
V2 -> V3: fix typo

 net/xfrm/xfrm_compat.c | 2 +-
 net/xfrm/xfrm_user.c   | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

Comments

Steffen Klassert June 30, 2023, 8:02 a.m. UTC | #1
On Fri, Jun 30, 2023 at 09:22:41AM +0800, Lin Ma wrote:
> According to all consumers code of attrs[XFRMA_SEC_CTX], like
> 
> * verify_sec_ctx_len(), convert to xfrm_user_sec_ctx*
> * xfrm_state_construct(), call security_xfrm_state_alloc whose prototype
> is int security_xfrm_state_alloc(.., struct xfrm_user_sec_ctx *sec_ctx);
> * copy_from_user_sec_ctx(), convert to xfrm_user_sec_ctx *
> ...
> 
> It seems that the expected parsing result for XFRMA_SEC_CTX should be
> structure xfrm_user_sec_ctx, and the current xfrm_sec_ctx is confusing
> and misleading (Luckily, they happen to have same size 8 bytes).
> 
> This commit amend the policy structure to xfrm_user_sec_ctx to avoid
> ambiguity.
> 
> Fixes: cf5cb79f6946 ("[XFRM] netlink: Establish an attribute policy")
> Signed-off-by: Lin Ma <linma@zju.edu.cn>
> ---
> V1 -> V2: also amend compat_policy XFRMA_SEC_CTX
> V2 -> V3: fix typo
> 
>  net/xfrm/xfrm_compat.c | 2 +-
>  net/xfrm/xfrm_user.c   | 3 ++-
>  2 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/net/xfrm/xfrm_compat.c b/net/xfrm/xfrm_compat.c
> index 8cbf45a8bcdc..655fe4ff8621 100644
> --- a/net/xfrm/xfrm_compat.c
> +++ b/net/xfrm/xfrm_compat.c
> @@ -108,7 +108,7 @@ static const struct nla_policy compat_policy[XFRMA_MAX+1] = {
>  	[XFRMA_ALG_COMP]	= { .len = sizeof(struct xfrm_algo) },
>  	[XFRMA_ENCAP]		= { .len = sizeof(struct xfrm_encap_tmpl) },
>  	[XFRMA_TMPL]		= { .len = sizeof(struct xfrm_user_tmpl) },
> -	[XFRMA_SEC_CTX]		= { .len = sizeof(struct xfrm_sec_ctx) },
> +	[XFRMA_SEC_CTX]		= { .len = sizeof(struct xfrm_user_sec_ctx) },
>  	[XFRMA_LTIME_VAL]	= { .len = sizeof(struct xfrm_lifetime_cur) },
>  	[XFRMA_REPLAY_VAL]	= { .len = sizeof(struct xfrm_replay_state) },
>  	[XFRMA_REPLAY_THRESH]	= { .type = NLA_U32 },
> diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
> index c34a2a06ca94..0c997a114d13 100644
> --- a/net/xfrm/xfrm_user.c
> +++ b/net/xfrm/xfrm_user.c
> @@ -3015,7 +3015,7 @@ const struct nla_policy xfrma_policy[XFRMA_MAX+1] = {
>  	[XFRMA_ALG_COMP]	= { .len = sizeof(struct xfrm_algo) },
>  	[XFRMA_ENCAP]		= { .len = sizeof(struct xfrm_encap_tmpl) },
>  	[XFRMA_TMPL]		= { .len = sizeof(struct xfrm_user_tmpl) },
> -	[XFRMA_SEC_CTX]		= { .len = sizeof(struct xfrm_sec_ctx) },
> +	[XFRMA_SEC_CTX]		= { .len = sizeof(struct xfrm_user_sec_ctx) },
>  	[XFRMA_LTIME_VAL]	= { .len = sizeof(struct xfrm_lifetime_cur) },
>  	[XFRMA_REPLAY_VAL]	= { .len = sizeof(struct xfrm_replay_state) },
>  	[XFRMA_REPLAY_THRESH]	= { .type = NLA_U32 },
> @@ -3035,6 +3035,7 @@ const struct nla_policy xfrma_policy[XFRMA_MAX+1] = {
>  	[XFRMA_SET_MARK]	= { .type = NLA_U32 },
>  	[XFRMA_SET_MARK_MASK]	= { .type = NLA_U32 },
>  	[XFRMA_IF_ID]		= { .type = NLA_U32 },
> +	[XFRMA_MTIMER_THRESH]	= { .type = NLA_U32 },

The above line is apparently missing, but does it really belong to this
patch? At least it is not mentioned in the commit message.
Lin Ma June 30, 2023, 8:16 a.m. UTC | #2
Hello Steffen,

> > +	[XFRMA_MTIMER_THRESH]	= { .type = NLA_U32 },
> 
> The above line is apparently missing, but does it really belong to this
> patch? At least it is not mentioned in the commit message.

Nope, my bad, it is about another ongoing patch. T.T

Sorry for the confusing patch, will resend it.

Regards
Lin
diff mbox series

Patch

diff --git a/net/xfrm/xfrm_compat.c b/net/xfrm/xfrm_compat.c
index 8cbf45a8bcdc..655fe4ff8621 100644
--- a/net/xfrm/xfrm_compat.c
+++ b/net/xfrm/xfrm_compat.c
@@ -108,7 +108,7 @@  static const struct nla_policy compat_policy[XFRMA_MAX+1] = {
 	[XFRMA_ALG_COMP]	= { .len = sizeof(struct xfrm_algo) },
 	[XFRMA_ENCAP]		= { .len = sizeof(struct xfrm_encap_tmpl) },
 	[XFRMA_TMPL]		= { .len = sizeof(struct xfrm_user_tmpl) },
-	[XFRMA_SEC_CTX]		= { .len = sizeof(struct xfrm_sec_ctx) },
+	[XFRMA_SEC_CTX]		= { .len = sizeof(struct xfrm_user_sec_ctx) },
 	[XFRMA_LTIME_VAL]	= { .len = sizeof(struct xfrm_lifetime_cur) },
 	[XFRMA_REPLAY_VAL]	= { .len = sizeof(struct xfrm_replay_state) },
 	[XFRMA_REPLAY_THRESH]	= { .type = NLA_U32 },
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index c34a2a06ca94..0c997a114d13 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -3015,7 +3015,7 @@  const struct nla_policy xfrma_policy[XFRMA_MAX+1] = {
 	[XFRMA_ALG_COMP]	= { .len = sizeof(struct xfrm_algo) },
 	[XFRMA_ENCAP]		= { .len = sizeof(struct xfrm_encap_tmpl) },
 	[XFRMA_TMPL]		= { .len = sizeof(struct xfrm_user_tmpl) },
-	[XFRMA_SEC_CTX]		= { .len = sizeof(struct xfrm_sec_ctx) },
+	[XFRMA_SEC_CTX]		= { .len = sizeof(struct xfrm_user_sec_ctx) },
 	[XFRMA_LTIME_VAL]	= { .len = sizeof(struct xfrm_lifetime_cur) },
 	[XFRMA_REPLAY_VAL]	= { .len = sizeof(struct xfrm_replay_state) },
 	[XFRMA_REPLAY_THRESH]	= { .type = NLA_U32 },
@@ -3035,6 +3035,7 @@  const struct nla_policy xfrma_policy[XFRMA_MAX+1] = {
 	[XFRMA_SET_MARK]	= { .type = NLA_U32 },
 	[XFRMA_SET_MARK_MASK]	= { .type = NLA_U32 },
 	[XFRMA_IF_ID]		= { .type = NLA_U32 },
+	[XFRMA_MTIMER_THRESH]	= { .type = NLA_U32 },
 };
 EXPORT_SYMBOL_GPL(xfrma_policy);