Tracing memory address access in kernel
Hello, I am facing issue of memory corruption where only one field of allocated structure is getting corrupted. I have bio structure and one of the page in bio vector is getting set to NULL. crash> struct bio_vec 0xffff88009dc5eb00 struct bio_vec { bv_page = 0xffffea000a434b80, bv_len = 4096, bv_offset = 0 } crash> struct bio_vec 0xffff88009dc5eb10 struct bio_vec { bv_page = 0x0, bv_len = 4096, bv_offset = 0 } crash> struct bio_vec 0xffff88009dc5eb20 struct bio_vec { bv_page = 0xffffea000a467500, bv_len = 4096, bv_offset = 0 } I have allocated contagious memory for bio vectors. As you can see in second bio vector bv_page is getting set to NULL. This address is valid till the time I do some operations in my module. After some operations bv_page is getting set to NULL. Other fields are having valid data. Is there any debugging technique / tool available which will track access to specific memory access? I would like to dump stack every time bv_page is accessed or modified Thanks and regards, Pritam Bankar
Hello Pritam, You may try moving or enlarging the bio_vec first, to see if the NULL is set due to memory corruption, or due to some other bugs. Next, try to insmod one by one to locate it. Adding some printk() next to the suspicious memcpy() also helps. I am also a newbie so I would also like to know if there’s any other good ways. :) Chriz.
El 4 dic 2018, a las 6:24 p. m., Pritam Bankar <pritambankar1988@gmail.com> escribió:
Hello,
I am facing issue of memory corruption where only one field of allocated structure is getting corrupted. I have bio structure and one of the page in bio vector is getting set to NULL.
crash> struct bio_vec 0xffff88009dc5eb00
struct bio_vec { bv_page = 0xffffea000a434b80, bv_len = 4096, bv_offset = 0 }
crash> struct bio_vec 0xffff88009dc5eb10 struct bio_vec { bv_page = 0x0, bv_len = 4096, bv_offset = 0
}
crash> struct bio_vec 0xffff88009dc5eb20 struct bio_vec { bv_page = 0xffffea000a467500, bv_len = 4096, bv_offset = 0
}
I have allocated contagious memory for bio vectors. As you can see in second bio vector bv_page is getting set to NULL. This address is valid till the time I do some operations in my module. After some operations bv_page is getting set to NULL. Other fields are having valid data.
Is there any debugging technique / tool available which will track access to specific memory access? I would like to dump stack every time bv_page is accessed or modified
Thanks and regards, Pritam Bankar
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Hi Pritam, On Tue, Dec 4, 2018 at 10:26 AM Pritam Bankar <pritambankar1988@gmail.com> wrote:
Hello,
I am facing issue of memory corruption where only one field of allocated structure is getting corrupted. I have bio structure and one of the page in bio vector is getting set to NULL.
<snip>
Is there any debugging technique / tool available which will track access to specific memory access? I would like to dump stack every time bv_page is accessed or modified
In these types of cases I usually use KASAN, or HW Breakpoint. with HW Breakpoint you can set an alert to monitor any read or write operation on some memory location. Check samples/hw_breakpoint/data_breakpoint.c for an example of breakpoints. KASAN can give you stacktraces when illegal memory access is done. Hope it helps. -- Regards Sudip
participants (3)
-
Chriz Chow -
Pritam Bankar -
Sudip Mukherjee