Re: [PATCH] libmpathutil: don't call pthread_testcancel as part of udev commands

Martin Wilck <[email protected]>
Newsgroups dev.linux.lists.dm-devel
Message-ID <[email protected]>
On Mon, 2026-08-10 at 17:05 -0400, Benjamin Marzinski wrote:
> Commit 47a654f0 ("libmpathutil: udev: prevent interruption by thread
> cancellation") added pthread_testcancel() calls to the udev command
> wrappers. This makes these commands cancellation points (but only
> after
> any waiting has already happened without cancellation), while the
> rest
> of the code assumes that they are not.
> 
> This can cause problems like in uev_update_path() when multipathd
> first
> calls udev_device_unref(pp->udev) and afterwards resets pp->udev. If
> the
> thread is cancelled after unref'ing device in the udev_device_unref()
> call, pp->udev will still point to the now-freed udev_device.
> 
> Fixes: 47a654f0 ("libmpathutil: udev: prevent interruption by thread
> cancellation")
> Signed-off-by: Benjamin Marzinski <[email protected]>

Reviewed-by: Martin Wilck <[email protected]>

> ---
>  libmpathutil/mt-libudev.c | 4 ----
>  1 file changed, 4 deletions(-)
> 
> diff --git a/libmpathutil/mt-libudev.c b/libmpathutil/mt-libudev.c
> index 813ce588..b81cf9c6 100644
> --- a/libmpathutil/mt-libudev.c
> +++ b/libmpathutil/mt-libudev.c
> @@ -14,7 +14,6 @@ static pthread_mutex_t libudev_mutex =
> PTHREAD_MUTEX_INITIALIZER;
>  		__r =
> func();						\
>  		pthread_mutex_unlock(&libudev_mutex);		
> 	\
>  		pthread_setcancelstate(__oldstate,
> NULL);		\
> -
> 		pthread_testcancel();					\
>  		return
> __r;						\
>  	}
>  
> @@ -27,7 +26,6 @@ static pthread_mutex_t libudev_mutex =
> PTHREAD_MUTEX_INITIALIZER;
>  		__r =
> func(__arg1);						\
>  		pthread_mutex_unlock(&libudev_mutex);		
> 	\
>  		pthread_setcancelstate(__oldstate,
> NULL);		\
> -
> 		pthread_testcancel();					\
>  		return
> __r;						\
>  	}
>  
> @@ -40,7 +38,6 @@ static pthread_mutex_t libudev_mutex =
> PTHREAD_MUTEX_INITIALIZER;
>  		__r = func(__arg1,
> __arg2);				\
>  		pthread_mutex_unlock(&libudev_mutex);		
> 	\
>  		pthread_setcancelstate(__oldstate,
> NULL);		\
> -
> 		pthread_testcancel();					\
>  		return
> __r;						\
>  	}
>  
> @@ -53,7 +50,6 @@ static pthread_mutex_t libudev_mutex =
> PTHREAD_MUTEX_INITIALIZER;
>  		__r = func(__arg1, __arg2,
> __arg3);			\
>  		pthread_mutex_unlock(&libudev_mutex);		
> 	\
>  		pthread_setcancelstate(__oldstate,
> NULL);		\
> -
> 		pthread_testcancel();					\
>  		return
> __r;						\
>  	}
>  

-- 
Dr. Martin Wilck <[email protected]>
SUSE Software Solutions Germany GmbH, Frankenstr. 146, 90461 Nürnberg,
Germany
Geschäftsführer: Jochen Jaser, Andrew McDonald (HRB 36809,AG Nürnberg)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.