How to disable address randomization ?

admin LI admin at hifiphile.com
Fri Jan 14 02:14:25 EST 2022


Hi Chan,

Thank you for pointing me to the right direction. 

Pointer Types
=============
Pointers printed without a specifier extension (i.e unadorned %p) are hashed to give a unique identifier without leaking kernel addresses to user space. On 64 bit machines the first 32 bits are zeroed. If you _really_ want the address see %px below.

⁣Get BlueMail for Android ​

On Jan 14, 2022, 01:36, at 01:36, Chan Kim <ckim at etri.re.kr> wrote:
>Hi,
>
>To print kernel virtual address, you should use %px instead of %p in
>the printk.
>
>Probably that’s why you couldn’t see the pointer values correctly.
>
>Chan
>
> 
>
>From: admin LI <admin at hifiphile.com> 
>Sent: Friday, January 14, 2022 6:02 AM
>To: kernelnewbies at kernelnewbies.org
>Subject: How to disable address randomization ?
>
> 
>
>Hi,
>
>I'm developing a kernel module for an ARM machine, while debugging I
>found addresses 
>printed are all randomized and useless for debugging.
>
>To prove I was not crazy I wrote this small program:
>
>---------------------------------
>#include <linux/init.h>
>#include <linux/module.h>
>#include <linux/kernel.h>
>#include <linux/slab.h>
>
>MODULE_LICENSE("GPL");
>MODULE_AUTHOR("Somebody");
>MODULE_DESCRIPTION("A simple example Linux module.");
>MODULE_VERSION("0.01");
>
>static int __init example_init(void) {
>    uint32_t a;
>    uint32_t b;
>    uint32_t c;
>    uint8_t d[10];
>    uint8_t *e;
>
>    printk(KERN_INFO "Hello, World!\n");
>    printk(KERN_INFO "&a %p\n",&a);
>    printk(KERN_INFO "&b %p\n",&b);
>    printk(KERN_INFO "&c %p\n",&c);
>    printk(KERN_INFO "&d %p\n",d);
>    printk(KERN_INFO "&d[0] %p\n",&d[0]);
>    printk(KERN_INFO "&d[1] %p\n",&d[1]);
>
>    e = kmalloc(10, GFP_KERNEL);
>    printk(KERN_INFO "&e[0] %p\n",&e[0]);
>    printk(KERN_INFO "&e[1] %p\n",&e[1]);
>
>    kfree(e);
>
> return 0;
>}
>
>static void __exit example_exit(void) {
> printk(KERN_INFO "Goodbye, World!\n");
>}
>
>module_init(example_init);
>module_exit(example_exit);
>---------------------------------
>And it gave me this output:
>
>Hello, World!
>&a b3f9fa31
>&b 27e1c68a
>&c da50d287
>&d 9f9aec2b
>&d[0] 9f9aec2b
>&d[1] cc627580
>&e[0] 98b8c9eb
>&e[1] 45f248f8
>
>Then I tested on my debian host machine which gave me the same kind of
>randomized addresses.
>
>When I search randomization the only thing I found is KASLR which I
>don't think is the same thing.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20220114/a6b03da5/attachment.html>


More information about the Kernelnewbies mailing list