inject filter submit_bio function to blkdev
by yntnm from LinuxQuestions.org on (#5SRRA)
I'm trying to inject a new submit bio function to the blkdev, from in-tree kernel module.
I'm using
Quote:
with LSM support
I was able to do it in lower version with no problem, but with the change of the make_request_fn I'm having a problem with the inject.
this is the code :
Code: #if LINUX_VERSION_CODE < KERNEL_VERSION(5,10)
queue = bdev_get_queue(bdev);
if (queue) {
vm_hold.blkdev_orig.make_request_fn = queue->make_request_fn;
queue->make_request_fn = test_injected_blkdev_make_request_fn;
}
#else
fops = bdev_get_fops(bdev);
if (fops) {
fops->submit_bio = test_injected_blkdev_make_request_fn;
//blk_mq_submit_bio(fops->submit_bio);
}
#endif // LINUX_VERSION_CODE < KERNEL_VERSION(5,10,44)the test function is just a sample:
Code:blk_qc_t test_injected_blkdev_make_request_fn(struct bio *bio)
{
pr_emerg("my test submit bio function\n");
return vm_hold.blkdev_orig.submit_bio(bio);
}when i'm calling my module to perform the injection i'm getting a crash that lock like that:
Code:8<--- cut here ---
[ 130.295126] Unable to handle kernel paging request at virtual address c0c6551c
[ 130.295141] pgd = 226518d8
[ 130.295152] [c0c6551c] *pgd=80000000007003, *pmd=440000000c0079d(bad)
[ 130.295194] Internal error: Oops: a0e [#1] SMP ARM
[ 130.295200] Modules linked in: rfcomm cmac fuse bnep hci_uart btbcm bluetooth ecdh_generic ecc 8021q garp stp llc brcmfmac brcmutil cfg80211 rfkill raspberrypi_hwmon bcm2835_codec(C) bcm2835_isp(C) bcm2835_v4l2(C) v4l2_mem2mem bcm2835_mmal_vchiq(C) videobuf2_dma_contig videobuf2_vmalloc videobuf2_memops videobuf2_v4l2 snd_bcm2835(C) videobuf2_common snd_pcm snd_timer snd videodev vc_sm_cma(C) mc uio_pdrv_genirq uio i2c_dev ip_tables x_tables ipv6
[ 130.356973] CPU: 3 PID: 1161 Comm: host Tainted: G C 5.10.76-v7l+ #58
[ 130.356977] Hardware name: BCM2835
[ 130.356993] PC is at test_inject_blkdev+0xf4/0x114
[ 130.357008] LR is at __irq_work_queue_local+0x3c/0x70
[ 130.378604] pc : [<c06e2614>] lr : [<c0351bcc>] psr: 60000013
[ 130.378608] sp : ca589e68 ip : ca589d78 fp : ca589e7c
[ 130.378613] r10: 00000003 r9 : 00000000 r8 : beba2644
[ 130.378618] r7 : ca471a80 r6 : c1205048 r5 : c0c6551c r4 : c2574240
[ 130.378627] r3 : c06e0294 r2 : f0fbb462 r1 : 00000d62 r0 : 00004670
[ 130.408779] Flags: nZCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment user
[ 130.408785] Control: 30c5383d Table: 02eeb680 DAC: bb5b2507
[ 130.408792] Process host (pid: 1161, stack limit = 0xa9b229bd)
[ 130.408798] Stack: (0xca589e68 to 0xca58a000)
[ 130.408807] 9e60: c13fd79c c13fd684 ca589e94 ca589e80 c06e26dc c06e252c
[ 130.440451] 9e80: 00004000 c13fd79c ca589ecc ca589e98 c06e3d5c c06e26bc ca589eb4 ca589ea8
[ 130.440458] 9ea0: c0ba4f7c f0fbb462 c1205048 c1205048 beba2644 ca471a80 00005391 00000000
[ 130.440464] 9ec0: ca589f0c ca589ed0 c06e5a40 c06e3cec 00000032 c020bf60 c833c354 00000000
[ 130.465317] 9ee0: 00f3b150 f0fbb462 00000005 c1205048 ca471a80 00005391 ca471a80 beba2644
[ 130.465324] 9f00: ca589fa4 ca589f10 c04574d8 c06e56a4 00000000 00000000 00000000 00000000
[ 130.465330] 9f20: 00000000 00000000 c020bf88 beba2644 c020d244 ca5133c0 c1205048 ca5133c0
[ 130.465336] 9f40: 00000032 00f3b150 ca588000 00000004 ca589f94 ca589f60 c04419b0 c04413c8
[ 130.465342] 9f60: 00000000 00000000 00000000 f0fbb462 ca588000 f0fbb462 00f3b150 00000000
[ 130.465350] 9f80: 00000000 00f3b590 00000036 c0200204 ca588000 00000036 00000000 ca589fa8
[ 130.515053] 9fa0: c0200040 c045737c 00000000 00000000 00000003 00005391 beba2644 00000000
[ 130.515059] 9fc0: 00000000 00000000 00f3b590 00000036 00000000 00000000 b6fdf000 00000000
[ 130.515065] 9fe0: 0002fcac beba2634 0001c214 b6f0651c 80000010 00000003 00000000 00000000
[ 130.539914] Backtrace:
[ 130.539926] [<c06e2520>] (test_inject_blkdev) from [<c06e26dc>] (nanolock_inject+0x2c/0x4c)
[ 130.539932] r5:c13fd684 r4:c13fd79c
[ 130.554836] [<c06e26b0>] (perform_test_inject) from [<c06e3d5c>] (nanolock_end_load_otpm+0x7c/0x2a8)
[ 130.554839] r4:c13fd79c r3:00004000
[ 130.554851] [<c06e3ce0>] (test_inject_blkdev_call) from [<c06e5a40>] (nanolock_ioctl+0x3a8/0x700)
[ 130.576265] r9:00000000 r8:00005391 r7:ca471a80 r6:beba2644 r5:c1205048 r4:c1205048
[ 130.576274] [<c06e5698>] (my_module_ioctl) from [<c04574d8>] (sys_ioctl+0x168/0x8fc)
[ 130.576281] r8:beba2644 r7:ca471a80 r6:00005391 r5:ca471a80 r4:c1205048
[ 130.576288] [<c0457370>] (sys_ioctl) from [<c0200040>] (ret_fast_syscall+0x0/0x28)
[ 130.576293] Exception stack(0xca589fa8 to 0xca589ff0)
[ 130.611458] 9fa0: 00000000 00000000 00000003 00005391 beba2644 00000000
[ 130.611464] 9fc0: 00000000 00000000 00f3b590 00000036 00000000 00000000 b6fdf000 00000000
[ 130.611470] 9fe0: 0002fcac beba2634 0001c214 b6f0651c
[ 130.633154] r10:00000036 r9:ca588000 r8:c0200204 r7:00000036 r6:00f3b590 r5:00000000
[ 130.633156] r4:00000000
[ 130.633163] Code: e3003294 e3040670 e34c306e e3001d62 (e5853000)
[ 130.633212] ---[ end trace 2588a376c135822c ]---At the older kernel version the code works perfectly. but with the new bio I'm straggling
any reference to the new bio system will help (i used google but i didn't find how to inject the new code properly).
Thanks
I'm using
Quote:
Linux raspberrypi 5.10.76-v7l+ |
I was able to do it in lower version with no problem, but with the change of the make_request_fn I'm having a problem with the inject.
this is the code :
Code: #if LINUX_VERSION_CODE < KERNEL_VERSION(5,10)
queue = bdev_get_queue(bdev);
if (queue) {
vm_hold.blkdev_orig.make_request_fn = queue->make_request_fn;
queue->make_request_fn = test_injected_blkdev_make_request_fn;
}
#else
fops = bdev_get_fops(bdev);
if (fops) {
fops->submit_bio = test_injected_blkdev_make_request_fn;
//blk_mq_submit_bio(fops->submit_bio);
}
#endif // LINUX_VERSION_CODE < KERNEL_VERSION(5,10,44)the test function is just a sample:
Code:blk_qc_t test_injected_blkdev_make_request_fn(struct bio *bio)
{
pr_emerg("my test submit bio function\n");
return vm_hold.blkdev_orig.submit_bio(bio);
}when i'm calling my module to perform the injection i'm getting a crash that lock like that:
Code:8<--- cut here ---
[ 130.295126] Unable to handle kernel paging request at virtual address c0c6551c
[ 130.295141] pgd = 226518d8
[ 130.295152] [c0c6551c] *pgd=80000000007003, *pmd=440000000c0079d(bad)
[ 130.295194] Internal error: Oops: a0e [#1] SMP ARM
[ 130.295200] Modules linked in: rfcomm cmac fuse bnep hci_uart btbcm bluetooth ecdh_generic ecc 8021q garp stp llc brcmfmac brcmutil cfg80211 rfkill raspberrypi_hwmon bcm2835_codec(C) bcm2835_isp(C) bcm2835_v4l2(C) v4l2_mem2mem bcm2835_mmal_vchiq(C) videobuf2_dma_contig videobuf2_vmalloc videobuf2_memops videobuf2_v4l2 snd_bcm2835(C) videobuf2_common snd_pcm snd_timer snd videodev vc_sm_cma(C) mc uio_pdrv_genirq uio i2c_dev ip_tables x_tables ipv6
[ 130.356973] CPU: 3 PID: 1161 Comm: host Tainted: G C 5.10.76-v7l+ #58
[ 130.356977] Hardware name: BCM2835
[ 130.356993] PC is at test_inject_blkdev+0xf4/0x114
[ 130.357008] LR is at __irq_work_queue_local+0x3c/0x70
[ 130.378604] pc : [<c06e2614>] lr : [<c0351bcc>] psr: 60000013
[ 130.378608] sp : ca589e68 ip : ca589d78 fp : ca589e7c
[ 130.378613] r10: 00000003 r9 : 00000000 r8 : beba2644
[ 130.378618] r7 : ca471a80 r6 : c1205048 r5 : c0c6551c r4 : c2574240
[ 130.378627] r3 : c06e0294 r2 : f0fbb462 r1 : 00000d62 r0 : 00004670
[ 130.408779] Flags: nZCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment user
[ 130.408785] Control: 30c5383d Table: 02eeb680 DAC: bb5b2507
[ 130.408792] Process host (pid: 1161, stack limit = 0xa9b229bd)
[ 130.408798] Stack: (0xca589e68 to 0xca58a000)
[ 130.408807] 9e60: c13fd79c c13fd684 ca589e94 ca589e80 c06e26dc c06e252c
[ 130.440451] 9e80: 00004000 c13fd79c ca589ecc ca589e98 c06e3d5c c06e26bc ca589eb4 ca589ea8
[ 130.440458] 9ea0: c0ba4f7c f0fbb462 c1205048 c1205048 beba2644 ca471a80 00005391 00000000
[ 130.440464] 9ec0: ca589f0c ca589ed0 c06e5a40 c06e3cec 00000032 c020bf60 c833c354 00000000
[ 130.465317] 9ee0: 00f3b150 f0fbb462 00000005 c1205048 ca471a80 00005391 ca471a80 beba2644
[ 130.465324] 9f00: ca589fa4 ca589f10 c04574d8 c06e56a4 00000000 00000000 00000000 00000000
[ 130.465330] 9f20: 00000000 00000000 c020bf88 beba2644 c020d244 ca5133c0 c1205048 ca5133c0
[ 130.465336] 9f40: 00000032 00f3b150 ca588000 00000004 ca589f94 ca589f60 c04419b0 c04413c8
[ 130.465342] 9f60: 00000000 00000000 00000000 f0fbb462 ca588000 f0fbb462 00f3b150 00000000
[ 130.465350] 9f80: 00000000 00f3b590 00000036 c0200204 ca588000 00000036 00000000 ca589fa8
[ 130.515053] 9fa0: c0200040 c045737c 00000000 00000000 00000003 00005391 beba2644 00000000
[ 130.515059] 9fc0: 00000000 00000000 00f3b590 00000036 00000000 00000000 b6fdf000 00000000
[ 130.515065] 9fe0: 0002fcac beba2634 0001c214 b6f0651c 80000010 00000003 00000000 00000000
[ 130.539914] Backtrace:
[ 130.539926] [<c06e2520>] (test_inject_blkdev) from [<c06e26dc>] (nanolock_inject+0x2c/0x4c)
[ 130.539932] r5:c13fd684 r4:c13fd79c
[ 130.554836] [<c06e26b0>] (perform_test_inject) from [<c06e3d5c>] (nanolock_end_load_otpm+0x7c/0x2a8)
[ 130.554839] r4:c13fd79c r3:00004000
[ 130.554851] [<c06e3ce0>] (test_inject_blkdev_call) from [<c06e5a40>] (nanolock_ioctl+0x3a8/0x700)
[ 130.576265] r9:00000000 r8:00005391 r7:ca471a80 r6:beba2644 r5:c1205048 r4:c1205048
[ 130.576274] [<c06e5698>] (my_module_ioctl) from [<c04574d8>] (sys_ioctl+0x168/0x8fc)
[ 130.576281] r8:beba2644 r7:ca471a80 r6:00005391 r5:ca471a80 r4:c1205048
[ 130.576288] [<c0457370>] (sys_ioctl) from [<c0200040>] (ret_fast_syscall+0x0/0x28)
[ 130.576293] Exception stack(0xca589fa8 to 0xca589ff0)
[ 130.611458] 9fa0: 00000000 00000000 00000003 00005391 beba2644 00000000
[ 130.611464] 9fc0: 00000000 00000000 00f3b590 00000036 00000000 00000000 b6fdf000 00000000
[ 130.611470] 9fe0: 0002fcac beba2634 0001c214 b6f0651c
[ 130.633154] r10:00000036 r9:ca588000 r8:c0200204 r7:00000036 r6:00f3b590 r5:00000000
[ 130.633156] r4:00000000
[ 130.633163] Code: e3003294 e3040670 e34c306e e3001d62 (e5853000)
[ 130.633212] ---[ end trace 2588a376c135822c ]---At the older kernel version the code works perfectly. but with the new bio I'm straggling
any reference to the new bio system will help (i used google but i didn't find how to inject the new code properly).
Thanks