[PATCH] ntb_tool: check null return of devm_kcalloc in tool_init_mws

Kang Chen posted 1 patch 2 years, 6 months ago
There is a newer version of this series
drivers/ntb/test/ntb_tool.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] ntb_tool: check null return of devm_kcalloc in tool_init_mws
Posted by Kang Chen 2 years, 6 months ago
devm_kcalloc may fails, tc->peers[pidx].outmws might be null
and will cause null pointer dereference later.

Signed-off-by: Kang Chen <void0red@gmail.com>
---
 drivers/ntb/test/ntb_tool.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/ntb/test/ntb_tool.c b/drivers/ntb/test/ntb_tool.c
index 5ee0afa62..eeeb4b1c9 100644
--- a/drivers/ntb/test/ntb_tool.c
+++ b/drivers/ntb/test/ntb_tool.c
@@ -998,6 +998,8 @@ static int tool_init_mws(struct tool_ctx *tc)
 		tc->peers[pidx].outmws =
 			devm_kcalloc(&tc->ntb->dev, tc->peers[pidx].outmw_cnt,
 				   sizeof(*tc->peers[pidx].outmws), GFP_KERNEL);
+		if (tc->peers[pidx].outmws == NULL)
+			return -ENOMEM;
 
 		for (widx = 0; widx < tc->peers[pidx].outmw_cnt; widx++) {
 			tc->peers[pidx].outmws[widx].pidx = pidx;
-- 
2.34.1
Re: [PATCH] ntb_tool: check null return of devm_kcalloc in tool_init_mws
Posted by Serge Semin 2 years, 6 months ago
On Sun, Feb 26, 2023 at 01:57:43PM +0800, Kang Chen wrote:
> devm_kcalloc may fails, tc->peers[pidx].outmws might be null
> and will cause null pointer dereference later.
> 
> Signed-off-by: Kang Chen <void0red@gmail.com>

Please add the fixes tag:
Fixes: 7f46c8b3a552 ("NTB: ntb_tool: Add full multi-port NTB API support")
so the patch could be noticeable by the stable kernel maintainers.

Other than that looks good.
Reviewed-by: Serge Semin <fancer.lancer@gmail.com>

* Please don't forget to add the Rb-tags on v2.

-Serge(y)

> ---
>  drivers/ntb/test/ntb_tool.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/ntb/test/ntb_tool.c b/drivers/ntb/test/ntb_tool.c
> index 5ee0afa62..eeeb4b1c9 100644
> --- a/drivers/ntb/test/ntb_tool.c
> +++ b/drivers/ntb/test/ntb_tool.c
> @@ -998,6 +998,8 @@ static int tool_init_mws(struct tool_ctx *tc)
>  		tc->peers[pidx].outmws =
>  			devm_kcalloc(&tc->ntb->dev, tc->peers[pidx].outmw_cnt,
>  				   sizeof(*tc->peers[pidx].outmws), GFP_KERNEL);
> +		if (tc->peers[pidx].outmws == NULL)
> +			return -ENOMEM;
>  
>  		for (widx = 0; widx < tc->peers[pidx].outmw_cnt; widx++) {
>  			tc->peers[pidx].outmws[widx].pidx = pidx;
> -- 
> 2.34.1
> 
>
[PATCH v2] ntb_tool: check null return of devm_kcalloc in tool_init_mws
Posted by Kang Chen 2 years, 6 months ago
devm_kcalloc may fails, tc->peers[pidx].outmws might be null
and will cause null pointer dereference later.

Fixes: 7f46c8b3a552 ("NTB: ntb_tool: Add full multi-port NTB API support")
Signed-off-by: Kang Chen <void0red@gmail.com>
Reviewed-by: Serge Semin <fancer.lancer@gmail.com>
---
v2 -> v1: add Fixes and Reviewed-by tags

 drivers/ntb/test/ntb_tool.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/ntb/test/ntb_tool.c b/drivers/ntb/test/ntb_tool.c
index 5ee0afa62..eeeb4b1c9 100644
--- a/drivers/ntb/test/ntb_tool.c
+++ b/drivers/ntb/test/ntb_tool.c
@@ -998,6 +998,8 @@ static int tool_init_mws(struct tool_ctx *tc)
 		tc->peers[pidx].outmws =
 			devm_kcalloc(&tc->ntb->dev, tc->peers[pidx].outmw_cnt,
 				   sizeof(*tc->peers[pidx].outmws), GFP_KERNEL);
+		if (tc->peers[pidx].outmws == NULL)
+			return -ENOMEM;
 
 		for (widx = 0; widx < tc->peers[pidx].outmw_cnt; widx++) {
 			tc->peers[pidx].outmws[widx].pidx = pidx;
-- 
2.34.1
Re: [PATCH v2] ntb_tool: check null return of devm_kcalloc in tool_init_mws
Posted by Dave Jiang 2 years, 6 months ago

On 3/7/23 5:20 AM, Kang Chen wrote:
> devm_kcalloc may fails, tc->peers[pidx].outmws might be null
> and will cause null pointer dereference later.
> 
> Fixes: 7f46c8b3a552 ("NTB: ntb_tool: Add full multi-port NTB API support")
> Signed-off-by: Kang Chen <void0red@gmail.com>
> Reviewed-by: Serge Semin <fancer.lancer@gmail.com>

You forgot to pick up my review tag. I do recommend using the tool 'b4'. 
It picks up all the tags for you and works rather well.

> ---
> v2 -> v1: add Fixes and Reviewed-by tags
> 
>   drivers/ntb/test/ntb_tool.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/ntb/test/ntb_tool.c b/drivers/ntb/test/ntb_tool.c
> index 5ee0afa62..eeeb4b1c9 100644
> --- a/drivers/ntb/test/ntb_tool.c
> +++ b/drivers/ntb/test/ntb_tool.c
> @@ -998,6 +998,8 @@ static int tool_init_mws(struct tool_ctx *tc)
>   		tc->peers[pidx].outmws =
>   			devm_kcalloc(&tc->ntb->dev, tc->peers[pidx].outmw_cnt,
>   				   sizeof(*tc->peers[pidx].outmws), GFP_KERNEL);
> +		if (tc->peers[pidx].outmws == NULL)
> +			return -ENOMEM;
>   
>   		for (widx = 0; widx < tc->peers[pidx].outmw_cnt; widx++) {
>   			tc->peers[pidx].outmws[widx].pidx = pidx;
Re: [PATCH v2] ntb_tool: check null return of devm_kcalloc in tool_init_mws
Posted by Kang Chen 2 years, 6 months ago
What a cool tool, thanks for your suggestions.

On Wed, Mar 8, 2023 at 12:06 AM Dave Jiang <dave.jiang@intel.com> wrote:
>
>
>
> On 3/7/23 5:20 AM, Kang Chen wrote:
> > devm_kcalloc may fails, tc->peers[pidx].outmws might be null
> > and will cause null pointer dereference later.
> >
> > Fixes: 7f46c8b3a552 ("NTB: ntb_tool: Add full multi-port NTB API support")
> > Signed-off-by: Kang Chen <void0red@gmail.com>
> > Reviewed-by: Serge Semin <fancer.lancer@gmail.com>
>
> You forgot to pick up my review tag. I do recommend using the tool 'b4'.
> It picks up all the tags for you and works rather well.
>
> > ---
> > v2 -> v1: add Fixes and Reviewed-by tags
> >
> >   drivers/ntb/test/ntb_tool.c | 2 ++
> >   1 file changed, 2 insertions(+)
> >
> > diff --git a/drivers/ntb/test/ntb_tool.c b/drivers/ntb/test/ntb_tool.c
> > index 5ee0afa62..eeeb4b1c9 100644
> > --- a/drivers/ntb/test/ntb_tool.c
> > +++ b/drivers/ntb/test/ntb_tool.c
> > @@ -998,6 +998,8 @@ static int tool_init_mws(struct tool_ctx *tc)
> >               tc->peers[pidx].outmws =
> >                       devm_kcalloc(&tc->ntb->dev, tc->peers[pidx].outmw_cnt,
> >                                  sizeof(*tc->peers[pidx].outmws), GFP_KERNEL);
> > +             if (tc->peers[pidx].outmws == NULL)
> > +                     return -ENOMEM;
> >
> >               for (widx = 0; widx < tc->peers[pidx].outmw_cnt; widx++) {
> >                       tc->peers[pidx].outmws[widx].pidx = pidx;
[PATCH v3] ntb_tool: check null return of devm_kcalloc in tool_init_mws
Posted by void0red 2 years, 6 months ago
From: Kang Chen <void0red@gmail.com>

devm_kcalloc may fails, tc->peers[pidx].outmws might be null
and will cause null pointer dereference later.

Fixes: 7f46c8b3a552 ("NTB: ntb_tool: Add full multi-port NTB API support")
Reviewed-by: Serge Semin <fancer.lancer@gmail.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Kang Chen <void0red@gmail.com>
---
v3 -> v2: add Reviewed-by tag
v2 -> v1: add Fixes and Reviewed-by tags

 drivers/ntb/test/ntb_tool.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/ntb/test/ntb_tool.c b/drivers/ntb/test/ntb_tool.c
index 5ee0afa62..eeeb4b1c9 100644
--- a/drivers/ntb/test/ntb_tool.c
+++ b/drivers/ntb/test/ntb_tool.c
@@ -998,6 +998,8 @@ static int tool_init_mws(struct tool_ctx *tc)
 		tc->peers[pidx].outmws =
 			devm_kcalloc(&tc->ntb->dev, tc->peers[pidx].outmw_cnt,
 				   sizeof(*tc->peers[pidx].outmws), GFP_KERNEL);
+		if (tc->peers[pidx].outmws == NULL)
+			return -ENOMEM;
 
 		for (widx = 0; widx < tc->peers[pidx].outmw_cnt; widx++) {
 			tc->peers[pidx].outmws[widx].pidx = pidx;
-- 
2.34.1
Re: [PATCH] ntb_tool: check null return of devm_kcalloc in tool_init_mws
Posted by Dave Jiang 2 years, 6 months ago

On 2/25/23 10:57 PM, Kang Chen wrote:
> devm_kcalloc may fails, tc->peers[pidx].outmws might be null
> and will cause null pointer dereference later.
> 
> Signed-off-by: Kang Chen <void0red@gmail.com>

Reviewed-by: Dave Jiang <dave.jiang@intel.com>

> ---
>   drivers/ntb/test/ntb_tool.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/ntb/test/ntb_tool.c b/drivers/ntb/test/ntb_tool.c
> index 5ee0afa62..eeeb4b1c9 100644
> --- a/drivers/ntb/test/ntb_tool.c
> +++ b/drivers/ntb/test/ntb_tool.c
> @@ -998,6 +998,8 @@ static int tool_init_mws(struct tool_ctx *tc)
>   		tc->peers[pidx].outmws =
>   			devm_kcalloc(&tc->ntb->dev, tc->peers[pidx].outmw_cnt,
>   				   sizeof(*tc->peers[pidx].outmws), GFP_KERNEL);
> +		if (tc->peers[pidx].outmws == NULL)
> +			return -ENOMEM;
>   
>   		for (widx = 0; widx < tc->peers[pidx].outmw_cnt; widx++) {
>   			tc->peers[pidx].outmws[widx].pidx = pidx;