* [ndctl PATCH 1/4] libndctl: fix potential buffer overflow in write_cache APIs
@ 2018-05-03 18:50 Vishal Verma
2018-05-03 18:50 ` [ndctl PATCH 2/4] libndctl: improve debug prints in wait_for_scrub_completion Vishal Verma
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Vishal Verma @ 2018-05-03 18:50 UTC (permalink / raw)
To: linux-nvdimm
We used a local stack variable to hold the sysfs path, which had a
potential to overflow. Instead, switch to the 'scratch space' bdbs->buf
to store the sysfs path as it is correctly sized for it.
Cc: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
ndctl/lib/libndctl.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index 59ea82a..2a3ef0c 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -3991,10 +3991,10 @@ static int __ndctl_namespace_set_write_cache(struct ndctl_namespace *ndns,
{
struct ndctl_ctx *ctx = ndctl_namespace_get_ctx(ndns);
struct ndctl_pfn *pfn = ndctl_namespace_get_pfn(ndns);
+ char *path = ndns->ndns_buf;
char buf[SYSFS_ATTR_SIZE];
int len = ndns->buf_len;
const char *bdev;
- char path[50];
if (state != 1 && state != 0)
return -ENXIO;
@@ -4034,9 +4034,9 @@ NDCTL_EXPORT int ndctl_namespace_write_cache_is_enabled(
struct ndctl_ctx *ctx = ndctl_namespace_get_ctx(ndns);
struct ndctl_pfn *pfn = ndctl_namespace_get_pfn(ndns);
int len = ndns->buf_len, wc;
+ char *path = ndns->ndns_buf;
char buf[SYSFS_ATTR_SIZE];
const char *bdev;
- char path[50];
if (pfn)
bdev = ndctl_pfn_get_block_device(pfn);
--
2.14.3
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [ndctl PATCH 2/4] libndctl: improve debug prints in wait_for_scrub_completion
2018-05-03 18:50 [ndctl PATCH 1/4] libndctl: fix potential buffer overflow in write_cache APIs Vishal Verma
@ 2018-05-03 18:50 ` Vishal Verma
2018-05-04 0:04 ` Dan Williams
2018-05-03 18:50 ` [ndctl PATCH 3/4] libndctl, test: fix a couple of unchecked returns Vishal Verma
2018-05-03 18:50 ` [ndctl PATCH 4/4] configure: add -Wunused-result and -D_FORTIFY_SOURCE=2 to cflags Vishal Verma
2 siblings, 1 reply; 7+ messages in thread
From: Vishal Verma @ 2018-05-03 18:50 UTC (permalink / raw)
To: linux-nvdimm
ndctl_bus_wait_for_scrub_completion() printed the same debug message
irrespective of whether we encountered a failure or not. Add a newe
debug message that is printed for failing cases.
Cc: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
ndctl/lib/libndctl.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index 2a3ef0c..6733b85 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -1248,7 +1248,11 @@ NDCTL_EXPORT int ndctl_bus_wait_for_scrub_completion(struct ndctl_bus *bus)
}
}
- dbg(ctx, "bus%d: scrub complete\n", ndctl_bus_get_id(bus));
+ if (rc == 0)
+ dbg(ctx, "bus%d: scrub complete\n", ndctl_bus_get_id(bus));
+ else
+ dbg(ctx, "bus%d: error waiting for scrub completion: %s\n",
+ ndctl_bus_get_id(bus), strerror(-rc));
if (fd)
close (fd);
return rc;
--
2.14.3
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [ndctl PATCH 3/4] libndctl, test: fix a couple of unchecked returns
2018-05-03 18:50 [ndctl PATCH 1/4] libndctl: fix potential buffer overflow in write_cache APIs Vishal Verma
2018-05-03 18:50 ` [ndctl PATCH 2/4] libndctl: improve debug prints in wait_for_scrub_completion Vishal Verma
@ 2018-05-03 18:50 ` Vishal Verma
2018-05-04 0:08 ` Dan Williams
2018-05-03 18:50 ` [ndctl PATCH 4/4] configure: add -Wunused-result and -D_FORTIFY_SOURCE=2 to cflags Vishal Verma
2 siblings, 1 reply; 7+ messages in thread
From: Vishal Verma @ 2018-05-03 18:50 UTC (permalink / raw)
To: linux-nvdimm
-Wunused-result with -D_FORTIFY_SOURCE=2 reported a couple of unchecked
return values, fix them by appropriately failing on errors.
Cc: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
ndctl/lib/libndctl.c | 5 ++++-
test/dax-pmd.c | 5 ++++-
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index 6733b85..47e005e 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -1243,7 +1243,10 @@ NDCTL_EXPORT int ndctl_bus_wait_for_scrub_completion(struct ndctl_bus *bus)
break;
}
dbg(ctx, "poll wake: revents: %d\n", fds.revents);
- pread(fd, buf, 1, 0);
+ if (pread(fd, buf, 1, 0) == -1) {
+ rc = -errno;
+ break;
+ }
fds.revents = 0;
}
}
diff --git a/test/dax-pmd.c b/test/dax-pmd.c
index 06fe522..65bee6f 100644
--- a/test/dax-pmd.c
+++ b/test/dax-pmd.c
@@ -125,7 +125,10 @@ int test_dax_directio(int dax_fd, unsigned long align, void *dax_addr, off_t off
rc = -ENXIO;
}
((char *) buf)[0] = 0;
- pread(fd2, buf, 4096, 0);
+ if (pread(fd2, buf, 4096, 0) != 4096) {
+ faili(i);
+ rc = -ENXIO;
+ }
if (strcmp(buf, "odirect data") != 0) {
faili(i);
rc = -ENXIO;
--
2.14.3
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [ndctl PATCH 4/4] configure: add -Wunused-result and -D_FORTIFY_SOURCE=2 to cflags
2018-05-03 18:50 [ndctl PATCH 1/4] libndctl: fix potential buffer overflow in write_cache APIs Vishal Verma
2018-05-03 18:50 ` [ndctl PATCH 2/4] libndctl: improve debug prints in wait_for_scrub_completion Vishal Verma
2018-05-03 18:50 ` [ndctl PATCH 3/4] libndctl, test: fix a couple of unchecked returns Vishal Verma
@ 2018-05-03 18:50 ` Vishal Verma
2018-05-03 19:06 ` Dan Williams
2 siblings, 1 reply; 7+ messages in thread
From: Vishal Verma @ 2018-05-03 18:50 UTC (permalink / raw)
To: linux-nvdimm
rpmbuild had these flags enabled, and reported a couple of errors that
local builds otherwise didn't. The errors hav now been fixed, and we
can enable these flags to catch future warnings and errors through
these flags.
Cc: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
configure.ac | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/configure.ac b/configure.ac
index cddad16..6dbfcee 100644
--- a/configure.ac
+++ b/configure.ac
@@ -147,7 +147,9 @@ my_CFLAGS="\
-Wsign-compare \
-Wstrict-prototypes \
-Wtype-limits \
--Wmaybe-uninitialized
+-Wmaybe-uninitialized \
+-Wunused-result \
+-D_FORTIFY_SOURCE=2
"
AC_SUBST([my_CFLAGS])
--
2.14.3
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [ndctl PATCH 4/4] configure: add -Wunused-result and -D_FORTIFY_SOURCE=2 to cflags
2018-05-03 18:50 ` [ndctl PATCH 4/4] configure: add -Wunused-result and -D_FORTIFY_SOURCE=2 to cflags Vishal Verma
@ 2018-05-03 19:06 ` Dan Williams
0 siblings, 0 replies; 7+ messages in thread
From: Dan Williams @ 2018-05-03 19:06 UTC (permalink / raw)
To: Vishal Verma; +Cc: linux-nvdimm
On Thu, May 3, 2018 at 11:50 AM, Vishal Verma <vishal.l.verma@intel.com> wrote:
> rpmbuild had these flags enabled, and reported a couple of errors that
> local builds otherwise didn't. The errors hav now been fixed, and we
*have
> can enable these flags to catch future warnings and errors through
> these flags.
>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
> ---
> configure.ac | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/configure.ac b/configure.ac
> index cddad16..6dbfcee 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -147,7 +147,9 @@ my_CFLAGS="\
> -Wsign-compare \
> -Wstrict-prototypes \
> -Wtype-limits \
> --Wmaybe-uninitialized
> +-Wmaybe-uninitialized \
> +-Wunused-result \
> +-D_FORTIFY_SOURCE=2
> "
> AC_SUBST([my_CFLAGS])
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [ndctl PATCH 2/4] libndctl: improve debug prints in wait_for_scrub_completion
2018-05-03 18:50 ` [ndctl PATCH 2/4] libndctl: improve debug prints in wait_for_scrub_completion Vishal Verma
@ 2018-05-04 0:04 ` Dan Williams
0 siblings, 0 replies; 7+ messages in thread
From: Dan Williams @ 2018-05-04 0:04 UTC (permalink / raw)
To: Vishal Verma; +Cc: linux-nvdimm
On Thu, May 3, 2018 at 11:50 AM, Vishal Verma <vishal.l.verma@intel.com> wrote:
> ndctl_bus_wait_for_scrub_completion() printed the same debug message
> irrespective of whether we encountered a failure or not. Add a newe
*new
> debug message that is printed for failing cases.
>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
> ---
> ndctl/lib/libndctl.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
> index 2a3ef0c..6733b85 100644
> --- a/ndctl/lib/libndctl.c
> +++ b/ndctl/lib/libndctl.c
> @@ -1248,7 +1248,11 @@ NDCTL_EXPORT int ndctl_bus_wait_for_scrub_completion(struct ndctl_bus *bus)
> }
> }
>
> - dbg(ctx, "bus%d: scrub complete\n", ndctl_bus_get_id(bus));
> + if (rc == 0)
> + dbg(ctx, "bus%d: scrub complete\n", ndctl_bus_get_id(bus));
> + else
> + dbg(ctx, "bus%d: error waiting for scrub completion: %s\n",
> + ndctl_bus_get_id(bus), strerror(-rc));
> if (fd)
> close (fd);
> return rc;
> --
> 2.14.3
>
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [ndctl PATCH 3/4] libndctl, test: fix a couple of unchecked returns
2018-05-03 18:50 ` [ndctl PATCH 3/4] libndctl, test: fix a couple of unchecked returns Vishal Verma
@ 2018-05-04 0:08 ` Dan Williams
0 siblings, 0 replies; 7+ messages in thread
From: Dan Williams @ 2018-05-04 0:08 UTC (permalink / raw)
To: Vishal Verma; +Cc: linux-nvdimm
On Thu, May 3, 2018 at 11:50 AM, Vishal Verma <vishal.l.verma@intel.com> wrote:
> -Wunused-result with -D_FORTIFY_SOURCE=2 reported a couple of unchecked
> return values, fix them by appropriately failing on errors.
*Building with '-Wunused-result -D_FORTIFY_SOURCE=2' reports...
>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
> ---
> ndctl/lib/libndctl.c | 5 ++++-
> test/dax-pmd.c | 5 ++++-
> 2 files changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
> index 6733b85..47e005e 100644
> --- a/ndctl/lib/libndctl.c
> +++ b/ndctl/lib/libndctl.c
> @@ -1243,7 +1243,10 @@ NDCTL_EXPORT int ndctl_bus_wait_for_scrub_completion(struct ndctl_bus *bus)
> break;
> }
> dbg(ctx, "poll wake: revents: %d\n", fds.revents);
> - pread(fd, buf, 1, 0);
> + if (pread(fd, buf, 1, 0) == -1) {
> + rc = -errno;
> + break;
> + }
> fds.revents = 0;
> }
> }
> diff --git a/test/dax-pmd.c b/test/dax-pmd.c
> index 06fe522..65bee6f 100644
> --- a/test/dax-pmd.c
> +++ b/test/dax-pmd.c
> @@ -125,7 +125,10 @@ int test_dax_directio(int dax_fd, unsigned long align, void *dax_addr, off_t off
> rc = -ENXIO;
> }
> ((char *) buf)[0] = 0;
> - pread(fd2, buf, 4096, 0);
> + if (pread(fd2, buf, 4096, 0) != 4096) {
> + faili(i);
> + rc = -ENXIO;
> + }
> if (strcmp(buf, "odirect data") != 0) {
> faili(i);
> rc = -ENXIO;
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2018-05-04 0:08 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-03 18:50 [ndctl PATCH 1/4] libndctl: fix potential buffer overflow in write_cache APIs Vishal Verma
2018-05-03 18:50 ` [ndctl PATCH 2/4] libndctl: improve debug prints in wait_for_scrub_completion Vishal Verma
2018-05-04 0:04 ` Dan Williams
2018-05-03 18:50 ` [ndctl PATCH 3/4] libndctl, test: fix a couple of unchecked returns Vishal Verma
2018-05-04 0:08 ` Dan Williams
2018-05-03 18:50 ` [ndctl PATCH 4/4] configure: add -Wunused-result and -D_FORTIFY_SOURCE=2 to cflags Vishal Verma
2018-05-03 19:06 ` Dan Williams
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.