Seven multipathd patches
cover Seven multipathd patches
Hello Christophe,
These seven patches are what I came up with while reviewing and testing multipathd. It would be appreciated if you could review these patches and if you would consider these for inclusion in the official multipath-tools git tree.
Thanks,
Bart.
PATCH 1/7 Minimize #include directives
Remove unneeded #include directives. Correct the comments next to the #include directives in multipathd/pidfile.c.
--- libmultipath/lock.c | 2 -- libmultipath/lock.h | 2 +- libmultipath/uevent.c | 1 - multipathd/pidfile.c | 8 +++----- 4 files changed, 4 insertions(+), 9 deletions(-)
libmultipath/lock.c +0 -2
@@ -1,6 +1,4 @@ -#include <pthread.h> #include "lock.h" -#include <stdio.h> void cleanup_lock (void * data) {
libmultipath/lock.h +1 -1
@@ -1,7 +1,7 @@#ifndef _LOCK_H#define _LOCK_H -#include <signal.h> +#include <pthread.h> /* * Wrapper for the mutex. Includes a ref-count to keep
libmultipath/uevent.c +0 -1
@@ -37,7 +37,6 @@#include <linux/types.h> #include <linux/netlink.h> #include <pthread.h> -#include <signal.h> #include <limits.h> #include <sys/mman.h> #include <libudev.h>
multipathd/pidfile.c +3 -5
@@ -1,11 +1,9 @@#include <sys/types.h> /* for pid_t */ #include <sys/stat.h> /* for open */ -#include <signal.h> /* for kill() */ -#include <errno.h> /* for ESHRC */ -#include <stdio.h> /* for f...() */ +#include <errno.h> /* for EACCESS and EAGAIN */ +#include <stdio.h> /* for snprintf() */ #include <string.h> /* for memset() */ -#include <stdlib.h> /* for atoi() */ -#include <unistd.h> /* for unlink() */ +#include <unistd.h> /* for ftruncate() */ #include <fcntl.h> /* for fcntl() */ #include "debug.h"
Signature · 1 line
2.9.2
PATCH 2/7 libmultipath: Declare more functions 'static'
In reply to Bart Van Assche--- libmultipath/waiter.c | 8 ++++---- libmultipath/waiter.h | 4 ---- 2 files changed, 4 insertions(+), 8 deletions(-)
libmultipath/waiter.c +4 -4
@@ -24,7 +24,7 @@pthread_attr_t waiter_attr; -struct event_thread *alloc_waiter (void ) +static struct event_thread *alloc_waiter (void ) {struct event_thread *wp;
@@ -35,7 +35,7 @@ struct event_thread *alloc_waiter (void)return wp; } -void free_waiter (void *data) +static void free_waiter (void *data) {struct event_thread *wp = (struct event_thread *)data;
@@ -67,7 +67,7 @@ void stop_waiter_thread (struct multipath *mpp, struct vectors *vecs)* returns the reschedule delay * negative means *stop* */ -int waiteventloop (struct event_thread *waiter) +static int waiteventloop (struct event_thread *waiter) {sigset_t set, oldset;int event_nr;
@@ -159,7 +159,7 @@ int waiteventloop (struct event_thread *waiter)return -1 ;/* never reach there */ } -void *waitevent (void *et) +static void *waitevent (void *et) {int r;struct event_thread *waiter;
libmultipath/waiter.h +0 -4
@@ -11,11 +11,7 @@ struct event_thread { struct vectors *vecs; }; -struct event_thread *alloc_waiter (void ); -void free_waiter (void *data);void stop_waiter_thread (struct multipath *mpp,struct vectors *vecs);int start_waiter_thread (struct multipath *mpp,struct vectors *vecs); -int waiteventloop (struct event_thread *waiter); -void *waitevent (void *et);#endif /* _WAITER_H */
Signature · 1 line
2.9.2
PATCH 3/7 libmultipath: Fix spelling in a log message
In reply to Bart Van Assche--- libmultipath/propsel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libmultipath/propsel.c +1 -1
@@ -459,7 +459,7 @@ out:condlog (3 ,"%s: no_path_retry = %s %s" , mp->alias, buff, origin); else if (mp->no_path_retry != NO_PATH_RETRY_UNDEF) - condlog(3, "%s: no_path_retry = %s (inheritied setting)", + condlog(3, "%s: no_path_retry = %s (inherited setting)", mp->alias, buff); else condlog(3, "%s: no_path_retry = undef (internal default)",
Signature · 1 line
2.9.2
PATCH 4/7 multipathd: Fix type of rcu_unregister()
In reply to Bart Van AsscheThis patch avoids that gcc reports the following compiler warning:
initialization from incompatible pointer type [-Wincompatible-pointer-types]
pthread_cleanup_push(rcu_unregister, NULL);
--- multipathd/main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
multipathd/main.c +1 -2
@@ -1126,10 +1126,9 @@ out:return r; } -static void *rcu_unregister (void *param) +static void rcu_unregister (void *param) {rcu_unregister_thread (); -return NULL ; } static void *
Signature · 1 line
2.9.2
PATCH 5/7 multipathd: Do not perform POSIX mutex operations inside a signal handler
In reply to Bart Van AsscheAccording to the POSIX standard, only functions that are async-signal-safe may be invoked from inside a signal handler. The only POSIX thread functions that are async-signal-safe are pthread_kill(), pthread_self() and pthread_sigmask(). See also
http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04_03.
--- multipathd/main.c | 12 +++++++++++- multipathd/uxlsnr.c | 2 -- multipathd/uxlsnr.h | 3 --- 3 files changed, 11 insertions(+), 6 deletions(-)
multipathd/main.c +11 -1
@@ -117,6 +117,11 @@ struct udev * udev;struct config *multipath_conf; +/* Local variables */ +static volatile sig_atomic_t exit_sig; +static volatile sig_atomic_t reconfig_sig; +static volatile sig_atomic_t log_reset_sig; +const char *daemon_status (void ) {
@@ -2070,6 +2075,10 @@ signal_set(int signo, void (*func) (int))void handle_signals (void ) { +if (exit_sig) { +condlog (2 ,"exit (signal)" ); +exit_daemon (); + }if (reconfig_sig) {condlog (2 ,"reconfigure (signal)" );set_config_state (DAEMON_CONFIGURE );
@@ -2080,6 +2089,7 @@ handle_signals(void)log_reset ("multipathd" );pthread_mutex_unlock (&logq_lock); } + exit_sig =0 ; reconfig_sig =0 ; log_reset_sig =0 ; }
@@ -2093,7 +2103,7 @@ sighup (int sig)static void sigend (int sig) { -exit_daemon (); + exit_sig =1 ; } static void
multipathd/uxlsnr.c +0 -2
@@ -49,8 +49,6 @@ struct client {LIST_HEAD (clients);pthread_mutex_t client_lock =PTHREAD_MUTEX_INITIALIZER ;struct pollfd *polls; -volatile sig_atomic_t reconfig_sig =0 ; -volatile sig_atomic_t log_reset_sig =0 ;/* * handle a new client joining
multipathd/uxlsnr.h +0 -3
@@ -6,7 +6,4 @@ typedef int (uxsock_trigger_fn)(char *, char **, int *, void *);void *uxsock_listen (uxsock_trigger_fn uxsock_trigger,void * trigger_data); -extern volatile sig_atomic_t reconfig_sig; -extern volatile sig_atomic_t log_reset_sig; -#endif
Signature · 1 line
2.9.2
PATCH 6/7 multipathd: Ensure that SIGINT, SIGTERM, SIGHUP and SIGUSR1 are delivered to the uxsock thread
In reply to Bart Van AsscheThe POSIX standard mentions that the only way to guarantee that signals are delivered to a specific thread is:
* Block all signals before the first pthread_create() call.
* Unblock signals from the thread that should receive signals.
Implement that approach in multipathd. And since ppoll() can return 0 if interrupted, also call handle_signals() if ppoll() returns 0.
--- multipathd/main.c | 7 ++----- multipathd/uxlsnr.c | 12 ++++++++---- 2 files changed, 10 insertions(+), 9 deletions(-)
multipathd/main.c +2 -5
@@ -2124,11 +2124,8 @@ signal_init(void)sigset_t set;sigemptyset (&set); -sigaddset (&set,SIGHUP ); -sigaddset (&set,SIGUSR1 ); -sigaddset (&set,SIGUSR2 ); -sigaddset (&set,SIGALRM ); -pthread_sigmask (SIG_BLOCK , &set,NULL ); +sigaddset (&set,SIGPIPE ); +pthread_sigmask (SIG_SETMASK , &set,NULL );signal_set (SIGHUP , sighup);signal_set (SIGUSR1 , sigusr1);
multipathd/uxlsnr.c +8 -4
@@ -150,9 +150,11 @@ void * uxsock_listen(uxsock_trigger_fn uxsock_trigger, void * trigger_data)condlog (0 ,"uxsock: failed to allocate poll fds" );return NULL ; } -pthread_sigmask (SIG_SETMASK ,NULL , &mask); -sigdelset (&mask,SIGHUP ); -sigdelset (&mask,SIGUSR1 ); +sigemptyset (&mask); +sigaddset (&mask,SIGINT ); +sigaddset (&mask,SIGTERM ); +sigaddset (&mask,SIGHUP ); +sigaddset (&mask,SIGUSR1 );while (1 ) {struct client *c, *tmp;int i, poll_count, num_clients;
@@ -208,8 +210,10 @@ void * uxsock_listen(uxsock_trigger_fn uxsock_trigger, void * trigger_data)break ; } -if (poll_count ==0 ) +if (poll_count ==0 ) { +handle_signals ();continue ; + }/* see if a client wants to speak to us */ for (i =1 ; i < num_clients +1 ; i++) {
Signature · 1 line
2.9.2
PATCH 7/7 multipathd: Fix a use-after-free
In reply to Bart Van AsscheAvoid that Valgrind reports the following:
Invalid read of size 4
at 0x40C7AE: child (main.c:2382)
by 0x40D2DC: main (main.c:2608)
Address 0x7ed255c is 76 bytes inside a block of size 416 free'd
at 0x4C2E38B: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) by 0x5DD37ED: free_config (config.c:539)
by 0x40B76C: rcu_free_config (main.c:1987)
by 0x4E3C1FF: call_rcu_thread (urcu-call-rcu-impl.h:332)
by 0x5047473: start_thread (pthread_create.c:333)
by 0x671C3EC: clone (clone.S:109)
Block was alloc'd at
at 0x4C2D12F: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) by 0x5DC7D9B: zalloc (memory.c:41)
by 0x5DD34D7: alloc_config (config.c:472)
by 0x5DD3A87: load_config (config.c:582)
by 0x40BF98: child (main.c:2246)
by 0x40D2DC: main (main.c:2608)
--- multipathd/main.c | 2 ++ 1 file changed, 2 insertions(+)
multipathd/main.c +2 -0
@@ -2376,9 +2376,11 @@ child (void * param) }lock (vecs->lock); + conf =get_multipath_config ();if (conf->queue_without_daemon ==QUE_NO_DAEMON_OFF ) vector_foreach_slot(vecs->mpvec, mpp, i)dm_queue_if_no_path (mpp->alias,0 ); +put_multipath_config (conf);remove_maps_and_stop_waiters (vecs);unlock (vecs->lock);
Signature · 1 line
2.9.2
Re: [PATCH 7/7] multipathd: Fix a use-after-free
Quoted 32 lines · Bart Van Assche
Avoid that Valgrind reports the following:
Invalid read of size 4
at0x40C7AE: child (main.c:2382)
by0x40D2DC: main (main.c:2608)
Address0x7ed255cis 76 bytes inside a block of size 416 free'd
at0x4C2E38B: free (in/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) by0x5DD37ED:free_config(config.c:539)
by0x40B76C:rcu_free_config(main.c:1987)
by0x4E3C1FF:call_rcu_thread(urcu-call-rcu-impl.h:332)
by0x5047473:start_thread(pthread_create.c:333)
by0x671C3EC: clone (clone.S:109)
Block was alloc'd at
at0x4C2D12F: malloc (in/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) by0x5DC7D9B: zalloc (memory.c:41)
by0x5DD34D7:alloc_config(config.c:472)
by0x5DD3A87:load_config(config.c:582)
by0x40BF98: child (main.c:2246)
by0x40D2DC: main (main.c:2608)Signed-off-by Bart Van Assche <[email protected]>--- multipathd/main.c | 2 ++ 1 file changed, 2 insertions(+)multipathd/main.c +0
-0@@ -2376,9 +2376,11 @@ child (void * param) }
multipathd/main.c child (void * param) · line 2386
Quoted 10 lines
multipathd/main.c +2
-0lock (vecs->lock); + conf =get_multipath_config ();if (conf->queue_without_daemon ==QUE_NO_DAEMON_OFF ) vector_foreach_slot(vecs->mpvec, mpp, i)dm_queue_if_no_path (mpp->alias,0 ); +put_multipath_config (conf);remove_maps_and_stop_waiters (vecs);unlock (vecs->lock);
This one is already included in my patch 'multipathd: Correctly invalidate configuration during shutdown', which also contains some additional fixes for RCU config access.
I would prefer taking that instead of this patch.
Cheers,
Hannes
Signature · 10 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton HRB 21284 (AG Nürnberg) -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
Re: [PATCH 7/7] multipathd: Fix a use-after-free
Quoted 22 lines · Hannes Reinecke
Quoted 7 lines · Bart Van Assche
multipathd/main.c +0
-0@@ -2376,9 +2376,11 @@ child (void * param) }multipathd/main.c child (void * param) · line 2386
Quoted 10 lines
multipathd/main.c +2
-0lock (vecs->lock); + conf =get_multipath_config ();if (conf->queue_without_daemon ==QUE_NO_DAEMON_OFF ) vector_foreach_slot(vecs->mpvec, mpp, i)dm_queue_if_no_path (mpp->alias,0 ); +put_multipath_config (conf);remove_maps_and_stop_waiters (vecs);unlock (vecs->lock);This one is already included in my patch 'multipathd: Correctly invalidate configuration during shutdown', which also contains some additional fixes for RCU config access.
Quoted 1 line
I would prefer taking that instead of this patch.
Hello Hannes,
You are right. I had not yet noticed that your patch includes the above change. Christophe, please drop this patch.
Bart.
Patches 1 to 6 are now merged.
Thanks.
Quoted 11 lines · Bart Van Assche
Hello Christophe,
These seven patches are what I came up with while reviewing and testing multipathd. It would be appreciated if you could review these patches and if you would consider these for inclusion in the official multipath-tools git tree.
Thanks,
Bart.