Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1009528pxb; Wed, 1 Sep 2021 15:11:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqzLYMxVk7RG816dYuov1ju6a1/021W7wi3/zO+c0oaITbVZUJ4yTCHiqN0bo2ao7A6+oB X-Received: by 2002:a17:906:408c:: with SMTP id u12mr26556ejj.413.1630534283168; Wed, 01 Sep 2021 15:11:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630534283; cv=none; d=google.com; s=arc-20160816; b=YiFFGENrLxN0VvPrEbSgrUtgt4R91UdJ3Uw3oVVdukvzIQT06EziLJLA8TzaVqFRIu 3uL2Xg4YtdeiIh7OTH4Mk3chmSX+tz9ueksult8tZOhQ9FpVjnJUhGNpJTND9Y/sH0Nf Et921+0rhdz1g0DPse5p6lcdVbbPDlXJPaSPr+jgrouZX0ZT+C8/BLQjiC8ZLGHGI5VM Ekb3ZUA4+6VpzDJMgWPvWVo8IJ9gUNmVoyxAwAfHhQhe1W+azNJfxOigNhGuQ4CSaniH qa7/wXqbNGFJIXbYKEmjmru4RQLdXGwcxzYP9FbdQHFhUs+fWWV6DeT6GPCsWW+36nTA iyoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=E0X4tHaw6Jokozr3sHxiec29YWEXiP0pTIEa57+rj6Y=; b=nLlb2gJP46YMtcX1J8GnwjzQTeMs72Y7P44inAklTs0GRf9dysj4x2LyzYIsjWJNX7 vLc3Lv44RzhCbE0QAIFo890cunpWlw3jBXg/6XzbhRlETjU+UVghb5RqtU11/gv3n5wE XnvB2AjOf4AAx2vP7rZECCNtZmn/QDglqU0cnkNS+jQL+CW6cZUEB7bX2PnLqkuLU4yM tiP6BWOU4Wwl3o2UHOHP05FhX94a5Vlme2fQE7/7AspOWTRTjvNq0pQDHqCUks0NihAj MV56CYqVEW9CovG4YpLAZDoHSze6PYFIYh1KumNBUU4nB4HxJpNeubuYrrN2ApcMJ7g7 b6Gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tcDW17OX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v18si41199edc.149.2021.09.01.15.10.48; Wed, 01 Sep 2021 15:11:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tcDW17OX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244325AbhIAM2r (ORCPT + 99 others); Wed, 1 Sep 2021 08:28:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:58128 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244332AbhIAM2c (ORCPT ); Wed, 1 Sep 2021 08:28:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A18F86101B; Wed, 1 Sep 2021 12:27:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1630499256; bh=m+aPwWsJcspwQAYpDPatNck7V0kmt2ZB6VygYcXBdLI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tcDW17OXaTDE4IKMPqY2SeM4viO4U2Ajlt6+/OO3MYNmC9exrFjUJZxEfIg0gxREp ZIcaqrAmIpNlKkc+fAcRln96m9cODB4/0KkC39Ec/0fn0qN3a4KMDEB1P4ViuZ0x79 UH1NNyFWE4dDpoJ4+8mX00Yw0G5kPyeQJs88oRa8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, TOTE Robot , Tuo Li , Mike Marciniszyn , Jason Gunthorpe , Sasha Levin Subject: [PATCH 4.9 06/16] IB/hfi1: Fix possible null-pointer dereference in _extend_sdma_tx_descs() Date: Wed, 1 Sep 2021 14:26:32 +0200 Message-Id: <20210901122249.116885140@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210901122248.920548099@linuxfoundation.org> References: <20210901122248.920548099@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tuo Li [ Upstream commit cbe71c61992c38f72c2b625b2ef25916b9f0d060 ] kmalloc_array() is called to allocate memory for tx->descp. If it fails, the function __sdma_txclean() is called: __sdma_txclean(dd, tx); However, in the function __sdma_txclean(), tx-descp is dereferenced if tx->num_desc is not zero: sdma_unmap_desc(dd, &tx->descp[0]); To fix this possible null-pointer dereference, assign the return value of kmalloc_array() to a local variable descp, and then assign it to tx->descp if it is not NULL. Otherwise, go to enomem. Fixes: 7724105686e7 ("IB/hfi1: add driver files") Link: https://lore.kernel.org/r/20210806133029.194964-1-islituo@gmail.com Reported-by: TOTE Robot Signed-off-by: Tuo Li Tested-by: Mike Marciniszyn Acked-by: Mike Marciniszyn Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/hw/hfi1/sdma.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/sdma.c b/drivers/infiniband/hw/hfi1/sdma.c index 76e63c88a87a..e9313e6f4b0e 100644 --- a/drivers/infiniband/hw/hfi1/sdma.c +++ b/drivers/infiniband/hw/hfi1/sdma.c @@ -3028,6 +3028,7 @@ static void __sdma_process_event(struct sdma_engine *sde, static int _extend_sdma_tx_descs(struct hfi1_devdata *dd, struct sdma_txreq *tx) { int i; + struct sdma_desc *descp; /* Handle last descriptor */ if (unlikely((tx->num_desc == (MAX_DESC - 1)))) { @@ -3048,12 +3049,10 @@ static int _extend_sdma_tx_descs(struct hfi1_devdata *dd, struct sdma_txreq *tx) if (unlikely(tx->num_desc == MAX_DESC)) goto enomem; - tx->descp = kmalloc_array( - MAX_DESC, - sizeof(struct sdma_desc), - GFP_ATOMIC); - if (!tx->descp) + descp = kmalloc_array(MAX_DESC, sizeof(struct sdma_desc), GFP_ATOMIC); + if (!descp) goto enomem; + tx->descp = descp; /* reserve last descriptor for coalescing */ tx->desc_limit = MAX_DESC - 1; -- 2.30.2