From patchwork Tue Mar 12 08:20:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kangjie Lu X-Patchwork-Id: 10848725 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 2C799139A for ; Tue, 12 Mar 2019 08:20:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 145E728EFC for ; Tue, 12 Mar 2019 08:20:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 024D429563; Tue, 12 Mar 2019 08:20:42 +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 AE36328EFC for ; Tue, 12 Mar 2019 08:20:42 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 61115211DBDEA; Tue, 12 Mar 2019 01:20:42 -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 7312B211CF35C for ; Tue, 12 Mar 2019 01:20:41 -0700 (PDT) Received: from localhost (unknown [127.0.0.1]) by mta-p6.oit.umn.edu (Postfix) with ESMTP id E28399D9 for ; Tue, 12 Mar 2019 08:20:40 +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 ucCG7YttkEaN for ; Tue, 12 Mar 2019 03:20:40 -0500 (CDT) Received: from mail-it1-f200.google.com (mail-it1-f200.google.com [209.85.166.200]) (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 B10A19A3 for ; Tue, 12 Mar 2019 03:20:40 -0500 (CDT) Received: by mail-it1-f200.google.com with SMTP id w200so1540376itc.8 for ; Tue, 12 Mar 2019 01:20:40 -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=6pXfUIxIQnph85qeigpOHBJdfRlD+BkO94R1xL/k3ys=; b=dfTUXLhYInVeRrm8NTfldheTVidbCXTfOANSZv3ZHLWY01F48xge8vVvOV2Tm6chBR qxJJ7nMdCpr/YpBMsrygKDRre2y1p9IAiJ/v4ohVKY75Fuq/mdwbr6sSAstbqUSFngxS G+QtYCVo7S85Gasz5q4Pr5oTM/jQ21sDIZ1ycDlJkykJJhA162AHhy7V064OqvIDplhN rHojbPHo33zxgqKQslN5ypHfDwv+Uu26puRebIf1PB6sVaoA/HeZhcKWC6DSj2tgs/st BzSPN94QUcBjkAcg2r+M6uzqeEpFR7PS6egeeQUdYbiOiPgpgN4hmgtMGi9/oaIRu3Qv 4puw== 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=6pXfUIxIQnph85qeigpOHBJdfRlD+BkO94R1xL/k3ys=; b=paPe6qTXscQCBfdpgFPZiGw2tlOt8kxmyxZXnTXV/W280IOu34/cDTqOwTjObBCKmu 1mE8Lg2fx84TC7RLMrRrzu/lU8HweiNqJAMuBwpANjOnTO9lNjA2Rzrq9FnhN9Ht+8st 8RvUbT0RNnaeWlYIpMJsyAcDW+a4qvJnk+hHy2Y8HGQb8Iofz/r0LieBMQ0jreYjkTUr ZRqWlSxISStVMDXkMXa4VVGqeDOI2JRRhmJ430t5FrJVPbB+yqj+JhcYHBHMwxEuvnCM 3YBy35FWDVOZf/+QaarT25mTVZbUWihFbgaTuMtA0i47KbBBrWP/DdEXBElbB8Drm7c3 VpyA== X-Gm-Message-State: APjAAAX0uqEeFqBXOF9c51pocFAbXdTUtcfyM/0/zqFkhqIq+r/gIZ0S lDrQhAkfqAUy35HWZjHu9JL8QbMvmRZu60ACr8QSsHF4B2FxLnyR8gZhffvZ4NSErUgn1SGrinZ ftm4YaQyN7OXYGj05E9myCLrF X-Received: by 2002:a02:c914:: with SMTP id t20mr1311304jao.29.1552378840337; Tue, 12 Mar 2019 01:20:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqxx7OyI740fzNpPsmdmOzldE83zpRp6vLwBJdEcDlRn+RDQ3Ss8kYrATO8AMmjDSyvz8d9luQ== X-Received: by 2002:a02:c914:: with SMTP id t20mr1311295jao.29.1552378840114; Tue, 12 Mar 2019 01:20:40 -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 d135sm998676itd.43.2019.03.12.01.20.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 01:20:39 -0700 (PDT) From: Kangjie Lu To: kjlu@umn.edu Subject: [PATCH] nvdimm: namespace_devs: fix a potential NULL pointer dereference Date: Tue, 12 Mar 2019 03:20:34 -0500 Message-Id: <20190312082034.5846-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 goes to blk_err to avoid NULL pointer dereference Signed-off-by: Kangjie Lu --- drivers/nvdimm/namespace_devs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c index 4b077555ac70..6f65261e151f 100644 --- a/drivers/nvdimm/namespace_devs.c +++ b/drivers/nvdimm/namespace_devs.c @@ -2245,9 +2245,12 @@ static struct device *create_namespace_blk(struct nd_region *nd_region, if (!nsblk->uuid) goto blk_err; memcpy(name, nd_label->name, NSLABEL_NAME_LEN); - if (name[0]) + if (name[0]) { nsblk->alt_name = kmemdup(name, NSLABEL_NAME_LEN, GFP_KERNEL); + if (!nsblk->alt_name) + goto blk_err; + } res = nsblk_add_resource(nd_region, ndd, nsblk, __le64_to_cpu(nd_label->dpa)); if (!res)