From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 522C1C433EF for ; Fri, 14 Jan 2022 07:32:38 +0000 (UTC) Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.94.2) (envelope-from ) id 1n8H4C-0002QG-Mx; Fri, 14 Jan 2022 02:32:08 -0500 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by shelob.surriel.com with esmtps (TLS1.2) tls TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1n8H4A-0002P2-JQ for kernelnewbies@kernelnewbies.org; Fri, 14 Jan 2022 02:32:06 -0500 Received: by mail-wr1-x42a.google.com with SMTP id k30so14058147wrd.9 for ; Thu, 13 Jan 2022 23:32:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hifiphile-com.20210112.gappssmtp.com; s=20210112; h=in-reply-to:references:thread-topic:user-agent:mime-version :content-transfer-encoding:subject:from:date:to:cc:message-id; bh=fdd7HKnc0Ao79xRIbGm0yjKmRusYktLRbod71H+wBE8=; b=dcnLLtNf/ZejtDFH4sQtpAM2MhuAMh7EV3BIrTaOtrraJmK3GHtDWpErxobO1v00F8 NyOFp95xBJmW+5E81fc8EKZrrKcXfJkQ3vMunKNeq5TJijCOR7I4opXUEDPVlsSe0FWk 3jY6mjaoQb4WdmBieoFOIGd5EFVHGkDsaZq5tZpgNEJiwFpL9VDYo+iqw8MT2jSy/Sz4 ANsIq/zQI8cXOTMNQvNwgTN1b7dIhYOHmdotT+YkgBlp9mA7woRpkF0c9j1/74vBOnAy XcoPw4oocQ+YtfuOJT8Q6RHZVbVyKpnvUL++cYJ574h1ok4jN6UFWaMnzi1nkv/MHvm0 u8oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:in-reply-to:references:thread-topic:user-agent :mime-version:content-transfer-encoding:subject:from:date:to:cc :message-id; bh=fdd7HKnc0Ao79xRIbGm0yjKmRusYktLRbod71H+wBE8=; b=np35GFN5inHMjfXLqYRKnqvocSCiADT+/GClJoPP+HTpmMYmgVG1OaiII9NcJsSv2Z L6OVBoNZEBFRA9XWZHtUaplyk2YszCnO9iefNR2GGt6teKnfPk61nYDAwD68I7gx2Mes BiPY49p5XB198TOyW9Q3OViAI4zAcH89YW8rjrA6F5eL+4v8HTFpBDZenAVEn24qsX4l iRuYIrULDUl65KlWXTkHP76XeKZSfQqYg9EhIUBpWfg9KQo+nqlk9J5ah4dXOka67OrP T4S+jJcfMVwqiUAiZBbHzNiBwnnlcX06eR7vQ0Nl3fn42aA5QxF16v/2RjxF3MRj65+B 3gKQ== X-Gm-Message-State: AOAM5310TiLCLkK1XzhDZdxop3N7lFPRk6LmPQiyeSiXpFLHG2D7xvhl wSP0siVacyUYZOqw0rG995sgYBGsw9+Tjowk X-Google-Smtp-Source: ABdhPJyF0nWENeGhEECKOl9n3mLi4l9XozLFzYWKt7M2LTqbGV9CfVM98f5T9q+cbzqLpJjpWQyZlg== X-Received: by 2002:adf:904d:: with SMTP id h71mr6918783wrh.569.1642145524147; Thu, 13 Jan 2022 23:32:04 -0800 (PST) Received: from ?IPV6:2a01:e34:ec1a:b010:2425:ce29:e778:70f4? ([2a01:e34:ec1a:b010:2425:ce29:e778:70f4]) by smtp.gmail.com with ESMTPSA id 8sm2880846wrz.60.2022.01.13.23.21.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 Jan 2022 23:31:33 -0800 (PST) In-Reply-To: References: X-Referenced-Uid: 4297 Thread-Topic: Re: How to disable address randomization ? User-Agent: Android X-Is-Generated-Message-Id: true MIME-Version: 1.0 X-Local-Message-Id: Subject: Re: How to disable address randomization ? From: admin LI Date: Fri, 14 Jan 2022 08:12:28 +0100 To: noloader@gmail.com Message-ID: Cc: kernelnewbies X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============7307272848408698409==" Errors-To: kernelnewbies-bounces@kernelnewbies.org --===============7307272848408698409== Content-Type: multipart/alternative; boundary="----QBCAVPBRUR4DAUWQWU8DJ91KE9B30H" Content-Transfer-Encoding: 7bit ------QBCAVPBRUR4DAUWQWU8DJ91KE9B30H Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Hi Jeff, Thanks for your help, finally I found this in kernel document=2E = Pointer Types =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Pointers printed w= ithout a specifier extension (i=2Ee unadorned %p) are hashed to give a uniq= ue identifier without leaking kernel addresses to user space=2E On 64 bit m= achines the first 32 bits are zeroed=2E If you _really_ want the address se= e %px below=2E =E2=81=A3Get BlueMail for Android =E2=80=8B On Jan 13, 202= 2, 23:44, at 23:44, Jeffrey Walton wrote: >On Thu, J= an 13, 2022 at 4:04 PM admin LI wrote: >> >> I'm de= veloping a kernel module for an ARM machine, while debugging I >found addre= sses >> printed are all randomized and useless for debugging=2E >> >> To pr= ove I was not crazy I wrote this small program: >> >> ---------------------= ------------ >> #include >> #include >>= #include >> #include >> >> MODULE_LICE= NSE("GPL"); >> MODULE_AUTHOR("Somebody"); >> MODULE_DESCRIPTION("A simple e= xample Linux module=2E"); >> MODULE_VERSION("0=2E01"); >> >> static int __i= nit example_init(void) { >> uint32_t a; >> uint32_t b; >> uint3= 2_t c; >> uint8_t d[10]; >> uint8_t *e; >> >> printk(KERN_INFO = "Hello, World!\n"); >> printk(KERN_INFO "&a %p\n",&a); >> printk(KE= RN_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 =3D kmalloc(10, GFP_KER= NEL); >> 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 randomi= zed addresses=2E >> >> When I search randomization the only thing I found i= s KASLR which I >don't think is the same thing=2E > >I think something else= may be going on, but I'll toss this out there >in case it helps=2E > >In t= he past randomization was disabled by writing 0 to >/proc/sys/kernel/random= ize_va_space=2E Something like: > > sysctl -w kernel=2Erandomize_va_spac= e=3D0 > >To make it permanent, change it in /etc/sysctl=2Econf=2E > >Jeff ------QBCAVPBRUR4DAUWQWU8DJ91KE9B30H Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
Hi Jeff,
=
Thanks for your help, finally I found this in = kernel document=2E

