All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] net: sched: fix unprotected access to rcu cookie pointer
@ 2018-07-09 17:26 Vlad Buslov
  2018-07-09 20:34 ` Marcelo Ricardo Leitner
  2018-07-12  6:01 ` David Miller
  0 siblings, 2 replies; 6+ messages in thread
From: Vlad Buslov @ 2018-07-09 17:26 UTC (permalink / raw)
  To: netdev; +Cc: davem, jhs, xiyou.wangcong, jiri, marcelo.leitner, Vlad Buslov

Fix action attribute size calculation function to take rcu read lock and
access act_cookie pointer with rcu dereference.

Fixes: eec94fdb0480 ("net: sched: use rcu for action cookie update")
Reported-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: Vlad Buslov <vladbu@mellanox.com>
---
 net/sched/act_api.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index 66dc19746c63..148a89ab789b 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -149,10 +149,15 @@ EXPORT_SYMBOL(__tcf_idr_release);
 
 static size_t tcf_action_shared_attrs_size(const struct tc_action *act)
 {
+	struct tc_cookie *act_cookie;
 	u32 cookie_len = 0;
 
-	if (act->act_cookie)
-		cookie_len = nla_total_size(act->act_cookie->len);
+	rcu_read_lock();
+	act_cookie = rcu_dereference(act->act_cookie);
+
+	if (act_cookie)
+		cookie_len = nla_total_size(act_cookie->len);
+	rcu_read_unlock();
 
 	return  nla_total_size(0) /* action number nested */
 		+ nla_total_size(IFNAMSIZ) /* TCA_ACT_KIND */
-- 
2.7.5

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

* Re: [PATCH net-next] net: sched: fix unprotected access to rcu cookie pointer
  2018-07-09 17:26 [PATCH net-next] net: sched: fix unprotected access to rcu cookie pointer Vlad Buslov
@ 2018-07-09 20:34 ` Marcelo Ricardo Leitner
  2018-07-09 20:44   ` Vlad Buslov
  2018-07-09 20:51   ` Eric Dumazet
  2018-07-12  6:01 ` David Miller
  1 sibling, 2 replies; 6+ messages in thread
From: Marcelo Ricardo Leitner @ 2018-07-09 20:34 UTC (permalink / raw)
  To: Vlad Buslov; +Cc: netdev, davem, jhs, xiyou.wangcong, jiri

On Mon, Jul 09, 2018 at 08:26:47PM +0300, Vlad Buslov wrote:
> Fix action attribute size calculation function to take rcu read lock and
> access act_cookie pointer with rcu dereference.
> 
> Fixes: eec94fdb0480 ("net: sched: use rcu for action cookie update")
> Reported-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
> Signed-off-by: Vlad Buslov <vladbu@mellanox.com>
> ---
>  net/sched/act_api.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/net/sched/act_api.c b/net/sched/act_api.c
> index 66dc19746c63..148a89ab789b 100644
> --- a/net/sched/act_api.c
> +++ b/net/sched/act_api.c
> @@ -149,10 +149,15 @@ EXPORT_SYMBOL(__tcf_idr_release);
>  
>  static size_t tcf_action_shared_attrs_size(const struct tc_action *act)
>  {
> +	struct tc_cookie *act_cookie;
>  	u32 cookie_len = 0;
>  
> -	if (act->act_cookie)
> -		cookie_len = nla_total_size(act->act_cookie->len);
> +	rcu_read_lock();
> +	act_cookie = rcu_dereference(act->act_cookie);
> +
> +	if (act_cookie)
> +		cookie_len = nla_total_size(act_cookie->len);
> +	rcu_read_unlock();

I am not sure if this is enough to fix the entire issue. Now it will
fetch the length correctly but, what guarantees that when it tries to
actually copy the key (tcf_action_dump_1), the same act_cookie pointer
will be used? As in, can't the new re-fetch be different/smaller than
the object used here?

>  
>  	return  nla_total_size(0) /* action number nested */
>  		+ nla_total_size(IFNAMSIZ) /* TCA_ACT_KIND */
> -- 
> 2.7.5
> 

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

* Re: [PATCH net-next] net: sched: fix unprotected access to rcu cookie pointer
  2018-07-09 20:34 ` Marcelo Ricardo Leitner
@ 2018-07-09 20:44   ` Vlad Buslov
  2018-07-12  2:29     ` Marcelo Ricardo Leitner
  2018-07-09 20:51   ` Eric Dumazet
  1 sibling, 1 reply; 6+ messages in thread
From: Vlad Buslov @ 2018-07-09 20:44 UTC (permalink / raw)
  To: Marcelo Ricardo Leitner; +Cc: netdev, davem, jhs, xiyou.wangcong, jiri


On Mon 09 Jul 2018 at 20:34, Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> wrote:
> On Mon, Jul 09, 2018 at 08:26:47PM +0300, Vlad Buslov wrote:
>> Fix action attribute size calculation function to take rcu read lock and
>> access act_cookie pointer with rcu dereference.
>> 
>> Fixes: eec94fdb0480 ("net: sched: use rcu for action cookie update")
>> Reported-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
>> Signed-off-by: Vlad Buslov <vladbu@mellanox.com>
>> ---
>>  net/sched/act_api.c | 9 +++++++--
>>  1 file changed, 7 insertions(+), 2 deletions(-)
>> 
>> diff --git a/net/sched/act_api.c b/net/sched/act_api.c
>> index 66dc19746c63..148a89ab789b 100644
>> --- a/net/sched/act_api.c
>> +++ b/net/sched/act_api.c
>> @@ -149,10 +149,15 @@ EXPORT_SYMBOL(__tcf_idr_release);
>>  
>>  static size_t tcf_action_shared_attrs_size(const struct tc_action *act)
>>  {
>> +	struct tc_cookie *act_cookie;
>>  	u32 cookie_len = 0;
>>  
>> -	if (act->act_cookie)
>> -		cookie_len = nla_total_size(act->act_cookie->len);
>> +	rcu_read_lock();
>> +	act_cookie = rcu_dereference(act->act_cookie);
>> +
>> +	if (act_cookie)
>> +		cookie_len = nla_total_size(act_cookie->len);
>> +	rcu_read_unlock();
>
> I am not sure if this is enough to fix the entire issue. Now it will
> fetch the length correctly but, what guarantees that when it tries to
> actually copy the key (tcf_action_dump_1), the same act_cookie pointer
> will be used? As in, can't the new re-fetch be different/smaller than
> the object used here?

I checked the code of nlmsg_put() and similar functions, and they check
that there is enough free space at skb tailroom. If not, they fail
gracefully and return error. Am I missing something?

>
>>  
>>  	return  nla_total_size(0) /* action number nested */
>>  		+ nla_total_size(IFNAMSIZ) /* TCA_ACT_KIND */
>> -- 
>> 2.7.5
>> 

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

* Re: [PATCH net-next] net: sched: fix unprotected access to rcu cookie pointer
  2018-07-09 20:34 ` Marcelo Ricardo Leitner
  2018-07-09 20:44   ` Vlad Buslov
@ 2018-07-09 20:51   ` Eric Dumazet
  1 sibling, 0 replies; 6+ messages in thread
From: Eric Dumazet @ 2018-07-09 20:51 UTC (permalink / raw)
  To: Marcelo Ricardo Leitner, Vlad Buslov
  Cc: netdev, davem, jhs, xiyou.wangcong, jiri



On 07/09/2018 01:34 PM, Marcelo Ricardo Leitner wrote:

> I am not sure if this is enough to fix the entire issue. Now it will
> fetch the length correctly but, what guarantees that when it tries to
> actually copy the key (tcf_action_dump_1), the same act_cookie pointer
> will be used? As in, can't the new re-fetch be different/smaller than
> the object used here?
> 

Yes, this presumably should use rtnl_dereference()

RTNL should be held between tcf_action_shared_attrs_size() and tcf_action_dump_1()

Although it might not be the case anymore, we keep changing this RTNL requirement
in dump operations ;)

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

* Re: [PATCH net-next] net: sched: fix unprotected access to rcu cookie pointer
  2018-07-09 20:44   ` Vlad Buslov
@ 2018-07-12  2:29     ` Marcelo Ricardo Leitner
  0 siblings, 0 replies; 6+ messages in thread
From: Marcelo Ricardo Leitner @ 2018-07-12  2:29 UTC (permalink / raw)
  To: Vlad Buslov; +Cc: netdev, davem, jhs, xiyou.wangcong, jiri

On Mon, Jul 09, 2018 at 11:44:38PM +0300, Vlad Buslov wrote:
> 
> On Mon 09 Jul 2018 at 20:34, Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> wrote:
> > On Mon, Jul 09, 2018 at 08:26:47PM +0300, Vlad Buslov wrote:
> >> Fix action attribute size calculation function to take rcu read lock and
> >> access act_cookie pointer with rcu dereference.
> >> 
> >> Fixes: eec94fdb0480 ("net: sched: use rcu for action cookie update")
> >> Reported-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
> >> Signed-off-by: Vlad Buslov <vladbu@mellanox.com>
> >> ---
> >>  net/sched/act_api.c | 9 +++++++--
> >>  1 file changed, 7 insertions(+), 2 deletions(-)
> >> 
> >> diff --git a/net/sched/act_api.c b/net/sched/act_api.c
> >> index 66dc19746c63..148a89ab789b 100644
> >> --- a/net/sched/act_api.c
> >> +++ b/net/sched/act_api.c
> >> @@ -149,10 +149,15 @@ EXPORT_SYMBOL(__tcf_idr_release);
> >>  
> >>  static size_t tcf_action_shared_attrs_size(const struct tc_action *act)
> >>  {
> >> +	struct tc_cookie *act_cookie;
> >>  	u32 cookie_len = 0;
> >>  
> >> -	if (act->act_cookie)
> >> -		cookie_len = nla_total_size(act->act_cookie->len);
> >> +	rcu_read_lock();
> >> +	act_cookie = rcu_dereference(act->act_cookie);
> >> +
> >> +	if (act_cookie)
> >> +		cookie_len = nla_total_size(act_cookie->len);
> >> +	rcu_read_unlock();
> >
> > I am not sure if this is enough to fix the entire issue. Now it will
> > fetch the length correctly but, what guarantees that when it tries to
> > actually copy the key (tcf_action_dump_1), the same act_cookie pointer
> > will be used? As in, can't the new re-fetch be different/smaller than
> > the object used here?
> 
> I checked the code of nlmsg_put() and similar functions, and they check
> that there is enough free space at skb tailroom. If not, they fail
> gracefully and return error. Am I missing something?

Talked offline with Vlad and I agree that this is fine as is.

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

Thanks,
Marcelo

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

* Re: [PATCH net-next] net: sched: fix unprotected access to rcu cookie pointer
  2018-07-09 17:26 [PATCH net-next] net: sched: fix unprotected access to rcu cookie pointer Vlad Buslov
  2018-07-09 20:34 ` Marcelo Ricardo Leitner
@ 2018-07-12  6:01 ` David Miller
  1 sibling, 0 replies; 6+ messages in thread
From: David Miller @ 2018-07-12  6:01 UTC (permalink / raw)
  To: vladbu; +Cc: netdev, jhs, xiyou.wangcong, jiri, marcelo.leitner

From: Vlad Buslov <vladbu@mellanox.com>
Date: Mon,  9 Jul 2018 20:26:47 +0300

> Fix action attribute size calculation function to take rcu read lock and
> access act_cookie pointer with rcu dereference.
> 
> Fixes: eec94fdb0480 ("net: sched: use rcu for action cookie update")
> Reported-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
> Signed-off-by: Vlad Buslov <vladbu@mellanox.com>

Applied.

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

end of thread, other threads:[~2018-07-12  6:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-09 17:26 [PATCH net-next] net: sched: fix unprotected access to rcu cookie pointer Vlad Buslov
2018-07-09 20:34 ` Marcelo Ricardo Leitner
2018-07-09 20:44   ` Vlad Buslov
2018-07-12  2:29     ` Marcelo Ricardo Leitner
2018-07-09 20:51   ` Eric Dumazet
2018-07-12  6:01 ` David Miller

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.