Skip to contentSkip to conversation

libmpathutil: don't call pthread_testcancel as part of udev commands

PATCH In review Benjamin Marzinski 2 participants 2 messages Aug 10 – Aug 19 Device mapper

lore
Share & tools
lore

Benjamin Marzinski

author maintainer
#0 lore raw

PATCH 1/1 libmpathutil: don't call pthread_testcancel as part of udev commands

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")
---
 libmpathutil/mt-libudev.c | 4 ----
 1 file changed, 4 deletions(-)
libmpathutil/mt-libudev.c +0 -4
index 813ce588..b81cf9c6 100644
@@ -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;						\
 	}
 
Signature · 1 line
2.46.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Benjamin Marzinski

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.

Quoted 3 lines
Fixes 47a654f0 ("libmpathutil: udev: prevent interruption by thread

cancellation")

Quoted 64 lines

---
 libmpathutil/mt-libudev.c | 4 ----

 1 file changed, 4 deletions(-)
libmpathutil/mt-libudev.c +0 -0
index 813ce588..b81cf9c6 100644
@@ -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; \
  }

libmpathutil/mt-libudev.c +0 -0
@@ -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; \
  }

libmpathutil/mt-libudev.c +0 -0
@@ -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; \
  }

libmpathutil/mt-libudev.c +0 -0
@@ -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; \
  }

Signature · 4 lines
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)