/usr/sbin
NameSizeModeActions
aa-load396800755editdlrm
aa-remove-unknown32250755editdlrm
aa-status400000755editdlrm
aa-teardown1370755editdlrm
accessdb149040755editdlrm
acpid539200755editdlrm
add-shell10530755editdlrm
addgnupghome30750755editdlrm
addgroup551910755editdlrm
adduser551910755editdlrm
agetty609920755editdlrm
apparmor_parser16298480755editdlrm
apparmor_status400000755editdlrm
applygnupgdefaults22170755editdlrm
argdist-bpfcc368620755editdlrm
arpd269600755editdlrm
arptables2244240755editdlrm
arptables-nft2244240755editdlrm
arptables-nft-restore2244240755editdlrm
arptables-nft-save2244240755editdlrm
arptables-restore2244240755editdlrm
arptables-save2244240755editdlrm
badblocks351440755editdlrm
bashreadline-bpfcc23800755editdlrm
bashreadline.bt6980755editdlrm
bcache-super-show146480755editdlrm
bindsnoop-bpfcc163460755editdlrm
biolatency-bpfcc113650755editdlrm
biolatency-kp.bt6640755editdlrm
biolatency.bt6810755editdlrm
biolatpcts-bpfcc102480755editdlrm
biopattern-bpfcc39570755editdlrm
biosdecode278560755editdlrm
biosnoop-bpfcc108330755editdlrm
biosnoop.bt11480755editdlrm
biostacks.bt9150755editdlrm
biotop-bpfcc95670755editdlrm
bitesize-bpfcc11660755editdlrm
bitesize.bt5670755editdlrm
blkdeactivate163510755editdlrm
blkdiscard229120755editdlrm
blkid557200755editdlrm
blkzone352000755editdlrm
blockdev352000755editdlrm
bpflist-bpfcc26010755editdlrm
bpftool16220755editdlrm
bridge1110960755editdlrm
btrfsdist-bpfcc66270755editdlrm
btrfsslower-bpfcc99850755editdlrm
cachestat-bpfcc65310755editdlrm
cachetop-bpfcc93670755editdlrm
cache_check14305680755editdlrm
cache_dump14305680755editdlrm
cache_metadata_size14305680755editdlrm
cache_repair14305680755editdlrm
cache_restore14305680755editdlrm
cache_writeback14305680755editdlrm
capable-bpfcc84770755editdlrm
capable.bt19260755editdlrm
capsh584560755editdlrm
cfdisk970080755editdlrm
cgdisk1704800755editdlrm
chcpu311040755editdlrm
chgpasswd597200755editdlrm
chmem352000755editdlrm
chpasswd557360755editdlrm
chronyd3062320755editdlrm
chroot394320755editdlrm
cobjnew-bpfcc530755editdlrm
compactsnoop-bpfcc113690755editdlrm
cpgr496080755editdlrm
cppw496080755editdlrm
cpudist-bpfcc70130755editdlrm
cpuunclaimed-bpfcc149380755editdlrm
cpuwalk.bt4970755editdlrm
criticalstat-bpfcc86070755editdlrm
cron600800755editdlrm
cryptdisks_start15440755editdlrm
cryptdisks_stop8440755editdlrm
cryptsetup2313200755editdlrm
ctrlaltdel147200755editdlrm
dbslower-bpfcc73910755editdlrm
dbstat-bpfcc37900755editdlrm
dcb824480755editdlrm
dcsnoop-bpfcc41260755editdlrm
dcsnoop.bt12610755editdlrm
dcstat-bpfcc38590755editdlrm
deadlock-bpfcc209430755editdlrm
debugfs2312880755editdlrm
delgroup189770755editdlrm
deluser189770755editdlrm
depmod1743280755editdlrm
devlink1544800755editdlrm
dhcpcd4048880755editdlrm
dirtop-bpfcc85680755editdlrm
dmeventd515920755editdlrm
dmidecode1384960755editdlrm
dmsetup1751600755editdlrm
dmstats1751600755editdlrm
dosfsck802640755editdlrm
dosfslabel393040755editdlrm
dpkg-preconfigure43560755editdlrm
dpkg-reconfigure45360755editdlrm
drsnoop-bpfcc68890755editdlrm
dumpe2fs351360755editdlrm
e2freefrag187440755editdlrm
e2fsck3730800755editdlrm
e2image433280755editdlrm
e2label1132160755editdlrm
e2mmpstatus351360755editdlrm
e2scrub72940755editdlrm
e2scrub_all53940755editdlrm
e2undo228400755editdlrm
e4crypt311040755editdlrm
e4defrag351280755editdlrm
ebtables2244240755editdlrm
ebtables-nft2244240755editdlrm
ebtables-nft-restore2244240755editdlrm
ebtables-nft-save2244240755editdlrm
ebtables-restore2244240755editdlrm
ebtables-save2244240755editdlrm
ebtables-translate2244240755editdlrm
era_check14305680755editdlrm
era_dump14305680755editdlrm
era_invalidate14305680755editdlrm
era_restore14305680755editdlrm
ethtool6673200755editdlrm
execsnoop-bpfcc100590755editdlrm
execsnoop.bt9280755editdlrm
exitsnoop-bpfcc96460755editdlrm
ext4dist-bpfcc66830755editdlrm
ext4slower-bpfcc99480755editdlrm
faillock228480755editdlrm
fatlabel393040755editdlrm
fdisk1171680755editdlrm
filefrag187600755editdlrm
filegone-bpfcc57760755editdlrm
filelife-bpfcc65280755editdlrm
fileslower-bpfcc73720755editdlrm
filetop-bpfcc64990755editdlrm
findfs147200755editdlrm
fixparts598800755editdlrm
fsadm245800755editdlrm
fsck434400755editdlrm
fsck.btrfs11850755editdlrm
fsck.cramfs311680755editdlrm
fsck.ext23730800755editdlrm
fsck.ext33730800755editdlrm
fsck.ext43730800755editdlrm
fsck.fat802640755editdlrm
fsck.minix557120755editdlrm
fsck.msdos802640755editdlrm
fsck.vfat802640755editdlrm
fsck.xfs25660755editdlrm
fsfreeze147200755editdlrm
fstab-decode146480755editdlrm
fstrim433920755editdlrm
funccount-bpfcc129810755editdlrm
funcinterval-bpfcc55900755editdlrm
funclatency-bpfcc115490755editdlrm
funcslower-bpfcc106300755editdlrm
gdisk2032480755editdlrm
genl1234720755editdlrm
getcap146480755editdlrm
gethostlatency-bpfcc39140755editdlrm
gethostlatency.bt12220755editdlrm
getpcaps146480755editdlrm
getty609920755editdlrm
groupadd728400755editdlrm
groupdel644240755editdlrm
groupmems597440755editdlrm
groupmod727440755editdlrm
grpck597200755editdlrm
grpconv513680755editdlrm
grpunconv513680755editdlrm
grub-bios-setup9815520755editdlrm
grub-install12258240755editdlrm
grub-macbless9691280755editdlrm
grub-mkconfig88400755editdlrm
grub-mkdevicemap723840755editdlrm
grub-probe9775760755editdlrm
grub-reboot48410755editdlrm
grub-set-default35560755editdlrm
halt15013040755editdlrm
hardirqs-bpfcc70190755editdlrm
hdparm1427760755editdlrm
iconvconfig352960755editdlrm
init1008160755editdlrm
inject-bpfcc164450755editdlrm
insmod1743280755editdlrm
install-sgmlcatalog45510755editdlrm
installkernel26590755editdlrm
integritysetup686720755editdlrm
invoke-rc.d165170755editdlrm
ip7729200755editdlrm
ip6tables2244240755editdlrm
ip6tables-apply70520755editdlrm
ip6tables-legacy951760755editdlrm
ip6tables-legacy-restore951760755editdlrm
ip6tables-legacy-save951760755editdlrm
ip6tables-nft2244240755editdlrm
ip6tables-nft-restore2244240755editdlrm
ip6tables-nft-save2244240755editdlrm
ip6tables-restore2244240755editdlrm
ip6tables-restore-translate2244240755editdlrm
ip6tables-save2244240755editdlrm
ip6tables-translate2244240755editdlrm
iptables2244240755editdlrm
iptables-apply70520755editdlrm
iptables-legacy951760755editdlrm
iptables-legacy-restore951760755editdlrm
iptables-legacy-save951760755editdlrm
iptables-nft2244240755editdlrm
iptables-nft-restore2244240755editdlrm
iptables-nft-save2244240755editdlrm
iptables-restore2244240755editdlrm
iptables-restore-translate2244240755editdlrm
iptables-save2244240755editdlrm
iptables-translate2244240755editdlrm
irqbalance602720755editdlrm
irqbalance-ui393040755editdlrm
iscsi-iname187440755editdlrm
iscsiadm3793200755editdlrm
iscsid2934320755editdlrm
iscsistart2810800755editdlrm
iscsi_discovery52930755editdlrm
isosize147200755editdlrm
iucode-tool556400755editdlrm
iucode_tool556400755editdlrm
javacalls-bpfcc550755editdlrm
javaflow-bpfcc540755editdlrm
javagc-bpfcc520755editdlrm
javaobjnew-bpfcc560755editdlrm
javastat-bpfcc540755editdlrm
javathreads-bpfcc570755editdlrm
kbdrate187520755editdlrm
killall5268560755editdlrm
killsnoop-bpfcc45540755editdlrm
killsnoop.bt8730755editdlrm
klockstat-bpfcc133560755editdlrm
kpartx431760755editdlrm
kvmexit-bpfcc114610755editdlrm
ldattach270080755editdlrm
ldconfig3870755editdlrm
ldconfig.real10512800755editdlrm
llcstat-bpfcc45840755editdlrm
loads.bt11270755editdlrm
locale-gen43160755editdlrm
logrotate965040755editdlrm
logsave144960755editdlrm
losetup763040755editdlrm
lsmod1743280755editdlrm
luksformat34010755editdlrm
lvchange31567120755editdlrm
lvconvert31567120755editdlrm
lvcreate31567120755editdlrm
lvdisplay31567120755editdlrm
lvextend31567120755editdlrm
lvm31567120755editdlrm
lvmconfig31567120755editdlrm
lvmdiskscan31567120755editdlrm
lvmdump103640755editdlrm
lvmpolld2416320755editdlrm
lvmsadc31567120755editdlrm
lvmsar31567120755editdlrm
lvreduce31567120755editdlrm
lvremove31567120755editdlrm
lvrename31567120755editdlrm
lvresize31567120755editdlrm
lvs31567120755editdlrm
lvscan31567120755editdlrm
lxc5890755editdlrm
lxd5890755editdlrm
make-bcache229120755editdlrm
mdadm6371440755editdlrm
mdflush-bpfcc22950755editdlrm
mdflush.bt7750755editdlrm
mdmon2650160755editdlrm
memleak-bpfcc212980755editdlrm
mkdosfs520480755editdlrm
mke2fs1337520755editdlrm
mkfs147200755editdlrm
mkfs.bfs229120755editdlrm
mkfs.btrfs5737520755editdlrm
mkfs.cramfs351440755editdlrm
mkfs.ext21337520755editdlrm
mkfs.ext31337520755editdlrm
mkfs.ext41337520755editdlrm
mkfs.fat520480755editdlrm
mkfs.minix434080755editdlrm
mkfs.msdos520480755editdlrm
mkfs.ntfs679760755editdlrm
mkfs.vfat520480755editdlrm
mkfs.xfs4495280755editdlrm
mkhomedir_helper228720755editdlrm
mkinitramfs157620755editdlrm
mklost+found146480755editdlrm
mkntfs679760755editdlrm
mkswap515920755editdlrm
ModemManager21655760755editdlrm
modinfo1743280755editdlrm
modprobe1743280755editdlrm
mount.fuse187360755editdlrm
mount.fuse3187360755editdlrm
mount.lowntfs-3g1218320755editdlrm
mount.ntfs1628240755editdlrm
mount.ntfs-3g1628240755editdlrm
mountsnoop-bpfcc149680755editdlrm
mpathpersist319600755editdlrm
multipath351280755editdlrm
multipathc187440755editdlrm
multipathd1458800755editdlrm
mysqld554679440755editdlrm
mysqld_qslower-bpfcc31250755editdlrm
naptime.bt10350755editdlrm
needrestart410920755editdlrm
netplan8020755editdlrm
netqtop-bpfcc57250755editdlrm
newusers890480755editdlrm
nfnl_osf187360755editdlrm
nfsdist-bpfcc50680755editdlrm
nfsslower-bpfcc139390755editdlrm
nft268560755editdlrm
nginx13141680755editdlrm
nodegc-bpfcc520755editdlrm
nodestat-bpfcc540755editdlrm
nologin146400755editdlrm
ntfsclone515920755editdlrm
ntfscp311040755editdlrm
ntfslabel229120755editdlrm
ntfsresize638880755editdlrm
ntfsundelete515920755editdlrm
offcputime-bpfcc137790755editdlrm
offwaketime-bpfcc156760755editdlrm
on_ac_power37880755editdlrm
oomkill-bpfcc20840755editdlrm
oomkill.bt11980755editdlrm
opensnoop-bpfcc145810755editdlrm
opensnoop.bt9530755editdlrm
overlayroot-chroot25100755editdlrm
ownership147920755editdlrm
pam-auth-update214650755editdlrm
pam_extrausers_chkpwd269442755editdlrm
pam_extrausers_update351360755editdlrm
pam_getenv28900755editdlrm
pam_namespace_helper4670755editdlrm
pam_timestamp_check146560755editdlrm
parted966640755editdlrm
partprobe147200755editdlrm
pdata_tools14305680755editdlrm
perlcalls-bpfcc550755editdlrm
perlflow-bpfcc540755editdlrm
perlstat-bpfcc540755editdlrm
php-fpm7.448033760755editdlrm
phpcalls-bpfcc540755editdlrm
phpdismod72780755editdlrm
phpenmod72780755editdlrm
phpflow-bpfcc530755editdlrm
phpquery63890755editdlrm
phpstat-bpfcc530755editdlrm
pidpersec-bpfcc11110755editdlrm
pidpersec.bt6280755editdlrm
pivot_root147200755editdlrm
plymouthd1500880755editdlrm
poweroff15013040755editdlrm
ppchcalls-bpfcc142240755editdlrm
profile-bpfcc147560755editdlrm
pvchange31567120755editdlrm
pvck31567120755editdlrm
pvcreate31567120755editdlrm
pvdisplay31567120755editdlrm
pvmove31567120755editdlrm
pvremove31567120755editdlrm
pvresize31567120755editdlrm
pvs31567120755editdlrm
pvscan31567120755editdlrm
pwck555920755editdlrm
pwconv472720755editdlrm
pwhistory_helper228480755editdlrm
pwunconv472720755editdlrm
pythoncalls-bpfcc570755editdlrm
pythonflow-bpfcc560755editdlrm
pythongc-bpfcc540755editdlrm
pythonstat-bpfcc560755editdlrm
rdmaucma-bpfcc50730755editdlrm
readahead-bpfcc66940755editdlrm
readprofile229440755editdlrm
reboot15013040755editdlrm
remove-shell11110755editdlrm
reset-trace-bpfcc34980755editdlrm
resize2fs719920755editdlrm
resolvconf1624800755editdlrm
rmmod1743280755editdlrm
rmt560240755editdlrm
rmt-tar560240755editdlrm
rsyslogd7901920755editdlrm
rtacct289920755editdlrm
rtcwake352000755editdlrm
rtmon1193120755editdlrm
rubycalls-bpfcc550755editdlrm
rubyflow-bpfcc540755editdlrm
rubygc-bpfcc520755editdlrm
rubyobjnew-bpfcc560755editdlrm
rubystat-bpfcc540755editdlrm
runlevel15013040755editdlrm
runqlat-bpfcc95260755editdlrm
runqlat.bt7880755editdlrm
runqlen-bpfcc82480755editdlrm
runqlen.bt10370755editdlrm
runqslower-bpfcc92250755editdlrm
runuser556800755editdlrm
service91040755editdlrm
setcap146480755editdlrm
setuids.bt17990755editdlrm
setvesablank147120755editdlrm
setvtrgb147760755editdlrm
sfdisk1089280755editdlrm
sgdisk1827680755editdlrm
shadowconfig22730755editdlrm
shmsnoop-bpfcc79850755editdlrm
shutdown15013040755editdlrm
slabratetop-bpfcc65370755editdlrm
sofdsnoop-bpfcc82550755editdlrm
softirqs-bpfcc57230755editdlrm
solisten-bpfcc61030755editdlrm
sshd9214160755editdlrm
ssllatency.bt21330755editdlrm
sslsniff-bpfcc140130755editdlrm
sslsnoop.bt20410755editdlrm
stackcount-bpfcc166550755editdlrm
start-stop-daemon486320755editdlrm
statsnoop-bpfcc50410755editdlrm
statsnoop.bt12940755editdlrm
sudo_logsrvd2544640755editdlrm
sudo_sendlog1348320755editdlrm
sulogin433920755editdlrm
swapin.bt6000755editdlrm
swaplabel188160755editdlrm
swapoff229120755editdlrm
swapon433920755editdlrm
switch_root229120755editdlrm
syncsnoop-bpfcc13000755editdlrm
syncsnoop.bt8390755editdlrm
syscount-bpfcc87710755editdlrm
syscount.bt8720755editdlrm
sysctl311120755editdlrm
tarcat9360755editdlrm
tc6452000755editdlrm
tclcalls-bpfcc540755editdlrm
tclflow-bpfcc530755editdlrm
tclobjnew-bpfcc550755editdlrm
tclstat-bpfcc530755editdlrm
tcpaccept-bpfcc92200755editdlrm
tcpaccept.bt17560755editdlrm
tcpcong-bpfcc205910755editdlrm
tcpconnect-bpfcc189020755editdlrm
tcpconnect.bt16150755editdlrm
tcpconnlat-bpfcc92850755editdlrm
tcpdrop-bpfcc76160755editdlrm
tcpdrop.bt24690755editdlrm
tcplife-bpfcc169490755editdlrm
tcplife.bt27850755editdlrm
tcpretrans-bpfcc140980755editdlrm
tcpretrans.bt21200755editdlrm
tcprtt-bpfcc89130755editdlrm
tcpstates-bpfcc140640755editdlrm
tcpsubnet-bpfcc78140755editdlrm
tcpsynbl-bpfcc21750755editdlrm
tcpsynbl.bt9620755editdlrm
tcptop-bpfcc129430755editdlrm
tcptracer-bpfcc181300755editdlrm
telinit15013040755editdlrm
thin_check14305680755editdlrm
thin_delta14305680755editdlrm
thin_dump14305680755editdlrm
thin_ls14305680755editdlrm
thin_metadata_size14305680755editdlrm
thin_repair14305680755editdlrm
thin_restore14305680755editdlrm
thin_rmap14305680755editdlrm
thin_trim14305680755editdlrm
threadsnoop-bpfcc18580755editdlrm
threadsnoop.bt7120755editdlrm
tipc926880755editdlrm
tplist-bpfcc41570755editdlrm
trace-bpfcc438920755editdlrm
ttysnoop-bpfcc76940755editdlrm
tune2fs1132160755editdlrm
ucalls119700755editdlrm
uflow81150755editdlrm
ufw49590755editdlrm
ugc78230755editdlrm
umount.udisks2146400755editdlrm
undump.bt7890755editdlrm
unix_chkpwd310402755editdlrm
unix_update351360755editdlrm
uobjnew61810755editdlrm
update-ca-certificates54460755editdlrm
update-catalog93930755editdlrm
update-grub640755editdlrm
update-grub-gfxpayload3010755editdlrm
update-grub2640755editdlrm
update-ieee-data34920755editdlrm
update-info-dir17000755editdlrm
update-initramfs69080755editdlrm
update-locale30570755editdlrm
update-passwd353920755editdlrm
update-pciids17780755editdlrm
update-rc.d181470755editdlrm
update-secureboot-policy76050755editdlrm
update-shells39840755editdlrm
update-xmlcatalog172840755editdlrm
upgrade-from-grub-legacy15960755editdlrm
usb_modeswitch610960755editdlrm
usb_modeswitch_dispatcher274180755editdlrm
useradd1432320755editdlrm
userdel931920755editdlrm
usermod1307120755editdlrm
ustat124120755editdlrm
uthreads41000755editdlrm
uuidd316240755editdlrm
validlocale17730755editdlrm
vcstime146400755editdlrm
vdpa353920755editdlrm
veritysetup449920755editdlrm
vfscount-bpfcc13900755editdlrm
vfscount.bt5150755editdlrm
vfsstat-bpfcc41590755editdlrm
vfsstat.bt7210755editdlrm
vgcfgbackup31567120755editdlrm
vgcfgrestore31567120755editdlrm
vgchange31567120755editdlrm
vgck31567120755editdlrm
vgconvert31567120755editdlrm
vgcreate31567120755editdlrm
vgdisplay31567120755editdlrm
vgexport31567120755editdlrm
vgextend31567120755editdlrm
vgimport31567120755editdlrm
vgimportclone31567120755editdlrm
vgmerge31567120755editdlrm
vgmknodes31567120755editdlrm
vgreduce31567120755editdlrm
vgremove31567120755editdlrm
vgrename31567120755editdlrm
vgs31567120755editdlrm
vgscan31567120755editdlrm
vgsplit31567120755editdlrm
vigr621440755editdlrm
vipw621440755editdlrm
virtiostat-bpfcc89000755editdlrm
visudo2587760755editdlrm
vpddecode149280755editdlrm
wakeuptime-bpfcc82910755editdlrm
wipefs392960755editdlrm
writeback.bt16990755editdlrm
xfsdist-bpfcc47230755editdlrm
xfsdist.bt9720755editdlrm
xfsslower-bpfcc79640755editdlrm
xfs_admin21740755editdlrm
xfs_bmap6950755editdlrm
xfs_copy926080755editdlrm
xfs_db7050880755editdlrm
xfs_estimate145040755editdlrm
xfs_freeze8000755editdlrm
xfs_fsr431920755editdlrm
xfs_growfs391520755editdlrm
xfs_info12940755editdlrm
xfs_io2085360755editdlrm
xfs_logprint801440755editdlrm
xfs_mdrestore350480755editdlrm
xfs_metadump8160755editdlrm
xfs_mkfile10400755editdlrm
xfs_ncheck6850755editdlrm
xfs_quota923280755editdlrm
xfs_repair6587600755editdlrm
xfs_rtcp185840755editdlrm
xfs_scrub1088160755editdlrm
xfs_scrub_all78410755editdlrm
xfs_spaceman433200755editdlrm
xtables-legacy-multi951760755editdlrm
xtables-monitor2244240755editdlrm
xtables-nft-multi2244240755editdlrm
zerofree144880755editdlrm
zfsdist-bpfcc54270755editdlrm
zfsslower-bpfcc86570755editdlrm
zic679840755editdlrm
zramctl558240755editdlrm
Edit: /usr/sbin/inject-bpfcc (16445B)
#! /usr/bin/python3 # # This script generates a BPF program with structure inspired by trace.py. The # generated program operates on PID-indexed stacks. Generally speaking, # bookkeeping is done at every intermediate function kprobe/kretprobe to enforce # the goal of "fail iff this call chain and these predicates". # # Top level functions(the ones at the end of the call chain) are responsible for # creating the pid_struct and deleting it from the map in kprobe and kretprobe # respectively. # # Intermediate functions(between should_fail_whatever and the top level # functions) are responsible for updating the stack to indicate "I have been # called and one of my predicate(s) passed" in their entry probes. In their exit # probes, they do the opposite, popping their stack to maintain correctness. # This implementation aims to ensure correctness in edge cases like recursive # calls, so there's some additional information stored in pid_struct for that. # # At the bottom level function(should_fail_whatever), we do a simple check to # ensure all necessary calls/predicates have passed before error injection. # # Note: presently there are a few hacks to get around various rewriter/verifier # issues. # # Note: this tool requires: # - CONFIG_BPF_KPROBE_OVERRIDE # # USAGE: inject [-h] [-I header] [-P probability] [-v] mode spec # # Copyright (c) 2018 Facebook, Inc. # Licensed under the Apache License, Version 2.0 (the "License") # # 16-Mar-2018 Howard McLauchlan Created this. import argparse import re from bcc import BPF class Probe: errno_mapping = { "kmalloc": "-ENOMEM", "bio": "-EIO", "alloc_page" : "true", } @classmethod def configure(cls, mode, probability, count): cls.mode = mode cls.probability = probability cls.count = count def __init__(self, func, preds, length, entry): # length of call chain self.length = length self.func = func self.preds = preds self.is_entry = entry def _bail(self, err): raise ValueError("error in probe '%s': %s" % (self.spec, err)) def _get_err(self): return Probe.errno_mapping[Probe.mode] def _get_if_top(self): # ordering guarantees that if this function is top, the last tup is top chk = self.preds[0][1] == 0 if not chk: return "" if Probe.probability == 1: early_pred = "false" else: early_pred = "bpf_get_prandom_u32() > %s" % str(int((1<<32)*Probe.probability)) # init the map # don't do an early exit here so the singular case works automatically # have an early exit for probability option enter = """ /* * Early exit for probability case */ if (%s) return 0; /* * Top level function init map */ struct pid_struct p_struct = {0, 0}; m.insert(&pid, &p_struct); """ % early_pred # kill the entry exit = """ /* * Top level function clean up map */ m.delete(&pid); """ return enter if self.is_entry else exit def _get_heading(self): # we need to insert identifier and ctx into self.func # gonna make a lot of formatting assumptions to make this work left = self.func.find("(") right = self.func.rfind(")") # self.event and self.func_name need to be accessible self.event = self.func[0:left] self.func_name = self.event + ("_entry" if self.is_entry else "_exit") func_sig = "struct pt_regs *ctx" # assume there's something in there, no guarantee its well formed if right > left + 1 and self.is_entry: func_sig += ", " + self.func[left + 1:right] return "int %s(%s)" % (self.func_name, func_sig) def _get_entry_logic(self): # there is at least one tup(pred, place) for this function text = """ if (p->conds_met >= %s) return 0; if (p->conds_met == %s && %s) { p->stack[%s] = p->curr_call; p->conds_met++; }""" text = text % (self.length, self.preds[0][1], self.preds[0][0], self.preds[0][1]) # for each additional pred for tup in self.preds[1:]: text += """ else if (p->conds_met == %s && %s) { p->stack[%s] = p->curr_call; p->conds_met++; } """ % (tup[1], tup[0], tup[1]) return text def _generate_entry(self): prog = self._get_heading() + """ { u32 pid = bpf_get_current_pid_tgid(); %s struct pid_struct *p = m.lookup(&pid); if (!p) return 0; /* * preparation for predicate, if necessary */ %s /* * Generate entry logic */ %s p->curr_call++; return 0; }""" prog = prog % (self._get_if_top(), self.prep, self._get_entry_logic()) return prog # only need to check top of stack def _get_exit_logic(self): text = """ if (p->conds_met < 1 || p->conds_met >= %s) return 0; if (p->stack[p->conds_met - 1] == p->curr_call) p->conds_met--; """ return text % str(self.length + 1) def _generate_exit(self): prog = self._get_heading() + """ { u32 pid = bpf_get_current_pid_tgid(); struct pid_struct *p = m.lookup(&pid); if (!p) return 0; p->curr_call--; /* * Generate exit logic */ %s %s return 0; }""" prog = prog % (self._get_exit_logic(), self._get_if_top()) return prog # Special case for should_fail_whatever def _generate_bottom(self): pred = self.preds[0][0] text = self._get_heading() + """ { u32 overridden = 0; int zero = 0; u32* val; val = count.lookup(&zero); if (val) overridden = *val; /* * preparation for predicate, if necessary */ %s /* * If this is the only call in the chain and predicate passes */ if (%s == 1 && %s && overridden < %s) { count.atomic_increment(zero); bpf_override_return(ctx, %s); return 0; } u32 pid = bpf_get_current_pid_tgid(); struct pid_struct *p = m.lookup(&pid); if (!p) return 0; /* * If all conds have been met and predicate passes */ if (p->conds_met == %s && %s && overridden < %s) { count.atomic_increment(zero); bpf_override_return(ctx, %s); } return 0; }""" return text % (self.prep, self.length, pred, Probe.count, self._get_err(), self.length - 1, pred, Probe.count, self._get_err()) # presently parses and replaces STRCMP # STRCMP exists because string comparison is inconvenient and somewhat buggy # https://github.com/iovisor/bcc/issues/1617 def _prepare_pred(self): self.prep = "" for i in range(len(self.preds)): new_pred = "" pred = self.preds[i][0] place = self.preds[i][1] start, ind = 0, 0 while start < len(pred): ind = pred.find("STRCMP(", start) if ind == -1: break new_pred += pred[start:ind] # 7 is len("STRCMP(") start = pred.find(")", start + 7) + 1 # then ind ... start is STRCMP(...) ptr, literal = pred[ind + 7:start - 1].split(",") literal = literal.strip() # x->y->z, some string literal # we make unique id with place_ind uuid = "%s_%s" % (place, ind) unique_bool = "is_true_%s" % uuid self.prep += """ char *str_%s = %s; bool %s = true;\n""" % (uuid, ptr.strip(), unique_bool) check = "\t%s &= *(str_%s++) == '%%s';\n" % (unique_bool, uuid) for ch in literal: self.prep += check % ch self.prep += check % r'\0' new_pred += unique_bool new_pred += pred[start:] self.preds[i] = (new_pred, place) def generate_program(self): # generate code to work around various rewriter issues self._prepare_pred() # special case for bottom if self.preds[-1][1] == self.length - 1: return self._generate_bottom() return self._generate_entry() if self.is_entry else self._generate_exit() def attach(self, bpf): if self.is_entry: bpf.attach_kprobe(event=self.event, fn_name=self.func_name) else: bpf.attach_kretprobe(event=self.event, fn_name=self.func_name) class Tool: examples =""" EXAMPLES: # ./inject.py kmalloc -v 'SyS_mount()' Fails all calls to syscall mount # ./inject.py kmalloc -v '(true) => SyS_mount()(true)' Explicit rewriting of above # ./inject.py kmalloc -v 'mount_subtree() => btrfs_mount()' Fails btrfs mounts only # ./inject.py kmalloc -v 'd_alloc_parallel(struct dentry *parent, const struct \\ qstr *name)(STRCMP(name->name, 'bananas'))' Fails dentry allocations of files named 'bananas' # ./inject.py kmalloc -v -P 0.01 'SyS_mount()' Fails calls to syscall mount with 1% probability """ # add cases as necessary error_injection_mapping = { "kmalloc": "should_failslab(struct kmem_cache *s, gfp_t gfpflags)", "bio": "should_fail_bio(struct bio *bio)", "alloc_page": "should_fail_alloc_page(gfp_t gfp_mask, unsigned int order)", } def __init__(self): parser = argparse.ArgumentParser(description="Fail specified kernel" + " functionality when call chain and predicates are met", formatter_class=argparse.RawDescriptionHelpFormatter, epilog=Tool.examples) parser.add_argument(dest="mode", choices=["kmalloc", "bio", "alloc_page"], help="indicate which base kernel function to fail") parser.add_argument(metavar="spec", dest="spec", help="specify call chain") parser.add_argument("-I", "--include", action="append", metavar="header", help="additional header files to include in the BPF program") parser.add_argument("-P", "--probability", default=1, metavar="probability", type=float, help="probability that this call chain will fail") parser.add_argument("-v", "--verbose", action="store_true", help="print BPF program") parser.add_argument("-c", "--count", action="store", default=-1, help="Number of fails before bypassing the override") self.args = parser.parse_args() self.program = "" self.spec = self.args.spec self.map = {} self.probes = [] self.key = Tool.error_injection_mapping[self.args.mode] # create_probes and associated stuff def _create_probes(self): self._parse_spec() Probe.configure(self.args.mode, self.args.probability, self.args.count) # self, func, preds, total, entry # create all the pair probes for fx, preds in self.map.items(): # do the enter self.probes.append(Probe(fx, preds, self.length, True)) if self.key == fx: continue # do the exit self.probes.append(Probe(fx, preds, self.length, False)) def _parse_frames(self): # sentinel data = self.spec + '\0' start, count = 0, 0 frames = [] cur_frame = [] i = 0 last_frame_added = 0 while i < len(data): # improper input if count < 0: raise Exception("Check your parentheses") c = data[i] count += c == '(' count -= c == ')' if not count: if c == '\0' or (c == '=' and data[i + 1] == '>'): # This block is closing a chunk. This means cur_frame must # have something in it. if not cur_frame: raise Exception("Cannot parse spec, missing parens") if len(cur_frame) == 2: frame = tuple(cur_frame) elif cur_frame[0][0] == '(': frame = self.key, cur_frame[0] else: frame = cur_frame[0], '(true)' frames.append(frame) del cur_frame[:] i += 1 start = i + 1 elif c == ')': cur_frame.append(data[start:i + 1].strip()) start = i + 1 last_frame_added = start i += 1 # We only permit spaces after the last frame if self.spec[last_frame_added:].strip(): raise Exception("Invalid characters found after last frame"); # improper input if count: raise Exception("Check your parentheses") return frames def _parse_spec(self): frames = self._parse_frames() frames.reverse() absolute_order = 0 for f in frames: # default case func, pred = f[0], f[1] if not self._validate_predicate(pred): raise Exception("Invalid predicate") if not self._validate_identifier(func): raise Exception("Invalid function identifier") tup = (pred, absolute_order) if func not in self.map: self.map[func] = [tup] else: self.map[func].append(tup) absolute_order += 1 if self.key not in self.map: self.map[self.key] = [('(true)', absolute_order)] absolute_order += 1 self.length = absolute_order def _validate_identifier(self, func): # We've already established paren balancing. We will only look for # identifier validity here. paren_index = func.find("(") potential_id = func[:paren_index] pattern = '[_a-zA-z][_a-zA-Z0-9]*$' if re.match(pattern, potential_id): return True return False def _validate_predicate(self, pred): if len(pred) > 0 and pred[0] == "(": open = 1 for i in range(1, len(pred)): if pred[i] == "(": open += 1 elif pred[i] == ")": open -= 1 if open != 0: # not well formed, break return False return True def _def_pid_struct(self): text = """ struct pid_struct { u64 curr_call; /* book keeping to handle recursion */ u64 conds_met; /* stack pointer */ u64 stack[%s]; }; """ % self.length return text def _attach_probes(self): self.bpf = BPF(text=self.program) for p in self.probes: p.attach(self.bpf) def _generate_program(self): # leave out auto includes for now self.program += '#include \n' for include in (self.args.include or []): self.program += "#include <%s>\n" % include self.program += self._def_pid_struct() self.program += "BPF_HASH(m, u32, struct pid_struct);\n" self.program += "BPF_ARRAY(count, u32, 1);\n" for p in self.probes: self.program += p.generate_program() + "\n" if self.args.verbose: print(self.program) def _main_loop(self): while True: try: self.bpf.perf_buffer_poll() except KeyboardInterrupt: exit() def run(self): self._create_probes() self._generate_program() self._attach_probes() self._main_loop() if __name__ == "__main__": Tool().run()