diff --git a/0001-ndctl-namespace-fix-a-resource-leak-in-file_write_in.patch b/0001-ndctl-namespace-fix-a-resource-leak-in-file_write_in.patch new file mode 100644 index 0000000000000000000000000000000000000000..a0104baf816a70081d832b34bd7088c454f79668 --- /dev/null +++ b/0001-ndctl-namespace-fix-a-resource-leak-in-file_write_in.patch @@ -0,0 +1,32 @@ +From b0d9cad81f2e811608b898922643f655043361aa Mon Sep 17 00:00:00 2001 +From: Vishal Verma +Date: Tue, 21 Jul 2020 23:17:27 -0600 +Subject: [PATCH 1/2] ndctl/namespace: fix a resource leak in + file_write_infoblock() + +Static analysis showed that we might leak 'fd' in the given function. +Fix the error path to close(fd) if 'fd >= 0' rather than just 'fd > 0'. + +Fixes: 7787807bcffe ("ndctl/namespace: Add write-infoblock command") +Cc: Dan Williams +Signed-off-by: Vishal Verma +--- + ndctl/namespace.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/ndctl/namespace.c b/ndctl/namespace.c +index 0550580..17e67c9 100644 +--- a/ndctl/namespace.c ++++ b/ndctl/namespace.c +@@ -1977,7 +1977,7 @@ static int file_write_infoblock(const char *path) + + free(buf); + out: +- if (fd > 0 && fd != STDOUT_FILENO) ++ if (fd >= 0 && fd != STDOUT_FILENO) + close(fd); + return rc; + } +-- +1.8.3.1 + diff --git a/0002-libndctl-fix-a-potential-buffer-overflow.patch b/0002-libndctl-fix-a-potential-buffer-overflow.patch new file mode 100644 index 0000000000000000000000000000000000000000..485d225323bdaa45025cce7aa2d1096a2b15531e --- /dev/null +++ b/0002-libndctl-fix-a-potential-buffer-overflow.patch @@ -0,0 +1,33 @@ +From 2f99e11812e6a4d9814bfc8ef038ca845db5394c Mon Sep 17 00:00:00 2001 +From: Vishal Verma +Date: Thu, 1 Oct 2020 11:10:00 -0600 +Subject: [PATCH 2/2] libndctl: fix a potential buffer overflow + +Static analysis points out that the 'buf' in ndctl_dimm_is_active was +inappropriately sized. We already have 'SYSFS_ATTR_SIZE' for such +buffers, and it looks like this was just an oversight. + +Fixes: 0a4509d7de2f ("ndctl: enumerate interleave sets") +Cc: Dan Williams +Signed-off-by: Vishal Verma +--- + ndctl/lib/libndctl.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c +index ee737cb..5b276a7 100644 +--- a/ndctl/lib/libndctl.c ++++ b/ndctl/lib/libndctl.c +@@ -3292,8 +3292,8 @@ NDCTL_EXPORT int ndctl_dimm_is_active(struct ndctl_dimm *dimm) + { + struct ndctl_ctx *ctx = ndctl_dimm_get_ctx(dimm); + char *path = dimm->dimm_buf; ++ char buf[SYSFS_ATTR_SIZE]; + int len = dimm->buf_len; +- char buf[20]; + + if (snprintf(path, len, "%s/state", dimm->dimm_path) >= len) { + err(ctx, "%s: buffer too small!\n", +-- +1.8.3.1 + diff --git a/ndctl.spec b/ndctl.spec index a2ac34c99f1e1f10a01f4bc91547588dacbfeb8a..644e530bc64ddad8b35ac6b6db3020fc3885799b 100644 --- a/ndctl.spec +++ b/ndctl.spec @@ -1,12 +1,15 @@ Name: ndctl Version: 68 -Release: 1 +Release: 2 Summary: Manage "libnvdimm" subsystem devices (Non-volatile Memory) License: GPLv2 Group: System Environment/Base Url: https://github.com/pmem/ndctl Source0: https://github.com/pmem/%{name}/archive/v%{version}.tar.gz#/%{name}-%{version}.tar.gz +Patch1: 0001-ndctl-namespace-fix-a-resource-leak-in-file_write_in.patch +Patch2: 0002-libndctl-fix-a-potential-buffer-overflow.patch + Requires: ndctl-libs%{?_isa} = %{version}-%{release} Requires: daxctl-libs%{?_isa} = %{version}-%{release} BuildRequires: autoconf @@ -87,7 +90,7 @@ control API for these devices. %prep -%setup -q ndctl-%{version} +%autosetup -Sgit -n ndctl-%{version} %build echo %{version} > version @@ -152,6 +155,9 @@ make check %changelog +* Fri Oct 30 2020 Zhiqiang Liu - 68-2 +- backport upstream patches to fix some potential problems + * Thu Jun 04 2020 lingsheng - 68-1 - update version 68