From 5ba79db1adc3bc653f18e480cfc857775414d520 Mon Sep 17 00:00:00 2001 From: wangxiaomeng Date: Fri, 8 Jul 2022 15:40:45 +0800 Subject: [PATCH 1/5] backport to fix crash when 'm LEN' < 252 for sg_ses --- 0006-sg_ses-fix-crash-when-m-LEN-252.patch | 57 ++++++++++++++++++++++ sg3_utils.spec | 9 +++- sg3_utils.yaml | 5 ++ 3 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 0006-sg_ses-fix-crash-when-m-LEN-252.patch create mode 100644 sg3_utils.yaml diff --git a/0006-sg_ses-fix-crash-when-m-LEN-252.patch b/0006-sg_ses-fix-crash-when-m-LEN-252.patch new file mode 100644 index 0000000..a1cafbc --- /dev/null +++ b/0006-sg_ses-fix-crash-when-m-LEN-252.patch @@ -0,0 +1,57 @@ +From bfbefdf2d9aa12107d08d796d6fc78862ab85402 Mon Sep 17 00:00:00 2001 +From: Douglas Gilbert +Date: Sun, 1 Aug 2021 03:14:05 +0000 +Subject: [PATCH] sg_ses: fix crash when 'm LEN' < 252 + +git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@907 6180dd3e-e324-4e3e-922d-17de1ae2f315 +--- + src/sg_ses.c | 14 ++++++++------ + 1 file changed, 8 insertions(+), 6 deletions(-) + +diff --git a/src/sg_ses.c b/src/sg_ses.c +index b9ac2e4..701359b 100644 +--- a/src/sg_ses.c ++++ b/src/sg_ses.c +@@ -5523,7 +5523,7 @@ int + main(int argc, char * argv[]) + { + bool have_cgs = false; +- int k, d_len, res, resid, vb; ++ int k, n, d_len, res, resid, vb; + int sg_fd = -1; + int pd_type = 0; + int ret = 0; +@@ -5757,15 +5757,17 @@ main(int argc, char * argv[]) + } + } + clear_scsi_pt_obj(ptvp); +- memset(enc_stat_rsp, 0, 4096); ++ memset(enc_stat_rsp, 0, enc_stat_rsp_sz); + } + #endif + + if (ptvp) { +- ret = sg_ll_request_sense_pt(ptvp, false, enc_stat_rsp, +- REQUEST_SENSE_RESP_SZ, ! op->quiet, vb); ++ n = (enc_stat_rsp_sz < REQUEST_SENSE_RESP_SZ) ? enc_stat_rsp_sz : ++ REQUEST_SENSE_RESP_SZ; ++ ret = sg_ll_request_sense_pt(ptvp, false, enc_stat_rsp, n, ++ ! op->quiet, vb); + if (0 == ret) { +- int sense_len = REQUEST_SENSE_RESP_SZ - get_scsi_pt_resid(ptvp); ++ int sense_len = n - get_scsi_pt_resid(ptvp); + struct sg_scsi_sense_hdr ssh; + + if ((sense_len > 7) && sg_scsi_normalize_sense(enc_stat_rsp, +@@ -5794,7 +5796,7 @@ main(int argc, char * argv[]) + " problems ahead\n", ret); + } + clear_scsi_pt_obj(ptvp); +- memset(enc_stat_rsp, 0, REQUEST_SENSE_RESP_SZ); ++ memset(enc_stat_rsp, 0, enc_stat_rsp_sz); + } + + if (op->nickname_str) +-- +2.27.0 + diff --git a/sg3_utils.spec b/sg3_utils.spec index 4f28d65..babbdf8 100644 --- a/sg3_utils.spec +++ b/sg3_utils.spec @@ -1,6 +1,6 @@ Name: sg3_utils Version: 1.45 -Release: 7 +Release: 8 Summary: Utilities that send SCSI commands to devices. License: GPL-2.0-or-later AND BSD URL: http://sg.danny.cz/sg/sg3_utils.html @@ -10,8 +10,10 @@ Patch0: 0000-sg3_utils-1.37-rescan-scsi-findremapped-enhance.patch Patch1: 0001-sg3_utils-1.37-rescan-downpress.patch Patch2: 0002-bugfix-sg3_utils-fix-syntax-error.patch Patch3: 0003-sg3_utils-1.42-delete-lun-rescan-scsi-bus-report-error.patch -Patch4: 0004-sg3_utils-fix-memset-coredump.patch +# Do not apply patch0004 to fix sg_ses -m LEN <252 coredump +##Patch4: 0004-sg3_utils-fix-memset-coredump.patch Patch5: 0005-sg3_utils-rescan-scsi-bus-list-all-LUNs-in-one-line.patch +Patch6: 0006-sg_ses-fix-crash-when-m-LEN-252.patch Provides: %{name}-libs Obsoletes: %{name}-libs @@ -75,6 +77,9 @@ rm -rf $RPM_BUILD_ROOT/%{_libdir}/*.la %{_mandir}/man8/* %changelog +* Fri Jul 8 2022 wangxiaomeng - 1.45-8 +- Delete patch0004, and backport patch0006 to fix crash when 'm LEN' < 252 + * Sat Jan 29 2022 Zhiqiang Liu - 1.45-7 - rescan scsi bus list all LUNs in one line diff --git a/sg3_utils.yaml b/sg3_utils.yaml new file mode 100644 index 0000000..22321e5 --- /dev/null +++ b/sg3_utils.yaml @@ -0,0 +1,5 @@ +version_control: github +src_repo: doug-gilbert/sg3_utils +tag_prefix: "^v" +seperator: "." + -- Gitee From e8c064fc69d914b1ccfd63cf699d85436a817b6c Mon Sep 17 00:00:00 2001 From: wangxiaomeng Date: Fri, 8 Jul 2022 15:56:52 +0800 Subject: [PATCH 2/5] fix spelling mistakes of separator for sg3_utils.yaml --- sg3_utils.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sg3_utils.yaml b/sg3_utils.yaml index 22321e5..5345855 100644 --- a/sg3_utils.yaml +++ b/sg3_utils.yaml @@ -1,5 +1,5 @@ version_control: github src_repo: doug-gilbert/sg3_utils tag_prefix: "^v" -seperator: "." +separator: "." -- Gitee From d006c2e907ec8c5ad46b6cb1103a330598f6f0b7 Mon Sep 17 00:00:00 2001 From: wangxiaomeng Date: Mon, 11 Jul 2022 10:46:13 +0800 Subject: [PATCH 3/5] delete origin patch0004 and rename patch0006 to patch0004 --- 0004-sg3_utils-fix-memset-coredump.patch | 29 ------------------- ...0004-sg_ses-fix-crash-when-m-LEN-252.patch | 0 sg3_utils.spec | 6 ++-- 3 files changed, 2 insertions(+), 33 deletions(-) delete mode 100644 0004-sg3_utils-fix-memset-coredump.patch rename 0006-sg_ses-fix-crash-when-m-LEN-252.patch => 0004-sg_ses-fix-crash-when-m-LEN-252.patch (100%) diff --git a/0004-sg3_utils-fix-memset-coredump.patch b/0004-sg3_utils-fix-memset-coredump.patch deleted file mode 100644 index ff6fdc5..0000000 --- a/0004-sg3_utils-fix-memset-coredump.patch +++ /dev/null @@ -1,29 +0,0 @@ -From dd2a61c9551ac5d2ac0c5902172fd8312edc22cb Mon Sep 17 00:00:00 2001 -From: yanglongkang -Date: Tue, 9 Feb 2021 11:39:32 +0800 -Subject: [PATCH] sg3_utils: fix memset coredump - -alloc MX_ALLOC_LEN size mem to enc_stat_rsp for -solving coredump problem. - -Signed-off-by: yanglongkang ---- - src/sg_ses.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/sg_ses.c b/src/sg_ses.c -index 23fc3b9..cf344b7 100644 ---- a/src/sg_ses.c -+++ b/src/sg_ses.c -@@ -5582,7 +5582,7 @@ main(int argc, char * argv[]) - enumerate_work(op); - goto early_out; - } -- enc_stat_rsp = sg_memalign(op->maxlen, 0, &free_enc_stat_rsp, false); -+ enc_stat_rsp = sg_memalign(MX_ALLOC_LEN, 0, &free_enc_stat_rsp, false); - if (NULL == enc_stat_rsp) { - pr2serr("Unable to get heap for enc_stat_rsp\n"); - goto err_out; --- -1.8.3.1 - diff --git a/0006-sg_ses-fix-crash-when-m-LEN-252.patch b/0004-sg_ses-fix-crash-when-m-LEN-252.patch similarity index 100% rename from 0006-sg_ses-fix-crash-when-m-LEN-252.patch rename to 0004-sg_ses-fix-crash-when-m-LEN-252.patch diff --git a/sg3_utils.spec b/sg3_utils.spec index babbdf8..307408c 100644 --- a/sg3_utils.spec +++ b/sg3_utils.spec @@ -10,10 +10,8 @@ Patch0: 0000-sg3_utils-1.37-rescan-scsi-findremapped-enhance.patch Patch1: 0001-sg3_utils-1.37-rescan-downpress.patch Patch2: 0002-bugfix-sg3_utils-fix-syntax-error.patch Patch3: 0003-sg3_utils-1.42-delete-lun-rescan-scsi-bus-report-error.patch -# Do not apply patch0004 to fix sg_ses -m LEN <252 coredump -##Patch4: 0004-sg3_utils-fix-memset-coredump.patch +Patch4: 0004-sg_ses-fix-crash-when-m-LEN-252.patch Patch5: 0005-sg3_utils-rescan-scsi-bus-list-all-LUNs-in-one-line.patch -Patch6: 0006-sg_ses-fix-crash-when-m-LEN-252.patch Provides: %{name}-libs Obsoletes: %{name}-libs @@ -78,7 +76,7 @@ rm -rf $RPM_BUILD_ROOT/%{_libdir}/*.la %changelog * Fri Jul 8 2022 wangxiaomeng - 1.45-8 -- Delete patch0004, and backport patch0006 to fix crash when 'm LEN' < 252 +- Backport patch to solve coredump problem, fix crash when 'm LEN' < 252 * Sat Jan 29 2022 Zhiqiang Liu - 1.45-7 - rescan scsi bus list all LUNs in one line -- Gitee From defd4e3f8a6e7473830d226f2bea6b6918512919 Mon Sep 17 00:00:00 2001 From: wangxiaomeng Date: Mon, 11 Jul 2022 11:04:14 +0800 Subject: [PATCH 4/5] backport to fix crash when 'm LEN' < 252 for sg_ses --- 0004-sg3_utils-fix-memset-coredump.patch | 29 ---------- 0004-sg_ses-fix-crash-when-m-LEN-252.patch | 63 ++++++++++++++++++++++ sg3_utils.spec | 7 ++- sg3_utils.yaml | 5 ++ 4 files changed, 73 insertions(+), 31 deletions(-) delete mode 100644 0004-sg3_utils-fix-memset-coredump.patch create mode 100644 0004-sg_ses-fix-crash-when-m-LEN-252.patch create mode 100644 sg3_utils.yaml diff --git a/0004-sg3_utils-fix-memset-coredump.patch b/0004-sg3_utils-fix-memset-coredump.patch deleted file mode 100644 index ff6fdc5..0000000 --- a/0004-sg3_utils-fix-memset-coredump.patch +++ /dev/null @@ -1,29 +0,0 @@ -From dd2a61c9551ac5d2ac0c5902172fd8312edc22cb Mon Sep 17 00:00:00 2001 -From: yanglongkang -Date: Tue, 9 Feb 2021 11:39:32 +0800 -Subject: [PATCH] sg3_utils: fix memset coredump - -alloc MX_ALLOC_LEN size mem to enc_stat_rsp for -solving coredump problem. - -Signed-off-by: yanglongkang ---- - src/sg_ses.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/sg_ses.c b/src/sg_ses.c -index 23fc3b9..cf344b7 100644 ---- a/src/sg_ses.c -+++ b/src/sg_ses.c -@@ -5582,7 +5582,7 @@ main(int argc, char * argv[]) - enumerate_work(op); - goto early_out; - } -- enc_stat_rsp = sg_memalign(op->maxlen, 0, &free_enc_stat_rsp, false); -+ enc_stat_rsp = sg_memalign(MX_ALLOC_LEN, 0, &free_enc_stat_rsp, false); - if (NULL == enc_stat_rsp) { - pr2serr("Unable to get heap for enc_stat_rsp\n"); - goto err_out; --- -1.8.3.1 - diff --git a/0004-sg_ses-fix-crash-when-m-LEN-252.patch b/0004-sg_ses-fix-crash-when-m-LEN-252.patch new file mode 100644 index 0000000..f76b03b --- /dev/null +++ b/0004-sg_ses-fix-crash-when-m-LEN-252.patch @@ -0,0 +1,63 @@ +From bfbefdf2d9aa12107d08d796d6fc78862ab85402 Mon Sep 17 00:00:00 2001 +From: Douglas Gilbert +Date: Sun, 1 Aug 2021 03:14:05 +0000 +Subject: [PATCH] sg_ses: fix crash when 'm LEN' < 252 + +git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@907 6180dd3e-e324-4e3e-922d-17de1ae2f315 + +fix issue:https://gitee.com/src-openeuler/sg3_utils/issues/I5G05L + +memset enc_stat_rsp by its true length + +Signed-off-by: wangxiaomeng +--- + src/sg_ses.c | 14 ++++++++------ + 1 file changed, 8 insertions(+), 6 deletions(-) + +diff --git a/src/sg_ses.c b/src/sg_ses.c +index b9ac2e4..701359b 100644 +--- a/src/sg_ses.c ++++ b/src/sg_ses.c +@@ -5523,7 +5523,7 @@ int + main(int argc, char * argv[]) + { + bool have_cgs = false; +- int k, d_len, res, resid, vb; ++ int k, n, d_len, res, resid, vb; + int sg_fd = -1; + int pd_type = 0; + int ret = 0; +@@ -5757,15 +5757,17 @@ main(int argc, char * argv[]) + } + } + clear_scsi_pt_obj(ptvp); +- memset(enc_stat_rsp, 0, 4096); ++ memset(enc_stat_rsp, 0, enc_stat_rsp_sz); + } + #endif + + if (ptvp) { +- ret = sg_ll_request_sense_pt(ptvp, false, enc_stat_rsp, +- REQUEST_SENSE_RESP_SZ, ! op->quiet, vb); ++ n = (enc_stat_rsp_sz < REQUEST_SENSE_RESP_SZ) ? enc_stat_rsp_sz : ++ REQUEST_SENSE_RESP_SZ; ++ ret = sg_ll_request_sense_pt(ptvp, false, enc_stat_rsp, n, ++ ! op->quiet, vb); + if (0 == ret) { +- int sense_len = REQUEST_SENSE_RESP_SZ - get_scsi_pt_resid(ptvp); ++ int sense_len = n - get_scsi_pt_resid(ptvp); + struct sg_scsi_sense_hdr ssh; + + if ((sense_len > 7) && sg_scsi_normalize_sense(enc_stat_rsp, +@@ -5794,7 +5796,7 @@ main(int argc, char * argv[]) + " problems ahead\n", ret); + } + clear_scsi_pt_obj(ptvp); +- memset(enc_stat_rsp, 0, REQUEST_SENSE_RESP_SZ); ++ memset(enc_stat_rsp, 0, enc_stat_rsp_sz); + } + + if (op->nickname_str) +-- +2.27.0 + diff --git a/sg3_utils.spec b/sg3_utils.spec index 4f28d65..307408c 100644 --- a/sg3_utils.spec +++ b/sg3_utils.spec @@ -1,6 +1,6 @@ Name: sg3_utils Version: 1.45 -Release: 7 +Release: 8 Summary: Utilities that send SCSI commands to devices. License: GPL-2.0-or-later AND BSD URL: http://sg.danny.cz/sg/sg3_utils.html @@ -10,7 +10,7 @@ Patch0: 0000-sg3_utils-1.37-rescan-scsi-findremapped-enhance.patch Patch1: 0001-sg3_utils-1.37-rescan-downpress.patch Patch2: 0002-bugfix-sg3_utils-fix-syntax-error.patch Patch3: 0003-sg3_utils-1.42-delete-lun-rescan-scsi-bus-report-error.patch -Patch4: 0004-sg3_utils-fix-memset-coredump.patch +Patch4: 0004-sg_ses-fix-crash-when-m-LEN-252.patch Patch5: 0005-sg3_utils-rescan-scsi-bus-list-all-LUNs-in-one-line.patch Provides: %{name}-libs @@ -75,6 +75,9 @@ rm -rf $RPM_BUILD_ROOT/%{_libdir}/*.la %{_mandir}/man8/* %changelog +* Fri Jul 8 2022 wangxiaomeng - 1.45-8 +- Backport patch to solve coredump problem, fix crash when 'm LEN' < 252 + * Sat Jan 29 2022 Zhiqiang Liu - 1.45-7 - rescan scsi bus list all LUNs in one line diff --git a/sg3_utils.yaml b/sg3_utils.yaml new file mode 100644 index 0000000..5345855 --- /dev/null +++ b/sg3_utils.yaml @@ -0,0 +1,5 @@ +version_control: github +src_repo: doug-gilbert/sg3_utils +tag_prefix: "^v" +separator: "." + -- Gitee From 5c0cc8bf9e379606fb1ef3fa972aa076d40c8f8a Mon Sep 17 00:00:00 2001 From: wangxiaomeng Date: Mon, 11 Jul 2022 11:20:14 +0800 Subject: [PATCH 5/5] Remove yaml file --- sg3_utils.yaml | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 sg3_utils.yaml diff --git a/sg3_utils.yaml b/sg3_utils.yaml deleted file mode 100644 index 5345855..0000000 --- a/sg3_utils.yaml +++ /dev/null @@ -1,5 +0,0 @@ -version_control: github -src_repo: doug-gilbert/sg3_utils -tag_prefix: "^v" -separator: "." - -- Gitee