All of lore.kernel.org
 help / color / mirror / Atom feed
* [Patch net] net_sched: fix backward compatibility for TCA_ACT_KIND
@ 2019-10-07 20:26 Cong Wang
  2019-10-08 12:12 ` Marcelo Ricardo Leitner
  2019-10-08 23:40 ` Jakub Kicinski
  0 siblings, 2 replies; 3+ messages in thread
From: Cong Wang @ 2019-10-07 20:26 UTC (permalink / raw)
  To: netdev; +Cc: Cong Wang, Marcelo Ricardo Leitner, Jamal Hadi Salim, Jiri Pirko

For TCA_ACT_KIND, we have to keep the backward compatibility too,
and rely on nla_strlcpy() to check and terminate the string with
a NUL.

Note for TC actions, nla_strcmp() is already used to compare kind
strings, so we don't need to fix other places.

Fixes: 199ce850ce11 ("net_sched: add policy validation for action attributes")
Reported-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: Jiri Pirko <jiri@resnulli.us>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
---
 net/sched/act_api.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index da99667589f8..4684f2f24b17 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -832,8 +832,7 @@ static struct tc_cookie *nla_memdup_cookie(struct nlattr **tb)
 }
 
 static const struct nla_policy tcf_action_policy[TCA_ACT_MAX + 1] = {
-	[TCA_ACT_KIND]		= { .type = NLA_NUL_STRING,
-				    .len = IFNAMSIZ - 1 },
+	[TCA_ACT_KIND]		= { .type = NLA_STRING },
 	[TCA_ACT_INDEX]		= { .type = NLA_U32 },
 	[TCA_ACT_COOKIE]	= { .type = NLA_BINARY,
 				    .len = TC_COOKIE_MAX_SIZE },
@@ -865,8 +864,10 @@ struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp,
 			NL_SET_ERR_MSG(extack, "TC action kind must be specified");
 			goto err_out;
 		}
-		nla_strlcpy(act_name, kind, IFNAMSIZ);
-
+		if (nla_strlcpy(act_name, kind, IFNAMSIZ) >= IFNAMSIZ) {
+			NL_SET_ERR_MSG(extack, "TC action name too long");
+			goto err_out;
+		}
 		if (tb[TCA_ACT_COOKIE]) {
 			cookie = nla_memdup_cookie(tb);
 			if (!cookie) {
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Patch net] net_sched: fix backward compatibility for TCA_ACT_KIND
  2019-10-07 20:26 [Patch net] net_sched: fix backward compatibility for TCA_ACT_KIND Cong Wang
@ 2019-10-08 12:12 ` Marcelo Ricardo Leitner
  2019-10-08 23:40 ` Jakub Kicinski
  1 sibling, 0 replies; 3+ messages in thread
From: Marcelo Ricardo Leitner @ 2019-10-08 12:12 UTC (permalink / raw)
  To: Cong Wang; +Cc: netdev, Jamal Hadi Salim, Jiri Pirko

On Mon, Oct 07, 2019 at 01:26:29PM -0700, Cong Wang wrote:
> For TCA_ACT_KIND, we have to keep the backward compatibility too,
> and rely on nla_strlcpy() to check and terminate the string with
> a NUL.
> 
> Note for TC actions, nla_strcmp() is already used to compare kind
> strings, so we don't need to fix other places.
> 
> Fixes: 199ce850ce11 ("net_sched: add policy validation for action attributes")
> Reported-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>

Reviewed-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>

> Cc: Jamal Hadi Salim <jhs@mojatatu.com>
> Cc: Jiri Pirko <jiri@resnulli.us>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
> ---
>  net/sched/act_api.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/net/sched/act_api.c b/net/sched/act_api.c
> index da99667589f8..4684f2f24b17 100644
> --- a/net/sched/act_api.c
> +++ b/net/sched/act_api.c
> @@ -832,8 +832,7 @@ static struct tc_cookie *nla_memdup_cookie(struct nlattr **tb)
>  }
>  
>  static const struct nla_policy tcf_action_policy[TCA_ACT_MAX + 1] = {
> -	[TCA_ACT_KIND]		= { .type = NLA_NUL_STRING,
> -				    .len = IFNAMSIZ - 1 },
> +	[TCA_ACT_KIND]		= { .type = NLA_STRING },
>  	[TCA_ACT_INDEX]		= { .type = NLA_U32 },
>  	[TCA_ACT_COOKIE]	= { .type = NLA_BINARY,
>  				    .len = TC_COOKIE_MAX_SIZE },
> @@ -865,8 +864,10 @@ struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp,
>  			NL_SET_ERR_MSG(extack, "TC action kind must be specified");
>  			goto err_out;
>  		}
> -		nla_strlcpy(act_name, kind, IFNAMSIZ);
> -
> +		if (nla_strlcpy(act_name, kind, IFNAMSIZ) >= IFNAMSIZ) {
> +			NL_SET_ERR_MSG(extack, "TC action name too long");
> +			goto err_out;
> +		}
>  		if (tb[TCA_ACT_COOKIE]) {
>  			cookie = nla_memdup_cookie(tb);
>  			if (!cookie) {
> -- 
> 2.21.0
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Patch net] net_sched: fix backward compatibility for TCA_ACT_KIND
  2019-10-07 20:26 [Patch net] net_sched: fix backward compatibility for TCA_ACT_KIND Cong Wang
  2019-10-08 12:12 ` Marcelo Ricardo Leitner
@ 2019-10-08 23:40 ` Jakub Kicinski
  1 sibling, 0 replies; 3+ messages in thread
From: Jakub Kicinski @ 2019-10-08 23:40 UTC (permalink / raw)
  To: Cong Wang; +Cc: netdev, Marcelo Ricardo Leitner, Jamal Hadi Salim, Jiri Pirko

On Mon,  7 Oct 2019 13:26:29 -0700, Cong Wang wrote:
> For TCA_ACT_KIND, we have to keep the backward compatibility too,
> and rely on nla_strlcpy() to check and terminate the string with
> a NUL.
> 
> Note for TC actions, nla_strcmp() is already used to compare kind
> strings, so we don't need to fix other places.
> 
> Fixes: 199ce850ce11 ("net_sched: add policy validation for action attributes")
> Reported-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
> Cc: Jamal Hadi Salim <jhs@mojatatu.com>
> Cc: Jiri Pirko <jiri@resnulli.us>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>

Applied, queued for 4.14+ as well.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-10-08 23:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-07 20:26 [Patch net] net_sched: fix backward compatibility for TCA_ACT_KIND Cong Wang
2019-10-08 12:12 ` Marcelo Ricardo Leitner
2019-10-08 23:40 ` Jakub Kicinski

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.