From patchwork Mon Mar 25 20:29:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kangjie Lu X-Patchwork-Id: 10870027 X-Patchwork-Delegate: andy.shevchenko@gmail.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 86B571708 for ; Mon, 25 Mar 2019 20:29:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6FF2628528 for ; Mon, 25 Mar 2019 20:29:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 621CD2857F; Mon, 25 Mar 2019 20:29:34 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 F3AE028528 for ; Mon, 25 Mar 2019 20:29:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729626AbfCYU3d (ORCPT ); Mon, 25 Mar 2019 16:29:33 -0400 Received: from mta-p7.oit.umn.edu ([134.84.196.207]:42016 "EHLO mta-p7.oit.umn.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729473AbfCYU3d (ORCPT ); Mon, 25 Mar 2019 16:29:33 -0400 Received: from localhost (unknown [127.0.0.1]) by mta-p7.oit.umn.edu (Postfix) with ESMTP id 7D84B82A for ; Mon, 25 Mar 2019 20:29:31 +0000 (UTC) X-Virus-Scanned: amavisd-new at umn.edu Received: from mta-p7.oit.umn.edu ([127.0.0.1]) by localhost (mta-p7.oit.umn.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rua1fzCPlojV for ; Mon, 25 Mar 2019 15:29:31 -0500 (CDT) Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mta-p7.oit.umn.edu (Postfix) with ESMTPS id 4832E70F for ; Mon, 25 Mar 2019 15:29:31 -0500 (CDT) Received: by mail-io1-f72.google.com with SMTP id e72so8633827iof.7 for ; Mon, 25 Mar 2019 13:29:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=umn.edu; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cYmBfUfAdcfQUMQk0UUWGDHr6j/vbPBvbhdd4LSLqZQ=; b=W38weuegHoFK7XNJ3IqsYKjWD4x+m4MrZAw0jcu2UqWGPlxtWneJK/lG96AO7/p6su +Gl89dffkOsiUd5zfVe1A/sxW7ci9ZMCcWxy2NutiXKyhTPYtxUls0FETlnA70cUIQdM rZ1xsS4Q1bE9phdDV9FO1X6zu9sQqwRLQzIIOwldknyPKLTqtkcFUMxM3cGiU8Wb013w 7RQPA9sTinmIpwZ+LJaQ2QA4GObqHGD5dknheJAizXMCygS/lg8s5aTOCMOEgzNsS04D ahHPJQmH1nFA94/9HggwbrXT+MLU/M2zDJxveqBfU24StrDPgoJUp/mqBihdCoJc2Y/x 1NBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cYmBfUfAdcfQUMQk0UUWGDHr6j/vbPBvbhdd4LSLqZQ=; b=r7/A5a+r+se58epwW8rupnlfbiM9P+0EWzDcXD6M9N4h3ttsPbEPzzd9DA8D3guRgC E1EL/xkl0d9sUvf4+FGY3xkrPJwYFC/wgly7JoUwCUtD9Q4svmgjEm4ysQ4rUYWf1hti Og/T6t15k6uqNyqMBRo5oRICyDD5O4CUXFlCKcHRwIe0I642Sm1scKqqJD0fDB5ZE+RJ KKev36cKNgXWvEGW5pK3sPU5hxLLTpYvjj185OKi9nPQx6tTTbNa2vvjVqxJVGD5GPnE f2fWV4gf+jLQjFBQEETvS09bq2emns/Jp2w1TtRZ+BmH8czh00o5rvKdZJxgX3Me+Ok3 EUBQ== X-Gm-Message-State: APjAAAVNoSQ/JHCqIe74YHDQQP/UTfrT7zx9u4v+kwAJ3MTBBApLM/aA e4CoickEq/V8MjuVDeLfavdhM/4yIAHDSYUdDz8ysxa/jBde5hJYt92ajd51Fb36ZQiLLdMLhzt ZvXXwxAOvCKk0bwV5PRfk2YyOLk7+3HBRWIU/NQ== X-Received: by 2002:a5e:8f03:: with SMTP id c3mr18105597iok.21.1553545770900; Mon, 25 Mar 2019 13:29:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqxAsSNCzR+kShiTxwq3nOLld0eYMJO8orfDU9EQIdDb+XLLSE+tWn+JPaH8aNGyjkvzTNjkfg== X-Received: by 2002:a5e:8f03:: with SMTP id c3mr18105588iok.21.1553545770685; Mon, 25 Mar 2019 13:29:30 -0700 (PDT) Received: from bee.dtc.umn.edu (cs-bee-u.cs.umn.edu. [128.101.106.63]) by smtp.gmail.com with ESMTPSA id k4sm9620251itc.32.2019.03.25.13.29.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Mar 2019 13:29:29 -0700 (PDT) From: Kangjie Lu To: kjlu@umn.edu Cc: pakki001@umn.edu, Darren Hart , Andy Shevchenko , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, Kees Cook , Andrew Banman , Varsha Rao , Colin Ian King , "Gustavo A. R. Silva" , Nicolai Stange , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] platform: uv: fix missing checks for kcalloc Date: Mon, 25 Mar 2019 15:29:22 -0500 Message-Id: <20190325202924.4624-1-kjlu@umn.edu> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190325125528.GM12016@zn.tnic> References: <20190325125528.GM12016@zn.tnic> Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In case kcalloc fails, the patch return an error to avoid potential NULL pointer dereference. Signed-off-by: Kangjie Lu Reviewed-by: Kees Cook --- v2: reuse existing error path as suggested by Borislav Petkov --- arch/x86/platform/uv/tlb_uv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/x86/platform/uv/tlb_uv.c b/arch/x86/platform/uv/tlb_uv.c index 2c53b0f19329..7b41b51b9a86 100644 --- a/arch/x86/platform/uv/tlb_uv.c +++ b/arch/x86/platform/uv/tlb_uv.c @@ -2133,14 +2133,18 @@ static int __init summarize_uvhub_sockets(int nuvhubs, */ static int __init init_per_cpu(int nuvhubs, int base_part_pnode) { - unsigned char *uvhub_mask; struct uvhub_desc *uvhub_descs; + unsigned char *uvhub_mask = NULL; if (is_uv3_hub() || is_uv2_hub() || is_uv1_hub()) timeout_us = calculate_destination_timeout(); uvhub_descs = kcalloc(nuvhubs, sizeof(struct uvhub_desc), GFP_KERNEL); + if (!uvhub_descs) + goto fail; uvhub_mask = kzalloc((nuvhubs+7)/8, GFP_KERNEL); + if (!uvhub_mask) + goto fail; if (get_cpu_topology(base_part_pnode, uvhub_descs, uvhub_mask)) goto fail;