mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* x86: randomize brk() and RLIMIT_DATA
@ 2007-10-25 13:41 Sami Farin
  2007-10-25 14:13 ` Arjan van de Ven
  0 siblings, 1 reply; 10+ messages in thread
From: Sami Farin @ 2007-10-25 13:41 UTC (permalink / raw)
  To: Linux kernel Mailing List; +Cc: Jiri Kosina

[-- Attachment #1: Type: text/plain, Size: 484 bytes --]

Would be neat if randomized brk and setrlimit(RLIMIT_DATA, ...)
worked in a predictable way:

$ gcc brk.c -fPIC -pie -m64;./a.out;./a.out;./a.out
sbrk=0x7f721b815000 main=0x7f721af04860
sbrk succeeded (brk=0x7f721b909240)
sbrk=0x7fc3d77e2000 main=0x7fc3d66fa860
sbrk failed: Cannot allocate memory (brk=0x7fc3d77e2000)
sbrk=0x7f05b0615000 main=0x7f05af76b860
sbrk failed: Cannot allocate memory (brk=0x7f05b0615000)

-- 
Do what you love because life is too short for anything else.


[-- Attachment #2: brk.c --]
[-- Type: text/plain, Size: 692 bytes --]

#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <errno.h>
#include <string.h>

int main(void)
{
	void *p;
	const struct rlimit rlim_data = {
		.rlim_cur = 10 << 20,
		.rlim_max = RLIM_INFINITY
	};
	int saved_errno;

	p = sbrk(0);
	fprintf(stderr, "sbrk=%p main=%p\n", p, &main);
	if (setrlimit(RLIMIT_DATA, &rlim_data) == -1) {
		fprintf(stderr, "setrlimit failed: %s\n", strerror(errno));
		return 1;
	}
	if (sbrk(1 << 20) == (void*)-1) {
		saved_errno = errno;
		fprintf(stderr, "sbrk failed: %s (brk=%p)\n",
			strerror(saved_errno), sbrk(0));
		return 1;
	} else {
		fprintf(stderr, "sbrk succeeded (brk=%p)\n", sbrk(0));
		return 0;
	}
}


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2007-10-26 13:25 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-25 13:41 x86: randomize brk() and RLIMIT_DATA Sami Farin
2007-10-25 14:13 ` Arjan van de Ven
2007-10-25 14:46   ` Jiri Kosina
2007-10-25 17:19     ` Sami Farin
2007-10-26 10:44       ` [PATCH] [RFC] brk randomization: compute RLIMIT_DATA properly (was Re: x86: randomize brk() and RLIMIT_DATA) Jiri Kosina
2007-10-26 12:02         ` Hugh Dickins
2007-10-26 12:16           ` Jiri Kosina
2007-10-26 12:30             ` Hugh Dickins
2007-10-26 12:33               ` Jan Engelhardt
2007-10-26 13:24                 ` Hugh Dickins

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®