netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][wireless-next] qtnfmac: check band before allocating cmd_skb to avoid resource leak
@ 2017-06-02 15:40 Colin King
  2017-06-02 17:32 ` Igor Mitsyanko
  2017-06-13  7:02 ` [wireless-next] " Kalle Valo
  0 siblings, 2 replies; 3+ messages in thread
From: Colin King @ 2017-06-02 15:40 UTC (permalink / raw)
  To: Igor Mitsyanko, Avinash Patil, Sergey Matyukevich, Kalle Valo,
	Dmitrii Lebed, Huizhao Wang, linux-wireless, netdev
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

The current code allocates cmd_skb and then will leak this if band->band
is an illegal value. It is simpler to sanity check the band first before
allocating cmd_skb so that we don't have to free cmd_skb if an invalid
band occurs.

Detected by CoverityScan, CID#1437561 ("Resource Leak")

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/net/wireless/quantenna/qtnfmac/commands.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/wireless/quantenna/qtnfmac/commands.c b/drivers/net/wireless/quantenna/qtnfmac/commands.c
index f0a0cfa7d8a1..cce62f39edaf 100644
--- a/drivers/net/wireless/quantenna/qtnfmac/commands.c
+++ b/drivers/net/wireless/quantenna/qtnfmac/commands.c
@@ -1300,12 +1300,6 @@ int qtnf_cmd_get_mac_chan_info(struct qtnf_wmac *mac,
 	int ret = 0;
 	u8 qband;
 
-	cmd_skb = qtnf_cmd_alloc_new_cmdskb(mac->macid, 0,
-					    QLINK_CMD_CHANS_INFO_GET,
-					    sizeof(*cmd));
-	if (!cmd_skb)
-		return -ENOMEM;
-
 	switch (band->band) {
 	case NL80211_BAND_2GHZ:
 		qband = QLINK_BAND_2GHZ;
@@ -1320,6 +1314,12 @@ int qtnf_cmd_get_mac_chan_info(struct qtnf_wmac *mac,
 		return -EINVAL;
 	}
 
+	cmd_skb = qtnf_cmd_alloc_new_cmdskb(mac->macid, 0,
+					    QLINK_CMD_CHANS_INFO_GET,
+					    sizeof(*cmd));
+	if (!cmd_skb)
+		return -ENOMEM;
+
 	cmd = (struct qlink_cmd_chans_info_get *)cmd_skb->data;
 	cmd->band = qband;
 	ret = qtnf_cmd_send_with_reply(mac->bus, cmd_skb, &resp_skb, &res_code,
-- 
2.11.0

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

* Re: [PATCH][wireless-next] qtnfmac: check band before allocating cmd_skb to avoid resource leak
  2017-06-02 15:40 [PATCH][wireless-next] qtnfmac: check band before allocating cmd_skb to avoid resource leak Colin King
@ 2017-06-02 17:32 ` Igor Mitsyanko
  2017-06-13  7:02 ` [wireless-next] " Kalle Valo
  1 sibling, 0 replies; 3+ messages in thread
From: Igor Mitsyanko @ 2017-06-02 17:32 UTC (permalink / raw)
  To: Colin King, Avinash Patil, Sergey Matyukevich, Kalle Valo,
	Dmitrii Lebed, Huizhao Wang, linux-wireless, netdev
  Cc: kernel-janitors, linux-kernel

On 06/02/2017 08:40 AM, Colin King wrote:
> External Email
>
>
> From: Colin Ian King <colin.king@canonical.com>
>
> The current code allocates cmd_skb and then will leak this if band->band
> is an illegal value. It is simpler to sanity check the band first before
> allocating cmd_skb so that we don't have to free cmd_skb if an invalid
> band occurs.
>
> Detected by CoverityScan, CID#1437561 ("Resource Leak")
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   drivers/net/wireless/quantenna/qtnfmac/commands.c | 12 ++++++------
>   1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/net/wireless/quantenna/qtnfmac/commands.c b/drivers/net/wireless/quantenna/qtnfmac/commands.c
> index f0a0cfa7d8a1..cce62f39edaf 100644
> --- a/drivers/net/wireless/quantenna/qtnfmac/commands.c
> +++ b/drivers/net/wireless/quantenna/qtnfmac/commands.c
> @@ -1300,12 +1300,6 @@ int qtnf_cmd_get_mac_chan_info(struct qtnf_wmac *mac,
>          int ret = 0;
>          u8 qband;
>
> -       cmd_skb = qtnf_cmd_alloc_new_cmdskb(mac->macid, 0,
> -                                           QLINK_CMD_CHANS_INFO_GET,
> -                                           sizeof(*cmd));
> -       if (!cmd_skb)
> -               return -ENOMEM;
> -
>          switch (band->band) {
>          case NL80211_BAND_2GHZ:
>                  qband = QLINK_BAND_2GHZ;
> @@ -1320,6 +1314,12 @@ int qtnf_cmd_get_mac_chan_info(struct qtnf_wmac *mac,
>                  return -EINVAL;
>          }
>
> +       cmd_skb = qtnf_cmd_alloc_new_cmdskb(mac->macid, 0,
> +                                           QLINK_CMD_CHANS_INFO_GET,
> +                                           sizeof(*cmd));
> +       if (!cmd_skb)
> +               return -ENOMEM;
> +
>          cmd = (struct qlink_cmd_chans_info_get *)cmd_skb->data;
>          cmd->band = qband;
>          ret = qtnf_cmd_send_with_reply(mac->bus, cmd_skb, &resp_skb, &res_code,
> --
> 2.11.0
>
Reviewed-by: Igor Mitsyanko <igor.mitsyanko.os@quantenna.com>

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

* Re: [wireless-next] qtnfmac: check band before allocating cmd_skb to avoid resource leak
  2017-06-02 15:40 [PATCH][wireless-next] qtnfmac: check band before allocating cmd_skb to avoid resource leak Colin King
  2017-06-02 17:32 ` Igor Mitsyanko
@ 2017-06-13  7:02 ` Kalle Valo
  1 sibling, 0 replies; 3+ messages in thread
From: Kalle Valo @ 2017-06-13  7:02 UTC (permalink / raw)
  To: Colin Ian King
  Cc: Igor Mitsyanko, Avinash Patil, Sergey Matyukevich, Dmitrii Lebed,
	Huizhao Wang, linux-wireless, netdev, kernel-janitors,
	linux-kernel

Colin Ian King <colin.king@canonical.com> wrote:

> From: Colin Ian King <colin.king@canonical.com>
> 
> The current code allocates cmd_skb and then will leak this if band->band
> is an illegal value. It is simpler to sanity check the band first before
> allocating cmd_skb so that we don't have to free cmd_skb if an invalid
> band occurs.
> 
> Detected by CoverityScan, CID#1437561 ("Resource Leak")
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> Reviewed-by: Igor Mitsyanko <igor.mitsyanko.os@quantenna.com>

Patch applied to wireless-drivers-next.git, thanks.

bc0384eedb66 qtnfmac: check band before allocating cmd_skb to avoid resource leak

-- 
https://patchwork.kernel.org/patch/9762863/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

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

end of thread, other threads:[~2017-06-13  7:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-02 15:40 [PATCH][wireless-next] qtnfmac: check band before allocating cmd_skb to avoid resource leak Colin King
2017-06-02 17:32 ` Igor Mitsyanko
2017-06-13  7:02 ` [wireless-next] " Kalle Valo

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