lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20231110150057.15717-5-lhruska@suse.cz>
Date:   Fri, 10 Nov 2023 16:00:57 +0100
From:   Lukas Hruska <lhruska@...e.cz>
To:     linux-debuggers@...r.kernel.org, linux-kernel@...r.kernel.org
Cc:     Michal Koutny <mkoutny@...e.com>,
        YOSHIDA Masanori <masanori.yoshida.tv@...achi.com>
Subject: [RFC PATCH 4/4 v1] livedump: Add tools to make livedump creation easier

Add tool wrapping all handling of livedump's sysfs. Add tool extracting the
dump from block device first checking the correct size of dumped memory. This
way the extraction can be done even after resizing the physical memory.

Signed-off-by: Lukas Hruska <lhruska@...e.cz>
---
 tools/livedump/livedump.sh         | 44 ++++++++++++++++++++++++++++++
 tools/livedump/livedump_extract.sh | 19 +++++++++++++
 2 files changed, 63 insertions(+)
 create mode 100755 tools/livedump/livedump.sh
 create mode 100755 tools/livedump/livedump_extract.sh

diff --git a/tools/livedump/livedump.sh b/tools/livedump/livedump.sh
new file mode 100755
index 000000000000..2cc67bbbc380
--- /dev/null
+++ b/tools/livedump/livedump.sh
@@ -0,0 +1,44 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# This is a wrapper for livedump's sysfs to make a complete memdump.
+# Usage: livedump block_device
+#
+# Author: Lukas Hruska <lhruska@...e.cz>
+#
+# This file has been put into the public domain.
+# You can do whatever you want with this file.
+#
+
+if [ $# -ne 1 ]; then
+	>&2 echo "Usage: livedump block_device"
+	>&2 echo "Not enough arugments"
+	exit 1
+fi
+
+DEV=$1
+
+write_and_check() {
+	NAME=$1
+	VAL=$2
+	PATH=$3
+
+	echo -n "$NAME: "
+	echo $VAL > $PATH
+	if [ $? -ne 0 ]; then
+		exit 1
+	fi
+	echo "OK"
+}
+
+CUR_STATE=`head -n 1 /sys/kernel/livedump/state`
+if [ $CUR_STATE -ne 0 ] && [ $CUR_STATE -ne 5 ]; then
+	write_and_check "reset" 5 /sys/kernel/livedump/state
+fi
+
+write_and_check "device" $DEV /sys/kernel/livedump/output
+write_and_check "init" 1 /sys/kernel/livedump/state
+write_and_check "start" 2 /sys/kernel/livedump/state
+write_and_check "sweep" 3 /sys/kernel/livedump/state
+write_and_check "finish" 4 /sys/kernel/livedump/state
+write_and_check "uninit" 5 /sys/kernel/livedump/state
diff --git a/tools/livedump/livedump_extract.sh b/tools/livedump/livedump_extract.sh
new file mode 100755
index 000000000000..c1dc69da7559
--- /dev/null
+++ b/tools/livedump/livedump_extract.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# This script extracts the ELF formatted livedump from block device with correct size.
+# Usage: livedump_extract block_device output_file
+#
+# Author: Lukas Hruska <lhruska@...e.cz>
+#
+# This file has been put into the public domain.
+# You can do whatever you want with this file.
+#
+device=$1
+output=$2
+
+head -c 4096 $device > /tmp/livedump_hdr
+size=$(readelf -l /tmp/livedump_hdr | tail -2 | tr '\n' ' ' | tr -s ' ' \
+	| cut -d ' ' -f 5,6 | xargs printf "%d + %d" | xargs expr)
+size=$(expr $size / 4096)
+dd if=$device of=$output count=$size bs=4096 status=progress
-- 
2.39.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