From patchwork Sat Mar 23 21:41:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Pakki X-Patchwork-Id: 10867291 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 6411B1669 for ; Sat, 23 Mar 2019 21:41:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3AA34286B6 for ; Sat, 23 Mar 2019 21:41:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 291A529620; Sat, 23 Mar 2019 21:41:36 +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 B5DE2286B6 for ; Sat, 23 Mar 2019 21:41:35 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3E45F211E9FD7; Sat, 23 Mar 2019 14:41:35 -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.205; helo=mta-p5.oit.umn.edu; envelope-from=pakki001@umn.edu; receiver=linux-nvdimm@lists.01.org Received: from mta-p5.oit.umn.edu (mta-p5.oit.umn.edu [134.84.196.205]) (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 9EC54211E9FD1 for ; Sat, 23 Mar 2019 14:41:34 -0700 (PDT) Received: from localhost (unknown [127.0.0.1]) by mta-p5.oit.umn.edu (Postfix) with ESMTP id A6286CC1 for ; Sat, 23 Mar 2019 21:41:33 +0000 (UTC) X-Virus-Scanned: amavisd-new at umn.edu Received: from mta-p5.oit.umn.edu ([127.0.0.1]) by localhost (mta-p5.oit.umn.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5RGoSoeVJYh1 for ; Sat, 23 Mar 2019 16:41:33 -0500 (CDT) Received: from mail-it1-f198.google.com (mail-it1-f198.google.com [209.85.166.198]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mta-p5.oit.umn.edu (Postfix) with ESMTPS id 7B4B6CC2 for ; Sat, 23 Mar 2019 16:41:33 -0500 (CDT) Received: by mail-it1-f198.google.com with SMTP id s3so5322940itl.0 for ; Sat, 23 Mar 2019 14:41:33 -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=nz+3mHW/r6/cPTjvFh7Xv0Gnmybwq6RbDIuJDUvdaGI=; b=mIi69M37AWXSfMaL2ckKk1tMQYLWgfr1JXC/Ipykgw16dp7u23F8ram1fEQn7AU8bj X1/sMjX/gYePmAYqRcYApgUsQkLjGyfjx5fHoDDMA/uKk8nqdFrinO/BV7V7Cw69LULI soq349KzeuhA81Qtjx6nbfOphLt8h3VCAHYp+LKyNfdaIsbEZYZoJuCcIEs7QrKXwHd8 c0AMzI1n7zRZaIwuNcc7RiHLDlFLSv/eCrcJEmoiMUxlE1yoCeP28aqmtQG3YFvlvdzL JuwnT150mJ7JZNkGeH9w1+umYLXrNZ0FY/bZm7Jpt1Q9b6wq64w4a+heEFXypfx3mlIk ExrA== 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=nz+3mHW/r6/cPTjvFh7Xv0Gnmybwq6RbDIuJDUvdaGI=; b=Akah9GfRQPYUAedHsD1+Q+oEUlIzUxMo0ubiFqH5ptvTOdXgKR95NnY9CNuVKIgZUm 4aVch+BYP4YhKA94QDmSPeIH9SeB43Src1TbWiA7ujm8gjLAre6u2dCIHLPCfJYH+pZ9 fKTB2rrnMQsTbrJj+E31OB0EhOGCECf+sAVaXsidB98/etUYYKpCwD1mEbyqwWaLbHXV gPP9LAr16PQgKWn3ASYhWo8iQJh4Aiiw4BBhoGXINs9JqUrokAUCAZq008ZZw9V7OBQ+ 62xSSfGuFA/2+YCyPRntJNmn66fRU5jdHUsGQwNM+9HPzXM567vPxbEqFvJQGJeIGIDC A5jA== X-Gm-Message-State: APjAAAWQHyEbHB4F5NvwzEz6vr9Qi54LVwmiIrQkabQv/yJR04rqI7aE Tb8JYoRX62VDsjtjUhxeWNiexpOGLFF3aTlUptVZnRUOrnKO/1orDA2VXLP+t1OdU3p2cggH2Nt pieFj4qv6Lmp7Siph9idEfjrA X-Received: by 2002:a24:b349:: with SMTP id z9mr840911iti.77.1553377293059; Sat, 23 Mar 2019 14:41:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqxGCg7FrqYBYcz1pWhbwLngsOi/MEqF87eI8Qr5X+DXO2LyftiWofxWhTnsTRPaTkd87ZJRNQ== X-Received: by 2002:a24:b349:: with SMTP id z9mr840900iti.77.1553377292875; Sat, 23 Mar 2019 14:41:32 -0700 (PDT) Received: from cs-u-syssec1.dtc.umn.edu (cs-u-syssec1.cs.umn.edu. [128.101.106.66]) by smtp.gmail.com with ESMTPSA id t74sm5115331itt.29.2019.03.23.14.41.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 23 Mar 2019 14:41:32 -0700 (PDT) From: Aditya Pakki To: pakki001@umn.edu Subject: [PATCH v2] nvdimm: btt_devs: fix a NULL pointer dereference Date: Sat, 23 Mar 2019 16:41:25 -0500 Message-Id: <20190323214125.10233-1-pakki001@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, kjlu@umn.edu, linux-kernel@vger.kernel.org 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. Signed-off-by: Aditya Pakki --- v1: Free nd_btt->id in case of failure and avoid double free, suggested by Dan Williams --- 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 b72a303176c7..119a4ead2e46 100644 --- a/drivers/nvdimm/btt_devs.c +++ b/drivers/nvdimm/btt_devs.c @@ -204,8 +204,14 @@ 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->id); + 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);