Re: calling hooks from inside timer interrupt handler freezes machine

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi

I actually followed your direction and made the pointer static. But that did not solve the problem which I think is expected if I am not wrong. Because even though the klife pointer passed in klife_open is local, we save the pointer in filp->private_data for any future access to that memory location. So even if the pointer gets destructed when we return from klife_open, we can still access that memory through filp->private_data?

Thanks,
- Meraj

Mulyadi Santosa <mulyadi.santosa@xxxxxxxxx> wrote:
Hi...

Comments are inlined...
> static int
> klife_open(struct inode* indode, struct file* filp)
> {
> int ret;
> struct klife *k;
>
> ret = klife_alloc(&k);
> if (ret)
> return ret;
>
OK, first you pass a pointer that lives inside kernel stack... Then..


> static int
> klife_alloc(struct klife **pk)
> {
> int ret;
> struct klife *k;
>
> k = kmalloc(sizeof(*k), GFP_KERNEL);
> if (!k)
> return -ENOMEM;
> memset(k, 0, sizeof(*k));
>
> ret = init_klife(k);
> if (ret)
> kfree(k);
>
> *pk = k;
>
> return ret;
> }
>
You assign memory block to this pointer. Then you get back to
klife_open(). This function itself eventually exits and the kernel stack
size is reduced (but not gone at the moment, esp register is just
increased IIRC).

Up until nothing mess with kernel stack, your hook will be just fine.
But as soon as something use kernel stack, it will overwrite your
klife_struct *k pointer so it no longer points to correct memory
address...and boom.

Solution: make that pointer static or put it outside function scope.
That way, it won't reside on kernel stack.

regards,

Mulyadi



Shape Yahoo! in your own image. Join our Network Research Panel today!

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux