Skip to content

Commit e15ca64

Browse files
committed
Format fixes; Confirmed, it does taint multiple files! Wohoo!
1 parent 9292e9d commit e15ca64

File tree

5 files changed

+72
-92
lines changed

5 files changed

+72
-92
lines changed

panda/debian/setup.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,17 @@ HTTP_PROXY="${HTTP_PROXY:-}"
6464
HTTPS_PROXY="${HTTPS_PROXY:-}"
6565

6666
# Finish building main panda container for the target ubuntu version
67+
# For local testing, feel free to reduce the TARGET_LIST to a smaller set of targets for faster compiling.
6768
DOCKER_BUILDKIT=1 docker build \
6869
--target whlpackager \
6970
-t packager \
7071
--build-arg HTTP_PROXY="${HTTP_PROXY}" \
7172
--build-arg HTTPS_PROXY="${HTTPS_PROXY}" \
7273
--build-arg BASE_IMAGE="ubuntu:${version}" \
74+
--build-arg TARGET_LIST="x86_64-softmmu,i386-softmmu,arm-softmmu,aarch64-softmmu,ppc-softmmu,mips-softmmu,mipsel-softmmu,mips64-softmmu,mips64el-softmmu" \
7375
--build-arg PACKAGE_VERSION="${tag_version}" \
7476
../..
7577

7678
# Copy deb file out of container to host
7779
docker run --rm -v $(pwd):/out packager bash -c "cp /*.whl /pandare.deb /out"
78-
mv pandare.deb pandare_${version}.deb
80+
mv pandare.deb pandare_${version}.deb

panda/plugins/file_taint/file_taint.cpp

Lines changed: 37 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ using FilePosition = uint64_t;
6161
static std::unordered_map<ReadKey, FilePosition> read_positions;
6262

