From patchwork Tue Mar 12 08:15:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kangjie Lu X-Patchwork-Id: 10848717 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 ADD201669 for ; Tue, 12 Mar 2019 08:15:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 93FF5294F5 for ; Tue, 12 Mar 2019 08:15:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8524C2950D; Tue, 12 Mar 2019 08:15:38 +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=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 22930294F5 for ; Tue, 12 Mar 2019 08:15:38 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id E2FBD211D6163; Tue, 12 Mar 2019 01:15:37 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.84.196.206; helo=mta-p6.oit.umn.edu; envelope-from=kjlu@umn.edu; receiver=linux-nvdimm@lists.01.org Received: from mta-p6.oit.umn.edu (mta-p6.oit.umn.edu [134.84.196.206]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D99F0211CF35C for ; Tue, 12 Mar 2019 01:15:36 -0700 (PDT) Received: from localhost (unknown [127.0.0.1]) by mta-p6.oit.umn.edu (Postfix) with ESMTP id 194B69A3 for ; Tue, 12 Mar 2019 08:15:36 +0000 (UTC) X-Virus-Scanned: amavisd-new at umn.edu Received: from mta-p6.oit.umn.edu ([127.0.0.1]) by localhost (mta-p6.oit.umn.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TJP1HPvSPI3V for ; Tue, 12 Mar 2019 03:15:36 -0500 (CDT) Received: from mail-io1-f70.google.com (mail-io1-f70.google.com [209.85.166.70]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mta-p6.oit.umn.edu (Postfix) with ESMTPS id E965E984 for ; Tue, 12 Mar 2019 03:15:35 -0500 (CDT) Received: by mail-io1-f70.google.com with SMTP id w11so1207258iom.20 for ; Tue, 12 Mar 2019 01:15:35 -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; bh=D52gZKic/kaXc1i1hUThp3TEp/h/NmLMpSvJunvUEZw=; b=LaQ/m0r8sDi26ETNVkiPDhcpxYotjlJesrU9Y9Nv/2cSxiN6NmdeobHZtZKb2JeKoR f49xGy7BfgfZX3nu7gWXRI9SpSTQchlQ3Nj4xnsMOzBjQ83bt/Y+DtQyooCdTDQIcoHs tCQJ+2fbSL1nf3gnOvmeWdiPDjOGEagAFtHq2JQlqZhAibIIlCb6UiY6j1DHXYOKneKj yCiPljolxWgBc7XJt7bUdLbsfvUnGGVBJwk4TzkdL6kBSsUox3a6KpksqYTzCqjU70Ep uCdWyeB+44gCjXnEFVrYBCfE8BtXBOKdMxV+5d826FbKtzxQSkb3zrxqP1WaZFM1jCkG rkEQ== 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; bh=D52gZKic/kaXc1i1hUThp3TEp/h/NmLMpSvJunvUEZw=; b=nP5fOHmVFhNJIQ+DUBNAihMYt5ueQCnYcsALGSHaDyNdyHMXcvK07ExmO6+GgA/8w7 yxJ0hJ1hBxXdLFzx+i3D9CwxBL0HX/6C7wBlA/knos5XJCBbeJd1oxyDYYb35HwUranD O9gpUTdsYOTTSwfRjZLQ8P/fvmreVjjdoRQjstzrLowNRbsx24rhwHX9p8qIv9QOCJAF dBEF4y/LYExpOHMiS3B2IuC6RzbUptynzC2WZle9HwPcrb0jnZnmiU5EH5/eZOj4NUnQ bAsPRcYcSJeTy4CpQ3htR9hIVng3W7njJWJ1A7RBD4U85fprPBHN1f+2bswMLLZFXIm3 dLEw== X-Gm-Message-State: APjAAAUSxplTag2b1cxzQJ97NbKvzmgRwSJQg8f6zvPHoL7sM0NopEM/ YioKACIo4bYn+VxLTjABKDVtI6aZnsNFgWCymMLOSjkVrc2tuL/Vl++i10FGE/UiqP8XCb3Vjjk +sNWVM66HEl2WCQctYGE3Ezet X-Received: by 2002:a24:3ac5:: with SMTP id m188mr1238453itm.109.1552378535385; Tue, 12 Mar 2019 01:15:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqwyR42N2k5Bx5GvyqkcRoP2BgeZvHfzqloKG6zHV23b+KTF+R7ReuZI34beY/yRk53/KQy2bg== X-Received: by 2002:a24:3ac5:: with SMTP id m188mr1238445itm.109.1552378535113; Tue, 12 Mar 2019 01:15:35 -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 z24sm3238862ioi.67.2019.03.12.01.15.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 01:15:34 -0700 (PDT) From: Kangjie Lu To: kjlu@umn.edu Subject: [PATCH] nvdimm: btt_devs: fix a NULL pointer dereference and a memory leak Date: Tue, 12 Mar 2019 03:15:29 -0500 Message-Id: <20190312081529.4889-1-kjlu@umn.edu> X-Mailer: git-send-email 2.17.1 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-nvdimm@lists.01.org, pakki001@umn.edu, linux-kernel@vger.kernel.org, Ross Zwisler MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP In case kmemdup fails, the fix releases resources and returns to avoid the NULL pointer dereference. Also, the error paths in the following code should release resources to avoid memory leaks. Signed-off-by: Kangjie Lu Reviewed-by: Vishal Verma --- drivers/nvdimm/btt_devs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/nvdimm/btt_devs.c b/drivers/nvdimm/btt_devs.c index 795ad4ff35ca..565ea0b6f765 100644 --- a/drivers/nvdimm/btt_devs.c +++ b/drivers/nvdimm/btt_devs.c @@ -196,8 +196,13 @@ static struct device *__nd_btt_create(struct nd_region *nd_region, } nd_btt->lbasize = lbasize; - if (uuid) + if (uuid) { uuid = kmemdup(uuid, 16, GFP_KERNEL); + if (!uuid) { + kfree(nd_btt); + return NULL; + } + } nd_btt->uuid = uuid; dev = &nd_btt->dev; dev_set_name(dev, "btt%d.%d", nd_region->id, nd_btt->id); @@ -209,6 +214,7 @@ static struct device *__nd_btt_create(struct nd_region *nd_region, dev_dbg(&ndns->dev, "failed, already claimed by %s\n", dev_name(ndns->claim)); put_device(dev); + kfree(uuid); return NULL; } return dev;