1
0
Fork 0

Implements insmod kernel module from local file

timestamps
dump_stack() 2018-09-22 13:18:25 +00:00
parent 623a7f08c1
commit 8649c791ea
5 changed files with 40 additions and 0 deletions

View File

@ -280,6 +280,16 @@ func (q *QemuSystem) CopyFile(user, localPath, remotePath string) (err error) {
return
}
func (q *QemuSystem) CopyAndInsmod(localKoPath string) (output string, err error) {
remoteKoPath := fmt.Sprintf("/tmp/module_%d.ko", rand.Int())
err = q.CopyFile("root", localKoPath, remoteKoPath)
if err != nil {
return
}
return q.Command("root", "insmod "+remoteKoPath)
}
// CopyAndRun is copy local file to qemu vm then run it
func (q *QemuSystem) CopyAndRun(user, path string) (output string, err error) {
remotePath := fmt.Sprintf("/tmp/executable_%d", rand.Int())

View File

@ -213,3 +213,30 @@ func TestQemuSystemCopyAndRun(t *testing.T) {
t.Fatal("Wrong output from copyied executable (" + output + "," + randStr + ")")
}
}
func TestQemuSystemCopyAndInsmod(t *testing.T) {
qemu, err := startTestQemu(t)
if err != nil {
t.Fatal(err)
}
defer qemu.Stop()
lsmodBefore, err := qemu.Command("root", "lsmod | wc -l")
if err != nil {
t.Fatal(err)
}
_, err = qemu.CopyAndInsmod(testConfigSampleKo)
if err != nil {
t.Fatal(err)
}
lsmodAfter, err := qemu.Command("root", "lsmod | wc -l")
if err != nil {
t.Fatal(err)
}
if lsmodBefore == lsmodAfter {
t.Fatal("insmod returns ok but there is no new kernel modules")
}
}

View File

@ -7,3 +7,4 @@ package qemukernel
const testConfigVmlinuz = "tools/qemu-debian-img/vmlinuz-bionic"
const testConfigInitrd = "tools/qemu-debian-img/initrd-bionic"
const testConfigRootfs = "tools/qemu-debian-img/bionic.img"
const testConfigSampleKo = "tools/qemu-debian-img/sample.ko"

View File

@ -2,3 +2,4 @@
*.log
vmlinuz*
initrd*
*.ko

View File

@ -14,5 +14,6 @@ Vagrant.configure("2") do |config|
cp bionic.img /vagrant/
cp /boot/vmlinuz-* /vagrant/vmlinuz-bionic
cp /boot/initrd-* /vagrant/vmlinuz-bionic
cp /lib/modules/`uname -r`/kernel/lib/test_static_key_base.ko /vagrant/sample.ko
SHELL
end