From patchwork Fri Mar 18 02:24:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Calaby X-Patchwork-Id: 8615801 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1A411C0553 for ; Fri, 18 Mar 2016 02:24:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 254A520328 for ; Fri, 18 Mar 2016 02:24:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3FF74202FE for ; Fri, 18 Mar 2016 02:24:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752637AbcCRCYQ (ORCPT ); Thu, 17 Mar 2016 22:24:16 -0400 Received: from mail-pf0-f178.google.com ([209.85.192.178]:36190 "EHLO mail-pf0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751361AbcCRCYP (ORCPT ); Thu, 17 Mar 2016 22:24:15 -0400 Received: by mail-pf0-f178.google.com with SMTP id u190so146135248pfb.3 for ; Thu, 17 Mar 2016 19:24:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sZNPMsiGoxdmNodLTdIluWYiqA0YlaKRrP1y3BKYjKM=; b=IAYwYvEc/ASCn7qq4VpOte/38uvNdGcgpN3EgaE33gi6CNkJabySBrgxb86TUWwn/E Xd2QaWg8ZIVNA5cujNbqxrYm6B4QJ5oqrlEQnJVsgzG5/B8xoG9oCMOxKqgS5qD1SjoK eMkPXzJbosweaXYkm9xNl6cnlcaGHPn6arxCGsJ+9zW4eWXPEnVIF+nK5tnhqopfQPde Xg7uINfcxiF3641wrUxZzq88KcNHot/+flScpb67NGRQYONr/g9+goHjaxV+zzaodKz2 gkmUPXFK6BtaKBKjKNCoHcjhGXMHCQBQk0eOkYCwt+k1qhk03UsCqlfCgz8icFAupYjR fTmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sZNPMsiGoxdmNodLTdIluWYiqA0YlaKRrP1y3BKYjKM=; b=a1GNoRox9DhtpkPJILJFhSOjUFe8QZKsO6EWNI/j9HLXblYBYzodbtgesfmhZaF09a /gml347/fu0m4e6hjx4/9zTNPjx4pcksLoeDAS1KvX4qld451BU7oGGOmC+9mzT33B+8 nSHvB85MttsGA1nH8k/lB4Qd9dCHdymOwKD/RIbjvw27xHacI6AcvKwCZB0NQtYhe6aw sSSUfiXNxFwaYnL+7JFc5F9lHY8v2Pu5aii9kzRSldFvJTlmJT4n6nueVJSVK8lcP2Or eqM4jy81+LHqSjp7w0csisqosS2bfwp6r6jmWSO29i4AG7jpQheCZlosOEIi0nP2r8Gf i/XA== X-Gm-Message-State: AD7BkJJsL0x4wxAGdHeRMQ9EJYwZALl4u64jwj7GyMq3V/NezPH+CAbOIxv2OM/Py9XKbA== X-Received: by 10.98.33.203 with SMTP id o72mr20039656pfj.96.1458267854102; Thu, 17 Mar 2016 19:24:14 -0700 (PDT) Received: from multimedia.lan (C-59-101-14-180.hay.connect.net.au. [59.101.14.180]) by smtp.gmail.com with ESMTPSA id rw2sm16392680pab.30.2016.03.17.19.24.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 17 Mar 2016 19:24:13 -0700 (PDT) From: Julian Calaby To: Kalle Valo Cc: Stanislaw Gruszka , Markus Elfring , Dan Carpenter , Jia-Ju Bai , Arnd Bergmann , linux-wireless@vger.kernel.org Subject: [PATCH 09/19] iwl4965: Fix a null pointer dereference in il_tx_queue_free and il_cmd_queue_free Date: Fri, 18 Mar 2016 13:24:06 +1100 Message-Id: <81035f8a7a40653b5ec61e1e6dcb02d1a0db92a6.1458262312.git.julian.calaby@gmail.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: References: Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jia-Ju Bai 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->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. Thanks Stanislaw for his suggestion. Signed-off-by: Jia-Ju Bai Acked-by: Stanislaw Gruszka Signed-off-by: Julian Calaby --- drivers/net/wireless/intel/iwlegacy/common.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/intel/iwlegacy/common.c b/drivers/net/wireless/intel/iwlegacy/common.c index c3afaf7..2cc3d42 100644 --- a/drivers/net/wireless/intel/iwlegacy/common.c +++ b/drivers/net/wireless/intel/iwlegacy/common.c @@ -2792,8 +2792,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) @@ -2871,8 +2873,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) @@ -3078,7 +3082,9 @@ err: kfree(txq->cmd[i]); out_free_arrays: kfree(txq->meta); + txq->meta = NULL; kfree(txq->cmd); + txq->cmd = NULL; return -ENOMEM; }