On Sun, Apr 28, 2024 at 2:15 PM stsp <stsp2@xxxxxxxxx> wrote:
But isn't that becoming a problem onceWait, who's the malicious party?
you are (maliciously) passed such fds via
exec() or SCM_RIGHTS? You may not know
about them (or about their creds), so you
won't close them. Or?
Anyone who can open a directory has,
at the time they do so, permission to do so. If you send that fd to
someone via SCM_RIGHTS, all you accomplish is that they now have the
fd.
In my scenario, the malicious party attacks an *existing* program that
opens an fd for purposes that it doesn't think are dangerous. And
then it gives the fd *to the malicious program* by whatever means
(could be as simple as dropping privs then doing dlopen). Then the
malicious program does OA2_INHERIT_CREDS and gets privileges it
shouldn't have.
Hold on -- what exactly are you talking about? A process doesThat the process that received them,My solution was to close such fds onI don't see what problem this solves.
exec and disallowing SCM_RIGHTS passage.
doesn't know they have O_CRED_ALLOW
within. So it won't deduce to close them
in time.
recvmsg() and doesn't trust the party at the other end. Then it
doesn't close the received fd. Then it does setuid(getuid()). Then
it does dlopen or exec of an untrusted program.
Okay, so the program now has a completely unknown fd. This is already
part of the thread model. It could be a cred-capturing fd, it could
be a device node, it could be a socket, it could be a memfd -- it
could be just about anything. How do any of your proposals or my
proposals cause an actual new problem here?
If the filesystem grants that UID permission to write, then it can write.This is fundamental to the whole model. If I stick a FAT formatted USBBut IIRC O_DIRECTORY only allows O_RDONLY.
drive in the system and mount it, then any process that can find its
way to the mountpoint can write to it. And if I open a dirfd, any
process with that dirfd can write it. This is old news and isn't a
problem.
I even re-checked now, and O_DIRECTORY|O_RDWR
gives EISDIR. So is it actually true that
whoever has dir_fd, can write to it?