dm_get_map: fix segfault when can't found target
PATCH 1/1 dm_get_map: fix segfault when can't found target
We got a segfault when we test multipath + iscsi.
(gdb) bt
#0 __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:74
#1 0x00007f694306cd23 in __GI___strdup (s=0x0) at strdup.c:41
#2 0x00007f69433a147c in dm_get_map (name=0x55d4bc090320 "3600140537cde137ea8c43d8a971462c7",
size=size@entry=0x55d4bc0270d8, outparams=outparams@entry=0x7f6941add640) at devmapper.c:688
#3 0x00007f69433cbbdf in update_multipath_table (mpp=mpp@entry=0x55d4bc026f30,
pathvec=pathvec@entry=0x55d4bc063990, flags=flags@entry=0) at structs_vec.c:426
#4 0x00007f69433cbfe5 in update_multipath_strings (mpp=0x55d4bc026f30, pathvec=0x55d4bc063990)
at structs_vec.c:526
#5 0x000055d4bb52e03e in check_path (vecs=0x55d4bbfad760, pp=0x7f692402d270, ticks=<optimized out>)
at main.c:2280
#6 0x000055d4bb52f3e2 in checkerloop (ap=0x55d4bbfad760) at main.c:2542
#7 0x00007f694305b3ba in start_thread (arg=<optimized out>) at pthread_create.c:443
#8 0x00007f69430ddb40 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
(gdb) f 2
#2 0x00007f69433a147c in dm_get_map (name=0x55d4bc090320 "3600140537cde137ea8c43d8a971462c7",
size=size@entry=0x55d4bc0270d8, outparams=outparams@entry=0x7f6941add640) at devmapper.c:688688 *outparams = strdup(params);
(gdb) l
683 *size = length;
684
685 if (!outparams)
686 r = DMP_OK;
687 else {
688 *outparams = strdup(params);
689 r = *outparams ? DMP_OK : DMP_ERR;
690 }
691
692 out:
(gdb) p params
$1 = 0x0
If can't found target, we should goto out
--- libmultipath/devmapper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
libmultipath/devmapper.c +2 -2
@@ -682,8 +682,8 @@ int dm_get_map(const char *name, unsigned long long *size, char **outparams) r =DMP_NOT_FOUND ;/* Fetch 1st target */ if (dm_get_next_target (dmt,NULL , &start, &length, - &target_type, ¶ms) !=NULL ) -/* more than one target */ + &target_type, ¶ms) !=NULL || !params) +/* more than one target or not found target */ goto out;if (size)
--
2.27.0
--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
Quoted 34 lines · Wu Guanghao
We got a segfault when we test multipath + iscsi.
(gdb) bt
#0 __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:74 #1 0x00007f694306cd23 in __GI___strdup (s=0x0) at strdup.c:41 #2 0x00007f69433a147c in dm_get_map (name=0x55d4bc090320 "3600140537cde137ea8c43d8a971462c7", size=size@entry=0x55d4bc0270d8, outparams=outparams@entry=0x7f6941add640) at devmapper.c:688 #3 0x00007f69433cbbdf in update_multipath_table (mpp=mpp@entry=0x55d4bc026f30, pathvec=pathvec@entry=0x55d4bc063990, flags=flags@entry=0) at structs_vec.c:426 #4 0x00007f69433cbfe5 in update_multipath_strings (mpp=0x55d4bc026f30, pathvec=0x55d4bc063990) at structs_vec.c:526 #5 0x000055d4bb52e03e in check_path (vecs=0x55d4bbfad760, pp=0x7f692402d270, ticks=<optimized out>) at main.c:2280 #6 0x000055d4bb52f3e2 in checkerloop (ap=0x55d4bbfad760) at main.c:2542 #7 0x00007f694305b3ba in start_thread (arg=<optimized out>) at pthread_create.c:443 #8 0x00007f69430ddb40 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81 (gdb) f 2 #2 0x00007f69433a147c in dm_get_map (name=0x55d4bc090320 "3600140537cde137ea8c43d8a971462c7", size=size@entry=0x55d4bc0270d8, outparams=outparams@entry=0x7f6941add640) at devmapper.c:688688 *outparams = strdup(params);
(gdb) l
683 *size = length;
684
685 if (!outparams)
686 r =DMP_OK;
687 else {
688 *outparams = strdup(params);
689 r = *outparams ?DMP_OK:DMP_ERR;
690 }
691
692 out:
(gdb) p params
$1 =0x0
Quoted 3 lines
If can't found target, we should goto out
Signed-off-by Wu Guanghao <[email protected]>
Quoted 20 lines
--- libmultipath/devmapper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)libmultipath/devmapper.c +2
-3@@ -682,8 +682,8 @@ int dm_get_map(const char *name, unsigned long long *size, char **outparams) r =DMP_NOT_FOUND ;/* Fetch 1st target */ if (dm_get_next_target (dmt,NULL , &start, &length, - &target_type, ¶ms) !=NULL ) -/* more than one target */ + &target_type, ¶ms) !=NULL || !params) +/* more than one target or not found target */ goto out;if (size) --
Quoted 1 line
2.27.0
--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
Martin Wilck
Reviewed-byQuoted 47 lines · Benjamin Marzinski
Quoted 46 lines · Wu Guanghao
We got a segfault when we test multipath + iscsi.
(gdb) bt
#0__strlen_avx2() at ../sysdeps/x86_64/multiarch/strlen- avx2.S:74
#10x00007f694306cd23in__GI___strdup(s=0x0) at strdup.c:41 #20x00007f69433a147cindm_get_map(name=0x55d4bc090320 "3600140537cde137ea8c43d8a971462c7", size=size@entry=0x55d4bc0270d8, outparams=outparams@entry=0x7f6941add640) at devmapper.c:688 #30x00007f69433cbbdfinupdate_multipath_table(mpp=mpp@entry=0x55d4bc026f30, pathvec=pathvec@entry=0x55d4bc063990, flags=flags@entry=0) at structs_vec.c:426
#40x00007f69433cbfe5inupdate_multipath_strings(mpp=0x55d4bc026f30, pathvec=0x55d4bc063990)
at structs_vec.c:526
#50x000055d4bb52e03eincheck_path(vecs=0x55d4bbfad760, pp=0x7f692402d270, ticks=<optimized out>)
at main.c:2280
#60x000055d4bb52f3e2in checkerloop (ap=0x55d4bbfad760) at main.c:2542
#70x00007f694305b3bainstart_thread(arg=<optimized out>) at pthread_create.c:443
#80x00007f69430ddb40in clone3 () at../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
(gdb) f 2
#20x00007f69433a147cindm_get_map(name=0x55d4bc090320 "3600140537cde137ea8c43d8a971462c7", size=size@entry=0x55d4bc0270d8, outparams=outparams@entry=0x7f6941add640) at devmapper.c:688 688 *outparams = strdup(params); (gdb) l
683 *size = length;
684
685 if (!outparams)
686 r =DMP_OK;
687 else {
688 *outparams = strdup(params); 689 r = *outparams ?DMP_OK:DMP_ERR; 690 }
691
692 out:
(gdb) p params
$1 =0x0
Quoted 5 lines
Quoted 3 lines
If can't found target, we should goto out
Signed-off-by Wu Guanghao <[email protected]>Reviewed-by Benjamin Marzinski <[email protected]>
Thanks! Note: We have two other callers of dm_get_next_target that should add a similar check.
--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel