Skip to content

Commit bf77208

Browse files
author
Valentin Obst
committed
release: version 0.1.0
1 parent 719519d commit bf77208

File tree

13 files changed

+121
-855
lines changed

13 files changed

+121
-855
lines changed

Cargo.lock

Lines changed: 0 additions & 86 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ strip = "symbols"
3131
anyhow = "1.0.75"
3232
clap = { version = "4.3.21", features = ["derive"] }
3333
env_logger = "0.10.0"
34-
goblin = "0.7.1"
3534
log = "0.4.20"
3635
nix = { version = "0.26.2", features = ["ioctl", "kmod"] }
3736
num-traits = "0.2.16"
38-
ruzstd = "0.4.0"
3937

4038
[build-dependencies]
4139
cbindgen = "0.25.0"

README.md

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# pmem
22

3-
`pmem` is a small tool for loading and interacting with the [linpmem driver](). It lets you use the features of the driver in scripts and on the command line. At the same time, this repository also provides a library that can be used by other programs that want to interface with the driver. The command-line application is simply a thin wrapper around this library.
3+
`pmem` is a small tool for loading and interacting with the [linpmem driver](https://github.com/velocidex/linpmem). It lets you use the features of the driver in scripts and on the command line. At the same time, this repository also provides a library that can be used by other programs that want to interface with the driver. The command-line application is simply a thin wrapper around this library.
44

55
## Building
66

@@ -30,7 +30,7 @@ cargo build --release
3030
```
3131
This will generate two static binaries located at `target/x86_64-unknown-linux-musl/release/`:
3232
- `pmem`: The fully-featured command-line client.
33-
- `loader`: A smaller program that is containing only the module loader and unloader.
33+
- `loader`: A smaller program that contains only the functionality needed to load and unload the driver.
3434

3535
## Installation
3636

@@ -40,7 +40,7 @@ cargo install --path . --locked
4040
```
4141
This command will install the `pmem` and `loader` binaries into Cargo's bin folder, e.g., `$HOME/.cargo/bin`.
4242

43-
Note: This will install the programs for the _current_ user, which is hopefully not the root user. In case you experience any troubles when running them through sudo or in a root shell, remember to add the binaries to root's PATH.
43+
Note: This will install the programs for the _current_ user, which is hopefully not the root user. In case you experience any troubles when running them through `sudo` or in a root shell, remember to add the binaries to root's PATH.
4444

4545
## Uninstall
4646

@@ -55,11 +55,14 @@ rm -rf path/to/linpmem-cli
5555

5656
## Usage
5757

58-
`pmem` is a command-line client for the `linpmem` driver. Thus, you first have to [build the driver](). Assuming that you managed to successfully build the driver, load it with the `insmod` subcommand:
58+
`pmem` is a command-line client for the `linpmem` driver. Thus, you first have to [build the driver](https://github.com/velocidex/linpmem#building). Assuming that you managed to successfully build the driver, load it with the `insmod` subcommand:
5959
```
6060
pmem insmod path/to/linpmem.ko
6161
```
62-
_Note: We are using a custom module loader, thus the system's `insmod` or `modprobe` binaries will not work._
62+
or the stand-alone loader
63+
```
64+
loader path/to/linpmem.ko
65+
```
6366

6467
Now, you can use `pmem` to interact with the driver:
6568
```
@@ -76,7 +79,7 @@ Commands:
7679
7780
Options:
7881
-a, --address <ADDRESS>
79-
Address for physical read/write operations
82+
Address for physical read operations
8083
8184
-v, --virt-address <VIRT_ADDRESS>
8285
Translate address in target process' address space (default: current process)
@@ -85,29 +88,48 @@ Options:
8588
Size of buffer read operations
8689
8790
-m, --mode <MODE>
88-
Access mode for read and write operations
91+
Access mode for read operations
8992
9093
[possible values: byte, word, dword, qword, buffer]
9194
92-
-w, --write <WRITE>
93-
Write the hex-encoded byte sequence
94-
9595
-p, --pid <PID>
9696
Target process for cr3 info and virtual-to-physical translations
9797
9898
--cr3
9999
Query cr3 value of target process (default: current process)
100100
101+
--verbose
102+
Display debug output
103+
101104
-h, --help
102105
Print help (see a summary with '-h')
103106
104107
-V, --version
105108
Print version
109+
106110
```
107111
By default, memory contents are written to stdout as raw bytes. Thus, you might want to use `xxd` to make them more human-friendly:
108112
```
109-
$ pmem --address 0x1ffe0040 -m buffer -s 16 | xxd
110-
00000000: 4453 4454 7818 0000 0170 424f 4348 5320 DSDTx....pBOCHS
113+
# echo 1 > /proc/sys/kernel/kptr_restrict
114+
$ sudo cat /proc/kallsyms | grep ' linux_banner$'
115+
ffffffff9823bf20 D linux_banner
116+
$ pmem -v 0xffffffff9823bf20
117+
0x000000070923bf20
118+
$ pmem -a 0x000000070923bf20 -m buffer -s 0x1000 | xxd
119+
00000000: 4c69 6e75 7820 7665 7273 696f 6e20 362e Linux version 6.
120+
00000010: 342e 3131 2d68 6172 6465 6e65 6431 2d31 4.11-hardened1-1
121+
00000020: 2d68 6172 6465 6e65 6420 286c 696e 7578 -hardened (linux
122+
00000030: 2d68 6172 6465 6e65 6440 6172 6368 6c69 -hardened@archli
123+
00000040: 6e75 7829 2028 6763 6320 2847 4343 2920 nux) (gcc (GCC)
124+
00000050: 3133 2e32 2e31 2032 3032 3330 3830 312c 13.2.1 20230801,
125+
00000060: 2047 4e55 206c 6420 2847 4e55 2042 696e GNU ld (GNU Bin
126+
00000070: 7574 696c 7329 2032 2e34 312e 3029 2023 utils) 2.41.0) #
127+
00000080: 3120 534d 5020 5052 4545 4d50 545f 4459 1 SMP PREEMPT_DY
128+
00000090: 4e41 4d49 4320 5475 652c 2032 3220 4175 NAMIC Tue, 22 Au
129+
000000a0: 6720 3230 3233 2031 393a 3234 3a31 3920 g 2023 19:24:19
130+
000000b0: 2b30 3030 300a 0000 81c9 0200 0000 0000 +0000...........
131+
000000c0: 0b41 a578 65f5 70f2 63b0 d013 0941 ff70 .A.xe.p.c....A.p
132+
000000d0: f2e9 b093 7274 0841 63b0 5f3b fca4 f40d ....rt.Ac._;....
111133
```
112134

113135
## Library
@@ -118,10 +140,12 @@ The normal build process also generates a static C library `libpmem.a` as well a
118140

119141
## Troubleshooting
120142

121-
At this point, a word of caution may be in order. Reading and writing arbitrary physical memory is considered dangerous. If you do not know what you are doing, DO NOT USE THIS TOOL.
143+
At this point, a word of caution may be in order. Reading arbitrary physical memory is considered dangerous. If you do not know what you are doing, DO NOT USE THIS TOOL.
122144

123-
For all the others, a good point to start may be the driver logs, simply:
145+
For all the others, a good point to start debugging may be taking a look at the driver logs, simply:
124146
```
125-
cat /proc/kmsg | grep linpmem
147+
sudo journalctl --since today -g linpmem
126148
```
127-
They can be made more verbose by building the driver with `DEBUG` defined. If you come to the conclusion that the problem is with the `pmem` tool and not the driver, please open an issue.
149+
They can be made more verbose by building the driver with `DEBUG` defined. The user-space tools will also display debug output when being run with the `--verbose` flag.
150+
151+
If you come to the conclusion that the problem is with the `pmem` tool and not the driver, please open an issue.

examples/c/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ TARGET_DIR = ../../target/x86_64-unknown-linux-musl/release
55
all: clean load_unload
66

77
load_unload:
8-
$(CC) -o $@ $@.c $(TARGET_DIR)/libpmem.a
8+
$(CC) --std=c11 -o $@ $@.c $(TARGET_DIR)/libpmem.a
99

1010
clean:
1111
rm load_unload

src/cli.rs

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use clap::{Args, Parser, Subcommand, ValueEnum};
22
use num_traits::{sign, Num};
3-
use crate::pte::PteParts;
43

54
#[derive(ValueEnum, Clone, Debug, Copy)]
65
pub enum AccessMode {
@@ -54,19 +53,11 @@ pub struct InsmodCli {
5453
pub kmod_path: Option<String>,
5554

5655
/// Unload the driver and remove its device file
57-
#[arg(short, long, default_value_t=false)]
56+
#[arg(short, long, default_value_t = false)]
5857
pub rm: bool,
5958

60-
/// Adjust the driver to the running kernel before loading
61-
#[arg(short, long, default_value_t=false)]
62-
pub adjust: bool,
63-
64-
/// Path to a valid driver for the running kernel
65-
#[arg(long)]
66-
pub valid_driver: Option<String>,
67-
6859
/// Display debug output
69-
#[arg(short, long, default_value_t=false)]
60+
#[arg(short, long, default_value_t = false)]
7061
pub verbose: bool,
7162
}
7263

@@ -92,7 +83,7 @@ pub struct Cli {
9283
#[command(subcommand)]
9384
pub subcommand: Option<Subcommands>,
9485

95-
/// Address for physical read/write operations
86+
/// Address for physical read operations
9687
#[arg(short, long, value_parser=maybe_hex::<u64>, requires("mode"))]
9788
pub address: Option<u64>,
9889

@@ -104,19 +95,10 @@ pub struct Cli {
10495
#[arg(short, long, value_parser=maybe_hex::<u64>, required_if_eq("mode", "buffer"))]
10596
pub size: Option<u64>,
10697

107-
/// Access mode for read and write operations
98+
/// Access mode for read operations
10899
#[arg(value_enum, short, long, rename_all = "lower", requires("address"))]
109100
pub mode: Option<AccessMode>,
110101

111-
/// Update the driver's PTE template. Expects a comma-separated list of pte
112-
/// parts. Leave empty to query the current value.
113-
#[arg(value_enum, long, num_args = 0.., value_delimiter = ',')]
114-
pub pte_parts: Option<Vec<PteParts>>,
115-
116-
/// Write the hex-encoded byte sequence
117-
#[arg(short, long, requires("address"))]
118-
pub write: Option<String>,
119-
120102
/// Target process for cr3 info and virtual-to-physical translations
121103
#[arg(short, long)]
122104
pub pid: Option<u32>,
@@ -126,6 +108,6 @@ pub struct Cli {
126108
pub cr3: bool,
127109

128110
/// Display debug output
129-
#[arg(long, default_value_t=false)]
111+
#[arg(long, default_value_t = false)]
130112
pub verbose: bool,
131113
}

0 commit comments

Comments
 (0)