From a398a5e4ac535f8862b937e26c85678c10d1dc09 Mon Sep 17 00:00:00 2001 From: Zhiqiang Liu Date: Sun, 30 Jan 2022 11:49:10 +0800 Subject: [PATCH] dev_name() determine whether the dev->aliases linked list is empty before obtaining the dev name If dev->aliases linked list is empty, then directly obtain the str address of dm_str_list saved in dev_aliases.n, an unknown address will be returned, which may cause segfault. So we need to judge whether the dev->aliases linked list is empty before getting it to avoid returning unknown address. Fix issue: https://gitee.com/src-openeuler/lvm2/issues/I4RZP9 Signed-off-by: Zhiqiang Liu (cherry picked from commit e3c6fd1364353d109af874a81f263b642334aa69) --- ...ne-whether-the-dev-aliases-linked-li.patch | 36 +++++++++++++++++++ lvm2.spec | 7 +++- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 0016-dev_name-determine-whether-the-dev-aliases-linked-li.patch diff --git a/0016-dev_name-determine-whether-the-dev-aliases-linked-li.patch b/0016-dev_name-determine-whether-the-dev-aliases-linked-li.patch new file mode 100644 index 0000000..cc17bab --- /dev/null +++ b/0016-dev_name-determine-whether-the-dev-aliases-linked-li.patch @@ -0,0 +1,36 @@ +From 472dd53a091e0e4b0d2db8fcd10da3f408873633 Mon Sep 17 00:00:00 2001 +From: Zhiqiang Liu +Date: Sun, 30 Jan 2022 11:37:51 +0800 +Subject: [PATCH] dev_name() determine whether the dev->aliases linked list is + empty before obtaining the dev name + +If dev->aliases linked list is empty, then directly obtain the str +address of dm_str_list saved in dev_aliases.n, an unknown address +will be returned, which may cause segfault. + +So we need to judge whether the dev->aliases linked list is empty before +getting it to avoid returning unknown address. + +Signed-off-by: Zhiqiang Liu +--- + lib/device/dev-cache.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c +index 33b75a9..1263820 100644 +--- a/lib/device/dev-cache.c ++++ b/lib/device/dev-cache.c +@@ -1703,8 +1703,8 @@ int dev_fd(struct device *dev) + + const char *dev_name(const struct device *dev) + { +- return (dev && dev->aliases.n) ? dm_list_item(dev->aliases.n, struct dm_str_list)->str : +- unknown_device_name(); ++ return (dev && dev->aliases.n && !dm_list_empty(&dev->aliases)) ?\ ++ dm_list_item(dev->aliases.n, struct dm_str_list)->str : unknown_device_name(); + } + + bool dev_cache_has_md_with_end_superblock(struct dev_types *dt) +-- +1.8.3.1 + diff --git a/lvm2.spec b/lvm2.spec index b0d2fff..fda3e55 100644 --- a/lvm2.spec +++ b/lvm2.spec @@ -43,7 +43,7 @@ Name: lvm2 Version: 2.03.09 -Release: 10 +Release: 11 Epoch: 8 Summary: Tools for logical volume management License: GPLv2+ and LGPLv2.1 and BSD @@ -64,6 +64,7 @@ Patch12: 0012-bugfix-lvm2-fix-the-reuse-of-va_list.patch Patch13: 0013-lvreduce-support-yes.patch Patch14: 0014-unit-test-modify-for-systems-with-PGSIZE-of-64K.patch Patch15: 0015-13-dm-disk.rules-check-DM_NAME-before-create-symlink.patch +Patch16: 0016-dev_name-determine-whether-the-dev-aliases-linked-li.patch BuildRequires: gcc BuildRequires: gcc-c++ @@ -489,6 +490,10 @@ fi %changelog +* Sun Jan 30 2022 Zhiqiang Liu - 8.2.03.09-11 +- dev_name() determine whether the dev->aliases linked list is + empty before obtaining the dev name + * Sun Jan 30 2022 Zhiqiang Liu - 8.2.03.09-10 - check DM_NAME before creating symlink in 13-dm-disk.rules