5

bashenables to run bash scripts with bash somescript, python python scripts with python3 somescript. Alternatively, with the right shebang, I can run directly the previous scripts with ./somescript.

For binary programs, I can run them as ./someprogram if they have the executable permission set.

But is there a GNU/Linux command to run a binary executable, say run, like in: run someprogram?

Typical use case is: someprogram is in a partition with noexec set. Such run command would enable to run myprogram as if it were in the partition where run is installed as usr/bin which is mounted with the exec flag.

Remark: it is not a chmodissue. someprogram has the exec permission set.

lalebarde
  • 203
  • 5
    https://unix.stackexchange.com/a/83866/108618 – Kamil Maciorowski Nov 20 '23 at 15:59
  • 2
  • None of your propositions work in my case. – lalebarde Nov 20 '23 at 16:18
  • 3
    The 1st comment link is about using the dynamic linker to execute any dynamically linked executable even without permission for execution. The title of the link is not to solve it. The solution is not about using chmod. Only the answer about ld.so (ld-linux ...). It won't work for statically linked executables though. What is yours? (file ./binary) – A.B Nov 20 '23 at 16:22
  • ok, thanks for the clarification. If I run /lib/ld-linux.so.2 someprogram, I get: error while loading shared libraries, wrong ELF class: ELFCLASS64 – lalebarde Nov 20 '23 at 16:49
  • 3
    @A.B and anyway, Linux won't allow ld-linux.so to mmap files as executable in the process memory if it's on a FS mounted with noexec, it would need to be copied with a FS without noexec. – Stéphane Chazelas Nov 20 '23 at 16:56
  • 1
    @KamilMaciorowski, that ld.so approach won't work for files on a FS mounted with noexec. – Stéphane Chazelas Nov 20 '23 at 16:57
  • 2
    @lalebarde, you'd likely need /lib64/ld-linux-x86-64.so.2 someprogram in your case, but even that won't work if the file is on a FS with noexec. noexec is especially to prevent the machine code from the file from being executed by the processor. You'd need to copy the file to a FS without noexec first. – Stéphane Chazelas Nov 20 '23 at 17:04
  • @Stéphane, thank you very much. I moved it and have now other problems possibly for further questions. So the answer is no way to run a program located in a noexec volume. – lalebarde Nov 20 '23 at 17:15
  • @StéphaneChazelas thanks for the information. Difficult to cheat the system – A.B Nov 20 '23 at 17:28
  • IIRC running the dynamic loader manually used to work even for non-executable files under older kernels. But you had to be able to read the file, and of course stuff like setuid didn't work. – ilkkachu Nov 20 '23 at 21:14
  • @ilkkachu it still works for a non-executable binary on a standard ("exec") mount. But on a noexec mount it fails as Stéphane Chazelas wrote. One gets this error: /lib64/ld-linux-x86-64.so.2 /tmp/sleep 1 /tmp/sleep: error while loading shared libraries: /tmp/sleep: failed to map segment from shared object. This is documented in Linux' mmap(2) for one of the multiple causes of EPERM. – A.B Nov 20 '23 at 22:03
  • @Stéphane, if you set your answer, I will validate it, thanks again. – lalebarde Nov 21 '23 at 07:42
  • IIRC, someone once managed to write a execve() in user space, so it might be possible. I think I read it somewhere here, so there might be a Q&A covering it here. – Stéphane Chazelas Nov 21 '23 at 09:17
  • 1
    @StéphaneChazelas this Q/A https://unix.stackexchange.com/questions/725590/does-linux-support-invoking-a-program-directly-via-its-inode-number/725597#725597 has some references about it. Anyway such code has to be available in an place where it can be executed, even if it's to "execute" code in a place where it can't naturally be. – A.B Nov 21 '23 at 11:08

0 Answers0