this post was submitted on 20 Feb 2024
24 points (96.2% liked)

Linux

48619 readers
1077 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

The context I came upon this question is dbus filedescriptor passing but the question is valid more broadly. Assume you are implementing some service that is supposed to receive some kind of filedescriptor for client processes. You get a message that is in some kind or another malformed but you have already received the filedescriptor.

What do you do with that fd? Is close()ing it guaranteed to be enough?

The question was sparked by a safety comment on rusts abstraction of a OwnedFd, which will run close() in its destructor and binds you by contract to only create it from a filedescriptor if close is all that is needed for cleanup.

This of course made me worry about the possibility of malicious clients sending special filedescriptors that accumulate some kind of ressource on the server process causing some kind of DOS.

I guess a secondary question is: Do you know any example where calling close() is not enough?

top 3 comments
sorted by: hot top controversial new old
[–] just_another_person@lemmy.world 3 points 10 months ago (1 children)

I think your last question is what I would focus on. There's not much you can do with malformed anything unless you're expecting, so I don't know what else you would do aside from throw an exception and move on.

[–] Killing_Spark@feddit.de 1 points 10 months ago (1 children)

Just not handling the filedescriptors isn't really an option though. They should at least be closed to ensure the process doesn't run out of filedescriptors which would be a pretty easy way of DOS'ing that service

[–] just_another_person@lemmy.world 2 points 10 months ago

Yes, I'm agreeing. You should be closing any open resources as part of your usual logic.