6

Compiled a binary from the golang source, but it won't execute. I tried downloading the binary, which also didn't work. Permissions all seem to be right. Running the file from go for some reason works.

Output of ~/go$ go run src/github.com/exercism/cli/exercism/main.go1:

NAME:
   exercism - A command line tool to interact with http://exercism.io

USAGE:
   main [global options] command [command options] [arguments...]

Output of ~/go/bin$ ./exercism:

bash: ./exercism: Permission denied

Output of ~/go/bin$ ls -al:

total 9932
drwxr-xr-x 2 joshua joshua     4096 Apr 28 12:17 .
drwxr-xr-x 5 joshua joshua     4096 Apr 28 12:17 ..
-rwxr-xr-x 1 joshua joshua 10159320 Apr 28 12:17 exercism

Output of ~/go/bin$ strace ./exercism:

execve("./exercism", ["./exercism"], [/* 42 vars */]) = -1 EACCES (Permission denied)
write(2, "strace: exec: Permission denied\n", 32strace: exec: Permission denied
) = 32
exit_group(1)                           = ?
+++ exited with 1 +++
3
  • 1
    Do you have execute access to the directory containing the file? You need that to cd into the directory in the first place, but you would get this error if you're already int he directory and the executable bit is removed. Commented Apr 28, 2017 at 17:17
  • 1
    Also, please edit your question and explain the connection between src/github.com/exercism/cli/exercism/main.go1 and ./exercism. In the first case, exercism is a directory and in the second a file. Commented Apr 28, 2017 at 17:19
  • I do have access to the directory; the error was a drive mounted with noexec in effect. Commented Apr 28, 2017 at 18:20

1 Answer 1

9

Check that noexec is not in effect on the mount point in question. Or choose a better place to launch your script from.

$ mount | grep noexec
[ snip ]
shm on /dev/shm type tmpfs (rw,nosuid,nodev,noexec,relatime)
$ cat > /dev/shm/some_script
#!/bin/sh
echo hi
$ chmod +x /dev/shm/some_script
$ /dev/shm/some_script
bash: /dev/shm/some_script: Permission denied
$ mv /dev/shm_script .
$ ./some_script
hi

noexec exists specifically to prevent security issues that come from having world-writable places storing executable files; you might put a file there, but someone else might rewrite it before you execute it, and now you're not executing the code you thought you were.

4
  • Brilliant. You're absolutely correct - I have /home mounted as a seperate partition with noexec in effect. To fix this, I would edit /etc/fstab, correct? Commented Apr 28, 2017 at 18:19
  • For a permanent fix, should be, yes. For a quick fix, you should also be able to run mount -o remount,exec /home as root. Commented Apr 28, 2017 at 18:22
  • Update: I had in my fstab LABEL=home /home ext4 defaults,user 0 2 ; user implies no exec. I changed it to defaults and rebooted, now it works like a charm. Thanks for the help! Commented Apr 28, 2017 at 18:29
  • 2
    Don't forget to Accept the answer. ;) Commented Apr 28, 2017 at 18:32

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.