6363
// Helper function that only prints if the verbose flag is set.
64-
void verbose_printf(const char *fmt, ...)
65-
{
64+
void verbose_printf(const char *fmt, ...) {
6665
va_list args;
6766
va_start(args, fmt);
6867
if (verbose) {
@@ -86,8 +85,7 @@ bool is_match(const std::string &filename) {
8685
// A normalized read_enter function. Called by both Linux and Windows
8786
// specific calls.
8887
void read_enter(const std::string &filename, uint64_t file_id,
89-
uint64_t position)
90-
{
88+
uint64_t position) {
9189
// Check if the filename matched, if not we don't have to do anything.
9290
if (!is_match(filename)) {
9391
verbose_printf("file_taint read_enter: filename \"%s\" not matched\n",
@@ -129,14 +127,15 @@ void read_enter(const std::string &filename, uint64_t file_id,
129127
// A normalized read_return function. Called by both Linux and Windows read return
130128
// implementations.
131129
void read_return(uint64_t file_id, uint64_t bytes_read,
132-
target_ulong buffer_addr)
133-
{
130+
target_ulong buffer_addr) {
134131
// Construct our read key (a tuple of PID, TID, and file ID (handle or
135132
// descriptor).
136133
ReadKey key;
137134
std::unique_ptr<OsiProc, decltype(free_osiproc)*> proc { get_current_process(first_cpu), free_osiproc };
138135
std::unique_ptr<OsiThread, decltype(free_osithread)*> thr { get_current_thread(first_cpu), free_osithread };
139-
if (!thr) return;
136+
if (!thr) {
137+
return;
138+
}
140139
key.process_id = proc ? proc->pid : 0;
141140
key.thread_id = thr->tid;
142141
key.file_id = file_id;
@@ -159,12 +158,10 @@ void read_return(uint64_t file_id, uint64_t bytes_read,
159158

160159
// Figure out if the read overlapped our desired range.
161160
uint64_t range_start = std::max(read_start_pos, min_byte_pos);
162-
uint64_t range_end =
163-
std::min(read_start_pos + bytes_read - 1, max_byte_pos);
161+
uint64_t range_end = std::min(read_start_pos + bytes_read - 1, max_byte_pos);
164162

165163
bool print_apply_message = true;
166-
for (uint64_t i = 0; i < bytes_read && tainted_byte_count < max_byte_count;
167-
i++) {
164+
for (uint64_t i = 0; i < bytes_read && tainted_byte_count < max_byte_count; i++) {
168165
uint64_t file_pos = read_start_pos + i;
169166
if (range_start <= file_pos && file_pos <= range_end) {
170167
if (print_apply_message) {
@@ -175,23 +172,20 @@ void read_return(uint64_t file_id, uint64_t bytes_read,
175172
print_apply_message = false;
176173
}
177174
hwaddr shadow_addr = panda_virt_to_phys(first_cpu, buffer_addr + i);
178-
if (shadow_addr == (hwaddr)(-1))
179-
{
175+
if (shadow_addr == (hwaddr)(-1)) {
180176
printf("file_taint can't label file_pos=%lu buffer_addr=0x%" PRIx64 ": mmu hasn't mapped virt->phys, i.e., it isnt actually there.\n", file_pos, buffer_addr + i);
181177
}
182178
ram_addr_t RamOffset = RAM_ADDR_INVALID;
183-
if (PandaPhysicalAddressToRamOffset(&RamOffset, shadow_addr, false) != MEMTX_OK)
184-
{
179+
if (PandaPhysicalAddressToRamOffset(&RamOffset, shadow_addr, false) != MEMTX_OK) {
185180
printf("file_taint can't label file_pos=%lu buffer_addr=0x%" PRIx64 " shadow_addr=0x%" PRIx64 ": physical map is not RAM.\n", file_pos, buffer_addr + i, shadow_addr);
186181
continue;
187182
}
188-
verbose_printf(
189-
"file_taint applying label: file_pos=%lu buffer_addr=%lu\n",
190-
file_pos, buffer_addr + i);
183+
verbose_printf("file_taint applying label: file_pos=%lu buffer_addr=%lu\n", file_pos, buffer_addr + i);
191184
if (positional) {
192185
taint2_label_ram(RamOffset, file_pos);
193-
if (use_symbolic_label)
186+
if (use_symbolic_label) {
194187
taint2_sym_label_ram(RamOffset, file_pos);
188+
}
195189
} else {
196190
taint2_label_ram(RamOffset, static_label);
197191
}
@@ -214,8 +208,7 @@ const NTSTATUS STATUS_PENDING = 0x00000103;
214208

215209
// Common code for Windows read enter. Extract the filename and offset of the
216210
// file handle and call the normalized read enter.
217-
void windows_read_enter(CPUState *cpu, uint64_t FileHandle)
218-
{
211+
void windows_read_enter(CPUState *cpu, uint64_t FileHandle) {
219212
// get_handle_name will assert if the filename is null
220213
char *filename = get_handle_name(cpu, FileHandle);
221214
std::string ob_path = filename;
@@ -244,8 +237,7 @@ void windows64_read_enter(CPUState *cpu, target_ulong pc, uint64_t FileHandle,
244237
uint64_t Event, uint64_t ApcRoutine,
245238
uint64_t ApcContext, uint64_t IoStatusBlock,
246239
uint64_t Buffer, uint32_t Length,
247-
uint64_t ByteOffset, uint64_t Key)
248-
{
240+
uint64_t ByteOffset, uint64_t Key) {
249241
windows_read_enter(cpu, FileHandle);
250242
}
251243

@@ -256,8 +248,7 @@ void windows64_read_return(CPUState *cpu, target_ulong pc, uint64_t FileHandle,
256248
uint64_t Event, uint64_t ApcRoutine,
257249
uint64_t ApcContext, uint64_t IoStatusBlock,
258250
uint64_t Buffer, uint32_t Length,
259-
uint64_t ByteOffset, uint64_t Key)
260-
{
251+
uint64_t ByteOffset, uint64_t Key) {
261252
struct {
262253
union {
263254
NTSTATUS status;
@@ -273,13 +264,11 @@ void windows64_read_return(CPUState *cpu, target_ulong pc, uint64_t FileHandle,
273264
}
274265

275266
if (io_status_block2.status == STATUS_PENDING) {
276-
printf(
277-
"file_taint read return: detected async read return, ignoring\n");
267+
printf("file_taint read return: detected async read return, ignoring\n");
278268
} else if (io_status_block2.status == STATUS_SUCCESS) {
279269
read_return(FileHandle, io_status_block2.information, Buffer);
280270
} else {
281-
printf("file_taint windows_read_return: detected read failure, "
282-
"ignoring\n");
271+
printf("file_taint windows_read_return: detected read failure, ignoring\n");
283272
}
284273
}
285274

@@ -291,8 +280,7 @@ void windows32_read_enter(CPUState *cpu, target_ulong pc, uint32_t FileHandle,
291280
uint32_t Event, uint32_t UserApcRoutine,
292281
uint32_t UserApcContext, uint32_t IoStatusBlock,
293282
uint32_t Buffer, uint32_t BufferLength,
294-
uint32_t ByteOffset, uint32_t Key)
295-
{
283+
uint32_t ByteOffset, uint32_t Key) {
296284
windows_read_enter(cpu, FileHandle);
297285
}
298286

@@ -303,8 +291,7 @@ void windows32_read_return(CPUState *cpu, target_ulong pc, uint32_t FileHandle,
303291
uint32_t Event, uint32_t UserApcRoutine,
304292
uint32_t UserApcContext, uint32_t IoStatusBlock,
305293
uint32_t Buffer, uint32_t BufferLength,
306-
uint32_t ByteOffset, uint32_t Key)
307-
{
294+
uint32_t ByteOffset, uint32_t Key) {
308295
struct {
309296
union {
310297
NTSTATUS status;
@@ -320,24 +307,23 @@ void windows32_read_return(CPUState *cpu, target_ulong pc, uint32_t FileHandle,
320307
}
321308

322309
if (io_status_block.status == STATUS_PENDING) {
323-
printf(
324-
"file_taint read return: detected async read return, ignoring\n");
310+
printf("file_taint read return: detected async read return, ignoring\n");
325311
} else if (io_status_block.status == STATUS_SUCCESS) {
326312
read_return(FileHandle, io_status_block.information, Buffer);
327313
} else {
328-
printf("file_taint windows_read_return: detected read failure, "
329-
"ignoring\n");
314+
printf("file_taint windows_read_return: detected read failure, ignoring\n");
330315
}
331316
}
332317
#endif // end of not TARGET_X86_64
333318
#endif // end of TARGET_I386
334319

335320
// Extract the filename and offset of the file descriptor and call the
336321
// normalized read enter.
337-
void linux_read_enter(CPUState *cpu, uint32_t fd)
338-
{
322+
void linux_read_enter(CPUState *cpu, uint32_t fd) {
339323
OsiProc *proc = get_current_process(cpu);
340-
if (!proc) return;
324+
if (!proc) {
325+
return;
326+
}
341327
// The filename in Linux should always be absolute.
342328
char *filename = osi_linux_fd_to_filename(cpu, proc, fd);
343329
if (filename != NULL) {
@@ -352,22 +338,19 @@ void linux_read_enter(CPUState *cpu, uint32_t fd)
352338

353339
// Handle a 32-bit Linux read enter. Call the common linux_read_enter.
354340
void linux_read_enter_32(CPUState *cpu, target_ulong pc, uint32_t fd,
355-
uint32_t buffer, uint32_t count)
356-
{
341+
uint32_t buffer, uint32_t count) {
357342
linux_read_enter(cpu, fd);
358343
}
359344

360345
// Handle a 64-bit Linux read enter. Call the common linux_read_enter.
361346
void linux_read_enter_64(CPUState *cpu, target_ulong pc, uint32_t fd,
362-
uint64_t buffer, uint32_t count)
363-
{
347+
uint64_t buffer, uint32_t count) {
364348
linux_read_enter(cpu, fd);
365349
}
366350

367351
// Extract the filename and use the position passed to pread to call the
368352
// normalized read enter.
369-
void linux_pread_enter(CPUState *cpu, uint32_t fd, uint64_t pos)
370-
{
353+
void linux_pread_enter(CPUState *cpu, uint32_t fd, uint64_t pos) {
371354
OsiProc *proc = get_current_process(cpu);
372355
// The filename in Linux should always be absolute.
373356
char *filename = osi_linux_fd_to_filename(cpu, proc, fd);
@@ -385,23 +368,20 @@ void linux_pread_enter(CPUState *cpu, uint32_t fd, uint64_t pos)
385368
}
386369
// Handle a 32-bit Linux pread enter. Calls the common linux_pread_enter.
387370
void linux_pread_enter_32(CPUState *cpu, target_ulong pc, uint32_t fd,
388-
uint32_t buf, uint32_t count, uint64_t pos)
389-
{
371+
uint32_t buf, uint32_t count, uint64_t pos) {
390372
linux_pread_enter(cpu, fd, pos);
391373
}
392374

393375
// Handle a 64-bit Linux pread enter. Calls the common linux_pread_enter.
394376
void linux_pread_enter_64(CPUState *cpu, target_ulong pc, uint32_t fd,
395-
uint64_t buf, uint32_t count, uint64_t pos)
396-
{
377+
uint64_t buf, uint32_t count, uint64_t pos) {
397378
linux_pread_enter(cpu, fd, pos);
398379
}
399380

400381
// Handle a 32-bit Linux read return. Extract the number of bytes read from EAX
401382
// and call the normalized read return.
402383
void linux_read_return_32(CPUState *cpu, target_ulong pc, uint32_t fd,
403-
uint32_t buffer, uint32_t count)
404-
{
384+
uint32_t buffer, uint32_t count) {
405385
ssize_t actually_read = 0;
406386
#if defined(TARGET_I386) && !defined(TARGET_X86_64)
407387
CPUArchState *env = (CPUArchState *)cpu->env_ptr;
@@ -430,8 +410,7 @@ void linux_read_return_32(CPUState *cpu, target_ulong pc, uint32_t fd,
430410
// Handle a 64-bit Linux read return. Extract the number of bytes read from RAX
431411
// and call the normalized read return.
432412
void linux_read_return_64(CPUState *cpu, target_ulong pc, uint32_t fd,
433-
uint64_t buffer, uint32_t count)
434-
{
413+
uint64_t buffer, uint32_t count) {
435414
ssize_t actually_read = 0;
436415
#if defined(TARGET_X86_64)
437416
CPUArchState *env = (CPUArchState *)cpu->env_ptr;
@@ -456,21 +435,18 @@ void linux_read_return_64(CPUState *cpu, target_ulong pc, uint32_t fd,
456435
}
457436

458437
void linux_pread_return_32(CPUState *cpu, target_ulong pc, uint32_t fd,
459-
uint32_t buf, uint32_t count, uint64_t pos)
460-
{
438+
uint32_t buf, uint32_t count, uint64_t pos) {
461439
// Just call the regular linux read return
462440
linux_read_return_32(cpu, pc, fd, buf, count);
463441
}
464442

465443
void linux_pread_return_64(CPUState *cpu, target_ulong pc, uint32_t fd,
466-
uint64_t buf, uint32_t count, uint64_t pos)
467-
{
444+
uint64_t buf, uint32_t count, uint64_t pos) {
468445
// Just call the regular linux read return
469446
linux_read_return_64(cpu, pc, fd, buf, count);
470447
}
471448

472-
bool init_plugin(void *self)
473-
{
449+
bool init_plugin(void *self) {
474450
// Parse arguments for file_taint
475451
panda_arg_list *args = panda_get_args("file_taint");
476452
target_filename =
@@ -560,10 +536,9 @@ bool init_plugin(void *self)
560536
return false;
561537
} break;
562538
}
563-
564539
return true;
565540
}
566541

567542
void uninit_plugin(void *self) {
568-
// intentionally left blank
543+
verbose_printf("file_taint: uninit_plugin called\n");
569544
}

0 commit comments

Comments
 (0)