linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] thunderbolt: xdomain: Fix to check return value of kmemdup
@ 2019-03-18 22:55 Aditya Pakki
  2019-03-20 10:51 ` Mika Westerberg
  2019-03-20 10:57 ` David Laight
  0 siblings, 2 replies; 4+ messages in thread
From: Aditya Pakki @ 2019-03-18 22:55 UTC (permalink / raw)
  To: pakki001
  Cc: kjlu, Andreas Noever, Michael Jamet, Mika Westerberg,
	Yehezkel Bernat, Alexei Starovoitov, Daniel Borkmann,
	David S. Miller, Jakub Kicinski, Jesper Dangaard Brouer,
	John Fastabend, linux-kernel, netdev, xdp-newbies, bpf

kmemdup can fail and return a NULL pointer. The patch modifies the
signature of tb_xdp_schedule_request and passes the failure error upstream.

Signed-off-by: Aditya Pakki <pakki001@umn.edu>
---
 drivers/thunderbolt/xdomain.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/thunderbolt/xdomain.c b/drivers/thunderbolt/xdomain.c
index e27dd8beb94b..b0e9cc30d708 100644
--- a/drivers/thunderbolt/xdomain.c
+++ b/drivers/thunderbolt/xdomain.c
@@ -526,7 +526,7 @@ static void tb_xdp_handle_request(struct work_struct *work)
 	kfree(xw);
 }
 
