[PATCH] setarch: add support for '-R' (disable randomization)

Thomas De Schampheleire patrickdepinguin at gmail.com
Thu Oct 22 07:42:55 UTC 2015


On Mon, Oct 19, 2015 at 11:27 PM, Denys Vlasenko
<vda.linux at googlemail.com> wrote:
> On Mon, Oct 19, 2015 at 4:55 PM, Thomas De Schampheleire
> <patrickdepinguin at gmail.com> wrote:
>> From: Jan Heylen <heyleke at gmail.com>
>>
>> This commit adds support for the -R flag of setarch, which disables
>> randomization of the virtual address space.
>>
>> Signed-off-by: Jan Heylen <heyleke at gmail.com>
>> Signed-off-by: Thomas De Schampheleire <thomas.de.schampheleire at gmail.com>
> ...
>>  int setarch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
>>  int setarch_main(int argc UNUSED_PARAM, char **argv)
>>  {
>> -       int pers;
>> +       unsigned long pers;
>> +       unsigned long options = 0;
>>
>>         /* Figure out what personality we are supposed to switch to ...
>>          * we can be invoked as either:
>> @@ -40,6 +47,7 @@ int setarch_main(int argc UNUSED_PARAM, char **argv)
>>                 applet_name = argv[1];
>>                 argv++;
>>         }
>> +
>>         if (applet_name[5] == '6') /* linux64 */
>>                 pers = PER_LINUX;
>>         else if (applet_name[5] == '3') /* linux32 */
>> @@ -48,9 +56,16 @@ int setarch_main(int argc UNUSED_PARAM, char **argv)
>>                 bb_show_usage();
>>
>>         argv++;
>> +       if(argv[0] && argv[0][0]=='-' && argv[0][1]=='R'){
>> +               options |= ADDR_NO_RANDOMIZE;
>> +               argv++;
>> +       }
>> +
>
> What about "linux32 -R -R -R PROG"?
>
>>         if (argv[0] == NULL)
>>                 bb_show_usage();
>>
>> +       pers |= options;
>> +
>
> You could have ORed ADDR_NO_RANDOMIZE to "pers" directly.
> "options" is not necessary.
>
> Applied with some edits. Thanks.

Thanks a lot, tested successfully.


More information about the busybox mailing list