| 1 |
#!/usr/bin/env stap |
| 2 |
# badname.stp |
| 3 |
# Prevent the creation of files with undesirable names. |
| 4 |
# Source: http://blog.cuviper.com/2009/04/08/hacking-linux-filenames/ |
| 5 |
|
| 6 |
# return non-zero if the filename should be blocked |
| 7 |
function filter:long (name:string) |
| 8 |
{ |
| 9 |
return isinstr(name, "XXXbadnameXXX") |
| 10 |
} |
| 11 |
|
| 12 |
global squash_inode_permission |
| 13 |
|
| 14 |
# We really want to probe may_create(). But, may_create() is now |
| 15 |
# always inlined, and stap can't find its arguments. So, we have to |
| 16 |
# probe may_create()'s callers. |
| 17 |
|
| 18 |
probe kernel.{function("vfs_create"), function("vfs_mknod"), |
| 19 |
function("vfs_mkdir"), function("vfs_symlink"), |
| 20 |
function("vfs_link"), function("vfs_rename")} |
| 21 |
{ |
| 22 |
# screen out the conditions which may_create will fail anyway |
| 23 |
if (@choose_defined($dentry->d_inode, $new_dentry->d_inode) |
| 24 |
|| @choose_defined($dir->i_flags, $new_dir->i_flags) & %{ S_DEAD %}) next |
| 25 |
|
| 26 |
# check that the new file meets our naming rules |
| 27 |
if (filter(kernel_string(@choose_defined($dentry->d_name->name, |
| 28 |
$new_dentry->d_name->name)))) |
| 29 |
squash_inode_permission[tid()] = 1 |
| 30 |
} |
| 31 |
|
| 32 |
probe kernel.function("inode_permission@fs/namei.c").return !, |
| 33 |
kernel.function("permission@fs/namei.c").return |
| 34 |
{ |
| 35 |
if (!$return && squash_inode_permission[tid()]) |
| 36 |
$return = -13 # -EACCES (Permission denied) |
| 37 |
delete squash_inode_permission[tid()] |
| 38 |
} |