Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1303504 > unrolled thread

[PATCH] iwl4965: Fix a null pointer dereference in il_tx_queue_free and il_cmd_queue_free

Started byJia-Ju Bai <baijiaju1990@163.com>
First post2016-01-07 13:00 +0100
Last post2016-01-11 13:20 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] iwl4965: Fix a null pointer dereference in il_tx_queue_free and il_cmd_queue_free Jia-Ju Bai <baijiaju1990@163.com> - 2016-01-07 13:00 +0100
    Re: [PATCH] iwl4965: Fix a null pointer dereference in  il_tx_queue_free and il_cmd_queue_free Stanislaw Gruszka <sgruszka@redhat.com> - 2016-01-11 13:20 +0100

#1303504 — [PATCH] iwl4965: Fix a null pointer dereference in il_tx_queue_free and il_cmd_queue_free

FromJia-Ju Bai <baijiaju1990@163.com>
Date2016-01-07 13:00 +0100
Subject[PATCH] iwl4965: Fix a null pointer dereference in il_tx_queue_free and il_cmd_queue_free
Message-ID<qOhou-7Bh-1@gated-at.bofh.it>
If "txq->cmd = kzalloc(...)" in il_tx_queue_init fails, 
"kfree(txq->cmd[i])" in il_tx_queue_free and il_cmd_queue_free 
in iwl4965_hw_txq_ctx_free will causes a null pointer dereference,
because txq->cmd is NULL at that time.

This patch fixes this problem by adding a if-check before kfree.
To avoid double free in il_tx_queue_free and il_cmd_queue_free 
caused by the fixing, txq->cmd[i], txq->meta and txq->cmd in
error handling code of il_tx_queue_init are assigned null values.
Otherwise, a double free will occur.

This patch has been tested in real device, and it actually fixes the bug.

Signed-off-by: Jia-Ju Bai <baijiaju1990@163.com>
---
 drivers/net/wireless/iwlegacy/common.c |   18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/net/wireless/iwlegacy/common.c b/drivers/net/wireless/iwlegacy/common.c
index 8871145..2656a15 100644
--- a/drivers/net/wireless/iwlegacy/common.c
+++ b/drivers/net/wireless/iwlegacy/common.c
@@ -2794,8 +2794,10 @@ il_tx_queue_free(struct il_priv *il, int txq_id)
 	il_tx_queue_unmap(il, txq_id);
 
 	/* De-alloc array of command/tx buffers */
-	for (i = 0; i < TFD_TX_CMD_SLOTS; i++)
-		kfree(txq->cmd[i]);
+	if (txq->cmd) {
+		for (i = 0; i < TFD_TX_CMD_SLOTS; i++)
+			kfree(txq->cmd[i]);
+	}
 
 	/* De-alloc circular buffer of TFDs */
 	if (txq->q.n_bd)
@@ -2873,8 +2875,10 @@ il_cmd_queue_free(struct il_priv *il)
 	il_cmd_queue_unmap(il);
 
 	/* De-alloc array of command/tx buffers */
-	for (i = 0; i <= TFD_CMD_SLOTS; i++)
-		kfree(txq->cmd[i]);
+	if (txq->cmd) {
+		for (i = 0; i <= TFD_CMD_SLOTS; i++)
+			kfree(txq->cmd[i]);
+	}
 
 	/* De-alloc circular buffer of TFDs */
 	if (txq->q.n_bd)
@@ -3076,11 +3080,15 @@ il_tx_queue_init(struct il_priv *il, u32 txq_id)
 
 	return 0;
 err:
-	for (i = 0; i < actual_slots; i++)
+	for (i = 0; i < actual_slots; i++) {
 		kfree(txq->cmd[i]);
+		txq->cmd[i] = NULL;
+	}
 out_free_arrays:
 	kfree(txq->meta);
+	txq->meta = NULL;
 	kfree(txq->cmd);
+	txq->cmd = NULL;
 
 	return -ENOMEM;
 }
-- 
1.7.9.5


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1306128 — Re: [PATCH] iwl4965: Fix a null pointer dereference in il_tx_queue_free and il_cmd_queue_free

FromStanislaw Gruszka <sgruszka@redhat.com>
Date2016-01-11 13:20 +0100
SubjectRe: [PATCH] iwl4965: Fix a null pointer dereference in il_tx_queue_free and il_cmd_queue_free
Message-ID<qPJC2-2eG-29@gated-at.bofh.it>
In reply to#1303504
On Thu, Jan 07, 2016 at 07:51:38PM +0800, Jia-Ju Bai wrote:
>  err:
> -	for (i = 0; i < actual_slots; i++)
> +	for (i = 0; i < actual_slots; i++) {
>  		kfree(txq->cmd[i]);
> +		txq->cmd[i] = NULL;

I don't think we need this, otherwise patch looks good.

Stanislaw

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web