From 4b116dbd7ae9ffb0f91993d37bfef1216e681fe4 Mon Sep 17 00:00:00 2001 From: yanshuai Date: Wed, 3 Apr 2024 15:43:02 +0800 Subject: [PATCH] Fix changing savedir directory mode (cherry picked from commit 086876a1844bc20d5ac88cfa01b010e6a0004fdf) --- Fix-changing-savedir-directory-mode.patch | 48 +++++++++++++++++++++++ targetcli.spec | 8 +++- 2 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 Fix-changing-savedir-directory-mode.patch diff --git a/Fix-changing-savedir-directory-mode.patch b/Fix-changing-savedir-directory-mode.patch new file mode 100644 index 0000000..854bb60 --- /dev/null +++ b/Fix-changing-savedir-directory-mode.patch @@ -0,0 +1,48 @@ +From b8eb1933d4fdcbe806edead8cfa94879d0fc2015 Mon Sep 17 00:00:00 2001 +From: Lee Duncan +Date: Mon, 24 Apr 2023 10:34:39 -0700 +Subject: [PATCH] Fix changing savedir directory mode + +Commit 9f5764dac39b ("saveconfig: set right perms on /etc/target/ dir") +fixed CVE-2020-13867 by ensuring that the mode of the target +meta-data directory (/etc/target) was always mode 0600. But users +can specify a different directory, such as "/tmp", and we don't +want targetcli changing the mode of such directories to 0600. So +only change the mode of the directory, when saving a config file, +if the directory is /etc/target. + +--- + targetcli/ui_root.py | 10 ++++++---- + 1 file changed, 6 insertions(+), 4 deletions(-) + +diff --git a/targetcli/ui_root.py b/targetcli/ui_root.py +index 39e5ee9..79ee985 100644 +--- a/targetcli/ui_root.py ++++ b/targetcli/ui_root.py +@@ -34,8 +34,9 @@ from .ui_backstore import complete_path, UIBackstores + from .ui_node import UINode + from .ui_target import UIFabricModule + +-default_save_file = "/etc/target/saveconfig.json" +-universal_prefs_file = "/etc/target/targetcli.conf" ++default_target_dir = "/etc/target" ++default_save_file = os.path.join(default_target_dir, "saveconfig.json") ++universal_prefs_file = os.path.join(default_target_dir, "targetcli.conf") + + class UIRoot(UINode): + ''' +@@ -112,8 +113,9 @@ class UIRoot(UINode): + finally: + os.umask(umask_original) + else: +- if (os.stat(dirname).st_mode & 0o777) != mode: +- os.chmod(dirname, mode) ++ if dirname == default_target_dir: ++ if (os.stat(dirname).st_mode & 0o777) != mode: ++ os.chmod(dirname, mode) + + def _save_backups(self, savefile): + ''' +-- +2.23.0 + diff --git a/targetcli.spec b/targetcli.spec index 8dc483b..3c9d194 100644 --- a/targetcli.spec +++ b/targetcli.spec @@ -2,9 +2,10 @@ Name: targetcli License: ASL 2.0 Summary: Generic SCSI target CLI shell Version: 2.1.54 -Release: 1 +Release: 2 URL: https://github.com/open-iscsi/targetcli-fb Source: https://github.com/open-iscsi/targetcli-fb/archive/v%{version}/targetcli-fb-%{version}.tar.gz +Patch01: Fix-changing-savedir-directory-mode.patch BuildArch: noarch BuildRequires: python3-devel python3-setuptools systemd Requires: python3-rtslib target-restore python3-configshell python3-six python3-dbus python3-gobject-base @@ -20,7 +21,7 @@ Summary: Help document for the %{name} package Help document for the %{name} package. %prep -%setup -q -n targetcli-fb-%{version} +%autosetup -n targetcli-fb-%{version} -p1 %build %py3_build @@ -47,6 +48,9 @@ install -m 644 systemd/* %{buildroot}%{_unitdir}/ %{_mandir}/man8/targetcli*.8* %changelog +* Sun Apr 7 2024 yanshuai - 2.1.54-2 +- Fix changing savedir directory mode + * Wed Dec 29 2021 wulei - 2.1.54-1 - Package update -- Gitee