Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to turn off ASLR on my own PC. But each time I type "sudo echo 0 > /proc/sys/kernel/randomize_va_space", the system shows that "Permission denied". How can I make it work? By the way, my OS kernel is 2.6.30.

Hope anyone can give me a hand.

Regards.

share|improve this question

migrated from stackoverflow.com Apr 4 '10 at 4:44

This question came from our site for professional and enthusiast programmers.

2  
This is a valid question on shell programming. –  liori Apr 3 '10 at 13:33
    
Why do you want to turn off ASLR?! –  Jeremy Visser May 25 at 12:18

3 Answers 3

up vote 10 down vote accepted

This is a common problem with sudo and shell redirection. The "sudoness" doesn't propagate past the redirection. One way to get around it is

sudo bash -c "echo 0 > /path/to/file"
share|improve this answer

The sudo only works for your echo command (not after the pipe).

You can try:

echo 0 | sudo tee /proc/sys/kernel/randomize_va_space
share|improve this answer

In your command, the I/O redirection > is handled by the current shell. The command is seen by the interpreter as 3 parts:

  1. sudo echo 0
  2. >
  3. /proc/sys/kernel/randomize_va_space

The echo is executed using the superuser privilege while the current shell (with normal user privilege) tries to write to /proc/sys/kernel/randomize_va_space, and thus triggers a Permission denied error.

There are several ways to overcome this. The first way is to run a shell with superuser privilege and pass the command to the shell using the -c switch:

sudo sh -c "echo 0 > /proc/sys/kernel/randomize_va_space"

(You may use sh for POSIX shell and bash for Bash)

Another way is to use the tee command. The tee command copies the contents from standard input to the standard output (usually means the "screen") as well as the listed files. Therefore, the following command prints the character A to the standard output as well as the files output1.txt and output2.txt.

echo A | tee output1.txt output2.txt

In your problem, writing to /proc/sys/kernel/randomize_va_space needs the superuser privilege while echo-ing 0 does not. So, the solution is:

echo 0 | sudo tee /proc/sys/kernel/randomize_va_space >/dev/null

The final redirection to /dev/null prevents the 0 from printing to the screen.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.