Re: [PATCH] libmultipath, kpartx: fix callers of dm_get_next_target()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, May 31, 2022 at 12:24:45PM +0200, mwilck@xxxxxxxx wrote:
> From: Martin Wilck <mwilck@xxxxxxxx>
> 
> 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@xxxxxxxx>

Reviewed-by: Benjamin Marzinski <bmarzins@xxxxxxxxxx>

> ---
>  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, &params);
> +	if (dm_get_next_target(dmt, NULL, &start, &length,
> +			       &target_type, &params) != 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, &params);
> +		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@xxxxxxxxxx
https://listman.redhat.com/mailman/listinfo/dm-devel




[Index of Archives]     [DM Crypt]     [Fedora Desktop]     [ATA RAID]     [Fedora Marketing]     [Fedora Packaging]     [Fedora SELinux]     [Yosemite Discussion]     [KDE Users]     [Fedora Docs]

  Powered by Linux