* [PATCH 0/5] multipath-tools: minor fixes in preparation of 0.14.0
@ 2026-01-16 11:30 Martin Wilck
2026-01-16 11:30 ` [PATCH 1/5] kpartx: avoid double-free of mapname Martin Wilck
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Martin Wilck @ 2026-01-16 11:30 UTC (permalink / raw)
To: Benjamin Marzinski, dm-devel; +Cc: Martin Wilck, Christophe Varoqui
This series fixes the double-free in kpartx introduced in 8c39e60 ("kpartx:
fix some memory leaks"), removes the long-obsolete "hotplug" mode of
kpartx, fixing another potential memory leak in the process, fixes a
false positive compiler warning, and adds two developer convenience
options to the Makefiles.
Martin Wilck (5):
kpartx: avoid double-free of mapname
kpartx: remove "hotplug" mode
multipathd: fix an uninitialized variable warning
Makefiles: add "ASAN=1" make parameter for AddressSanitizer
Makefiles: add "OPT=" make parameter
.github/actions/spelling/expect.txt | 3 +
Makefile.inc | 12 +++-
README.md | 9 +++
kpartx/kpartx.c | 94 ++++-------------------------
multipathd/main.c | 2 +-
5 files changed, 35 insertions(+), 85 deletions(-)
--
2.52.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/5] kpartx: avoid double-free of mapname
2026-01-16 11:30 [PATCH 0/5] multipath-tools: minor fixes in preparation of 0.14.0 Martin Wilck
@ 2026-01-16 11:30 ` Martin Wilck
2026-01-16 11:30 ` [PATCH 2/5] kpartx: remove "hotplug" mode Martin Wilck
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Martin Wilck @ 2026-01-16 11:30 UTC (permalink / raw)
To: Benjamin Marzinski, dm-devel; +Cc: Martin Wilck, Christophe Varoqui
The variable mapname is sometimes allocated and sometimes not.
To avoid double-free and still free allocated memory cleanly,
introduce a helper pointer for storing possibly allocated memory.
Signed-off-by: Martin Wilck <mwilck@suse.com>
---
kpartx/kpartx.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/kpartx/kpartx.c b/kpartx/kpartx.c
index 7ec89b4..6f2ec4e 100644
--- a/kpartx/kpartx.c
+++ b/kpartx/kpartx.c
@@ -245,7 +245,8 @@ main(int argc, char **argv){
char *loopdev __attribute__((cleanup(cleanup_charp))) = NULL;
char *delim __attribute__((cleanup(cleanup_charp))) = NULL;
char *uuid __attribute__((cleanup(cleanup_charp))) = NULL;
- char *mapname __attribute__((cleanup(cleanup_charp))) = NULL;
+ char *_mapname __attribute__((cleanup(cleanup_charp))) = NULL;
+ char *mapname;
int hotplug = 0;
int loopcreated = 0;
struct stat buf;
@@ -388,11 +389,15 @@ main(int argc, char **argv){
off = find_devname_offset(device);
if (!loopdev) {
- mapname = dm_mapname(major(buf.st_rdev), minor(buf.st_rdev));
- if (mapname)
- uuid = dm_mapuuid(mapname);
+ _mapname = dm_mapname(major(buf.st_rdev), minor(buf.st_rdev));
+ if (_mapname)
+ uuid = dm_mapuuid(_mapname);
}
+ mapname = _mapname;
+ if (!mapname)
+ mapname = device + off;
+
/*
* We are called for a non-DM device.
* Make up a fake UUID for the device, unless "-d -f" is given.
@@ -402,9 +407,6 @@ main(int argc, char **argv){
if (!uuid && !(what == DELETE && force_devmap))
uuid = nondm_create_uuid(buf.st_rdev);
- if (!mapname)
- mapname = device + off;
-
if (delim == NULL) {
delim = xmalloc(DELIM_SIZE);
memset(delim, 0, DELIM_SIZE);
--
2.52.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/5] kpartx: remove "hotplug" mode
2026-01-16 11:30 [PATCH 0/5] multipath-tools: minor fixes in preparation of 0.14.0 Martin Wilck
2026-01-16 11:30 ` [PATCH 1/5] kpartx: avoid double-free of mapname Martin Wilck
@ 2026-01-16 11:30 ` Martin Wilck
2026-01-16 11:30 ` [PATCH 3/5] multipathd: fix an uninitialized variable warning Martin Wilck
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Martin Wilck @ 2026-01-16 11:30 UTC (permalink / raw)
To: Benjamin Marzinski, dm-devel; +Cc: Martin Wilck, Christophe Varoqui
This functionality has been obsolete for a long time.
Signed-off-by: Martin Wilck <mwilck@suse.com>
---
kpartx/kpartx.c | 78 +++----------------------------------------------
1 file changed, 4 insertions(+), 74 deletions(-)
diff --git a/kpartx/kpartx.c b/kpartx/kpartx.c
index 6f2ec4e..9bdd204 100644
--- a/kpartx/kpartx.c
+++ b/kpartx/kpartx.c
@@ -145,56 +145,6 @@ find_devname_offset (char * device)
return (int)(q - device);
}
-static char *
-get_hotplug_device(void)
-{
- unsigned int major, minor, off, len;
- char *mapname;
- char *devname = NULL;
- char *device = NULL;
- char *var = NULL;
- struct stat buf;
-
- var = getenv("ACTION");
-
- if (!var || strcmp(var, "add"))
- return NULL;
-
- /* Get dm mapname for hotpluged device. */
- if (!(devname = getenv("DEVNAME")))
- return NULL;
-
- if (stat(devname, &buf))
- return NULL;
-
- major = major(buf.st_rdev);
- minor = minor(buf.st_rdev);
-
- if (!(mapname = dm_mapname(major, minor))) /* Not dm device. */
- return NULL;
-
- off = find_devname_offset(devname);
- len = strlen(mapname);
-
- /* Dirname + mapname + \0 */
- if (!(device = (char *)malloc(sizeof(char) * (off + len + 1)))) {
- free(mapname);
- return NULL;
- }
-
- /* Create new device name. */
- snprintf(device, off + 1, "%s", devname);
- snprintf(device + off, len + 1, "%s", mapname);
-
- if (strlen(device) != (off + len)) {
- free(device);
- free(mapname);
- return NULL;
- }
- free(mapname);
- return device;
-}
-
static int
check_uuid(char *uuid, char *part_uuid, char **err_msg) {
char *map_uuid = strchr(part_uuid, '-');
@@ -239,7 +189,7 @@ main(int argc, char **argv){
struct slice all;
struct pt *ptp;
enum action what = LIST;
- char *type, *diskdevice, *device, *progname;
+ char *type, *diskdevice, *device;
int verbose = 0;
char partname[PARTNAME_SIZE], params[PARTNAME_SIZE + 16];
char *loopdev __attribute__((cleanup(cleanup_charp))) = NULL;
@@ -247,7 +197,6 @@ main(int argc, char **argv){
char *uuid __attribute__((cleanup(cleanup_charp))) = NULL;
char *_mapname __attribute__((cleanup(cleanup_charp))) = NULL;
char *mapname;
- int hotplug = 0;
int loopcreated = 0;
struct stat buf;
@@ -258,24 +207,7 @@ main(int argc, char **argv){
memset(&all, 0, sizeof(all));
memset(&partname, 0, sizeof(partname));
- /* Check whether hotplug mode. */
- progname = strrchr(argv[0], '/');
-
- if (!progname)
- progname = argv[0];
- else
- progname++;
-
- if (!strcmp(progname, "kpartx.dev")) { /* Hotplug mode */
- hotplug = 1;
-
- /* Setup for original kpartx variables */
- if (!(device = get_hotplug_device()))
- exit(1);
-
- diskdevice = device;
- what = ADD;
- } else if (argc < 2) {
+ if (argc < 2) {
usage();
exit(1);
}
@@ -337,12 +269,10 @@ main(int argc, char **argv){
exit(1);
}
- if (hotplug) {
- /* already got [disk]device */
- } else if (optind == argc-2) {
+ if (optind == argc - 2) {
device = argv[optind];
diskdevice = argv[optind+1];
- } else if (optind == argc-1) {
+ } else if (optind == argc - 1) {
diskdevice = device = argv[optind];
} else {
usage();
--
2.52.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/5] multipathd: fix an uninitialized variable warning
2026-01-16 11:30 [PATCH 0/5] multipath-tools: minor fixes in preparation of 0.14.0 Martin Wilck
2026-01-16 11:30 ` [PATCH 1/5] kpartx: avoid double-free of mapname Martin Wilck
2026-01-16 11:30 ` [PATCH 2/5] kpartx: remove "hotplug" mode Martin Wilck
@ 2026-01-16 11:30 ` Martin Wilck
2026-01-16 11:30 ` [PATCH 4/5] Makefiles: add "ASAN=1" make parameter for AddressSanitizer Martin Wilck
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Martin Wilck @ 2026-01-16 11:30 UTC (permalink / raw)
To: Benjamin Marzinski, dm-devel; +Cc: Martin Wilck, Christophe Varoqui
This isn't necessary in practice, but it fixes a compile warning.
Signed-off-by: Martin Wilck <mwilck@suse.com>
---
multipathd/main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/multipathd/main.c b/multipathd/main.c
index 356091e..61e0ea3 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -3905,7 +3905,7 @@ child (__attribute__((unused)) void *param)
int rc;
struct config *conf;
char *envp;
- enum daemon_status state;
+ enum daemon_status state = DAEMON_INIT;
int exit_code = 1;
int fpin_marginal_paths = 0;
--
2.52.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/5] Makefiles: add "ASAN=1" make parameter for AddressSanitizer
2026-01-16 11:30 [PATCH 0/5] multipath-tools: minor fixes in preparation of 0.14.0 Martin Wilck
` (2 preceding siblings ...)
2026-01-16 11:30 ` [PATCH 3/5] multipathd: fix an uninitialized variable warning Martin Wilck
@ 2026-01-16 11:30 ` Martin Wilck
2026-01-16 11:30 ` [PATCH 5/5] Makefiles: add "OPT=" make parameter Martin Wilck
2026-01-19 23:10 ` [PATCH 0/5] multipath-tools: minor fixes in preparation of 0.14.0 Benjamin Marzinski
5 siblings, 0 replies; 7+ messages in thread
From: Martin Wilck @ 2026-01-16 11:30 UTC (permalink / raw)
To: Benjamin Marzinski, dm-devel; +Cc: Martin Wilck, Christophe Varoqui
It's now possible to enable AddressSanitizer by passing the parameter
`ASAN=1` on the "make" command line.
Signed-off-by: Martin Wilck <mwilck@suse.com>
---
.github/actions/spelling/expect.txt | 3 +++
Makefile.inc | 7 +++++--
README.md | 3 +++
3 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt
index 0b680aa..29ca8e8 100644
--- a/.github/actions/spelling/expect.txt
+++ b/.github/actions/spelling/expect.txt
@@ -6,6 +6,7 @@ alloc
alltgpt
alua
aptpl
+ASAN
ascq
ata
autoconfig
@@ -78,6 +79,7 @@ getrlimit
getuid
github
gitlab
+google
GPT
hbtl
hds
@@ -197,6 +199,7 @@ rpmbuild
rport
rtpi
rtprio
+sanitizer
sas
sbp
scsi
diff --git a/Makefile.inc b/Makefile.inc
index 539415d..8356254 100644
--- a/Makefile.inc
+++ b/Makefile.inc
@@ -9,6 +9,9 @@
# Uncomment to disable dmevents polling support
# ENABLE_DMEVENTS_POLL = 0
#
+# Use ASAN=1 on make command line to enable address sanitizer
+ASAN :=
+#
# Readline library to use, libedit, libreadline, or empty
# Caution: Using libreadline may make the multipathd binary undistributable,
# see https://github.com/opensvc/multipath-tools/issues/36
@@ -122,11 +125,11 @@ CPPFLAGS := $(FORTIFY_OPT) $(CPPFLAGS) $(D_URCU_VERSION) $(D_CMOCKA_VERSION) \
-DWSTRINGOP_TRUNCATION=$(if $(WSTRINGOP_TRUNCATION),1,0) \
-MMD -MP
CFLAGS := -std=$(C_STD) $(CFLAGS) $(OPTFLAGS) $(WARNFLAGS) -pipe \
- -fexceptions -fno-strict-aliasing
+ -fexceptions -fno-strict-aliasing $(if $(ASAN),-fsanitize=address)
BIN_CFLAGS := -fPIE -DPIE
LIB_CFLAGS := -fPIC
SHARED_FLAGS := -shared
-LDFLAGS := $(LDFLAGS) -Wl,-z,relro -Wl,-z,now -Wl,-z,defs
+LDFLAGS := $(LDFLAGS) -Wl,-z,relro -Wl,-z,now -Wl,-z,defs $(if $(ASAN),-lasan)
BIN_LDFLAGS := -pie
# Source code directories. Don't modify.
diff --git a/README.md b/README.md
index 530caed..8ff139c 100644
--- a/README.md
+++ b/README.md
@@ -107,6 +107,9 @@ See "Passing standard compiler flags" below for an exception.
The following variables can be passed to the `make` command line:
* `V=1`: enable verbose build.
+ * `ASAN=1`: Enable
+ [AddressSanitizer](https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer)
+ during build for debugging memory allocation. This is off by default.
* `plugindir="/some/path"`: directory where libmultipath plugins (path
checkers, prioritizers, and foreign multipath support) will be looked up.
This used to be the run-time option `multipath_dir` in earlier versions.
--
2.52.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 5/5] Makefiles: add "OPT=" make parameter
2026-01-16 11:30 [PATCH 0/5] multipath-tools: minor fixes in preparation of 0.14.0 Martin Wilck
` (3 preceding siblings ...)
2026-01-16 11:30 ` [PATCH 4/5] Makefiles: add "ASAN=1" make parameter for AddressSanitizer Martin Wilck
@ 2026-01-16 11:30 ` Martin Wilck
2026-01-19 23:10 ` [PATCH 0/5] multipath-tools: minor fixes in preparation of 0.14.0 Benjamin Marzinski
5 siblings, 0 replies; 7+ messages in thread
From: Martin Wilck @ 2026-01-16 11:30 UTC (permalink / raw)
To: Benjamin Marzinski, dm-devel; +Cc: Martin Wilck, Christophe Varoqui
Our OPTFLAGS variable contains stack protection options which are
intended to be overridable by distribution build scripts. When developers
just want to experiment with optimization levels, they often just want
to modify the `-O` level. Introduce a variable `OPT` that allows to do just
that by passing e.g. `OPT=-O0` to the `make` command line.
Signed-off-by: Martin Wilck <mwilck@suse.com>
---
Makefile.inc | 5 ++++-
README.md | 6 ++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/Makefile.inc b/Makefile.inc
index 8356254..c6aa6ed 100644
--- a/Makefile.inc
+++ b/Makefile.inc
@@ -12,6 +12,9 @@
# Use ASAN=1 on make command line to enable address sanitizer
ASAN :=
#
+# Override on make command line if desired
+OPT := -O2
+
# Readline library to use, libedit, libreadline, or empty
# Caution: Using libreadline may make the multipathd binary undistributable,
# see https://github.com/opensvc/multipath-tools/issues/36
@@ -105,7 +108,7 @@ SYSTEMD_LIBDEPS := $(if $(SYSTEMD),$(if $(shell test $(SYSTEMD) -gt 209 && echo
MODPROBE_UNIT := $(shell test "0$(SYSTEMD)" -lt 245 2>/dev/null || \
echo "modprobe@dm_multipath.service")
-OPTFLAGS := -O2 -g $(STACKPROT) --param=ssp-buffer-size=4
+OPTFLAGS := $(OPT) -g $(STACKPROT) --param=ssp-buffer-size=4
# Set WARN_ONLY=1 to avoid compilation erroring out due to warnings. Useful during development.
WARN_ONLY :=
diff --git a/README.md b/README.md
index 8ff139c..888998b 100644
--- a/README.md
+++ b/README.md
@@ -107,6 +107,12 @@ See "Passing standard compiler flags" below for an exception.
The following variables can be passed to the `make` command line:
* `V=1`: enable verbose build.
+ * `OPT=`: set optimization flags. You may want to set `OPT="-O0"` for
+ debugging, for example. The default is `-O2`. Note that it is also
+ possible to set `OPTFLAGS`, which takes precedence over `OPT`. `OPTFLAGS`
+ sets additional options by default, which are intended for distribution
+ build environments to override. For quick customization of the optimization
+ level, use `OPT`.
* `ASAN=1`: Enable
[AddressSanitizer](https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer)
during build for debugging memory allocation. This is off by default.
--
2.52.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 0/5] multipath-tools: minor fixes in preparation of 0.14.0
2026-01-16 11:30 [PATCH 0/5] multipath-tools: minor fixes in preparation of 0.14.0 Martin Wilck
` (4 preceding siblings ...)
2026-01-16 11:30 ` [PATCH 5/5] Makefiles: add "OPT=" make parameter Martin Wilck
@ 2026-01-19 23:10 ` Benjamin Marzinski
5 siblings, 0 replies; 7+ messages in thread
From: Benjamin Marzinski @ 2026-01-19 23:10 UTC (permalink / raw)
To: Martin Wilck; +Cc: dm-devel, Martin Wilck, Christophe Varoqui
On Fri, Jan 16, 2026 at 12:30:37PM +0100, Martin Wilck wrote:
> This series fixes the double-free in kpartx introduced in 8c39e60 ("kpartx:
> fix some memory leaks"), removes the long-obsolete "hotplug" mode of
> kpartx, fixing another potential memory leak in the process, fixes a
> false positive compiler warning, and adds two developer convenience
> options to the Makefiles.
For the set:
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
>
> Martin Wilck (5):
> kpartx: avoid double-free of mapname
> kpartx: remove "hotplug" mode
> multipathd: fix an uninitialized variable warning
> Makefiles: add "ASAN=1" make parameter for AddressSanitizer
> Makefiles: add "OPT=" make parameter
>
> .github/actions/spelling/expect.txt | 3 +
> Makefile.inc | 12 +++-
> README.md | 9 +++
> kpartx/kpartx.c | 94 ++++-------------------------
> multipathd/main.c | 2 +-
> 5 files changed, 35 insertions(+), 85 deletions(-)
>
> --
> 2.52.0
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-01-19 23:10 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-16 11:30 [PATCH 0/5] multipath-tools: minor fixes in preparation of 0.14.0 Martin Wilck
2026-01-16 11:30 ` [PATCH 1/5] kpartx: avoid double-free of mapname Martin Wilck
2026-01-16 11:30 ` [PATCH 2/5] kpartx: remove "hotplug" mode Martin Wilck
2026-01-16 11:30 ` [PATCH 3/5] multipathd: fix an uninitialized variable warning Martin Wilck
2026-01-16 11:30 ` [PATCH 4/5] Makefiles: add "ASAN=1" make parameter for AddressSanitizer Martin Wilck
2026-01-16 11:30 ` [PATCH 5/5] Makefiles: add "OPT=" make parameter Martin Wilck
2026-01-19 23:10 ` [PATCH 0/5] multipath-tools: minor fixes in preparation of 0.14.0 Benjamin Marzinski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox