Skip to contentSkip to conversation

Loadable module and kernel gp

DISCUSSION Christian Hildner 4 participants 5 messages Jan 23, 2004 – Jan 26, 2004

lore
Share & tools
lore
#0 lore raw

Hi,

does anybody know a simple way for a loadable module to get the gp value of the kernel? Is there any sample code?

Christian

#1 lore raw

At compile time you can get it from the System.map. The symbol is at the end and called __gp. Of course you might want to have some cross-checks that you pick up the right System.map. I usually take some known and exported symbols.

But there's surely some dynamic way, too...

Regards,
Erich

Quoted 4 lines · Christian Hildner

does anybody know a simple way for a loadable module to get the gp value of the kernel? Is there any sample code?

Christian

#2 lore raw
In reply to Christian Hildner
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Christian Hildner

Christian> Hi, does anybody know a simple way for a loadable module Christian> to get the gp value of the kernel? Is there any sample Christian> code?

The safest way is probably to materialize a function pointer for a function that is known to be in the kernel (and exported) and then to read the second word.

	--david
#3 lore raw
In reply to Christian Hildner
Quoted 11 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

On Fri, 23 Jan 2004 10:52:00 +0100, Christian Hildner

<[email protected]> said:

Christian> Hi, does anybody know a simple way for a loadable module Christian> to get the gp value of the kernel? Is there any sample Christian> code?

The safest way is probably to materialize a function pointer for a function that is known to be in the kernel (and exported) and then to read the second word.

In case "materialzie a function pointer" is total greek:

#include <linux/slab.h>

struct fptr {
	unsigned long func_addr;
	unsigned long gp;
};

your_routine()

{
	struct fptr = (struct fptr *)kmalloc; /*function known to be in kernel */

	printk("Kernel gp is %lx\n", fptr->gp);
}

Untested ... kmalloc is declared "inline" so that might mess things up. Just choose some other exported thing if it is.

#4 lore raw
In reply to Christian Hildner
Quoted 5 lines · Tony
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On Fri, 23 Jan 2004 10:52:00 +0100, Christian Hildner

<[email protected]> said:

Quoted 8 lines
Quoted 8 lines

Christian> Hi, does anybody know a simple way for a loadable module Christian> to get the gp value of the kernel? Is there any sample Christian> code?

The safest way is probably to materialize a function pointer for a function that is known to be in the kernel (and exported) and then to read the second word.

Yes, that's it, thanks. Sometimes good solutions are also simple. I'll try it.

Quoted 18 lines

In case "materialzie a function pointer" is total greek:

#include <linux/slab.h>

struct fptr {
	unsigned long func_addr;
	unsigned long gp;
};

your_routine()

{
	struct fptr = (struct fptr *)kmalloc; /*function known to be in kernel */

	printk("Kernel gp is %lx\n", fptr->gp);
}
Quoted 3 lines

Untested ... kmalloc is declared "inline" so that might mess things up. Just choose some other exported thing if it is.

I hope the compiler will not explode if I request the pointer to an inlined function ;-). I like the idea of using kmalloc since this symbol should be present in almost any kernel.

Thanks

Christian