1
0
Fork 0
libnvme/debian/patches/upstream/0001-alloc-helper.patch
Daniel Baumann 3dd70921f9
Cherry-picking upstream commits to fix buffer overflow during scanning devices that do not support sub-4k reads (Closes: #1054631).
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Signed-off-by: Daniel Baumann <daniel@debian.org>
2025-02-16 10:52:11 +01:00

44 lines
1.1 KiB
Diff

Author: Tomas Bzatek <tbzatek@redhat.com>
Description: util: Introduce alloc helper with alignment support
Similar to nvme-cli an alloc helper is needed for a couple
of ioctls sent out during tree scan.
diff -Naurp libnvme.orig/src/nvme/private.h libnvme/src/nvme/private.h
--- libnvme.orig/src/nvme/private.h
+++ libnvme/src/nvme/private.h
@@ -145,6 +145,8 @@ nvme_ctrl_t __nvme_lookup_ctrl(nvme_subs
const char *host_iface, const char *trsvcid,
nvme_ctrl_t p);
+void *__nvme_alloc(size_t len);
+
#if (LOG_FUNCNAME == 1)
#define __nvme_log_func __func__
#else
diff -Naurp libnvme.orig/src/nvme/util.c libnvme/src/nvme/util.c
--- libnvme.orig/src/nvme/util.c
+++ libnvme/src/nvme/util.c
@@ -7,6 +7,7 @@
* Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
*/
+#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
@@ -901,3 +902,15 @@ int nvme_uuid_random(unsigned char uuid[
return 0;
}
+
+void *__nvme_alloc(size_t len)
+{
+ size_t _len = round_up(len, 0x1000);
+ void *p;
+
+ if (posix_memalign((void *)&p, getpagesize(), _len))
+ return NULL;
+
+ memset(p, 0, _len);
+ return p;
+}