public inbox for dm-devel@redhat.com
 help / color / mirror / Atom feed
From: Benjamin Marzinski <bmarzins@redhat.com>
To: Martin Wilck <martin.wilck@suse.com>
Cc: dm-devel@lists.linux.dev,
	Christophe Varoqui <christophe.varoqui@opensvc.com>,
	Martin Wilck <mwilck@suse.com>
Subject: Re: [PATCH] kpartx: fix segfault when operating on regular files
Date: Mon, 26 Jan 2026 10:27:06 -0500	[thread overview]
Message-ID: <aXeHyiI7YtdQKCZx@redhat.com> (raw)
In-Reply-To: <20260126121325.208908-1-mwilck@suse.com>

On Mon, Jan 26, 2026 at 01:13:25PM +0100, Martin Wilck wrote:
> The following problem has been introduced in multipath-tools 0.14.0:
> 
> > truncate -s1G /tmp/img
> > kpartx -a /tmp/img
> double free or corruption (out)
> Aborted                    (core dumped) kpartx -a /tmp/img
> 
> Fix it by always allocating "uuid" on the heap, rather than
> using a static char array.
> 
> Fixes: 8c39e60 ("kpartx: fix some memory leaks")
> Fixes: https://github.com/opensvc/multipath-tools/issues/139
> ---
> 
> Note: This issue also affects the pending github PRs for the
> stable branches 0.13.y, 0.12.y, 0.11.y, and 0.10.y.
> 
> A fix will be pushed to these PRs ASAP.
> 
> ---
>  kpartx/devmapper.c | 16 ++++++++--------
>  kpartx/kpartx.c    |  5 ++++-
>  2 files changed, 12 insertions(+), 9 deletions(-)
> 
> diff --git a/kpartx/devmapper.c b/kpartx/devmapper.c
> index d49c680..45dac58 100644
> --- a/kpartx/devmapper.c
> +++ b/kpartx/devmapper.c
> @@ -1,6 +1,7 @@
>  /*
>   * Copyright (c) 2004, 2005 Christophe Varoqui
>   */
> +#define _GNU_SOURCE
>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <string.h>
> @@ -699,14 +700,13 @@ out:
>  
>  char *nondm_create_uuid(dev_t devt)
>  {
> -#define NONDM_UUID_BUFLEN (34 + sizeof(NONDM_UUID_PREFIX) + \
> -			   sizeof(NONDM_UUID_SUFFIX))
> -	static char uuid_buf[NONDM_UUID_BUFLEN];
> -	snprintf(uuid_buf, sizeof(uuid_buf), "%s_%u:%u_%s",
> -		 NONDM_UUID_PREFIX, major(devt), minor(devt),
> -		 NONDM_UUID_SUFFIX);
> -	uuid_buf[NONDM_UUID_BUFLEN-1] = '\0';
> -	return uuid_buf;
> +	char *uuid;
> +
> +	if (asprintf(&uuid, "%s_%u:%u_%s", NONDM_UUID_PREFIX, major(devt),
> +		     minor(devt), NONDM_UUID_SUFFIX) >= 0)
> +		return uuid;
> +	else
> +		return NULL;
>  }
>  
>  int nondm_parse_uuid(const char *uuid, unsigned int *major, unsigned int *minor)
> diff --git a/kpartx/kpartx.c b/kpartx/kpartx.c
> index 9bdd204..cfd8212 100644
> --- a/kpartx/kpartx.c
> +++ b/kpartx/kpartx.c
> @@ -334,8 +334,11 @@ main(int argc, char **argv){
>  	 * This allows deletion of partitions created with older kpartx
>  	 * versions which didn't use the fake UUID during creation.
>  	 */
> -	if (!uuid && !(what == DELETE && force_devmap))
> +	if (!uuid && !(what == DELETE && force_devmap)) {
>  		uuid = nondm_create_uuid(buf.st_rdev);
> +		if (!uuid)

We should probably print an error message before we exit, but
otherwise, this looks good.

-Ben

> +			exit(1);
> +	}
>  
>  	if (delim == NULL) {
>  		delim = xmalloc(DELIM_SIZE);
> -- 
> 2.52.0


  reply	other threads:[~2026-01-26 15:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-26 12:13 [PATCH] kpartx: fix segfault when operating on regular files Martin Wilck
2026-01-26 15:27 ` Benjamin Marzinski [this message]
2026-01-26 15:58   ` Benjamin Marzinski
2026-01-26 15:48 ` Bastian Blank

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aXeHyiI7YtdQKCZx@redhat.com \
    --to=bmarzins@redhat.com \
    --cc=christophe.varoqui@opensvc.com \
    --cc=dm-devel@lists.linux.dev \
    --cc=martin.wilck@suse.com \
    --cc=mwilck@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox