Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5194589imm; Tue, 31 Jul 2018 07:04:32 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdQ0lbZl3oQXayy7IL86hMWJA8SCnfZuCYgs53LfkFOJsPw7PTRuIAKJhWD0d2lhsX0etRv X-Received: by 2002:a63:5d58:: with SMTP id o24-v6mr20967365pgm.349.1533045872274; Tue, 31 Jul 2018 07:04:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533045872; cv=none; d=google.com; s=arc-20160816; b=wMiCWwqutG3adRkUYoVqKI5t1GWX2MAL3l1KiUNMS5RVQ+FK8HRPStef8ztO4Z9Gg5 jDHb5x5O26hFgHKwKbPR4wF2gbBrXh3hb/cTzvZ6KFFQDJlQf9Dya9qeT2531v8GIsB1 LN2Ctqe4vwEonq5J/+4/ktRi7pT9y3ikoxD/AkprlUxLm82JiMaCXIA1KNOfsedjRY4X 01C4m34ICWdPjYRGpKpXWd2gnkgH2WTWtyjLkDkp/Czpg0QBPE+lUOxwxCPhRbFkKuH3 At4dHedY+l+P98Y1GAUyhfDcVvrF6XpaZ5u9piQmPzP855Al53ERz0G6KNoemGyTtfhY YlEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:arc-authentication-results; bh=LWOO4xHvV/al3z71hhSA5YNM2p1zmmhomUQ64Hc1dqA=; b=UIxa2KTnoR+FrVPpVH/593m/r6meTG36u91EUWvOvaBoZF/VkTA6HLEWwVUmEUXXep xvcs3RaPKXcsRkOGYva3ajnjloC+3U8cKOb3+HVqwNKMjf9VPXWuV5Nx5H6hbsv2rCdL DpdbXhSxI33uIO3ApltsbMllHlboVcikFlB10m9LAL38LMuuJ4Ybu7VMgjlQS8ykfjd4 mk/2ijg47RSCYBC91/9kI1p5qjjXQke9gKQ4fhjV/gWYzsVjvKDJrwFIpjMDp2NWZnkQ F/Io5EZ4lOThJ95R9gN1PuUq0RLJ3URjhezWrtsp32wrJTKgxj/mmrkL4usaP+vHFAYm UClg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s2-v6si15206611pfs.2.2018.07.31.07.04.16; Tue, 31 Jul 2018 07:04:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732304AbeGaPnA (ORCPT + 99 others); Tue, 31 Jul 2018 11:43:00 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:49504 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727397AbeGaPnA (ORCPT ); Tue, 31 Jul 2018 11:43:00 -0400 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1fkVEI-0002tU-4L; Tue, 31 Jul 2018 14:02:26 +0000 From: Colin King To: Boris Ostrovsky , Juergen Gross , xen-devel@lists.xenproject.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] xen/gntdev: don't dereference a null gntdev_dmabuf on allocation failure Date: Tue, 31 Jul 2018 15:02:25 +0100 Message-Id: <20180731140225.22717-1-colin.king@canonical.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King Currently when the allocation of gntdev_dmabuf fails, the error exit path will call dmabuf_imp_free_storage and causes a null pointer dereference on gntdev_dmabuf. Fix this by adding an error exit path that won't free gntdev_dmabuf. Detected by CoverityScan, CID#1472124 ("Dereference after null check") Fixes: bf8dc55b1358 ("xen/gntdev: Implement dma-buf import functionality") Signed-off-by: Colin Ian King --- drivers/xen/gntdev-dmabuf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/xen/gntdev-dmabuf.c b/drivers/xen/gntdev-dmabuf.c index 744cfe9b0311..cba6b586bfbd 100644 --- a/drivers/xen/gntdev-dmabuf.c +++ b/drivers/xen/gntdev-dmabuf.c @@ -568,7 +568,7 @@ static struct gntdev_dmabuf *dmabuf_imp_alloc_storage(int count) gntdev_dmabuf = kzalloc(sizeof(*gntdev_dmabuf), GFP_KERNEL); if (!gntdev_dmabuf) - goto fail; + goto fail_no_free; gntdev_dmabuf->u.imp.refs = kcalloc(count, sizeof(gntdev_dmabuf->u.imp.refs[0]), @@ -591,6 +591,7 @@ static struct gntdev_dmabuf *dmabuf_imp_alloc_storage(int count) fail: dmabuf_imp_free_storage(gntdev_dmabuf); +fail_no_free: return ERR_PTR(-ENOMEM); } -- 2.17.1