netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: sched: fix a error path in fw_change()
@ 2022-12-01 15:15 Li Qiong
  2022-12-03  4:59 ` Jakub Kicinski
  2022-12-03 19:46 ` Cong Wang
  0 siblings, 2 replies; 4+ messages in thread
From: Li Qiong @ 2022-12-01 15:15 UTC (permalink / raw)
  To: Jamal Hadi Salim, Cong Wang, Jiri Pirko, David S . Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: netdev, linux-kernel, Yu Zhe, Li Qiong

The 'pfp' pointer could be null if can't find the target filter.
Check 'pfp' pointer and fix this error path.

Signed-off-by: Li Qiong <liqiong@nfschina.com>
---
 net/sched/cls_fw.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/net/sched/cls_fw.c b/net/sched/cls_fw.c
index a32351da968c..b898e4a81146 100644
--- a/net/sched/cls_fw.c
+++ b/net/sched/cls_fw.c
@@ -289,6 +289,12 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,
 			if (pfp == f)
 				break;
 
+		if (!pfp) {
+			tcf_exts_destroy(&fnew->exts);
+			kfree(fnew);
+			return err;
+		}
+
 		RCU_INIT_POINTER(fnew->next, rtnl_dereference(pfp->next));
 		rcu_assign_pointer(*fp, fnew);
 		tcf_unbind_filter(tp, &f->res);
-- 
2.11.0


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

* Re: [PATCH] net: sched: fix a error path in fw_change()
  2022-12-01 15:15 [PATCH] net: sched: fix a error path in fw_change() Li Qiong
@ 2022-12-03  4:59 ` Jakub Kicinski
  2022-12-03 19:46 ` Cong Wang
  1 sibling, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2022-12-03  4:59 UTC (permalink / raw)
  To: Li Qiong
  Cc: Jamal Hadi Salim, Cong Wang, Jiri Pirko, David S . Miller,
	Eric Dumazet, Paolo Abeni, netdev, linux-kernel, Yu Zhe

On Thu,  1 Dec 2022 23:15:32 +0800 Li Qiong wrote:
> The 'pfp' pointer could be null if can't find the target filter.
> Check 'pfp' pointer and fix this error path.

Sounds like a fix, we need a Fixes tag.

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

* Re: [PATCH] net: sched: fix a error path in fw_change()
  2022-12-01 15:15 [PATCH] net: sched: fix a error path in fw_change() Li Qiong
  2022-12-03  4:59 ` Jakub Kicinski
@ 2022-12-03 19:46 ` Cong Wang
  2022-12-05  2:36   ` liqiong
  1 sibling, 1 reply; 4+ messages in thread
From: Cong Wang @ 2022-12-03 19:46 UTC (permalink / raw)
  To: Li Qiong
  Cc: Jamal Hadi Salim, Jiri Pirko, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, linux-kernel, Yu Zhe

On Thu, Dec 01, 2022 at 11:15:32PM +0800, Li Qiong wrote:
> The 'pfp' pointer could be null if can't find the target filter.
> Check 'pfp' pointer and fix this error path.

Did you see any actual kernel crash? And do you have a reproducer too?
Please include them if you do.

> 
> Signed-off-by: Li Qiong <liqiong@nfschina.com>
> ---
>  net/sched/cls_fw.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/net/sched/cls_fw.c b/net/sched/cls_fw.c
> index a32351da968c..b898e4a81146 100644
> --- a/net/sched/cls_fw.c
> +++ b/net/sched/cls_fw.c
> @@ -289,6 +289,12 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,
>  			if (pfp == f)
>  				break;
>  
> +		if (!pfp) {
> +			tcf_exts_destroy(&fnew->exts);
> +			kfree(fnew);
> +			return err;


BTW, err is 0 here, you have to set some error here.

Thanks.

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

* Re: [PATCH] net: sched: fix a error path in fw_change()
  2022-12-03 19:46 ` Cong Wang
@ 2022-12-05  2:36   ` liqiong
  0 siblings, 0 replies; 4+ messages in thread
From: liqiong @ 2022-12-05  2:36 UTC (permalink / raw)
  To: Cong Wang
  Cc: Jamal Hadi Salim, Jiri Pirko, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, linux-kernel, Yu Zhe



在 2022年12月04日 03:46, Cong Wang 写道:
> On Thu, Dec 01, 2022 at 11:15:32PM +0800, Li Qiong wrote:
>> The 'pfp' pointer could be null if can't find the target filter.
>> Check 'pfp' pointer and fix this error path.
> Did you see any actual kernel crash? And do you have a reproducer too?
> Please include them if you do.
Found this by  'smatch' tool,  I check and find it may be a real problem at the risk
of NULL pointer. Like 'fw_delete()', It checks  'pfp' and 'pfp == f' too.
 



>
>> Signed-off-by: Li Qiong <liqiong@nfschina.com>
>> ---
>>  net/sched/cls_fw.c | 6 ++++++
>>  1 file changed, 6 insertions(+)
>>
>> diff --git a/net/sched/cls_fw.c b/net/sched/cls_fw.c
>> index a32351da968c..b898e4a81146 100644
>> --- a/net/sched/cls_fw.c
>> +++ b/net/sched/cls_fw.c
>> @@ -289,6 +289,12 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,
>>  			if (pfp == f)
>>  				break;
>>  
>> +		if (!pfp) {
>> +			tcf_exts_destroy(&fnew->exts);
>> +			kfree(fnew);
>> +			return err;
>
> BTW, err is 0 here, you have to set some error here.
You are right,  It should return  '-EINVAL'  -- can't get the target filter.



>
> Thanks.




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

end of thread, other threads:[~2022-12-05  2:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-01 15:15 [PATCH] net: sched: fix a error path in fw_change() Li Qiong
2022-12-03  4:59 ` Jakub Kicinski
2022-12-03 19:46 ` Cong Wang
2022-12-05  2:36   ` liqiong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).