dump_systemstate: Wait for buxton to really start 35/302335/4 accepted/tizen_unified_toolchain accepted/tizen/unified/20240430.020606 accepted/tizen/unified/toolchain/20240507.011851 accepted/tizen/unified/x/20240430.094809
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Tue, 5 Dec 2023 09:44:47 +0000 (10:44 +0100)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Fri, 26 Apr 2024 14:37:38 +0000 (16:37 +0200)
Otherwise crash_worker will directly access sqlite database, and create its tmp/journal
files with inappropriate (crash_worker) user and group - consequently breaking access
to the files to buxton service itself and rest of the system.

Change-Id: I7be39c433efa39effb07b5714d6a5e773b68e15d

packaging/crash-worker.spec
src/dump_systemstate/BUGS [new file with mode: 0644]
src/dump_systemstate/CMakeLists.txt
src/dump_systemstate/helpers/buxton-wait [new file with mode: 0755]
src/dump_systemstate/programs/crash-worker-programs.conf

index a7a2c70..72b90e7 100644 (file)
@@ -16,7 +16,7 @@
 
 Name:           crash-worker
 Summary:        Coredump handler and report generator for Tizen
-Version:        8.0.4
+Version:        9.0.0
 Release:        1
 Group:          Framework/system
 License:        MIT
@@ -324,6 +324,7 @@ chsmack -a "System" -t %{crash_path}
 %license LICENSE.MIT
 %{_sysconfdir}/dump_systemstate.conf.d/files/*.conf*
 %{_sysconfdir}/dump_systemstate.conf.d/programs/*.conf*
+%{_libexecdir}/dump_systemstate/buxton-wait
 
 %if %{with regdumper}
 %files support-regdump
diff --git a/src/dump_systemstate/BUGS b/src/dump_systemstate/BUGS
new file mode 100644 (file)
index 0000000..685d20e
--- /dev/null
@@ -0,0 +1,75 @@
+This document lists bugs and limitations currently known in dump_systemstate.
+
+buxton-wait
+===========
+
+Gathering buxton (also known as vconf) database can happen in either direct
+or indirect method as described below:
+
+ - indirect method means data is gathered from buxton2 service and is
+   used by default when service is available
+
+ - direct method means that buxton2ctl accesses buxton sqlite database
+   directly - this method is used automatically by tools when buxton
+   service is not available
+
+Unfortunately, when direct method is used as fallback (eg. during
+early boot) it causes buxton database to break as described in
+following scenario:
+
+1. crash happens
+
+2. crash-manager is executed via kernel's kernel.core_pattern sysctl
+   setting
+
+3. crash-manager drops privileges * changes gid and uid to
+   crash_worker:crash_worker * drops all capabilities keeping only 4
+   caps (including cap_dac_override)
+
+4. crash-manager executes various processes: * minicoredumper etc. to
+   grab core, potentialy in minimized form * processes to dump logs -
+   mainly dump_systemstate
+
+5. dump_systemstate executes various programs as configured in
+   /etc/dumpsystate* configuration files
+
+* one of the processes executed is buxton2ctl which dumps buxton2ctl
+
+* if buxton2 service is running, then indirect method is used and
+  there is no problem
+
+Unfortunately, if buxton2 service is not running following occur:
+
+* buxton databases are normally readable only by buxton user, the db
+  in /var/lib/buxton2 is rwx------ buxton:buxton
+
+* normally the database would not be readable because processes run by
+  dump_systemstate and buxton2ctl are run with crash_worker uid:gid,
+  BUT process also have cap_dac_override capability inherited which
+  overrides DAC rights
+
+* consequently, buxton2ctl can access the database (unix permissions
+  (DAC) are ignored due to caps)
+
+* unfortunately, the database is sqlite database and sqlite internally
+  always creates joural files: /var/lib/buxton2/system.db (always
+  exists) /var/lib/buxton2/system.db-wal (created by crash_worker)
+  /var/lib/buxton2/system.db-shm (created by crash_worker)
+
+* normally when root user access the db it does change ownership to
+  the owner of original file, but crash_worker does not have this
+  permission so we end up with following:
+
+    root:~> ls -l /var/lib/buxton2/
+    total 48
+    -rw-r--r-- 1 buxton buxton             16384  Jan 1 1970  system.db
+    -rw-r--r-- 1 crash_worker crash_worker 32768  Dec 8 18:43 system.db-shm
+    -rw-r--r-- 1 crash_worker crash_worker 0      Jan 1 1970  system.db-wal
+
+Consequently, next processes that run (including buxton2d service) can
+not access and work on its databases. This causes numerous problems
+including lack of sdb access (this is because state is kept and
+communicated by vconf/buxton db).
+
+To avoid this problem we only use indirect method via the means of
+buxton-wait helper script.
index 3085cde..c9ba611 100644 (file)
@@ -31,6 +31,10 @@ INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin
                PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
                GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
 
+INSTALL(FILES helpers/buxton-wait DESTINATION libexec/${PROJECT_NAME}
+               PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
+               GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
+
 INSTALL(DIRECTORY files DESTINATION ${DUMP_SYSTEMSTATE_CONFIG_DIR_PATH}
         PATTERN "files/*.conf*"
         PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
diff --git a/src/dump_systemstate/helpers/buxton-wait b/src/dump_systemstate/helpers/buxton-wait
new file mode 100755 (executable)
index 0000000..17be1a0
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+# Helper program to ensure buxton databases are already opened
+#
+# This program is needed because buxton2ctl as launched via dump_systemstate,
+# via crash-manager, has high enough permissions to create sqlite journal files
+# in /var/lib/buxton2. (The files are created internally via libsqlite logic and
+# client has no control over it).
+#
+# By waiting for buxton2 service to start we want to ensure the needed sqlite
+# files are already created with correct permissions.
+
+
+WAIT_SEC=30
+BUXTON_SERVICE=buxton2.service
+BUXTON_BIN=/usr/bin/buxton2ctl
+
+for i in $(seq 1 $WAIT_SEC); do
+       if systemctl is-active "$BUXTON_SERVICE"; then
+               exec $BUXTON_BIN "$@"
+               break
+       fi
+       sleep 1
+done
+
+exit 0
index a96e2af..38f90c6 100644 (file)
@@ -29,14 +29,14 @@ allowdumpsysargs=yes
 order=140
 cmdflag=b
 title=System configuration
-path=/usr/bin/buxton2ctl
+path=/usr/libexec/dump_systemstate/buxton-wait
 args=dump memory
 
 [buxton system]
 order=141
 cmdflag=b
 title=System configuration
-path=/usr/bin/buxton2ctl
+path=/usr/libexec/dump_systemstate/buxton-wait
 args=dump system
 
 [Tizen packages]