Skip to contentSkip to conversation

segment faulty occured in dm_get_status()

PATCH In review [email protected] 3 participants 8 messages Oct 18, 2016 – Oct 19, 2016 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 segment faulty occured in dm_get_status()

From: "tang.junhui" <[email protected]>

segment faulty occured in dm_get_status(), the call trace is:
----------------------------------------------------------------------
(gdb) bt

0  0x000000338ec328a5 in raise () from /lib64/libc.so.6
1  0x000000338ec3400d in abort () from /lib64/libc.so.6
2  0x000000000040596d in sigsegv ()
3  <signal handler called>
4  0x000000338ec480ac in vfprintf () from /lib64/libc.so.6
5  0x000000338ec6f9d2 in vsnprintf () from /lib64/libc.so.6
6  0x000000338ec4f4a3 in snprintf () from /lib64/libc.so.6
7  0x00007f43fe66bbb9 in dm_get_status (name=0x7f43f0001eb0 "spathe",

outstatus=<value optimized out>) at devmapper.c:521
8 0x00007f43fe68c058 in update_multipath_status (mpp=0x7f43f000ad60, pathvec=<value optimized out>) at structs_vec.c:465
9 update_multipath_strings (mpp=0x7f43f000ad60, pathvec=<value optimized out>) at structs_vec.c:495
10 0x0000000000409056 in check_path ()
11 0x0000000000409c7e in checkerloop ()
12 0x0000003b27207851 in start_thread () from /lib64/libpthread.so.0 13 0x000000338ece890d in clone () from /lib64/libc.so.6
-----------------------------------------------------------------------
we debuged the code, and found that targets information storing in the list dmt->head which fetching from kernel by executing dm_task_run() is null.
-----------------------------------------------------------------------
rbx 0x7f43c4000d60 139929027874144
(gdb) p *(struct dm_task *)0x7f43c4000d60
$3 = {type = 10, dev_name = 0x7f43c4000d40 "spathe", head = 0x0, tail = 0x0, read_only = 0, event_nr = 0, major = -1, minor = -1,
allow_default_major_fallback = 1, uid = 0, gid = 0, mode = 384,

  read_ahead = 4294967295, read_ahead_flags = 0, dmi = {
      v4 = 0x7f43c40011e0, v1 = 0x7f43c40011e0}, newname = 0x0, message =
      0x0, geometry = 0x0, sector = 0, no_flush = 0,
        no_open_count = 1, skip_lockfs = 0, query_inactive_table = 0,
	suppress_identical_reload = 0, existing_table_size = 0,
	  cookie_set = 0, uuid = 0x0}

-----------------------------------------------------------------------
since status is not initioned to null, so after calling dm_get_next_target(dmt, next, &start, &length,&target_type, &status),status becaming wild pointer, which lead snprintf() into the situation of segment faulty.

---
 libmultipath/devmapper.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
libmultipath/devmapper.c +6 -2
index 5eb1713..89aa5da 100644
@@ -534,8 +534,8 @@ dm_get_status(char * name, char * outstatus)
 	int r = 1;
 	struct dm_task *dmt;
 	uint64_t start, length;
-	char *target_type;
-	char *status;
+	char *target_type = NULL;
+	char *status = NULL;
 
 	if (!(dmt = dm_task_create(DM_DEVICE_STATUS)))
 		return 1;
@@ -551,6 +551,10 @@ dm_get_status(char * name, char * outstatus)
 	/* Fetch 1st target */
 	dm_get_next_target(dmt, NULL, &start, &length,
 			   &target_type, &status);
+	if (!status) {
+		condlog(2, "get null status.");
+		goto out;
+	}
 
 	if (snprintf(outstatus, PARAMS_SIZE, "%s", status) <= PARAMS_SIZE)
 		r = 0;
Signature · 1 line
2.8.1.windows.1
#1 lore raw

PATCH 2/3 access vecs memory outside of locking range in check_path()

From: "tang.junhui" <[email protected]>

