1

While trying to learn about how ld-2.17.so works to change the permission of chmod executable itself, and thought if i can change the permission of ld-2.17.so itself.

I ran chmod 666 ld-2.17.so in a test centos 7 machine and after it I can't run any command since most of the commands use ld-2.17.so.

I have already read this answer, Recovering from removing execute permission from ld-linux.so

It gives a very general answer but not a specific solution. Is there anywhere in Centos7 i can find ld-2.17.so cache to recover /lib64/ld-2.17.so permission back to normal?

Edit: I have tried to scp this file, /lib64/ld-2.17.so from other machine to affected machine, but I get permission denied error.

Thank you in advance

MaverickD
  • 359
  • 2
  • 11

1 Answers1

3

If you have an executable file you can write to, you could copy the contents of ld.so to that file using bash's read:

while IFS= read -d '' -r  line; do printf "%s\0" "$line"; done > executable-file < /lib64/ld-2.17.so

Example:

bash-4.2$ ll foo
-rwxr-xr-x 1 muru muru 29K Aug 23 13:02 foo*
bash-4.2$ while IFS= read -d '' -r  line; do printf "%s\0" "$line"; done > foo < /lib64/ld-2.17.so
bash-4.2$ ./foo
Usage: ld.so [OPTION]... EXECUTABLE-FILE [ARGS-FOR-PROGRAM...]
You have invoked `ld.so', the helper program for shared library executables.
...

Then you can use it to run chmod:

bash-4.2$ ./foo /bin/chmod
/bin/chmod: missing operand
Try '/bin/chmod --help' for more information.
muru
  • 69,900
  • 13
  • 192
  • 292
  • Thankk you muru. That's really helpful. Could you please suggest if i don't have any sample executable available is there any unused executable that I can use from within Linux? One more question, how do you know bash's `read` doesn't used dynamic libraries. thank you – MaverickD Aug 23 '18 at 07:56
  • 1
    @MaverickD the assumption here is that you already have a running shell from before you messed up `ld.so`. If you don't, and you don't have a statically compiled shell (like busybox) available, you have to reboot and use recovery methods, plain and simple. As for sample executables, pick any except `chmod` and then reinstall that command later once you have fixed `ld.so`. (or you can save the contents to a different file, using the same `read` method) – muru Aug 23 '18 at 07:58