From patchwork Fri Mar 1 13:51:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Duoming Zhou X-Patchwork-Id: 208864 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp1089284dyb; Fri, 1 Mar 2024 05:52:26 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWwuO+zLLbGMAmHPlpqP4VibNWB8HTlF2oNABtTyFAgGd4Vhp4qrMO6ZqgMeMwC+dOjiceIPlsJDvUXlJ3GKXz3XEUa2g== X-Google-Smtp-Source: AGHT+IH8c9Wn9jrxjVq/H+sYcjHg2zMQzfsfG1GFaOS5wXmK2YBOzV3jeqss61pqkW6WOq++CIDB X-Received: by 2002:a05:6358:5722:b0:17b:f51e:9960 with SMTP id a34-20020a056358572200b0017bf51e9960mr2112019rwf.13.1709301145828; Fri, 01 Mar 2024 05:52:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709301145; cv=pass; d=google.com; s=arc-20160816; b=faFFmbRt2ZbE+aAqlibqYa4yB+6mSn6yr42yhFMqDhIinDtRzU6JfQoY80UUbRqVhu rUDhHrk0aRxlXmgXgnXTR1uhcexT4j40vFmE5Xgsy3nzIBvdFFNOVAWp6805rRzLykeg gY5b0M8XxCNelgnxxOR5pVJD30mI/2PenAV/nJQWszdvLkOBqqonUkU9el6tmN3n3bfp LWNg7G20+fQReSczVtsOI5MTZNSizSZ7PZ+h3vaZ6I86mWNiySuMq+5I+4nL+uqTB4lv AG/Ys5R/PhVk7Ov1lLX29qz9oh2ni+48F009WBcJogB6y+h4PH+d+MaRpcAfjhYFHPg7 ZYzQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:message-id:date :subject:cc:to:from; bh=uJJHs5LZ8KK4nWtoAmOsMFB3tTWqfMpL9+QfiphP9DQ=; fh=0/x6sSBlommb8Fhoa1ZL5Y92glGjMmpikW9SqdkRpSc=; b=ysFHJU+gNH2CtByEVnhijtZf/tpIU84i4WG56zrggkGhZEpWx0nLv2IZ+wiYBDpvW8 kM2cKagnGQuI2M/dqA0yCqVr21jpHqV8dZAJtQ5dh7sirPIsaDssYJmUh/sqGB6loj/E CZ0JIukT3eTQ2Bx8K7RJoOyrw/WNxYq5Vtbuie89BhOXhPeqplu3S3ZXpi14k/2gzW5f 3oNkCMe5nMHmGrWXURw5xbqTGdcTNruS7k/nnecEk7hU/v33BYu1+dMW4ls0YVlRgnou 7s8XqTe8TWuBZxFTPR9foX/bjsGH7KjP6zko7IP5cLAViTlXOdgE7SuoE7gxo5W/W/XS /a+g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=zju.edu.cn); spf=pass (google.com: domain of linux-kernel+bounces-88516-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88516-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 6-20020a0562140cc600b0068f0699ab3csi3765462qvx.400.2024.03.01.05.52.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 05:52:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88516-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=zju.edu.cn); spf=pass (google.com: domain of linux-kernel+bounces-88516-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88516-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 9987D1C21BDA for ; Fri, 1 Mar 2024 13:52:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1A30E6EF16; Fri, 1 Mar 2024 13:52:11 +0000 (UTC) Received: from sgoci-sdnproxy-4.icoremail.net (sgoci-sdnproxy-4.icoremail.net [129.150.39.64]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 51A5D5F84C; Fri, 1 Mar 2024 13:52:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=129.150.39.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709301129; cv=none; b=EiDWXbWMFBav/DmqABUyZulEAaW44N3fuDypw/WkhlzZ9+TmR1KEx+iNd1RkjhXu26pBlYuAV3/ZsIuvd/bWiUrYlM5oYD3esVQsnK6B+QOQgdRHrSpyqN3WlB0U63zIl2fuQpXLdS5ncDWY6nXUU7rWonkWv47kug8/LondUUc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709301129; c=relaxed/simple; bh=Vvdvmn75+7dlWtviPz9CBYNJ1bczhRoIOAinCLpgtxk=; h=From:To:Cc:Subject:Date:Message-Id; b=Ky72xGfP5ddtQBJtDPvmGQRL4hHmQok8q+tYTOOxF5gYbHBlLeOlInwG6oB2mVKZAZobwIcK+0+25Tno0Ku5yP2TaZgCyIj2rjnpBcHhoJx1QcOUOQuEdwN+BdW3esh8AUz3kiAnLJNdwuYn99cCKp+Qd4edsewyeTvhFErsEpw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zju.edu.cn; spf=pass smtp.mailfrom=zju.edu.cn; arc=none smtp.client-ip=129.150.39.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zju.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zju.edu.cn Received: from ubuntu.localdomain (unknown [218.12.19.153]) by mail-app2 (Coremail) with SMTP id by_KCgBXmahn3eFl7391Ag--.39411S2; Fri, 01 Mar 2024 21:51:45 +0800 (CST) From: Duoming Zhou To: linux-kernel@vger.kernel.org Cc: arend.vanspriel@broadcom.com, kvalo@kernel.org, konrad.dybcio@linaro.org, hdegoede@redhat.com, minipli@grsecurity.net, linux-wireless@vger.kernel.org, brcm80211@lists.linux.dev, brcm80211-dev-list.pdl@broadcom.com, Duoming Zhou Subject: [PATCH] wifi: brcmfmac: pcie: handle randbuf allocation failure Date: Fri, 1 Mar 2024 21:51:34 +0800 Message-Id: <20240301135134.29577-1-duoming@zju.edu.cn> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: by_KCgBXmahn3eFl7391Ag--.39411S2 X-Coremail-Antispam: 1UD129KBjvJXoW7XFW3ury5uw18Zw1fJFWDArb_yoW8JF18pa yfJFyjkr1UWw4F9a98GFWxCryYv3ZIy3y2gr4xu3s3uryrAFyFkry0kFyI9r1UCr4Iya47 tFWUtrnxWFsxJ37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9Y14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2 Y2ka0xkIwI1lc7CjxVAaw2AFwI0_Jw0_GFyl42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x 0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2 zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF 4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWU CwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCT nIWIevJa73UjIFyTuYvjfUonmRUUUUU X-CM-SenderInfo: qssqjiasttq6lmxovvfxof0/1tbiAwUHAWXg0lMPlwA1sp Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792332158176251529 X-GMAIL-MSGID: 1792332158176251529 The kzalloc() in brcmf_pcie_download_fw_nvram() will return null if the physical memory has run out. As a result, if we use get_random_bytes() to generate random bytes in the randbuf, the null pointer dereference bug will happen. Return -ENOMEM from brcmf_pcie_download_fw_nvram() if kzalloc() fails for randbuf. Fixes: 91918ce88d9f ("wifi: brcmfmac: pcie: Provide a buffer of random bytes to the device") Signed-off-by: Duoming Zhou --- drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index d7fb88bb6ae..5ab9c902e49 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -1730,6 +1730,8 @@ static int brcmf_pcie_download_fw_nvram(struct brcmf_pciedev_info *devinfo, address -= rand_len; randbuf = kzalloc(rand_len, GFP_KERNEL); + if (!randbuf) + return -ENOMEM; get_random_bytes(randbuf, rand_len); memcpy_toio(devinfo->tcm + address, randbuf, rand_len); kfree(randbuf);