there are vecs->mpvec memory accesses outside of locking range in check_path(), the judgments is not necessary since the they has existed in vector_foreach_slot(), so delete them.

---
 multipathd/main.c | 45 ++++++++++++++++++++++-----------------------
 1 file changed, 22 insertions(+), 23 deletions(-)
multipathd/main.c +22 -23
index b6eb696..e369a79 100644
@@ -1804,30 +1804,29 @@ checkerloop (void *ap)
 			condlog(4, "timeout waiting for DAEMON_IDLE");
 			continue;
 		}
-		if (vecs->pathvec) {
-			pthread_cleanup_push(cleanup_lock, &vecs->lock);
-			lock(&vecs->lock);
-			pthread_testcancel();
-			vector_foreach_slot (vecs->pathvec, pp, i) {
-				rc = check_path(vecs, pp, ticks);
-				if (rc < 0) {
-					vector_del_slot(vecs->pathvec, i);
-					free_path(pp);
-					i--;
-				} else
-					num_paths += rc;
-			}
-			lock_cleanup_pop(vecs->lock);
-		}
-		if (vecs->mpvec) {
-			pthread_cleanup_push(cleanup_lock, &vecs->lock);
-			lock(&vecs->lock);
-			pthread_testcancel();
-			defered_failback_tick(vecs->mpvec);
-			retry_count_tick(vecs->mpvec);
-			missing_uev_wait_tick(vecs);
-			lock_cleanup_pop(vecs->lock);
+
+		pthread_cleanup_push(cleanup_lock, &vecs->lock);
+		lock(&vecs->lock);
+		pthread_testcancel();
+		vector_foreach_slot (vecs->pathvec, pp, i) {
+			rc = check_path(vecs, pp, ticks);
+			if (rc < 0) {
+				vector_del_slot(vecs->pathvec, i);
+				free_path(pp);
+				i--;
+			} else
+				num_paths += rc;
 		}
+		lock_cleanup_pop(vecs->lock);
+
+		pthread_cleanup_push(cleanup_lock, &vecs->lock);
+		lock(&vecs->lock);
+		pthread_testcancel();
+		defered_failback_tick(vecs->mpvec);
+		retry_count_tick(vecs->mpvec);
+		missing_uev_wait_tick(vecs);
+		lock_cleanup_pop(vecs->lock);
+
 		if (count)
 			count--;
 		else {
Signature · 1 line
2.8.1.windows.1
#2 lore raw

Re: [PATCH 2/3] access vecs memory outside of locking range in check_path()

Quoted 5 lines · On Tue, Oct 18, 2016 at 10:51:08AM +0800, [email protected] wrote:

From: "tang.junhui" <[email protected]>

there are vecs->mpvec memory accesses outside of locking range in check_path(), the judgments is not necessary since the they has existed in vector_foreach_slot(), so delete them.

ACK

-Ben

Quoted 64 lines
---
 multipathd/main.c | 45 ++++++++++++++++++++++-----------------------
 1 file changed, 22 insertions(+), 23 deletions(-)
multipathd/main.c +22 -23
index b6eb696..e369a79 100644
@@ -1804,30 +1804,29 @@ checkerloop (void *ap)
 			condlog(4, "timeout waiting for DAEMON_IDLE");
 			continue;
 		}
-		if (vecs->pathvec) {
-			pthread_cleanup_push(cleanup_lock, &vecs->lock);
-			lock(&vecs->lock);
-			pthread_testcancel();
-			vector_foreach_slot (vecs->pathvec, pp, i) {
-				rc = check_path(vecs, pp, ticks);
-				if (rc < 0) {
-					vector_del_slot(vecs->pathvec, i);
-					free_path(pp);
-					i--;
-				} else
-					num_paths += rc;
-			}
-			lock_cleanup_pop(vecs->lock);
-		}
-		if (vecs->mpvec) {
-			pthread_cleanup_push(cleanup_lock, &vecs->lock);
-			lock(&vecs->lock);
-			pthread_testcancel();
-			defered_failback_tick(vecs->mpvec);
-			retry_count_tick(vecs->mpvec);
-			missing_uev_wait_tick(vecs);
-			lock_cleanup_pop(vecs->lock);
+
+		pthread_cleanup_push(cleanup_lock, &vecs->lock);
+		lock(&vecs->lock);
+		pthread_testcancel();
+		vector_foreach_slot (vecs->pathvec, pp, i) {
+			rc = check_path(vecs, pp, ticks);
+			if (rc < 0) {
+				vector_del_slot(vecs->pathvec, i);
+				free_path(pp);
+				i--;
+			} else
+				num_paths += rc;
 		}
+		lock_cleanup_pop(vecs->lock);
+
+		pthread_cleanup_push(cleanup_lock, &vecs->lock);
+		lock(&vecs->lock);
+		pthread_testcancel();
+		defered_failback_tick(vecs->mpvec);
+		retry_count_tick(vecs->mpvec);
+		missing_uev_wait_tick(vecs);
+		lock_cleanup_pop(vecs->lock);
+
 		if (count)
 			count--;
 		else {
Signature · 1 line
2.8.1.windows.1
#3 lore raw

Re: [PATCH 2/3] access vecs memory outside of locking range in check_path()

Merged.

Quoted 77 lines · Benjamin Marzinski
Quoted 5 lines · On Tue, Oct 18, 2016 at 10:51:08AM +0800, [email protected] wrote:

From: "tang.junhui" <[email protected]>

there are vecs->mpvec memory accesses outside of locking range in check_path(), the judgments is not necessary since the they has existed in vector_foreach_slot(), so delete them.

ACK

-Ben

Quoted 64 lines
---
 multipathd/main.c | 45 ++++++++++++++++++++++-----------------------
 1 file changed, 22 insertions(+), 23 deletions(-)
multipathd/main.c +22 -24
index b6eb696..e369a79 100644
@@ -1804,30 +1804,29 @@ checkerloop (void *ap)
                      condlog(4, "timeout waiting for DAEMON_IDLE");
                      continue;
              }
-             if (vecs->pathvec) {
-                     pthread_cleanup_push(cleanup_lock, &vecs->lock);
-                     lock(&vecs->lock);
-                     pthread_testcancel();
-                     vector_foreach_slot (vecs->pathvec, pp, i) {
-                             rc = check_path(vecs, pp, ticks);
-                             if (rc < 0) {
-                                     vector_del_slot(vecs->pathvec, i);
-                                     free_path(pp);
-                                     i--;
-                             } else
-                                     num_paths += rc;
-                     }
-                     lock_cleanup_pop(vecs->lock);
-             }
-             if (vecs->mpvec) {
-                     pthread_cleanup_push(cleanup_lock, &vecs->lock);
-                     lock(&vecs->lock);
-                     pthread_testcancel();
-                     defered_failback_tick(vecs->mpvec);
-                     retry_count_tick(vecs->mpvec);
-                     missing_uev_wait_tick(vecs);
-                     lock_cleanup_pop(vecs->lock);
+
+             pthread_cleanup_push(cleanup_lock, &vecs->lock);
+             lock(&vecs->lock);
+             pthread_testcancel();
+             vector_foreach_slot (vecs->pathvec, pp, i) {
+                     rc = check_path(vecs, pp, ticks);
+                     if (rc < 0) {
+                             vector_del_slot(vecs->pathvec, i);
+                             free_path(pp);
+                             i--;
+                     } else
+                             num_paths += rc;
              }
+             lock_cleanup_pop(vecs->lock);
+
+             pthread_cleanup_push(cleanup_lock, &vecs->lock);
+             lock(&vecs->lock);
+             pthread_testcancel();
+             defered_failback_tick(vecs->mpvec);
+             retry_count_tick(vecs->mpvec);
+             missing_uev_wait_tick(vecs);
+             lock_cleanup_pop(vecs->lock);
+
              if (count)
                      count--;
              else {
--

2.8.1.windows.1

#4 lore raw

PATCH 3/3 Treat PATH_TIMEOUT as PATH_DOWN

In reply to [email protected]

From: "tang.junhui" <[email protected]>

Treat PATH_TIMEOUT as PATH_DOWN since it is basically the same as PATH_DOWN, except with a different state name. So change it to PATH_DOWN immediately if it is PATH_TIMEOUT according to the method in pathinfo(). After the modification all PATH_TIMEOUTs are equal to PATH_DOWN since the rest of pp->state is assigned all in pathinfo().

---
 multipathd/main.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
multipathd/main.c +5 -1
index e369a79..f715eb5 100644
@@ -1528,6 +1528,10 @@ check_path (struct vectors * vecs, struct path * pp, int ticks)
 		put_multipath_config(conf);
 		return 1;
 	}
+
+	if (newstate == PATH_TIMEOUT)
+		newstate = PATH_DOWN;
+
 	if (!pp->mpp) {
 		if (!strlen(pp->wwid) && pp->initialized != INIT_MISSING_UDEV &&
 		    (newstate == PATH_UP || newstate == PATH_GHOST)) {
@@ -1601,7 +1605,7 @@ check_path (struct vectors * vecs, struct path * pp, int ticks)
 		pp->checkint = conf->checkint;
 		put_multipath_config(conf);
 
-		if (newstate == PATH_DOWN || newstate == PATH_SHAKY || newstate == PATH_TIMEOUT) {
+		if (newstate == PATH_DOWN || newstate == PATH_SHAKY) {
 			/*
 			 * proactively fail path in the DM
 			 */
Signature · 1 line
2.8.1.windows.1
#5 lore raw

Re: [PATCH 3/3] Treat PATH_TIMEOUT as PATH_DOWN

Quoted 7 lines · On Tue, Oct 18, 2016 at 10:51:09AM +0800, [email protected] wrote:

From: "tang.junhui" <[email protected]>

Treat PATH_TIMEOUT as PATH_DOWN since it is basically the same as PATH_DOWN, except with a different state name. So change it to PATH_DOWN immediately if it is PATH_TIMEOUT according to the method in pathinfo(). After the modification all PATH_TIMEOUTs are equal to PATH_DOWN since the rest of pp->state is assigned all in pathinfo().

NACK. The whole point of PATH_TIMEOUT is to let the user know that instead of actually getting errors returned by the path checker, the path checker is timing out. To do this, we need to keep the state set to PATH_TIMEOUT, so that it will actually print the correct state string.

Another possibility would be to remove PATH_TIMEOUT and instead keep track of the reason for the PATH_DOWN state, and then when printing the checker state in snprint_chk_state(), use that to print the correct state string.

-Ben

Quoted 32 lines
---
 multipathd/main.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
multipathd/main.c +5 -1
index e369a79..f715eb5 100644
@@ -1528,6 +1528,10 @@ check_path (struct vectors * vecs, struct path * pp, int ticks)
 		put_multipath_config(conf);
 		return 1;
 	}
+
+	if (newstate == PATH_TIMEOUT)
+		newstate = PATH_DOWN;
+
 	if (!pp->mpp) {
 		if (!strlen(pp->wwid) && pp->initialized != INIT_MISSING_UDEV &&
 		    (newstate == PATH_UP || newstate == PATH_GHOST)) {
@@ -1601,7 +1605,7 @@ check_path (struct vectors * vecs, struct path * pp, int ticks)
 		pp->checkint = conf->checkint;
 		put_multipath_config(conf);
 
-		if (newstate == PATH_DOWN || newstate == PATH_SHAKY || newstate == PATH_TIMEOUT) {
+		if (newstate == PATH_DOWN || newstate == PATH_SHAKY) {
 			/*
 			 * proactively fail path in the DM
 			 */
Signature · 1 line
2.8.1.windows.1
#6 lore raw
In reply to [email protected]
Quoted 3 lines · On Tue, Oct 18, 2016 at 10:51:07AM +0800, [email protected] wrote:

From: "tang.junhui" <[email protected]>

ACK. Obviously we don't want uninitialized pointers. But do you know what as going on with the device that caused it to return no target? Was there simply no table loaded for the device?

-Ben

Quoted 74 lines

segment faulty occured in dm_get_status(), the call trace is:
----------------------------------------------------------------------
(gdb) bt

0  0x000000338ec328a5 in raise () from /lib64/libc.so.6
1  0x000000338ec3400d in abort () from /lib64/libc.so.6
2  0x000000000040596d in sigsegv ()
3  <signal handler called>
4  0x000000338ec480ac in vfprintf () from /lib64/libc.so.6
5  0x000000338ec6f9d2 in vsnprintf () from /lib64/libc.so.6
6  0x000000338ec4f4a3 in snprintf () from /lib64/libc.so.6
7  0x00007f43fe66bbb9 in dm_get_status (name=0x7f43f0001eb0 "spathe",

outstatus=<value optimized out>) at devmapper.c:521
8 0x00007f43fe68c058 in update_multipath_status (mpp=0x7f43f000ad60, pathvec=<value optimized out>) at structs_vec.c:465
9 update_multipath_strings (mpp=0x7f43f000ad60, pathvec=<value optimized out>) at structs_vec.c:495
10 0x0000000000409056 in check_path ()
11 0x0000000000409c7e in checkerloop ()
12 0x0000003b27207851 in start_thread () from /lib64/libpthread.so.0 13 0x000000338ece890d in clone () from /lib64/libc.so.6
-----------------------------------------------------------------------
we debuged the code, and found that targets information storing in the list dmt->head which fetching from kernel by executing dm_task_run() is null.
-----------------------------------------------------------------------
rbx 0x7f43c4000d60 139929027874144
(gdb) p *(struct dm_task *)0x7f43c4000d60
$3 = {type = 10, dev_name = 0x7f43c4000d40 "spathe", head = 0x0, tail = 0x0, read_only = 0, event_nr = 0, major = -1, minor = -1,
allow_default_major_fallback = 1, uid = 0, gid = 0, mode = 384,

  read_ahead = 4294967295, read_ahead_flags = 0, dmi = {
      v4 = 0x7f43c40011e0, v1 = 0x7f43c40011e0}, newname = 0x0, message =
      0x0, geometry = 0x0, sector = 0, no_flush = 0,
        no_open_count = 1, skip_lockfs = 0, query_inactive_table = 0,
	suppress_identical_reload = 0, existing_table_size = 0,
	  cookie_set = 0, uuid = 0x0}

-----------------------------------------------------------------------
since status is not initioned to null, so after calling dm_get_next_target(dmt, next, &start, &length,&target_type, &status),status becaming wild pointer, which lead snprintf() into the situation of segment faulty.

---
 libmultipath/devmapper.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
libmultipath/devmapper.c +6 -2
index 5eb1713..89aa5da 100644
@@ -534,8 +534,8 @@ dm_get_status(char * name, char * outstatus)
 	int r = 1;
 	struct dm_task *dmt;
 	uint64_t start, length;
-	char *target_type;
-	char *status;
+	char *target_type = NULL;
+	char *status = NULL;
 
 	if (!(dmt = dm_task_create(DM_DEVICE_STATUS)))
 		return 1;
@@ -551,6 +551,10 @@ dm_get_status(char * name, char * outstatus)
 	/* Fetch 1st target */
 	dm_get_next_target(dmt, NULL, &start, &length,
 			   &target_type, &status);
+	if (!status) {
+		condlog(2, "get null status.");
+		goto out;
+	}
 
 	if (snprintf(outstatus, PARAMS_SIZE, "%s", status) <= PARAMS_SIZE)
 		r = 0;
Signature · 1 line
2.8.1.windows.1
#7 lore raw

Merged.

Quoted 86 lines · Benjamin Marzinski
Quoted 3 lines · On Tue, Oct 18, 2016 at 10:51:07AM +0800, [email protected] wrote:

From: "tang.junhui" <[email protected]>

ACK. Obviously we don't want uninitialized pointers. But do you know what as going on with the device that caused it to return no target? Was there simply no table loaded for the device?

-Ben

Quoted 74 lines

segment faulty occured in dm_get_status(), the call trace is:
----------------------------------------------------------------------
(gdb) bt

0  0x000000338ec328a5 in raise () from /lib64/libc.so.6
1  0x000000338ec3400d in abort () from /lib64/libc.so.6
2  0x000000000040596d in sigsegv ()
3  <signal handler called>
4  0x000000338ec480ac in vfprintf () from /lib64/libc.so.6
5  0x000000338ec6f9d2 in vsnprintf () from /lib64/libc.so.6
6  0x000000338ec4f4a3 in snprintf () from /lib64/libc.so.6
7  0x00007f43fe66bbb9 in dm_get_status (name=0x7f43f0001eb0 "spathe",

outstatus=<value optimized out>) at devmapper.c:521
8 0x00007f43fe68c058 in update_multipath_status (mpp=0x7f43f000ad60, pathvec=<value optimized out>) at structs_vec.c:465
9 update_multipath_strings (mpp=0x7f43f000ad60, pathvec=<value optimized out>) at structs_vec.c:495
10 0x0000000000409056 in check_path ()
11 0x0000000000409c7e in checkerloop ()
12 0x0000003b27207851 in start_thread () from /lib64/libpthread.so.0 13 0x000000338ece890d in clone () from /lib64/libc.so.6
-----------------------------------------------------------------------
we debuged the code, and found that targets information storing in the list dmt->head which fetching from kernel by executing dm_task_run() is null.
-----------------------------------------------------------------------
rbx 0x7f43c4000d60 139929027874144
(gdb) p *(struct dm_task *)0x7f43c4000d60
$3 = {type = 10, dev_name = 0x7f43c4000d40 "spathe", head = 0x0, tail = 0x0, read_only = 0, event_nr = 0, major = -1, minor = -1,
allow_default_major_fallback = 1, uid = 0, gid = 0, mode = 384,

  read_ahead = 4294967295, read_ahead_flags = 0, dmi = {
      v4 = 0x7f43c40011e0, v1 = 0x7f43c40011e0}, newname = 0x0, message =
      0x0, geometry = 0x0, sector = 0, no_flush = 0,
        no_open_count = 1, skip_lockfs = 0, query_inactive_table = 0,
      suppress_identical_reload = 0, existing_table_size = 0,
        cookie_set = 0, uuid = 0x0}

-----------------------------------------------------------------------
since status is not initioned to null, so after calling dm_get_next_target(dmt, next, &start, &length,&target_type, &status),status becaming wild pointer, which lead snprintf() into the situation of segment faulty.

---
 libmultipath/devmapper.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
libmultipath/devmapper.c +6 -3
index 5eb1713..89aa5da 100644
@@ -534,8 +534,8 @@ dm_get_status(char * name, char * outstatus)
      int r = 1;
      struct dm_task *dmt;
      uint64_t start, length;
-     char *target_type;
-     char *status;
+     char *target_type = NULL;
+     char *status = NULL;
 
      if (!(dmt = dm_task_create(DM_DEVICE_STATUS)))
              return 1;
@@ -551,6 +551,10 @@ dm_get_status(char * name, char * outstatus)
      /* Fetch 1st target */
      dm_get_next_target(dmt, NULL, &start, &length,
                         &target_type, &status);
+     if (!status) {
+             condlog(2, "get null status.");
+             goto out;
+     }
 
      if (snprintf(outstatus, PARAMS_SIZE, "%s", status) <= PARAMS_SIZE)
              r = 0;
--

2.8.1.windows.1