|
|
Subscribe / Log in / New account

Cook: security things in Linux v5.1

Cook: security things in Linux v5.1

Posted May 29, 2019 18:35 UTC (Wed) by epa (subscriber, #39769)
Parent article: Cook: security things in Linux v5.1

Is it possible to use the new race-free signalling in shell scripts?


to post comments

Cook: security things in Linux v5.1

Posted May 29, 2019 19:14 UTC (Wed) by josh (subscriber, #17465) [Link] (5 responses)

Not today, but if you had helper programs for it, sure. You could modify coreutils `kill` to accept an fd number, for instance, and then pass it a pidfd via redirection. And you could modify the shell or create a helper program that spawns a process and gives you a pidfd, or obtains a pidfd for an existing process for you. (In the latter case you'd want to check it before using it.)

Cook: security things in Linux v5.1

Posted May 30, 2019 3:26 UTC (Thu) by wahern (subscriber, #37304) [Link] (2 responses)

I assume `exec 3</proc/$pid` would work to acquire a handle in the shell, but I haven't tested it.

Cook: security things in Linux v5.1

Posted May 30, 2019 15:43 UTC (Thu) by mgedmin (subscriber, #34497) [Link] (1 responses)

Don't you need to open it with the O_DIRECTORY flag? I don't think shell redirection will pass it.

Cook: security things in Linux v5.1

Posted May 30, 2019 16:21 UTC (Thu) by nybble41 (subscriber, #55106) [Link]

No, the O_DIRECTORY flag just causes the open() call to fail if the path does not refer to a directory. You can open directories without it. The shell has no issues redirecting from a directory rather than a file. You can test that yourself easily:

$ ls -l /proc/self/fd 3</etc
total 0
lrwx------ 1 user group 64 May 30 11:16 0 -> /dev/pts/N
lrwx------ 1 user group 64 May 30 11:16 1 -> /dev/pts/N
lrwx------ 1 user group 64 May 30 11:16 2 -> /dev/pts/N
lr-x------ 1 user group 64 May 30 11:16 3 -> /etc/
lr-x------ 1 user group 64 May 30 11:16 4 -> /proc/NNNN/fd/

Cook: security things in Linux v5.1

Posted May 30, 2019 4:53 UTC (Thu) by epa (subscriber, #39769) [Link] (1 responses)

Are fd numbers safe against reuse? (If the process dies in the meantime, might not the same fd number be used for some other file, or even an unrelated process?)

Cook: security things in Linux v5.1

Posted May 30, 2019 5:00 UTC (Thu) by epa (subscriber, #39769) [Link]

Sorry, an fd number means the number of an already open file handle, so 0 for stdin, 1 for stdout and so on. This is obviously race-free once opened. But how to open the fd safely?


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds