From patchwork Sun Jan 10 02:19:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia-Ju Bai X-Patchwork-Id: 7993931 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B306D9F6CD for ; Sun, 10 Jan 2016 02:20:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CCAB020259 for ; Sun, 10 Jan 2016 02:20:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CA68D20204 for ; Sun, 10 Jan 2016 02:20:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756704AbcAJCTP (ORCPT ); Sat, 9 Jan 2016 21:19:15 -0500 Received: from m12-11.163.com ([220.181.12.11]:46018 "EHLO m12-11.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756634AbcAJCTO (ORCPT ); Sat, 9 Jan 2016 21:19:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=mC1CLUalcr3LqztLsm cb8RQu+Nu/66ep65qgxXmdPtg=; b=fiiasFMyjWcrHYEkL5Ccr7gv3fZ8dxvf0T CrYr8dfLN95z1MfXUNkkPzRyEjv+dQ1uqYFk6+iEP4ak/rNLJrcpyls1Q97TX0+V kULfCq5rtitBnJ/CO/UV8tMfnfohcF8k9+TdSjs0q/MSZYiqhlpWSDiAkuGef5EM lHdZfxvCI= Received: from bai-oslab.tsinghua.edu.cn (unknown [166.111.70.16]) by smtp7 (Coremail) with SMTP id C8CowECZgECKv5FWYzZ6AA--.1697S2; Sun, 10 Jan 2016 10:18:55 +0800 (CST) From: Jia-Ju Bai To: sgruszka@redhat.com, kvalo@codeaurora.org, johannes.berg@intel.com, emmanuel.grumbach@intel.com Cc: ilw@linux.intel.com, linuxwifi@intel.com, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] iwl4965: Fix a null pointer dereference in il_tx_queue_free and il_cmd_queue_free Date: Sun, 10 Jan 2016 10:19:09 +0800 Message-Id: <1452392349-3561-1-git-send-email-baijiaju1990@163.com> X-Mailer: git-send-email 1.7.9.5 X-CM-TRANSID: C8CowECZgECKv5FWYzZ6AA--.1697S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7CryUWFyUuFyUCF4UZFy3XFb_yoW8ur1xpF W3Cr90ka1DXF42grZFyF48Z3W5X3Z5Jr47Wayru3s0yr1fCFyFvF1IyF1F9rWkuanFka40 vrWq9F1rWr1UArDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07USjgsUUUUU= X-Originating-IP: [166.111.70.16] X-CM-SenderInfo: xedlyx5dmximizq6il2tof0z/1tbipRDrelUL9PDRXQAAsy 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_SIGNED, FREEMAIL_FROM,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable 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 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 --- 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; }