From patchwork Sat Dec 15 02:32:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Singh X-Patchwork-Id: 10732001 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 385CC1399 for ; Sat, 15 Dec 2018 02:32:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E41A32D1DC for ; Sat, 15 Dec 2018 02:32:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D15E12D1F5; Sat, 15 Dec 2018 02:32:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37BFC2D1DC for ; Sat, 15 Dec 2018 02:32:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727668AbeLOCce (ORCPT ); Fri, 14 Dec 2018 21:32:34 -0500 Received: from esa4.microchip.iphmx.com ([68.232.154.123]:27902 "EHLO esa4.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726609AbeLOCcd (ORCPT ); Fri, 14 Dec 2018 21:32:33 -0500 X-IronPort-AV: E=Sophos;i="5.56,355,1539673200"; d="scan'208";a="23954410" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa4.microchip.iphmx.com with ESMTP/TLS/AES128-SHA; 14 Dec 2018 19:32:33 -0700 Received: from NAM01-SN1-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.76.37) with Microsoft SMTP Server (TLS) id 14.3.352.0; Fri, 14 Dec 2018 19:32:32 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector1-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SOASolXGKVowa1R2NqGKwG3/eao6ZovmfpIKE5EVn80=; b=FvwPK9Dsm3iAv4IQEwKFFDOougCYwxDRoY6adDhAkKSUjGJEW0O+X3j3EZEkr1QCzEoda+yhwL6yOdQ1J7m6NSAPzYt6T+1OrK/oAxhGLH9Ux9v+F3sEewMq52mu/KdXyP91IZ+rM2C6kdRzl8svCIFOR5SEUZojyY1CSRFq/Cg= Received: from BN7PR11MB2562.namprd11.prod.outlook.com (52.135.244.32) by BN7PR11MB2851.namprd11.prod.outlook.com (52.135.246.154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1425.19; Sat, 15 Dec 2018 02:32:29 +0000 Received: from BN7PR11MB2562.namprd11.prod.outlook.com ([fe80::c410:c1c4:ad61:381]) by BN7PR11MB2562.namprd11.prod.outlook.com ([fe80::c410:c1c4:ad61:381%4]) with mapi id 15.20.1425.021; Sat, 15 Dec 2018 02:32:29 +0000 From: To: CC: , , , Subject: [PATCH] staging: wilc1000: fix NULL dereference inside wilc_scan() Thread-Topic: [PATCH] staging: wilc1000: fix NULL dereference inside wilc_scan() Thread-Index: AQHUlB5sTXCQlMXBeESV7dD3h0T68w== Date: Sat, 15 Dec 2018 02:32:29 +0000 Message-ID: <1544841131-9804-1-git-send-email-ajay.kathat@microchip.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MAXPR01CA0089.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:49::31) To BN7PR11MB2562.namprd11.prod.outlook.com (2603:10b6:406:b0::32) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Ajay.Kathat@microchip.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [183.82.18.41] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;BN7PR11MB2851;6:E4RW1cO55q6VKiFEKrztz/fDfs9eErtLeDFRNTMxMTtvzUpmYZdJtmkyta+iFgJ5cNYkar1b25eO3gkwCaeVeQD1EQ9yWrLNnePvDVeAcin7egQBSvL4j/zzAdGHpZfKlgtTmv2dgwaWvuqoOYUPnyxjLQSOOj59G6mIAiJkXyFQgzAngDq6JgXMv7NxIBVuahg4OoD/k3ceNmnNQ26OdPAUNTsH26BqCZ15NJR7DkhdRrL8zbLTbsV1KypRj8fth2tZjDp60thCfVcXvekW8cSKv42/XMN5KUc+LsbLh8f7PdP/0v+4W0/dsyasxKhsDtMNzMBApQhUeBfm9rYiR+AbeKbANwR6vzo0WrR9jvnhUO8I2NQT3f4+Fja9Hft4cbnwiE2IHn5cnFF/UbDaQvROxaEeq/a15iodPcDwF2xaRx11iwRIxTTxZCamOqfUZIqpBqGynSRfOxsiNeWR8w==;5:UDMKahIeEmWURcd6crdsiK2jmWShOEwqTiYwUxTscIHTMmQdkbzT8B3VhHjoSmucqwW8l5cTjexIcIc7ztx1esbRuyqV2qPbUll4qodqJP6RCeKnlXP9OxQ1SQ/MA9V6ll8J34fOtivPuF19mxOClkLvBm+t7U/mVeB90hp22xw=;7:QK+C+n7ltleoasZZcB7Fx/vFHhtQ4qV5+kXcRgmUZZ+DyYb9ZrT5Wex4C0q78/VL2Bb3hYsKqPJDCEuFSCt7KLkibLMc+5tqwxJEkjIsmuoiW/AiBEoFWqmARxB6dA/bE5gmcgclQYD+Ia0a5NmhgQ== x-ms-office365-filtering-correlation-id: c05aca5d-8232-4e2f-9eb1-08d662358ef9 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020);SRVR:BN7PR11MB2851; x-ms-traffictypediagnostic: BN7PR11MB2851: x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(3230021)(999002)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231475)(944501520)(52105112)(10201501046)(3002001)(148016)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(20161123562045)(20161123564045)(201708071742011)(7699051)(76991095);SRVR:BN7PR11MB2851;BCL:0;PCL:0;RULEID:;SRVR:BN7PR11MB2851; x-forefront-prvs: 088751B4D4 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(366004)(346002)(376002)(39860400002)(136003)(396003)(199004)(189003)(4326008)(5660300001)(99286004)(5640700003)(66066001)(2501003)(6916009)(2616005)(476003)(6436002)(2906002)(486006)(107886003)(256004)(105586002)(53936002)(81166006)(8936002)(8676002)(6506007)(2351001)(106356001)(81156014)(386003)(68736007)(6486002)(102836004)(6512007)(71190400001)(186003)(86362001)(575784001)(72206003)(54906003)(478600001)(78486014)(316002)(26005)(97736004)(14454004)(6116002)(52116002)(25786009)(71200400001)(3846002)(7736002)(36756003)(305945005);DIR:OUT;SFP:1101;SCL:1;SRVR:BN7PR11MB2851;H:BN7PR11MB2562.namprd11.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: aOIp4/q93cGZhsn0ARguts+WEgaG0+XucJRy+nciimGPhPwQfVjbpk99ACFkbk7zgLxOsL+fBi7VAREqTa5nRu3S1tqVTupjCjSqT66T5dFvXTYeYv8N/ZRGetGl9lS+kSnQtt+aRCmanXvgLWH6AQHrjzp49+lNkT8oitVy2TJx5IFV9HdLfplnuiEhZNxua+D1XFxUFuHeETWWs3wJ3Bjs3/PnZmDiJ3FtpCm/KiTgZhJNiJgHcGFfl1ZF0WmCcsZPjW3q3dbKAqnY9yySa43xO0vea8TbROlDmhj6+63ZbpTF57pd+3k1fssST8qn spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: c05aca5d-8232-4e2f-9eb1-08d662358ef9 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Dec 2018 02:32:29.5235 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR11MB2851 X-OriginatorOrg: microchip.com Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ajay Singh Added NULL check before accessing 'hidden_net' pointer inside wilc_scan() to fix the issue found by static code checker. Fixes: 8f1a0ac1eba7 ("staging: wilc1000: handle scan operation callback from cfg80211 context") Reported-by: Dan Carpenter Signed-off-by: Ajay Singh --- drivers/staging/wilc1000/host_interface.c | 48 +++++++++++++++++-------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c index b8603f2..70c854d 100644 --- a/drivers/staging/wilc1000/host_interface.c +++ b/drivers/staging/wilc1000/host_interface.c @@ -246,27 +246,29 @@ int wilc_scan(struct wilc_vif *vif, u8 scan_source, u8 scan_type, hif_drv->usr_scan_req.ch_cnt = 0; - wid_list[index].id = WID_SSID_PROBE_REQ; - wid_list[index].type = WID_STR; - - for (i = 0; i < hidden_net->n_ssids; i++) - valuesize += ((hidden_net->net_info[i].ssid_len) + 1); - hdn_ntwk_wid_val = kmalloc(valuesize + 1, GFP_KERNEL); - wid_list[index].val = hdn_ntwk_wid_val; - if (wid_list[index].val) { - buffer = wid_list[index].val; - - *buffer++ = hidden_net->n_ssids; - - for (i = 0; i < hidden_net->n_ssids; i++) { - *buffer++ = hidden_net->net_info[i].ssid_len; - memcpy(buffer, hidden_net->net_info[i].ssid, - hidden_net->net_info[i].ssid_len); - buffer += hidden_net->net_info[i].ssid_len; - } + if (hidden_net) { + wid_list[index].id = WID_SSID_PROBE_REQ; + wid_list[index].type = WID_STR; + + for (i = 0; i < hidden_net->n_ssids; i++) + valuesize += ((hidden_net->net_info[i].ssid_len) + 1); + hdn_ntwk_wid_val = kmalloc(valuesize + 1, GFP_KERNEL); + wid_list[index].val = hdn_ntwk_wid_val; + if (wid_list[index].val) { + buffer = wid_list[index].val; + + *buffer++ = hidden_net->n_ssids; + + for (i = 0; i < hidden_net->n_ssids; i++) { + *buffer++ = hidden_net->net_info[i].ssid_len; + memcpy(buffer, hidden_net->net_info[i].ssid, + hidden_net->net_info[i].ssid_len); + buffer += hidden_net->net_info[i].ssid_len; + } - wid_list[index].size = (s32)(valuesize + 1); - index++; + wid_list[index].size = (s32)(valuesize + 1); + index++; + } } wid_list[index].id = WID_INFO_ELEMENT_PROBE; @@ -316,8 +318,10 @@ int wilc_scan(struct wilc_vif *vif, u8 scan_source, u8 scan_type, jiffies + msecs_to_jiffies(HOST_IF_SCAN_TIMEOUT)); error: - kfree(hidden_net->net_info); - kfree(hdn_ntwk_wid_val); + if (hidden_net) { + kfree(hidden_net->net_info); + kfree(hdn_ntwk_wid_val); + } return result; }