* [PATCH net 0/2][pull request] Intel Wired LAN Driver Updates 2023-01-09 (ice)
@ 2023-01-09 22:53 Tony Nguyen
2023-01-09 22:53 ` [PATCH net 1/2] ice: Fix potential memory leak in ice_gnss_tty_write() Tony Nguyen
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Tony Nguyen @ 2023-01-09 22:53 UTC (permalink / raw)
To: davem, kuba, pabeni, edumazet; +Cc: Tony Nguyen, netdev
This series contains updates to ice driver only.
Jiasheng Jiang frees allocated cmd_buf if write_buf allocation failed to
prevent memory leak.
Yuan Can adds check, and proper cleanup, of gnss_tty_port allocation call
to avoid memory leaks.
The following are changes since commit 7d6ceeb1875cc08dc3d1e558e191434d94840cd5:
af_unix: selftest: Fix the size of the parameter to connect()
and are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/net-queue 100GbE
Jiasheng Jiang (1):
ice: Add check for kzalloc
Yuan Can (1):
ice: Fix potential memory leak in ice_gnss_tty_write()
drivers/net/ethernet/intel/ice/ice_gnss.c | 24 ++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)
--
2.38.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH net 1/2] ice: Fix potential memory leak in ice_gnss_tty_write()
2023-01-09 22:53 [PATCH net 0/2][pull request] Intel Wired LAN Driver Updates 2023-01-09 (ice) Tony Nguyen
@ 2023-01-09 22:53 ` Tony Nguyen
2023-01-09 22:53 ` [PATCH net 2/2] ice: Add check for kzalloc Tony Nguyen
2023-01-11 2:30 ` [PATCH net 0/2][pull request] Intel Wired LAN Driver Updates 2023-01-09 (ice) patchwork-bot+netdevbpf
2 siblings, 0 replies; 8+ messages in thread
From: Tony Nguyen @ 2023-01-09 22:53 UTC (permalink / raw)
To: davem, kuba, pabeni, edumazet
Cc: Yuan Can, netdev, anthony.l.nguyen, Leon Romanovsky, Gurucharan G
From: Yuan Can <yuancan@huawei.com>
The ice_gnss_tty_write() return directly if the write_buf alloc failed,
leaking the cmd_buf.
Fix by free cmd_buf if write_buf alloc failed.
Fixes: d6b98c8d242a ("ice: add write functionality for GNSS TTY")
Signed-off-by: Yuan Can <yuancan@huawei.com>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
---
drivers/net/ethernet/intel/ice/ice_gnss.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/net/ethernet/intel/ice/ice_gnss.c b/drivers/net/ethernet/intel/ice/ice_gnss.c
index b5a7f246d230..a1915551c69a 100644
--- a/drivers/net/ethernet/intel/ice/ice_gnss.c
+++ b/drivers/net/ethernet/intel/ice/ice_gnss.c
@@ -363,6 +363,7 @@ ice_gnss_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
/* Send the data out to a hardware port */
write_buf = kzalloc(sizeof(*write_buf), GFP_KERNEL);
if (!write_buf) {
+ kfree(cmd_buf);
err = -ENOMEM;
goto exit;
}
--
2.38.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net 2/2] ice: Add check for kzalloc
2023-01-09 22:53 [PATCH net 0/2][pull request] Intel Wired LAN Driver Updates 2023-01-09 (ice) Tony Nguyen
2023-01-09 22:53 ` [PATCH net 1/2] ice: Fix potential memory leak in ice_gnss_tty_write() Tony Nguyen
@ 2023-01-09 22:53 ` Tony Nguyen
2023-01-10 10:56 ` Leon Romanovsky
2023-01-11 2:26 ` Jakub Kicinski
2023-01-11 2:30 ` [PATCH net 0/2][pull request] Intel Wired LAN Driver Updates 2023-01-09 (ice) patchwork-bot+netdevbpf
2 siblings, 2 replies; 8+ messages in thread
From: Tony Nguyen @ 2023-01-09 22:53 UTC (permalink / raw)
To: davem, kuba, pabeni, edumazet
Cc: Jiasheng Jiang, netdev, anthony.l.nguyen, Jiri Pirko, Gurucharan G
From: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Add the check for the return value of kzalloc in order to avoid
NULL pointer dereference.
Moreover, use the goto-label to share the clean code.
Fixes: d6b98c8d242a ("ice: add write functionality for GNSS TTY")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
---
drivers/net/ethernet/intel/ice/ice_gnss.c | 23 ++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/drivers/net/ethernet/intel/ice/ice_gnss.c b/drivers/net/ethernet/intel/ice/ice_gnss.c
index a1915551c69a..43e199b5b513 100644
--- a/drivers/net/ethernet/intel/ice/ice_gnss.c
+++ b/drivers/net/ethernet/intel/ice/ice_gnss.c
@@ -461,6 +461,9 @@ static struct tty_driver *ice_gnss_create_tty_driver(struct ice_pf *pf)
for (i = 0; i < ICE_GNSS_TTY_MINOR_DEVICES; i++) {
pf->gnss_tty_port[i] = kzalloc(sizeof(*pf->gnss_tty_port[i]),
GFP_KERNEL);
+ if (!pf->gnss_tty_port[i])
+ goto err_out;
+
pf->gnss_serial[i] = NULL;
tty_port_init(pf->gnss_tty_port[i]);
@@ -470,21 +473,23 @@ static struct tty_driver *ice_gnss_create_tty_driver(struct ice_pf *pf)
err = tty_register_driver(tty_driver);
if (err) {
dev_err(dev, "Failed to register TTY driver err=%d\n", err);
-
- for (i = 0; i < ICE_GNSS_TTY_MINOR_DEVICES; i++) {
- tty_port_destroy(pf->gnss_tty_port[i]);
- kfree(pf->gnss_tty_port[i]);
- }
- kfree(ttydrv_name);
- tty_driver_kref_put(pf->ice_gnss_tty_driver);
-
- return NULL;
+ goto err_out;
}
for (i = 0; i < ICE_GNSS_TTY_MINOR_DEVICES; i++)
dev_info(dev, "%s%d registered\n", ttydrv_name, i);
return tty_driver;
+
+err_out:
+ while (i--) {
+ tty_port_destroy(pf->gnss_tty_port[i]);
+ kfree(pf->gnss_tty_port[i]);
+ }
+ kfree(ttydrv_name);
+ tty_driver_kref_put(pf->ice_gnss_tty_driver);
+
+ return NULL;
}
/**
--
2.38.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH net 2/2] ice: Add check for kzalloc
2023-01-09 22:53 ` [PATCH net 2/2] ice: Add check for kzalloc Tony Nguyen
@ 2023-01-10 10:56 ` Leon Romanovsky
2023-01-11 2:26 ` Jakub Kicinski
1 sibling, 0 replies; 8+ messages in thread
From: Leon Romanovsky @ 2023-01-10 10:56 UTC (permalink / raw)
To: Tony Nguyen
Cc: davem, kuba, pabeni, edumazet, Jiasheng Jiang, netdev,
Jiri Pirko, Gurucharan G
On Mon, Jan 09, 2023 at 02:53:58PM -0800, Tony Nguyen wrote:
> From: Jiasheng Jiang <jiasheng@iscas.ac.cn>
>
> Add the check for the return value of kzalloc in order to avoid
> NULL pointer dereference.
> Moreover, use the goto-label to share the clean code.
>
> Fixes: d6b98c8d242a ("ice: add write functionality for GNSS TTY")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> Reviewed-by: Jiri Pirko <jiri@nvidia.com>
> Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
> Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
> ---
> drivers/net/ethernet/intel/ice/ice_gnss.c | 23 ++++++++++++++---------
> 1 file changed, 14 insertions(+), 9 deletions(-)
>
Thanks,
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net 2/2] ice: Add check for kzalloc
2023-01-09 22:53 ` [PATCH net 2/2] ice: Add check for kzalloc Tony Nguyen
2023-01-10 10:56 ` Leon Romanovsky
@ 2023-01-11 2:26 ` Jakub Kicinski
2023-01-11 19:31 ` Tony Nguyen
1 sibling, 1 reply; 8+ messages in thread
From: Jakub Kicinski @ 2023-01-11 2:26 UTC (permalink / raw)
To: Tony Nguyen
Cc: davem, pabeni, edumazet, Jiasheng Jiang, netdev, Jiri Pirko,
Gurucharan G
On Mon, 9 Jan 2023 14:53:58 -0800 Tony Nguyen wrote:
> @@ -470,21 +473,23 @@ static struct tty_driver *ice_gnss_create_tty_driver(struct ice_pf *pf)
> err = tty_register_driver(tty_driver);
> if (err) {
> dev_err(dev, "Failed to register TTY driver err=%d\n", err);
> -
> - for (i = 0; i < ICE_GNSS_TTY_MINOR_DEVICES; i++) {
> - tty_port_destroy(pf->gnss_tty_port[i]);
> - kfree(pf->gnss_tty_port[i]);
> - }
> - kfree(ttydrv_name);
> - tty_driver_kref_put(pf->ice_gnss_tty_driver);
> -
> - return NULL;
> + goto err_out;
FTR I think that depending on i == ICE_GNSS_TTY_MINOR_DEVICES
here is fragile. I can merge as is, since the code is technically
correct, but what you should have done is crate a new label, say
err_unreg_all_ports, do:
goto err_unreg_all_ports;
> }
>
> for (i = 0; i < ICE_GNSS_TTY_MINOR_DEVICES; i++)
> dev_info(dev, "%s%d registered\n", ttydrv_name, i);
>
> return tty_driver;
> +
And here add:
err_unreg_all_ports:
i = ICE_GNSS_TTY_MINOR_DEVICES;
> +err_out:
> + while (i--) {
> + tty_port_destroy(pf->gnss_tty_port[i]);
> + kfree(pf->gnss_tty_port[i]);
> + }
> + kfree(ttydrv_name);
> + tty_driver_kref_put(pf->ice_gnss_tty_driver);
> +
> + return NULL;
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net 0/2][pull request] Intel Wired LAN Driver Updates 2023-01-09 (ice)
2023-01-09 22:53 [PATCH net 0/2][pull request] Intel Wired LAN Driver Updates 2023-01-09 (ice) Tony Nguyen
2023-01-09 22:53 ` [PATCH net 1/2] ice: Fix potential memory leak in ice_gnss_tty_write() Tony Nguyen
2023-01-09 22:53 ` [PATCH net 2/2] ice: Add check for kzalloc Tony Nguyen
@ 2023-01-11 2:30 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 8+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-01-11 2:30 UTC (permalink / raw)
To: Tony Nguyen; +Cc: davem, kuba, pabeni, edumazet, netdev
Hello:
This series was applied to netdev/net.git (master)
by Tony Nguyen <anthony.l.nguyen@intel.com>:
On Mon, 9 Jan 2023 14:53:56 -0800 you wrote:
> This series contains updates to ice driver only.
>
> Jiasheng Jiang frees allocated cmd_buf if write_buf allocation failed to
> prevent memory leak.
>
> Yuan Can adds check, and proper cleanup, of gnss_tty_port allocation call
> to avoid memory leaks.
>
> [...]
Here is the summary with links:
- [net,1/2] ice: Fix potential memory leak in ice_gnss_tty_write()
https://git.kernel.org/netdev/net/c/f58985620f55
- [net,2/2] ice: Add check for kzalloc
https://git.kernel.org/netdev/net/c/40543b3d9d2c
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net 2/2] ice: Add check for kzalloc
2023-01-11 2:26 ` Jakub Kicinski
@ 2023-01-11 19:31 ` Tony Nguyen
2023-01-11 20:01 ` Jakub Kicinski
0 siblings, 1 reply; 8+ messages in thread
From: Tony Nguyen @ 2023-01-11 19:31 UTC (permalink / raw)
To: Jakub Kicinski
Cc: davem, pabeni, edumazet, Jiasheng Jiang, netdev, Jiri Pirko,
Gurucharan G
On 1/10/2023 6:26 PM, Jakub Kicinski wrote:
> On Mon, 9 Jan 2023 14:53:58 -0800 Tony Nguyen wrote:
>> @@ -470,21 +473,23 @@ static struct tty_driver *ice_gnss_create_tty_driver(struct ice_pf *pf)
>> err = tty_register_driver(tty_driver);
>> if (err) {
>> dev_err(dev, "Failed to register TTY driver err=%d\n", err);
>> -
>> - for (i = 0; i < ICE_GNSS_TTY_MINOR_DEVICES; i++) {
>> - tty_port_destroy(pf->gnss_tty_port[i]);
>> - kfree(pf->gnss_tty_port[i]);
>> - }
>> - kfree(ttydrv_name);
>> - tty_driver_kref_put(pf->ice_gnss_tty_driver);
>> -
>> - return NULL;
>> + goto err_out;
>
> FTR I think that depending on i == ICE_GNSS_TTY_MINOR_DEVICES
> here is fragile. I can merge as is, since the code is technically
> correct
Hi Jakub,
Thanks for the suggestion/improvement. This won't be here much longer as
we will be converting to use the kernel infrastructure [1] soon, but
will keep this in mind for the future.
This was mainly to ensure the existing implementations got
corrected/could be backported.
Thanks,
Tony
[1]
https://lore.kernel.org/netdev/20221215231047.3595649-1-anthony.l.nguyen@intel.com/
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net 2/2] ice: Add check for kzalloc
2023-01-11 19:31 ` Tony Nguyen
@ 2023-01-11 20:01 ` Jakub Kicinski
0 siblings, 0 replies; 8+ messages in thread
From: Jakub Kicinski @ 2023-01-11 20:01 UTC (permalink / raw)
To: Tony Nguyen
Cc: davem, pabeni, edumazet, Jiasheng Jiang, netdev, Jiri Pirko,
Gurucharan G
On Wed, 11 Jan 2023 11:31:55 -0800 Tony Nguyen wrote:
> Hi Jakub,
>
> Thanks for the suggestion/improvement. This won't be here much longer as
> we will be converting to use the kernel infrastructure [1] soon, but
> will keep this in mind for the future.
>
> This was mainly to ensure the existing implementations got
> corrected/could be backported.
Ack, to be clear - I did not mean to request a follow up.
Only to suggest a better way of dealing with the error path
for future code.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-01-11 20:05 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-09 22:53 [PATCH net 0/2][pull request] Intel Wired LAN Driver Updates 2023-01-09 (ice) Tony Nguyen
2023-01-09 22:53 ` [PATCH net 1/2] ice: Fix potential memory leak in ice_gnss_tty_write() Tony Nguyen
2023-01-09 22:53 ` [PATCH net 2/2] ice: Add check for kzalloc Tony Nguyen
2023-01-10 10:56 ` Leon Romanovsky
2023-01-11 2:26 ` Jakub Kicinski
2023-01-11 19:31 ` Tony Nguyen
2023-01-11 20:01 ` Jakub Kicinski
2023-01-11 2:30 ` [PATCH net 0/2][pull request] Intel Wired LAN Driver Updates 2023-01-09 (ice) patchwork-bot+netdevbpf
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).