1

I never understood this, because if you have access to read a file, doesn't that mean you would be able to copy it somewhere else, thus allowing you to execute it anyway?

What am I missing?

Fragsworth
  • 1,121
  • 2
  • 12
  • 14

3 Answers3

6

The Executable flag is there to indicate to the kernel that the data should be read and then run. This is implemented by having a different call for executing something and reading something. For compiled programs it is quite possible to have execute-only access to it and not have read access; you can't even 'cp' them elsewhere. For interpreted items like shell-scripts, read is needed for execution.

I know one Linux distro that uses the execute flag to control what scripts fire at bootup.

In short, the Execute flag is used to indicate the ability of compiled code to run. Interpreted code is run through the parent processor and may only need 'read'.

sysadmin1138
  • 131,083
  • 18
  • 173
  • 296
0

Some potential reasons:

  • It protects the file from being accidentally executed.
  • It's obvious this way what files are executables (on Windows you need to check the registry for the list of executable file extensions to know that)
  • It protects you against some security exploits (attackers do not only need a way to put a file on your system and somehow execute it, they also need a way to change its permissions).
  • If the only disks the user can write to have an umask/mount option that "removes" the execute bit, they can't copy it somewhere else and make it executable (at least, not on that machine, and you might have to take other precautions too)

There are probably other reasons...

JanC
  • 400
  • 2
  • 5
  • The most important one that you sort-of covered but not explicitly - Prevents a user from loading a remote file onto the system, then executing that file locally on the system. – Chris Thorpe Oct 17 '10 at 05:32
  • It doesn't really prevent a user from doing that (unless precautions are taken like I mention in my last point). – JanC Oct 17 '10 at 18:30
0

doesn't that mean you would be able to copy it somewhere else, thus allowing you to execute it anyway?

No, this is not correct.

There are scenarios when you can't execute a file, even if it has the executable bit set. Here are at least two of them:

  • a restricted shell which explicitly prohibits execution
  • a filesystem mounted with noexec option
halp
  • 2,098
  • 1
  • 19
  • 13