⬢ DragonFlyBSD Kernel Audit
DF-3218 / applyfix.sh
← back to finding ↓ download raw
#!/bin/sh
# Rebuild both-fixed dirfs_vfsops.c: start from .orig, apply 3218 fix, then 3222 fix.
cd /usr/src/sys/vfs/dirfs
cp dirfs_vfsops.c.orig dirfs_vfsops.c
awk '
/dbg\(9, "failed to open ROOT node/ { print; state=1; next }
state == 1 && /dirfs_free_vp\(dmp, dnp\);/ {
	print "\t\t\tdmp->dm_root = NULL;"
	print "\t\t\tdirfs_node_drop(dmp, dnp);\t/* drop life-of-mount ref */"
	state=2; next
}
state == 2 && /dirfs_node_free\(dmp, dnp\);/ { state=0; next }
{ print }
' dirfs_vfsops.c.orig > dirfs_vfsops.c
awk '
/Attempt to copy from kernel address/ { state=1; next }
state == 1 && /error = copystr\(data/ { next }
state == 1 && /if \(error\) \{/ { state=2; next }
state == 2 && /kfree\(dmp, M_DIRFS\);/ {
	print "\t\tkfree(dmp, M_DIRFS);"
	state=3
	next
}
state == 3 && /goto failure;/ {
	print "\t\tgoto failure;"
	state=4
	next
}
state == 4 && /^		}/ { state=0; next }
{ print }
' dirfs_vfsops.c > v2.c && mv v2.c dirfs_vfsops.c
echo "=== combined diff vs .orig ==="
diff dirfs_vfsops.c.orig dirfs_vfsops.c
cd /usr/obj/usr/src/sys/VKDIRFS && make KERNEL=kernel all > /tmp/vkbothfix.log 2>&1
echo "rebuild rc=$?"