From patchwork Fri May 15 08:33:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?SsOpcsO0bWUgUG91aWxsZXI=?= X-Patchwork-Id: 215605 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E654C433E0 for ; Fri, 15 May 2020 08:34:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DB7A120657 for ; Fri, 15 May 2020 08:34:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=silabs.onmicrosoft.com header.i=@silabs.onmicrosoft.com header.b="YjiIkmVJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728056AbgEOIeE (ORCPT ); Fri, 15 May 2020 04:34:04 -0400 Received: from mail-dm6nam11on2086.outbound.protection.outlook.com ([40.107.223.86]:6138 "EHLO NAM11-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728015AbgEOIeD (ORCPT ); Fri, 15 May 2020 04:34:03 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TpkibvZ71J4dIkCBQJhw3yWeGefBLq1nNS/VPhhOO4g/vIfBUDYpxfWmIK57STWUxBwNHhXkHPYnl0IM9tl0CiIIqQau8F5mFAYi5eJ5toXPUxudzzMFPjb7/2m0SuOpRRwfSWYC6COmnipOKoITh59P2CoKMtDW9gPURU2VqvoUfNkn6hFZ/fDL5hpizxeB+FUjq6MuJ/O4wfrG0rDWBtZp3ekEzfmsnWyTRxXhwu0AXklDpggW2eCXOb+E3Xad/GJBOhNM0QdRRZKN0aJRdIrIABz8uUKRP7pdz1u4t3rj7cFI2K8rVH0uX+PvaxPu6SB79sFp2ZGMU30CL5M28A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gUUFM756JXmxwyceH0imV4Uq4UE4xaRnUvhSWgljqwY=; b=es8L4ZNb0Zj0SvlyJPFPNtlSRnpmLvGvAv5zX4EV8IMrtSsKiKqWZwf7/220HaE2IAD1DtgiRhIGAUIubZFPcITjwQ+WXHFXa1D+fQhjArdZrfQTPmpgilozmVWzr/7X7fyCkYLf/b77KnJlgRGTlNz4J1fKcuj9taLaqtbFIyOPZ1ovazf0+kjR8L0O95xVgIcNY1N7+zACLWwoCFbaO1Pg1k3A6XB1bygxIF5OgyLCgqlzwXzb7hEFgJ43z8P88/o+aBTVF9dn6jcAzaJ6ODhu/AbJxHh9KW2bIRmfjjThO3xzheBbcu5vgdTo8dtboghX1ixYn6WG/tn16OmqLg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=silabs.com; dmarc=pass action=none header.from=silabs.com; dkim=pass header.d=silabs.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silabs.onmicrosoft.com; s=selector2-silabs-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gUUFM756JXmxwyceH0imV4Uq4UE4xaRnUvhSWgljqwY=; b=YjiIkmVJIM5Uv9WWiF4EGceAt1g21Yz8CRU1gJOrA5okJJa+mNloAqqGPLcRsv1ieit/P8/WOSk2IbCAfQpP//O37HjWKcsLHi4wWDrJ4q2wghgewlCT7MEorax+ckBHIIMa6DJqlWTTZMjq4V4WqNJKGHnLcwHRHljPCCkrLNs= Authentication-Results: driverdev.osuosl.org; dkim=none (message not signed) header.d=none; driverdev.osuosl.org; dmarc=none action=none header.from=silabs.com; Received: from MWHPR11MB1775.namprd11.prod.outlook.com (2603:10b6:300:10e::14) by MWHPR11MB1310.namprd11.prod.outlook.com (2603:10b6:300:28::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.26; Fri, 15 May 2020 08:33:54 +0000 Received: from MWHPR11MB1775.namprd11.prod.outlook.com ([fe80::e055:3e6d:ff4:56da]) by MWHPR11MB1775.namprd11.prod.outlook.com ([fe80::e055:3e6d:ff4:56da%5]) with mapi id 15.20.3000.022; Fri, 15 May 2020 08:33:54 +0000 From: Jerome Pouiller To: devel@driverdev.osuosl.org, linux-wireless@vger.kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Kalle Valo , "David S . Miller" , =?utf-8?b?SsOpcsO0bWUgUG91aWxsZXI=?= , Dan Carpenter Subject: [PATCH 03/19] staging: wfx: check pointers returned by allocations Date: Fri, 15 May 2020 10:33:09 +0200 Message-Id: <20200515083325.378539-4-Jerome.Pouiller@silabs.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200515083325.378539-1-Jerome.Pouiller@silabs.com> References: <20200515083325.378539-1-Jerome.Pouiller@silabs.com> X-ClientProxiedBy: PR0P264CA0076.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:18::16) To MWHPR11MB1775.namprd11.prod.outlook.com (2603:10b6:300:10e::14) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from pc-42.home (82.67.86.106) by PR0P264CA0076.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:18::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.24 via Frontend Transport; Fri, 15 May 2020 08:33:52 +0000 X-Mailer: git-send-email 2.26.2 X-Originating-IP: [82.67.86.106] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 25e9ad93-f6aa-477b-a8d6-08d7f8aab3bc X-MS-TrafficTypeDiagnostic: MWHPR11MB1310: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:109; X-Forefront-PRVS: 04041A2886 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FLRmaPrFR66IoO0pAxMYHXEZCjzcX/QrAXudOW1o8Hn7wuW/enUF0PYhhs1N88iEJTi7MasXm8ghdSfo4J13SZW27WuEGVkpFDAkK8/ftG4/P2khXM5ZPo26vqFhGKFhLX0eRrhwMoWRAEzt8wfFGJZtGf93INxDXFyyARBHbpsuMwHjZ00nix7Wmuihl3Upg+UZLfjoj7WvaSD77ZHAZIABEOBtRcnoG5Cp0bXc5mm9A61qG+2ypbxfNxtWDDiANss3NQkBARiKLDZTVV4eVbAPIFPHThObvjMxrGEmNvh9CmJZuWXD6XF9R3VnxG/OzSHOf0voKhxv/8qIEXIVrc3H4E4ExaEdtjce9jlpp9EDB9iR8exlb5zMAl/0om+7EYWZF0gCtyqXsBe0jnMsFQ+dSwD14963gY/BHBnkWHjc/wdsAXbeg4NWbuWwj5zrAElybfE1NhuWlkgD+rEw7QiDQvyBBVY1Hs8t9GK37TewIyAV2xD7LLwnYnCEqx42WwuQZKRJtQSzFiMO6Ja5UQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MWHPR11MB1775.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(346002)(136003)(376002)(366004)(39850400004)(396003)(8886007)(66556008)(186003)(6512007)(66946007)(966005)(6506007)(36756003)(316002)(66476007)(26005)(52116002)(16526019)(6666004)(54906003)(2906002)(2616005)(478600001)(66574014)(956004)(8936002)(86362001)(8676002)(6486002)(5660300002)(4326008)(1076003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Qgr5o1s4VthL720BE1UX9vjTTrHrVy2iWQQ+bEb0wBnCf9AEDtKCtduoMzQKnj/GoLAhpLBO3TcWVpxVE6ImNTKJ6mOBNCLpNOJRkqIMtiSwvO+D8rcuuCwWnaw+Aj+UgyVM9leips5HJbdhSH6ToM22OWzTlj6Sm5/KVbI0T3N8+ExBBOP0hK7dsh9Mf2nybrWSOTan691ixYEiukUuQ6y04PmNPuD2IE2nCcRc8Mv3n4G4SCxmuguOUh5U4PVYf9bV7RWwoeyIqUZ2HuMsZfIlaeGda3EEm4p6TjEcIbFkw8mos0m52V44OPkKWhzOiyjfoXrVLGE8wC4oWcFjYqfvpLFRejoFKEUTxB0lapULZ3/ycIzdJznU68uT2hvzjnngF1XN7cn9IJtkea2HrC2ENrAlU7SK6iKVbScFU3v+kmBb3K3Navanmdv5HN15cRuIVkUMHloyvQWQHTOKCYQi6geplIduEQPejVycQ64= X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: 25e9ad93-f6aa-477b-a8d6-08d7f8aab3bc X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 May 2020 08:33:54.0988 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 54dbd822-5231-4b20-944d-6f4abcd541fb X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: N3RxXwmsGbRVC4kGAv/lAtFC2bJNvuEr2EZ6s2UEx7klkVU/NlSzmFZcQ96JDhqUyFux5U3GjmOGYxXmj7yQNA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR11MB1310 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Jérôme Pouiller Until now, the driver did not always check if the allocations success. The issue was discussed here: https://lore.kernel.org/netdev/2026476.QLiXXEGFCf@pc-42/ Reported-by: Dan Carpenter Signed-off-by: Jérôme Pouiller --- drivers/staging/wfx/hif_tx.c | 43 ++++++++++++++++++++++++++++++++ drivers/staging/wfx/hif_tx_mib.c | 2 ++ 2 files changed, 45 insertions(+) diff --git a/drivers/staging/wfx/hif_tx.c b/drivers/staging/wfx/hif_tx.c index 58adfaf8066d..1cb71f0ad804 100644 --- a/drivers/staging/wfx/hif_tx.c +++ b/drivers/staging/wfx/hif_tx.c @@ -134,6 +134,8 @@ int hif_shutdown(struct wfx_dev *wdev) if (wdev->chip_frozen) return 0; wfx_alloc_hif(0, &hif); + if (!hif) + return -ENOMEM; wfx_fill_header(hif, -1, HIF_REQ_ID_SHUT_DOWN, 0); ret = wfx_cmd_send(wdev, hif, NULL, 0, true); // After this command, chip won't reply. Be sure to give enough time to @@ -157,6 +159,8 @@ int hif_configuration(struct wfx_dev *wdev, const u8 *conf, size_t len) struct hif_msg *hif; struct hif_req_configuration *body = wfx_alloc_hif(buf_len, &hif); + if (!hif) + return -ENOMEM; body->length = cpu_to_le16(len); memcpy(body->pds_data, conf, len); wfx_fill_header(hif, -1, HIF_REQ_ID_CONFIGURATION, buf_len); @@ -171,6 +175,8 @@ int hif_reset(struct wfx_vif *wvif, bool reset_stat) struct hif_msg *hif; struct hif_req_reset *body = wfx_alloc_hif(sizeof(*body), &hif); + if (!hif) + return -ENOMEM; body->reset_flags.reset_stat = reset_stat; wfx_fill_header(hif, wvif->id, HIF_REQ_ID_RESET, sizeof(*body)); ret = wfx_cmd_send(wvif->wdev, hif, NULL, 0, false); @@ -187,6 +193,10 @@ int hif_read_mib(struct wfx_dev *wdev, int vif_id, u16 mib_id, struct hif_req_read_mib *body = wfx_alloc_hif(sizeof(*body), &hif); struct hif_cnf_read_mib *reply = kmalloc(buf_len, GFP_KERNEL); + if (!body || !reply) { + ret = -ENOMEM; + goto out; + } body->mib_id = cpu_to_le16(mib_id); wfx_fill_header(hif, vif_id, HIF_REQ_ID_READ_MIB, sizeof(*body)); ret = wfx_cmd_send(wdev, hif, reply, buf_len, false); @@ -204,6 +214,7 @@ int hif_read_mib(struct wfx_dev *wdev, int vif_id, u16 mib_id, memcpy(val, &reply->mib_data, le16_to_cpu(reply->length)); else memset(val, 0xFF, val_len); +out: kfree(hif); kfree(reply); return ret; @@ -217,6 +228,8 @@ int hif_write_mib(struct wfx_dev *wdev, int vif_id, u16 mib_id, int buf_len = sizeof(struct hif_req_write_mib) + val_len; struct hif_req_write_mib *body = wfx_alloc_hif(buf_len, &hif); + if (!hif) + return -ENOMEM; body->mib_id = cpu_to_le16(mib_id); body->length = cpu_to_le16(val_len); memcpy(&body->mib_data, val, val_len); @@ -241,6 +254,8 @@ int hif_scan(struct wfx_vif *wvif, struct cfg80211_scan_request *req, compiletime_assert(IEEE80211_MAX_SSID_LEN == HIF_API_SSID_SIZE, "API inconsistency"); + if (!hif) + return -ENOMEM; for (i = 0; i < req->n_ssids; i++) { memcpy(body->ssid_def[i].ssid, req->ssids[i].ssid, IEEE80211_MAX_SSID_LEN); @@ -288,6 +303,8 @@ int hif_stop_scan(struct wfx_vif *wvif) // body associated to HIF_REQ_ID_STOP_SCAN is empty wfx_alloc_hif(0, &hif); + if (!hif) + return -ENOMEM; wfx_fill_header(hif, wvif->id, HIF_REQ_ID_STOP_SCAN, 0); ret = wfx_cmd_send(wvif->wdev, hif, NULL, 0, false); kfree(hif); @@ -305,6 +322,8 @@ int hif_join(struct wfx_vif *wvif, const struct ieee80211_bss_conf *conf, WARN_ON(!conf->basic_rates); WARN_ON(sizeof(body->ssid) < ssidlen); WARN(!conf->ibss_joined && !ssidlen, "joining an unknown BSS"); + if (!hif) + return -ENOMEM; body->infrastructure_bss_mode = !conf->ibss_joined; body->short_preamble = conf->use_short_preamble; if (channel && channel->flags & IEEE80211_CHAN_NO_IR) @@ -333,6 +352,8 @@ int hif_set_bss_params(struct wfx_vif *wvif, int aid, int beacon_lost_count) struct hif_req_set_bss_params *body = wfx_alloc_hif(sizeof(*body), &hif); + if (!hif) + return -ENOMEM; body->aid = cpu_to_le16(aid); body->beacon_lost_count = beacon_lost_count; wfx_fill_header(hif, wvif->id, HIF_REQ_ID_SET_BSS_PARAMS, @@ -349,6 +370,8 @@ int hif_add_key(struct wfx_dev *wdev, const struct hif_req_add_key *arg) // FIXME: only send necessary bits struct hif_req_add_key *body = wfx_alloc_hif(sizeof(*body), &hif); + if (!hif) + return -ENOMEM; // FIXME: swap bytes as necessary in body memcpy(body, arg, sizeof(*body)); if (wfx_api_older_than(wdev, 1, 5)) @@ -369,6 +392,8 @@ int hif_remove_key(struct wfx_dev *wdev, int idx) struct hif_msg *hif; struct hif_req_remove_key *body = wfx_alloc_hif(sizeof(*body), &hif); + if (!hif) + return -ENOMEM; body->entry_index = idx; wfx_fill_header(hif, -1, HIF_REQ_ID_REMOVE_KEY, sizeof(*body)); ret = wfx_cmd_send(wdev, hif, NULL, 0, false); @@ -388,6 +413,8 @@ int hif_set_edca_queue_params(struct wfx_vif *wvif, u16 queue, return -ENOMEM; WARN_ON(arg->aifs > 255); + if (!hif) + return -ENOMEM; body->aifsn = arg->aifs; body->cw_min = cpu_to_le16(arg->cw_min); body->cw_max = cpu_to_le16(arg->cw_max); @@ -414,6 +441,8 @@ int hif_set_pm(struct wfx_vif *wvif, bool ps, int dynamic_ps_timeout) if (!body) return -ENOMEM; + if (!hif) + return -ENOMEM; if (ps) { body->pm_mode.enter_psm = 1; // Firmware does not support more than 128ms @@ -435,6 +464,8 @@ int hif_start(struct wfx_vif *wvif, const struct ieee80211_bss_conf *conf, struct hif_req_start *body = wfx_alloc_hif(sizeof(*body), &hif); WARN_ON(!conf->beacon_int); + if (!hif) + return -ENOMEM; body->dtim_period = conf->dtim_period; body->short_preamble = conf->use_short_preamble; body->channel_number = channel->hw_value; @@ -456,6 +487,8 @@ int hif_beacon_transmit(struct wfx_vif *wvif, bool enable) struct hif_req_beacon_transmit *body = wfx_alloc_hif(sizeof(*body), &hif); + if (!hif) + return -ENOMEM; body->enable_beaconing = enable ? 1 : 0; wfx_fill_header(hif, wvif->id, HIF_REQ_ID_BEACON_TRANSMIT, sizeof(*body)); @@ -470,6 +503,8 @@ int hif_map_link(struct wfx_vif *wvif, u8 *mac_addr, int flags, int sta_id) struct hif_msg *hif; struct hif_req_map_link *body = wfx_alloc_hif(sizeof(*body), &hif); + if (!hif) + return -ENOMEM; if (mac_addr) ether_addr_copy(body->mac_addr, mac_addr); body->map_link_flags = *(struct hif_map_link_flags *)&flags; @@ -487,6 +522,8 @@ int hif_update_ie_beacon(struct wfx_vif *wvif, const u8 *ies, size_t ies_len) int buf_len = sizeof(struct hif_req_update_ie) + ies_len; struct hif_req_update_ie *body = wfx_alloc_hif(buf_len, &hif); + if (!hif) + return -ENOMEM; body->ie_flags.beacon = 1; body->num_ies = cpu_to_le16(1); memcpy(body->ie, ies, ies_len); @@ -504,6 +541,8 @@ int hif_sl_send_pub_keys(struct wfx_dev *wdev, struct hif_req_sl_exchange_pub_keys *body = wfx_alloc_hif(sizeof(*body), &hif); + if (!hif) + return -ENOMEM; body->algorithm = HIF_SL_CURVE25519; memcpy(body->host_pub_key, pubkey, sizeof(body->host_pub_key)); memcpy(body->host_pub_key_mac, pubkey_hmac, @@ -524,6 +563,8 @@ int hif_sl_config(struct wfx_dev *wdev, const unsigned long *bitmap) struct hif_msg *hif; struct hif_req_sl_configure *body = wfx_alloc_hif(sizeof(*body), &hif); + if (!hif) + return -ENOMEM; memcpy(body->encr_bmp, bitmap, sizeof(body->encr_bmp)); wfx_fill_header(hif, -1, HIF_REQ_ID_SL_CONFIGURE, sizeof(*body)); ret = wfx_cmd_send(wdev, hif, NULL, 0, false); @@ -538,6 +579,8 @@ int hif_sl_set_mac_key(struct wfx_dev *wdev, const u8 *slk_key, int destination) struct hif_req_set_sl_mac_key *body = wfx_alloc_hif(sizeof(*body), &hif); + if (!hif) + return -ENOMEM; memcpy(body->key_value, slk_key, sizeof(body->key_value)); body->otp_or_ram = destination; wfx_fill_header(hif, -1, HIF_REQ_ID_SET_SL_MAC_KEY, sizeof(*body)); diff --git a/drivers/staging/wfx/hif_tx_mib.c b/drivers/staging/wfx/hif_tx_mib.c index 567c61d1fe2e..1689cb42acc0 100644 --- a/drivers/staging/wfx/hif_tx_mib.c +++ b/drivers/staging/wfx/hif_tx_mib.c @@ -222,6 +222,8 @@ int hif_set_tx_rate_retry_policy(struct wfx_vif *wvif, int ret; arg = kzalloc(size, GFP_KERNEL); + if (!arg) + return -ENOMEM; arg->num_tx_rate_policies = 1; arg->tx_rate_retry_policy[0].policy_index = policy_index; arg->tx_rate_retry_policy[0].short_retry_count = 255;