Pointer Types
=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Pointers printed without a specifier extension (i=2Ee unadorne= d %p) are hashed to give a unique identifier without leaking kernel address= es to user space=2E On 64 bit machines the first 32 bits are zeroed=2E If y= ou _really_ want the address see %px below=2E

On Jan 13, 2022, at 23:44, Jeffrey Walton <noloader@gmail=2Ecom> wrote:
On Thu, Jan 13, 2022 at 4:04 PM admin LI <admin@hifiphile=2Ecom> w=
rote:

I'm develo= ping a kernel module for an ARM machine, while debugging I found addresses<= br> printed are all randomized and useless for debugging=2E

To prov= e I was not crazy I wrote this small program:



#include <= linux/init=2Eh>
#include <linux/module=2Eh>
#include <l= inux/kernel=2Eh>
#include <linux/slab=2Eh>

MODULE_LICE= NSE("GPL");
MODULE_AUTHOR("Somebody");
MODULE_DESCRIPTION("A simple= example Linux module=2E");
MODULE_VERSION("0=2E01");

static in= t __init example_init(void) {
uint32_t a;
uint32_t b;
= uint32_t c;
uint8_t d[10];
uint8_t *e;

print= k(KERN_INFO "Hello, World!\n");
printk(KERN_INFO "&a %p\n",&= ;a);
printk(KERN_INFO "&b %p\n",&b);
printk(KERN_IN= FO "&c %p\n",&c);
printk(KERN_INFO "&d %p\n",d);
= printk(KERN_INFO "&d[0] %p\n",&d[0]);
printk(KERN_INFO "&= amp;d[1] %p\n",&d[1]);

e =3D 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;
}<= br>
static void __exit example_exit(void) {
printk(KERN_INFO "Good= bye, World!\n");
}

module_init(example_init);
module_exit(e= xample_exit);


And it gave me this output:

Hello, World!=
&a b3f9fa31
&b 27e1c68a
&c da50d287
&d 9f9= aec2b
&d[0] 9f9aec2b
&d[1] cc627580
&e[0] 98b8c9eb<= br> &e[1] 45f248f8

Then I tested on my debian host machine whic= h gave me the same kind of randomized addresses=2E

When I search ra= ndomization the only thing I found is KASLR which I don't think is the same= thing=2E

I think something else may be going on, but I= 'll toss this out there
in case it helps=2E

In the past randomiza= tion was disabled by writing 0 to
/proc/sys/kernel/randomize_va_space=2E= Something like:

sysctl -w kernel=2Erandomize_va_space=3D0
To make it permanent, change it in /etc/sysctl=2Econf=2E

Jeff
<= /pre>
------QBCAVPBRUR4DAUWQWU8DJ91KE9B30H-- --===============7307272848408698409== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies --===============7307272848408698409==--