Skip to content

Commit 47d154e

Browse files
committed
Merge tag 'libnvdimm-for-6.6' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm
Pull nvdimm updates from Dave Jiang: "This is mostly small cleanups, fixes, and with a change to prevent zero-sized namespace exposed to user for nvdimm. Summary: - kstrtobool() conversion for nvdimm - Add REQ_OP_WRITE for virtio_pmem - Header files update for of_pmem - Restrict zero-sized namespace from being exposed to user - Avoid unnecessary endian conversion - Fix mem leak in nvdimm pmu - Fix dereference after free in nvdimm pmu" * tag 'libnvdimm-for-6.6' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm: nvdimm: Fix dereference after free in register_nvdimm_pmu() nvdimm: Fix memleak of pmu attr_groups in unregister_nvdimm_pmu() nvdimm/pfn_dev: Avoid unnecessary endian conversion nvdimm/pfn_dev: Prevent the creation of zero-sized namespaces nvdimm: Explicitly include correct DT includes virtio_pmem: add the missing REQ_OP_WRITE for flush bio nvdimm: Use kstrtobool() instead of strtobool()
2 parents 4debf77 + 08ca690 commit 47d154e

File tree

7 files changed

+26
-15
lines changed

7 files changed

+26
-15
lines changed

drivers/nvdimm/namespace_devs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/*
33
* Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
44
*/
5+
#include <linux/kstrtox.h>
56
#include <linux/module.h>
67
#include <linux/device.h>
78
#include <linux/sort.h>
@@ -1338,7 +1339,7 @@ static ssize_t force_raw_store(struct device *dev,
13381339
struct device_attribute *attr, const char *buf, size_t len)
13391340
{
13401341
bool force_raw;
1341-
int rc = strtobool(buf, &force_raw);
1342+
int rc = kstrtobool(buf, &force_raw);
13421343

13431344
if (rc)
13441345
return rc;

drivers/nvdimm/nd_perf.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ int register_nvdimm_pmu(struct nvdimm_pmu *nd_pmu, struct platform_device *pdev)
308308

309309
rc = perf_pmu_register(&nd_pmu->pmu, nd_pmu->pmu.name, -1);
310310
if (rc) {
311-
kfree(nd_pmu->pmu.attr_groups);
312311
nvdimm_pmu_free_hotplug_memory(nd_pmu);
312+
kfree(nd_pmu->pmu.attr_groups);
313313
return rc;
314314
}
315315

@@ -324,6 +324,7 @@ void unregister_nvdimm_pmu(struct nvdimm_pmu *nd_pmu)
324324
{
325325
perf_pmu_unregister(&nd_pmu->pmu);
326326
nvdimm_pmu_free_hotplug_memory(nd_pmu);
327+
kfree(nd_pmu->pmu.attr_groups);
327328
kfree(nd_pmu);
328329
}
329330
EXPORT_SYMBOL_GPL(unregister_nvdimm_pmu);

drivers/nvdimm/nd_virtio.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ int async_pmem_flush(struct nd_region *nd_region, struct bio *bio)
105105
* parent bio. Otherwise directly call nd_region flush.
106106
*/
107107
if (bio && bio->bi_iter.bi_sector != -1) {
108-
struct bio *child = bio_alloc(bio->bi_bdev, 0, REQ_PREFLUSH,
108+
struct bio *child = bio_alloc(bio->bi_bdev, 0,
109+
REQ_OP_WRITE | REQ_PREFLUSH,
109110
GFP_ATOMIC);
110111

111112
if (!child)

drivers/nvdimm/of_pmem.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
#define pr_fmt(fmt) "of_pmem: " fmt
44

5-
#include <linux/of_platform.h>
6-
#include <linux/of_address.h>
5+
#include <linux/of.h>
76
#include <linux/libnvdimm.h>
87
#include <linux/module.h>
98
#include <linux/ioport.h>
9+
#include <linux/platform_device.h>
1010
#include <linux/slab.h>
1111

1212
struct of_pmem_private {

drivers/nvdimm/pfn_devs.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,9 @@ int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig)
452452
u64 checksum, offset;
453453
struct resource *res;
454454
enum nd_pfn_mode mode;
455+
resource_size_t res_size;
455456
struct nd_namespace_io *nsio;
456-
unsigned long align, start_pad;
457+
unsigned long align, start_pad, end_trunc;
457458
struct nd_pfn_sb *pfn_sb = nd_pfn->pfn_sb;
458459
struct nd_namespace_common *ndns = nd_pfn->ndns;
459460
const uuid_t *parent_uuid = nd_dev_to_uuid(&ndns->dev);
@@ -503,6 +504,7 @@ int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig)
503504
align = le32_to_cpu(pfn_sb->align);
504505
offset = le64_to_cpu(pfn_sb->dataoff);
505506
start_pad = le32_to_cpu(pfn_sb->start_pad);
507+
end_trunc = le32_to_cpu(pfn_sb->end_trunc);
506508
if (align == 0)
507509
align = 1UL << ilog2(offset);
508510
mode = le32_to_cpu(pfn_sb->mode);
@@ -584,7 +586,8 @@ int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig)
584586
*/
585587
nsio = to_nd_namespace_io(&ndns->dev);
586588
res = &nsio->res;
587-
if (offset >= resource_size(res)) {
589+
res_size = resource_size(res);
590+
if (offset >= res_size) {
588591
dev_err(&nd_pfn->dev, "pfn array size exceeds capacity of %s\n",
589592
dev_name(&ndns->dev));
590593
return -EOPNOTSUPP;
@@ -598,18 +601,20 @@ int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig)
598601
return -EOPNOTSUPP;
599602
}
600603

601-
if (!IS_ALIGNED(res->start + le32_to_cpu(pfn_sb->start_pad),
602-
memremap_compat_align())) {
604+
if (!IS_ALIGNED(res->start + start_pad, memremap_compat_align())) {
603605
dev_err(&nd_pfn->dev, "resource start misaligned\n");
604606
return -EOPNOTSUPP;
605607
}
606608

607-
if (!IS_ALIGNED(res->end + 1 - le32_to_cpu(pfn_sb->end_trunc),
608-
memremap_compat_align())) {
609+
if (!IS_ALIGNED(res->end + 1 - end_trunc, memremap_compat_align())) {
609610
dev_err(&nd_pfn->dev, "resource end misaligned\n");
610611
return -EOPNOTSUPP;
611612
}
612613

614+
if (offset >= (res_size - start_pad - end_trunc)) {
615+
dev_err(&nd_pfn->dev, "bad offset with small namespace\n");
616+
return -EOPNOTSUPP;
617+
}
613618
return 0;
614619
}
615620
EXPORT_SYMBOL(nd_pfn_validate);
@@ -810,7 +815,8 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn)
810815
else
811816
return -ENXIO;
812817

813-
if (offset >= size) {
818+
if (offset >= (size - end_trunc)) {
819+
/* This results in zero size devices */
814820
dev_err(&nd_pfn->dev, "%s unable to satisfy requested alignment\n",
815821
dev_name(&ndns->dev));
816822
return -ENXIO;

drivers/nvdimm/pmem.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/moduleparam.h>
1818
#include <linux/badblocks.h>
1919
#include <linux/memremap.h>
20+
#include <linux/kstrtox.h>
2021
#include <linux/vmalloc.h>
2122
#include <linux/blk-mq.h>
2223
#include <linux/pfn_t.h>
@@ -385,7 +386,7 @@ static ssize_t write_cache_store(struct device *dev,
385386
bool write_cache;
386387
int rc;
387388

388-
rc = strtobool(buf, &write_cache);
389+
rc = kstrtobool(buf, &write_cache);
389390
if (rc)
390391
return rc;
391392
dax_write_cache(pmem->dax_dev, write_cache);

drivers/nvdimm/region_devs.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <linux/scatterlist.h>
66
#include <linux/memregion.h>
77
#include <linux/highmem.h>
8+
#include <linux/kstrtox.h>
89
#include <linux/sched.h>
910
#include <linux/slab.h>
1011
#include <linux/hash.h>
@@ -275,7 +276,7 @@ static ssize_t deep_flush_store(struct device *dev, struct device_attribute *att
275276
const char *buf, size_t len)
276277
{
277278
bool flush;
278-
int rc = strtobool(buf, &flush);
279+
int rc = kstrtobool(buf, &flush);
279280
struct nd_region *nd_region = to_nd_region(dev);
280281

281282
if (rc)
@@ -530,7 +531,7 @@ static ssize_t read_only_store(struct device *dev,
530531
struct device_attribute *attr, const char *buf, size_t len)
531532
{
532533
bool ro;
533-
int rc = strtobool(buf, &ro);
534+
int rc = kstrtobool(buf, &ro);
534535
struct nd_region *nd_region = to_nd_region(dev);
535536

536537
if (rc)

0 commit comments

Comments
 (0)