Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp875610pxb; Wed, 1 Sep 2021 11:52:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvbKymSCpMVSce2OBGsri2VscSjvj4ojfvdj4wcz/Zhx/AN5KASGjxKONjf099HHDyZB65 X-Received: by 2002:a02:878e:: with SMTP id t14mr921277jai.4.1630522345635; Wed, 01 Sep 2021 11:52:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630522345; cv=none; d=google.com; s=arc-20160816; b=qUzrWmGsvvML0hUPgwro0sJtkJOpo5P9Vci4PZvAPt5hdx6TxWLSn9olKT4CRDcdXL 9UonICP62HOyLAtCohqXlH7KSBNhD1EYWyxBMS5Cp5x8g5VSNlcd7ob+iLOZtT4Jz5ID fc1IcNsdFQiA/mM3l24wuHHb4PCItdwOnFQBzDl/F1y6+Sv33C9fNUyQ6wkFimeIoJEo dISLRNcq1fjGLT7hTZBzwkDKIoIgheeqNRIPU86cOQqyocogjAZOrh26+aCZly9ZkEl0 viryc+PjsW5oHIuVAgaVXQzsYm3CsGsMLslylpcadav3CiuEFYvtRFaO99HPq7G+dsu4 qE0Q== 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=IHcwATRYEfZOoi2iXxeGT1fPDgEHxYvQ5e1kfjg0EUs=; b=AOjEiFtaNQzGvrVW9jwJ/ir44PvKLAaTv8oze3BBgGO7ADv2tGH6H9G9nFAS2zQYOZ 2EwemdwR0wX/y3RK3TMR+UwrzWmud79Be+U17hjdpAfKN6u+GH8L6/R257qa+AppVp/J naR10FcZEOsiMlEup5focTAKdU5lcKbBABoqhxq4hdk+buCWWUg/3vBWdD0nSxfy5Gnn rX+Am1ZiL4Lva8yBU9fpbFrLp4S3FzShKDSAMa0z8x9hlr4eke4wfwRPhGu8dTOs8hS8 2vj0eSFr85GZFGfxcU8fdHQiHQNNq2+gna+jhRW6cvqbs3zfr3eZWsj1dN28Romfe+WV XONg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0FnbNzsG; 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 m2si428889ili.39.2021.09.01.11.52.14; Wed, 01 Sep 2021 11:52:25 -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=0FnbNzsG; 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 S244739AbhIAMaw (ORCPT + 99 others); Wed, 1 Sep 2021 08:30:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:59862 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244571AbhIAM34 (ORCPT ); Wed, 1 Sep 2021 08:29:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A0A4E6102A; Wed, 1 Sep 2021 12:28:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1630499338; bh=SSgTprFdfkjFhkooqfWAOUr0gc5o9bqBCiA0UxVorWo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0FnbNzsGRfSwPHlc3FlJgxnydwb1TXtP0nxyU+1znRROsFZMvp4lUKtK5HthvV//L DVMEY0iFHWE3IQ1vCZ3VdLg47CbYzm2QlF1rfbEsJI9YjzV004qSzt6PlXHi5VGK0y CIR6WcDuPL5/0FAQwLyQ8xPX1eabulW3KappuP7A= 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.14 07/23] IB/hfi1: Fix possible null-pointer dereference in _extend_sdma_tx_descs() Date: Wed, 1 Sep 2021 14:26:52 +0200 Message-Id: <20210901122250.016752834@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210901122249.786673285@linuxfoundation.org> References: <20210901122249.786673285@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 741938409f8e..c1c6d2c570aa 100644 --- a/drivers/infiniband/hw/hfi1/sdma.c +++ b/drivers/infiniband/hw/hfi1/sdma.c @@ -3067,6 +3067,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)))) { @@ -3087,12 +3088,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