Message ID | 20220531102445.18518-1-mwilck@suse.com (mailing list archive) |
---|---|
State | Not Applicable, archived |
Delegated to: | Mike Snitzer |
Headers | show |
Series | libmultipath, kpartx: fix callers of dm_get_next_target() | expand |
On Tue, May 31, 2022 at 12:24:45PM +0200, mwilck@suse.com wrote: > From: Martin Wilck <mwilck@suse.com> > > dm_get_next_target() may return NULL for target_type and params > in some situations. Follows the same idea as the previous patch > "dm_get_map: fix segfault when can't found target" by Wu Guanghao. > > Signed-off-by: Martin Wilck <mwilck@suse.com> Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com> > --- > kpartx/devmapper.c | 6 ++++-- > libmultipath/devmapper.c | 10 ++++++++++ > 2 files changed, 14 insertions(+), 2 deletions(-) > > diff --git a/kpartx/devmapper.c b/kpartx/devmapper.c > index 49ffd31..bf14c78 100644 > --- a/kpartx/devmapper.c > +++ b/kpartx/devmapper.c > @@ -412,8 +412,10 @@ dm_get_map(const char *mapname, char * outparams) > goto out; > > /* Fetch 1st target */ > - dm_get_next_target(dmt, NULL, &start, &length, > - &target_type, ¶ms); > + if (dm_get_next_target(dmt, NULL, &start, &length, > + &target_type, ¶ms) != NULL || !params) > + /* more than one target or not found target */ > + goto out; > > if (snprintf(outparams, PARAMS_SIZE, "%s", params) <= PARAMS_SIZE) > r = 0; > diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c > index 9819e29..1ada3fb 100644 > --- a/libmultipath/devmapper.c > +++ b/libmultipath/devmapper.c > @@ -1715,6 +1715,16 @@ int dm_reassign_table(const char *name, char *old, char *new) > do { > next = dm_get_next_target(dmt, next, &start, &length, > &target, ¶ms); > + if (!target || !params) { > + /* > + * We can't call dm_task_add_target() with > + * invalid parameters. But simply dropping this > + * target feels wrong, too. Abort and warn. > + */ > + condlog(1, "%s: invalid target found in map %s", > + __func__, name); > + goto out_reload; > + } > buff = strdup(params); > if (!buff) { > condlog(3, "%s: failed to replace target %s, " > -- > 2.36.1 -- dm-devel mailing list dm-devel@redhat.com https://listman.redhat.com/mailman/listinfo/dm-devel
diff --git a/kpartx/devmapper.c b/kpartx/devmapper.c index 49ffd31..bf14c78 100644 --- a/kpartx/devmapper.c +++ b/kpartx/devmapper.c @@ -412,8 +412,10 @@ dm_get_map(const char *mapname, char * outparams) goto out; /* Fetch 1st target */ - dm_get_next_target(dmt, NULL, &start, &length, - &target_type, ¶ms); + if (dm_get_next_target(dmt, NULL, &start, &length, + &target_type, ¶ms) != NULL || !params) + /* more than one target or not found target */ + goto out; if (snprintf(outparams, PARAMS_SIZE, "%s", params) <= PARAMS_SIZE) r = 0; diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 9819e29..1ada3fb 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -1715,6 +1715,16 @@ int dm_reassign_table(const char *name, char *old, char *new) do { next = dm_get_next_target(dmt, next, &start, &length, &target, ¶ms); + if (!target || !params) { + /* + * We can't call dm_task_add_target() with + * invalid parameters. But simply dropping this + * target feels wrong, too. Abort and warn. + */ + condlog(1, "%s: invalid target found in map %s", + __func__, name); + goto out_reload; + } buff = strdup(params); if (!buff) { condlog(3, "%s: failed to replace target %s, "