From 56a0c4264e9bdd98f1956b796542d80a2e9dd63c Mon Sep 17 00:00:00 2001 From: Zhiqiang Liu Date: Fri, 14 Oct 2022 10:38:47 +0800 Subject: [PATCH] tune2fs:fix one segfault problem fix issue:https://gitee.com/src-openeuler/e2fsprogs/issues/I5RYHG Signed-off-by: Zhiqiang Liu (cherry picked from commit a90d365e90075a29ab564ec29bf6734ed47b587b) --- ...2fs-segfault-when-ext2fs_run_ext3_jo.patch | 57 +++++++++++++++++++ ...main-should-return-rc-when-some-erro.patch | 39 +++++++++++++ ...-fs-freed-in-ext2fs_run_ext3_journal.patch | 35 ++++++++++++ e2fsprogs.spec | 8 ++- 4 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 0019-tune2fs-fix-tune2fs-segfault-when-ext2fs_run_ext3_jo.patch create mode 100644 0020-tune2fs-tune2fs_main-should-return-rc-when-some-erro.patch create mode 100644 0021-tune2fs-exit-directly-when-fs-freed-in-ext2fs_run_ext3_journal.patch diff --git a/0019-tune2fs-fix-tune2fs-segfault-when-ext2fs_run_ext3_jo.patch b/0019-tune2fs-fix-tune2fs-segfault-when-ext2fs_run_ext3_jo.patch new file mode 100644 index 0000000..db95fc0 --- /dev/null +++ b/0019-tune2fs-fix-tune2fs-segfault-when-ext2fs_run_ext3_jo.patch @@ -0,0 +1,57 @@ +From 66ecb6abe5d2c74191bb4bc24f3da036e5fa1213 Mon Sep 17 00:00:00 2001 +From: Zhiqiang Liu +Date: Mon, 5 Sep 2022 19:16:03 +0800 +Subject: [PATCH] tune2fs: fix tune2fs segfault when ext2fs_run_ext3_journal() + fails + +When ext2fs_run_ext3_journal() fails, tune2fs cmd will occur one +segfault problem as follows. +(gdb) bt +#0 0x00007fdadad69917 in ext2fs_mmp_stop (fs=0x0) at mmp.c:405 +#1 0x0000558fa5a9365a in main (argc=, argv=) at tune2fs.c:3440 + +misc/tune2fs.c: +main() + -> ext2fs_open2(&fs) + -> ext2fs_mmp_start + ...... + -> retval = ext2fs_run_ext3_journal(&fs) + -> if (retval) + // if ext2fs_run_ext3_journal fails, close and free fs. + -> ext2fs_close_free(&fs) + -> rc = 1 + -> goto closefs + ...... +closefs: + -> if (rc) + -> ext2fs_mmp_stop(fs) // fs has been set to NULL, boom!! + -> (ext2fs_close_free(&fs) ? 1 : 0); // close and free fs + +In main() of tune2fs cmd, if ext2fs_run_ext3_journal() fails, +we should set rc=1 and goto closefs tag, in which will release fs +resource. + +Fix: a2292f8a5108 ("tune2fs: reset MMP state on error exit") +Signed-off-by: Zhiqiang Liu +Signed-off-by: zhanchengbin +Signed-off-by: Theodore Ts'o +--- + misc/tune2fs.c | 2 -- + 1 file changed, 2 deletions(-) + +diff --git a/misc/tune2fs.c b/misc/tune2fs.c +index a7ff16de..98e38983 100644 +--- a/misc/tune2fs.c ++++ b/misc/tune2fs.c +@@ -3106,8 +3106,6 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n" + com_err("tune2fs", retval, + "while recovering journal.\n"); + printf(_("Please run e2fsck -fy %s.\n"), argv[1]); +- if (fs) +- ext2fs_close_free(&fs); + rc = 1; + goto closefs; + } +-- +2.33.0 + diff --git a/0020-tune2fs-tune2fs_main-should-return-rc-when-some-erro.patch b/0020-tune2fs-tune2fs_main-should-return-rc-when-some-erro.patch new file mode 100644 index 0000000..7964a7f --- /dev/null +++ b/0020-tune2fs-tune2fs_main-should-return-rc-when-some-erro.patch @@ -0,0 +1,39 @@ +From 77ac16dfba42e0d152b1e99359e01a933f8cc6f9 Mon Sep 17 00:00:00 2001 +From: Zhiqiang Liu +Date: Mon, 5 Sep 2022 23:40:01 +0800 +Subject: [PATCH] tune2fs: tune2fs_main() should return rc when some error, + occurs + +If some error occurs, tune2fs_main() will go to closefs tag for +releasing resource, and it should return correct value (rc) instead +of 0 when ext2fs_close_free(&fs) successes. + +Signed-off-by: Zhiqiang Liu +Reviewed-by: Artem Blagodarenko +Signed-off-by: Theodore Ts'o +--- + misc/tune2fs.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/misc/tune2fs.c b/misc/tune2fs.c +index 98e38983..bed3d95b 100644 +--- a/misc/tune2fs.c ++++ b/misc/tune2fs.c +@@ -3243,6 +3243,7 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n" + fputs(_("Error in using clear_mmp. " + "It must be used with -f\n"), + stderr); ++ rc = 1; + goto closefs; + } + } +@@ -3447,5 +3448,5 @@ closefs: + + if (feature_64bit) + convert_64bit(fs, feature_64bit); +- return (ext2fs_close_free(&fs) ? 1 : 0); ++ return (ext2fs_close_free(&fs) ? 1 : rc); + } +-- +2.33.0 + diff --git a/0021-tune2fs-exit-directly-when-fs-freed-in-ext2fs_run_ext3_journal.patch b/0021-tune2fs-exit-directly-when-fs-freed-in-ext2fs_run_ext3_journal.patch new file mode 100644 index 0000000..501120b --- /dev/null +++ b/0021-tune2fs-exit-directly-when-fs-freed-in-ext2fs_run_ext3_journal.patch @@ -0,0 +1,35 @@ +From 3d967e53033c85ad5d3af1a42efb2c4f7501c356 Mon Sep 17 00:00:00 2001 +From: lijinlin3@huawei.com +Date: Fri, 16 Sep 2022 18:15:02 +0200 +Subject: [PATCH] tune2fs: exit directly when fs freed in ext2fs_run_ext3_journal + +In ext2fs_run_ext3_journal(), fs will be free and reallocate. But +reallocating by ext2fs_open() may fail in some cases, such as device +being offline at the same time. In these cases, goto closefs will +cause segfault, fix it by exiting directly. + +Signed-off-by: Li Jinlin +--- + misc/tune2fs.c | 7 +++++-- + 1 file changed, 5 insertions(+), 2 deletions(-) + +diff --git a/misc/tune2fs.c b/misc/tune2fs.c +index 088f87e5..ee57dc7c 100644 +--- a/misc/tune2fs.c ++++ b/misc/tune2fs.c +@@ -3344,8 +3344,11 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n" + com_err("tune2fs", retval, + "while recovering journal.\n"); + printf(_("Please run e2fsck -fy %s.\n"), argv[1]); +- rc = 1; +- goto closefs; ++ if (fs) { ++ rc = 1; ++ goto closefs; ++ } ++ exit(1); + } + sb = fs->super; + } +-- +2.23.0 diff --git a/e2fsprogs.spec b/e2fsprogs.spec index 56367a1..273c28a 100644 --- a/e2fsprogs.spec +++ b/e2fsprogs.spec @@ -1,6 +1,6 @@ Name: e2fsprogs Version: 1.46.4 -Release: 15 +Release: 16 Summary: Second extended file system management tools License: GPLv2+ and LGPLv2 and MIT URL: http://e2fsprogs.sourceforge.net/ @@ -25,6 +25,9 @@ Patch15: 0015-libext2fs-add-sanity-check-to-extent-manipulation.patch Patch16: 0016-e2fsprogs-add-sw64.patch Patch17: 0017-tune2fs-do-not-change-j_tail_sequence-in-journal-sup.patch Patch18: 0018-debugfs-teach-logdump-the-n-num_trans-option.patch +Patch19: 0019-tune2fs-fix-tune2fs-segfault-when-ext2fs_run_ext3_jo.patch +Patch20: 0020-tune2fs-tune2fs_main-should-return-rc-when-some-erro.patch +Patch21: 0021-tune2fs-exit-directly-when-fs-freed-in-ext2fs_run_ext3_journal.patch BuildRequires: gcc pkgconfig texinfo @@ -166,6 +169,9 @@ exit 0 %{_mandir}/man8/* %changelog +* Fri Oct 14 2022 Zhiqiang Liu - 1.46.4-16 +- tune2fs: fix segfault problem + * Fri Sep 23 2022 zhanchengbin - 1.46.4-15 - test: fix ACL-printing tests from community -- Gitee