diff mbox

[net,1/1] cls_api.c: Fix dumping of non-existing actions' stats.

Message ID 20150203173251.GB6246@zenon.in.qult.net
State Superseded, archived
Delegated to: David Miller
Headers show

Commit Message

Ignacy Gawędzki Feb. 3, 2015, 5:32 p.m. UTC
In tcf_exts_dump_stats(), ensure that exts->actions is not empty before
accessing the first element of that list and calling tcf_action_copy_stats()
on it.  This fixes some random segvs when adding filters of type "basic" with
no particular action.

This also fixes the dumping of those "no-action" filters, which more often
than not made calls to tcf_action_copy_stats() fail and consequently netlink
attributes added by the caller to be removed by a call to nla_nest_cancel().

Signed-off-by: Ignacy Gawędzki <ignacy.gawedzki@green-communications.fr>
---
 net/sched/cls_api.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Cong Wang Feb. 3, 2015, 5:39 p.m. UTC | #1
On Tue, Feb 3, 2015 at 9:32 AM, Ignacy Gawędzki
<ignacy.gawedzki@green-communications.fr> wrote:
> In tcf_exts_dump_stats(), ensure that exts->actions is not empty before
> accessing the first element of that list and calling tcf_action_copy_stats()
> on it.  This fixes some random segvs when adding filters of type "basic" with
> no particular action.
>
> This also fixes the dumping of those "no-action" filters, which more often
> than not made calls to tcf_action_copy_stats() fail and consequently netlink
> attributes added by the caller to be removed by a call to nla_nest_cancel().
>
> Signed-off-by: Ignacy Gawędzki <ignacy.gawedzki@green-communications.fr>
> ---
>  net/sched/cls_api.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
> index aad6a67..30e6967 100644
> --- a/net/sched/cls_api.c
> +++ b/net/sched/cls_api.c
> @@ -602,9 +602,12 @@ EXPORT_SYMBOL(tcf_exts_dump);
>  int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts)
>  {
>  #ifdef CONFIG_NET_CLS_ACT
> -       struct tc_action *a = tcf_exts_first_act(exts);
> -       if (tcf_action_copy_stats(skb, a, 1) < 0)
> -               return -1;
> +       struct tc_action *a;
> +       if (!list_empty(&exts->actions)) {
> +               a = tcf_exts_first_act(exts);
> +               if (tcf_action_copy_stats(skb, a, 1) < 0)
> +                       return -1;
> +       }

Hmm, or just fix tcf_exts_first_act()? Let it call list_first_entry_or_null().

Also, please add Fixes: tag.

Fixes: commit 33be627159913b094bb578e83e9a7fdc66c10208
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Eric Dumazet Feb. 3, 2015, 5:51 p.m. UTC | #2
On Tue, 2015-02-03 at 09:39 -0800, Cong Wang wrote:

> Also, please add Fixes: tag.
> 
> Fixes: commit 33be627159913b094bb578e83e9a7fdc66c10208

Or more exactly use this format for Fixes tag :

Fixes: 33be62715991 ("net_sched: act: use standard struct list_head")

(assuming this commit is indeed the one introducing the problem)


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller Feb. 5, 2015, 4:26 a.m. UTC | #3
From: Ignacy Gawędzki <ignacy.gawedzki@green-communications.fr>
Date: Tue, 3 Feb 2015 18:32:51 +0100

> In tcf_exts_dump_stats(), ensure that exts->actions is not empty before
> accessing the first element of that list and calling tcf_action_copy_stats()
> on it.  This fixes some random segvs when adding filters of type "basic" with
> no particular action.
> 
> This also fixes the dumping of those "no-action" filters, which more often
> than not made calls to tcf_action_copy_stats() fail and consequently netlink
> attributes added by the caller to be removed by a call to nla_nest_cancel().
> 
> Signed-off-by: Ignacy Gawędzki <ignacy.gawedzki@green-communications.fr>

Applied, thanks.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Cong Wang Feb. 25, 2015, 12:20 a.m. UTC | #4
On Wed, Feb 4, 2015 at 8:26 PM, David Miller <davem@davemloft.net> wrote:
> From: Ignacy Gawędzki <ignacy.gawedzki@green-communications.fr>
> Date: Tue, 3 Feb 2015 18:32:51 +0100
>
>> In tcf_exts_dump_stats(), ensure that exts->actions is not empty before
>> accessing the first element of that list and calling tcf_action_copy_stats()
>> on it.  This fixes some random segvs when adding filters of type "basic" with
>> no particular action.
>>
>> This also fixes the dumping of those "no-action" filters, which more often
>> than not made calls to tcf_action_copy_stats() fail and consequently netlink
>> attributes added by the caller to be removed by a call to nla_nest_cancel().
>>
>> Signed-off-by: Ignacy Gawędzki <ignacy.gawedzki@green-communications.fr>
>
> Applied, thanks.

Dave, please queue this patch for -stable as well, if you haven't done yet.
It needs to backport back to 3.14.

Thanks!
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller Feb. 25, 2015, 2:15 a.m. UTC | #5
From: Cong Wang <cwang@twopensource.com>
Date: Tue, 24 Feb 2015 16:20:42 -0800

> On Wed, Feb 4, 2015 at 8:26 PM, David Miller <davem@davemloft.net> wrote:
>> From: Ignacy Gawędzki <ignacy.gawedzki@green-communications.fr>
>> Date: Tue, 3 Feb 2015 18:32:51 +0100
>>
>>> In tcf_exts_dump_stats(), ensure that exts->actions is not empty before
>>> accessing the first element of that list and calling tcf_action_copy_stats()
>>> on it.  This fixes some random segvs when adding filters of type "basic" with
>>> no particular action.
>>>
>>> This also fixes the dumping of those "no-action" filters, which more often
>>> than not made calls to tcf_action_copy_stats() fail and consequently netlink
>>> attributes added by the caller to be removed by a call to nla_nest_cancel().
>>>
>>> Signed-off-by: Ignacy Gawędzki <ignacy.gawedzki@green-communications.fr>
>>
>> Applied, thanks.
> 
> Dave, please queue this patch for -stable as well, if you haven't done yet.
> It needs to backport back to 3.14.

Done.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index aad6a67..30e6967 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -602,9 +602,12 @@  EXPORT_SYMBOL(tcf_exts_dump);
 int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts)
 {
 #ifdef CONFIG_NET_CLS_ACT
-	struct tc_action *a = tcf_exts_first_act(exts);
-	if (tcf_action_copy_stats(skb, a, 1) < 0)
-		return -1;
+	struct tc_action *a;
+	if (!list_empty(&exts->actions)) {
+		a = tcf_exts_first_act(exts);
+		if (tcf_action_copy_stats(skb, a, 1) < 0)
+			return -1;
+	}
 #endif
 	return 0;
 }