From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Keith Busch <keith.busch@intel.com>,
Dan Williams <dan.j.williams@intel.com>,
Ross Zwisler <zwisler@kernel.org>,
Vishal Verma <vishal.l.verma@intel.com>,
Dave Jiang <dave.jiang@intel.com>
Cc: "Gustavo A. R. Silva" <gustavo@embeddedor.com>,
linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org
Subject: [PATCH] libnvdimm: fix NULL pointer dereference
Date: Tue, 24 Jul 2018 08:40:06 -0500 [thread overview]
Message-ID: <20180724134006.GA2775@embeddedor.com> (raw)
ndd is being dereferenced before it is null checked, hence there is a
potential null pointer dereference.
Fix this by moving the pointer dereference after ndd has been properly
null checked at line 554: if (!ndd)
Addresses-Coverity-ID: 1472020 ("Dereference before null check")
Fixes: 42218e643bd2 ("libnvdimm: Use max contiguous area for namespace size")
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
drivers/nvdimm/dimm_devs.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/nvdimm/dimm_devs.c b/drivers/nvdimm/dimm_devs.c
index 9e977cb..1dc3125 100644
--- a/drivers/nvdimm/dimm_devs.c
+++ b/drivers/nvdimm/dimm_devs.c
@@ -546,7 +546,7 @@ resource_size_t nd_pmem_max_contiguous_dpa(struct nd_region *nd_region,
struct nd_mapping *nd_mapping)
{
struct nvdimm_drvdata *ndd = to_ndd(nd_mapping);
- struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(ndd->dev);
+ struct nvdimm_bus *nvdimm_bus;
resource_size_t max = 0;
struct resource *res;
@@ -554,6 +554,8 @@ resource_size_t nd_pmem_max_contiguous_dpa(struct nd_region *nd_region,
if (!ndd)
return 0;
+ nvdimm_bus = walk_to_nvdimm_bus(ndd->dev);
+
if (reserve_free_pmem(nvdimm_bus, nd_mapping))
return 0;
for_each_dpa_resource(ndd, res) {
--
2.7.4
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm
next reply other threads:[~2018-07-24 13:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-24 13:40 Gustavo A. R. Silva [this message]
2018-07-24 19:46 ` [PATCH] libnvdimm: fix NULL pointer dereference Keith Busch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180724134006.GA2775@embeddedor.com \
--to=gustavo@embeddedor.com \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=keith.busch@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvdimm@lists.01.org \
--cc=vishal.l.verma@intel.com \
--cc=zwisler@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).