#!/usr/bin/stap -g # Author: Soren Hansen # License: GPLv2+ # # Rewrite the "count" argument on x86 when attempting vfs_write to "mem" file. function filename_from_file:string(file:long) { dentry = dentry_from_file(file); filename = @cast(dentry, "dentry", "kernel")->d_name->name; return kernel_string(filename); } function fsname_from_file:string(file:long) { mnt = mnt_from_file(file); sb = @cast(mnt, "vfsmount", "kernel")->mnt_sb; fstype = @cast(sb, "super_block", "kernel")->s_type; fsname = @cast(fstype, "file_system_type", "kernel")->name; return kernel_string(fsname); } function mnt_from_file:long(file:long) { return @cast(file, "file", "kernel")->f_path->mnt; } function dentry_from_file:long(file:long) { return @cast(file, "file", "kernel")->f_path->dentry; } /* * Probes */ function not_a_chance () %{ CONTEXT->regs->dx = 0; %} probe kprobe.function("vfs_write") { file = pointer_arg(1) if ((fsname_from_file(file) == "proc") && (filename_from_file(file) == "mem")) { not_a_chance(); } }