1 Star 0 Fork 40

sqfu/multipath-tools

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0015-clear-mpp-path-reference-when-path-is-freed-otherwis.patch 4.03 KB
一键复制 编辑 原始数据 按行查看 历史
lixiaokeng 提交于 2021-11-23 21:49 . upgrade to 0.8.7
From c6530acb0a5ed3acb8ad930ef9e54a27c17d1521 Mon Sep 17 00:00:00 2001
From: root <root@localhost.localdomain>
Date: Fri, 22 Mar 2019 19:48:35 +0800
Subject: [PATCH 15/15] clear mpp path reference when path is freed, otherwise
double free may occur in verify_paths.
call stack:
vecs=vecs@entry=0x557b01d62140, rpvec=rpvec@entry=0x0) at structs_vec.c:521
at main.c:574
uev=<optimized out>) at main.c:510
uev_trigger=uev_trigger@entry=0x557affdfe3d0 <uev_trigger>, trigger_data=<optimized out>)
at uevent.c:178
---
libmultipath/discovery.c | 10 ++++++----
libmultipath/discovery.h | 2 +-
multipathd/main.c | 24 +++++++++++++++++++++++-
3 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
index 72982ac..2144447 100644
--- a/libmultipath/discovery.c
+++ b/libmultipath/discovery.c
@@ -115,7 +115,7 @@ transport (int h)
}
int
-remove_local_path (vector pathvec, struct path *pp)
+remove_local_path (vector pathvec, struct path *pp, int isfree)
{
int i = -1;
@@ -130,7 +130,9 @@ remove_local_path (vector pathvec, struct path *pp)
if ((i = find_slot(pathvec, (void *)pp)) != -1) {
vector_del_slot(pathvec, i);
}
- free_path(pp);
+ if(isfree){
+ free_path(pp);
+ }
return 0;
}
@@ -238,7 +240,7 @@ path_discover (vector pathvec, struct config * conf,
if (err == 1)
return 1;
if (err == 0)
- remove_local_path(pathvec, pp);
+ remove_local_path(pathvec, pp, 1);
return 0;
}
else {
@@ -251,7 +253,7 @@ path_discover (vector pathvec, struct config * conf,
if (err)
return err;
- remove_local_path(pathvec, pp);
+ remove_local_path(pathvec, pp, 1);
return err;
}
}
diff --git a/libmultipath/discovery.h b/libmultipath/discovery.h
index 26b6db1..d51bc0e 100644
--- a/libmultipath/discovery.h
+++ b/libmultipath/discovery.h
@@ -58,7 +58,7 @@ bool has_uid_fallback(struct path *pp);
int get_uid(struct path * pp, int path_state, struct udev_device *udev,
int allow_fallback);
bool is_vpd_page_supported(int fd, int pg);
-int remove_local_path(vector pathvec, struct path *pp);
+int remove_local_path(vector pathvec, struct path *pp, int isfree);
/*
* discovery bitmask
diff --git a/multipathd/main.c b/multipathd/main.c
index 47ca1b5..118dadd 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -884,6 +884,21 @@ check_path_wwid_change(struct path *pp)
return false;
}
+static
+void clear_ref_from_mpp(struct path * pp, struct vectors * vecs)
+{
+ struct multipath * mpp = NULL;
+ int i = -1;
+
+ mpp = find_mp_by_wwid(vecs->mpvec, pp->wwid);
+ if(!!mpp){
+ condlog(2, "%s: clear path from mpp %s", pp->dev, mpp->alias);
+ if ((i = find_slot(mpp->paths, (void *)pp)) != -1){
+ vector_del_slot(mpp->paths, i);
+ }
+ }
+}
+
static int
uev_add_path (struct uevent *uev, struct vectors * vecs, int need_do_map)
{
@@ -975,6 +990,7 @@ uev_add_path (struct uevent *uev, struct vectors * vecs, int need_do_map)
i = find_slot(vecs->pathvec, (void *)pp);
if (i != -1)
vector_del_slot(vecs->pathvec, i);
+ clear_ref_from_mpp(pp, vecs);
free_path(pp);
} else {
condlog(0, "%s: failed to reinitialize path",
@@ -1036,8 +1052,11 @@ ev_add_path (struct path * pp, struct vectors * vecs, int need_do_map)
int ret;
/* if pp is local path,remove it and return 0. */
- if (!remove_local_path(vecs->pathvec, pp))
+ if (!remove_local_path(vecs->pathvec, pp, 0)){
+ clear_ref_from_mpp(pp, vecs);
+ free_path(pp);
return 0;
+ }
/*
* need path UID to go any further
@@ -1052,6 +1071,7 @@ ev_add_path (struct path * pp, struct vectors * vecs, int need_do_map)
int i = find_slot(vecs->pathvec, (void *)pp);
if (i != -1)
vector_del_slot(vecs->pathvec, i);
+ clear_ref_from_mpp(pp, vecs);
free_path(pp);
return 1;
}
@@ -1305,6 +1325,8 @@ ev_remove_path (struct path *pp, struct vectors * vecs, int need_do_map)
/* mpp == NULL */
if ((i = find_slot(vecs->pathvec, (void *)pp)) != -1)
vector_del_slot(vecs->pathvec, i);
+
+ clear_ref_from_mpp(pp, vecs);
free_path(pp);
}
out:
--
1.8.3.1
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/fu-shanqing/multipath-tools.git
git@gitee.com:fu-shanqing/multipath-tools.git
fu-shanqing
multipath-tools
multipath-tools
master

搜索帮助