From: chrishell <chris@chrishell.de>
To: kernelnewbies@kernelnewbies.org
Subject: Re: linked list within a kernel probe
Date: Thu, 12 Jan 2023 15:48:12 +0100 [thread overview]
Message-ID: <bc23f6d2-55ad-020c-fc79-97d7a614eee8@chrishell.de> (raw)
In-Reply-To: <BYAPR11MB3527A974A7DD2BA0660F49B7D9FE9@BYAPR11MB3527.namprd11.prod.outlook.com>
hello Billie, thank you for your support. As you can see I have 2
different structures. The first one is defined for a global structure,
which holds all information which I need within the kprobe (called
kprobe_head). Then I have another structure (called kprobe_mem_cache),
which is defined to be the structure the linked list is made of. So the
head of the linked list is within a structure different of the struct
the linked list is made of. I hope this is not a problem, but should not.
First I tried to initialize the head of the linked list.
INIT_LIST_HEAD(pHead->p_mem_cache) but this lead to a crash already!
To remind:
struct kprobe_head {
struct list_head *p_mem_cache;
struct kprobe_fsops *pfops;
struct kprobe *pProbe;
};
and
pHead = (struct kprobe_head*) kzalloc(sizeof(struct kprobe_head),
GFP_KERNEL);
(this is done in the _init function)
Then I tried it the way you saw in my first mail, with a struct on the
stack. Which is wrong, but at least Im able to setup the list, and can
traverse the list, even shortly after leaving the function, until the
memory is used again. But I can see this is not a solution.
My question now is: which pointer has to be INIT_LIST_HEAD and when?
Thank you in advance
BR Christian
>
>>
>> static __u8 _kprobe_setup_cache_elements( struct kprobe_head *pHead,
>> __u16 elements, __u32 size)
>> {
> …
>> struct list_head local_head;
>>
>> INIT_LIST_HEAD(&local_head);
>>
> …
>> pHead->p_mem_cache = &local_head;
> …
>> }
>
> just from a quick look at this code, my guess is that you should not be using stack addresses in your list.
> Your local_head is on the stack, therefore it gets corrupted after you exit your function and invoke other functions.
> Did you really mean to store a pointer to local_head, or was your intention to point to the first element on local_head?
>
>
>
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
next prev parent reply other threads:[~2023-01-12 15:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-03 18:52 linked list within a kernel probe chrishell
2023-01-08 22:24 ` chrishell
2023-01-09 16:15 ` Billie Alsup (balsup)
2023-01-12 14:48 ` chrishell [this message]
2023-01-09 17:56 ` Tom Mitchell
2023-01-12 15:05 ` chrishell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bc23f6d2-55ad-020c-fc79-97d7a614eee8@chrishell.de \
--to=chris@chrishell.de \
--cc=kernelnewbies@kernelnewbies.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).