-static void
+static bool
 tb_xdp_schedule_request(struct tb *tb, const struct tb_xdp_header *hdr,
 			size_t size)
 {
@@ -534,13 +534,16 @@ tb_xdp_schedule_request(struct tb *tb, const struct tb_xdp_header *hdr,
 
 	xw = kmalloc(sizeof(*xw), GFP_KERNEL);
 	if (!xw)
-		return;
+		return false;
 
 	INIT_WORK(&xw->work, tb_xdp_handle_request);
 	xw->pkg = kmemdup(hdr, size, GFP_KERNEL);
+	if (!xw->pkg)
+		return false;
 	xw->tb = tb;
 
 	queue_work(tb->wq, &xw->work);
+	return true;
 }
 
 /**
@@ -1417,8 +1420,7 @@ bool tb_xdomain_handle_request(struct tb *tb, enum tb_cfg_pkg_type type,
 	 */
 	if (uuid_equal(&hdr->uuid, &tb_xdp_uuid)) {
 		if (type == TB_CFG_PKG_XDOMAIN_REQ) {
-			tb_xdp_schedule_request(tb, hdr, size);
-			return true;
+			return tb_xdp_schedule_request(tb, hdr, size);
 		}
 		return false;
 	}
-- 
2.17.1


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

* Re: [PATCH] thunderbolt: xdomain: Fix to check return value of kmemdup
  2019-03-18 22:55 [PATCH] thunderbolt: xdomain: Fix to check return value of kmemdup Aditya Pakki
@ 2019-03-20 10:51 ` Mika Westerberg
  2019-03-20 10:57 ` David Laight
  1 sibling, 0 replies; 4+ messages in thread
From: Mika Westerberg @ 2019-03-20 10:51 UTC (permalink / raw)
  To: Aditya Pakki
  Cc: kjlu, Andreas Noever, Michael Jamet, Yehezkel Bernat,
	Alexei Starovoitov, Daniel Borkmann, David S. Miller,
	Jakub Kicinski, Jesper Dangaard Brouer, John Fastabend,
	linux-kernel, netdev, xdp-newbies, bpf

On Mon, Mar 18, 2019 at 05:55:08PM -0500, Aditya Pakki wrote:
> @@ -1417,8 +1420,7 @@ bool tb_xdomain_handle_request(struct tb *tb, enum tb_cfg_pkg_type type,
>  	 */
>  	if (uuid_equal(&hdr->uuid, &tb_xdp_uuid)) {
>  		if (type == TB_CFG_PKG_XDOMAIN_REQ) {
> -			tb_xdp_schedule_request(tb, hdr, size);
> -			return true;
> +			return tb_xdp_schedule_request(tb, hdr, size);

Please remove parens as well that there is only a single statement
following the if-block.

Otherwise looks fine.

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

* RE: [PATCH] thunderbolt: xdomain: Fix to check return value of kmemdup
  2019-03-18 22:55 [PATCH] thunderbolt: xdomain: Fix to check return value of kmemdup Aditya Pakki
  2019-03-20 10:51 ` Mika Westerberg
@ 2019-03-20 10:57 ` David Laight
  2019-03-20 12:18   ` Mukesh Ojha
  1 sibling, 1 reply; 4+ messages in thread
From: David Laight @ 2019-03-20 10:57 UTC (permalink / raw)
  To: 'Aditya Pakki'
  Cc: kjlu, Andreas Noever, Michael Jamet, Mika Westerberg,
	Yehezkel Bernat, Alexei Starovoitov, Daniel Borkmann,
	David S. Miller, Jakub Kicinski, Jesper Dangaard Brouer,
	John Fastabend, linux-kernel, netdev, xdp-newbies, bpf

From: Aditya Pakki
> Sent: 18 March 2019 22:55
> 
> kmemdup can fail and return a NULL pointer. The patch modifies the
> signature of tb_xdp_schedule_request and passes the failure error upstream.
> 
> Signed-off-by: Aditya Pakki <pakki001@umn.edu>
> ---
>  drivers/thunderbolt/xdomain.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/thunderbolt/xdomain.c b/drivers/thunderbolt/xdomain.c
> index e27dd8beb94b..b0e9cc30d708 100644
> --- a/drivers/thunderbolt/xdomain.c
> +++ b/drivers/thunderbolt/xdomain.c
> @@ -526,7 +526,7 @@ static void tb_xdp_handle_request(struct work_struct *work)
>  	kfree(xw);
>  }
> 
> -static void
> +static bool
>  tb_xdp_schedule_request(struct tb *tb, const struct tb_xdp_header *hdr,
>  			size_t size)
>  {
> @@ -534,13 +534,16 @@ tb_xdp_schedule_request(struct tb *tb, const struct tb_xdp_header *hdr,
> 
>  	xw = kmalloc(sizeof(*xw), GFP_KERNEL);
>  	if (!xw)
> -		return;
> +		return false;
> 
>  	INIT_WORK(&xw->work, tb_xdp_handle_request);
>  	xw->pkg = kmemdup(hdr, size, GFP_KERNEL);
> +	if (!xw->pkg)
> +		return false;

You're leaking 'xw' here.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


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

* Re: [PATCH] thunderbolt: xdomain: Fix to check return value of kmemdup
  2019-03-20 10:57 ` David Laight
@ 2019-03-20 12:18   ` Mukesh Ojha
  0 siblings, 0 replies; 4+ messages in thread
From: Mukesh Ojha @ 2019-03-20 12:18 UTC (permalink / raw)
  To: David Laight, 'Aditya Pakki'
  Cc: kjlu, Andreas Noever, Michael Jamet, Mika Westerberg,
	Yehezkel Bernat, Alexei Starovoitov, Daniel Borkmann,
	David S. Miller, Jakub Kicinski, Jesper Dangaard Brouer,
	John Fastabend, linux-kernel, netdev, xdp-newbies, bpf


On 3/20/2019 4:27 PM, David Laight wrote:
> From: Aditya Pakki
>> Sent: 18 March 2019 22:55
>>
>> kmemdup can fail and return a NULL pointer. The patch modifies the
>> signature of tb_xdp_schedule_request and passes the failure error upstream.
>>
>> Signed-off-by: Aditya Pakki <pakki001@umn.edu>
>> ---
>>   drivers/thunderbolt/xdomain.c | 10 ++++++----
>>   1 file changed, 6 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/thunderbolt/xdomain.c b/drivers/thunderbolt/xdomain.c
>> index e27dd8beb94b..b0e9cc30d708 100644
>> --- a/drivers/thunderbolt/xdomain.c
>> +++ b/drivers/thunderbolt/xdomain.c
>> @@ -526,7 +526,7 @@ static void tb_xdp_handle_request(struct work_struct *work)
>>   	kfree(xw);
>>   }
>>
>> -static void
>> +static bool
>>   tb_xdp_schedule_request(struct tb *tb, const struct tb_xdp_header *hdr,
>>   			size_t size)
>>   {
>> @@ -534,13 +534,16 @@ tb_xdp_schedule_request(struct tb *tb, const struct tb_xdp_header *hdr,
>>
>>   	xw = kmalloc(sizeof(*xw), GFP_KERNEL);
>>   	if (!xw)
>> -		return;
>> +		return false;
>>
>>   	INIT_WORK(&xw->work, tb_xdp_handle_request);
>>   	xw->pkg = kmemdup(hdr, size, GFP_KERNEL);
>> +	if (!xw->pkg)
>> +		return false;
> You're leaking 'xw' here.


Yes , Clean up is missing otherwise patch looks good.

Mukesh

>
> 	David
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
>

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

end of thread, other threads:[~2019-03-20 12:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-18 22:55 [PATCH] thunderbolt: xdomain: Fix to check return value of kmemdup Aditya Pakki
2019-03-20 10:51 ` Mika Westerberg
2019-03-20 10:57 ` David Laight
2019-03-20 12:18   ` Mukesh Ojha

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).