mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] syslog does not detect a closed file descriptor
@ 2024-09-26  9:08 Jef STEELANT (EXT)
  2024-09-26 16:42 ` Markus Wichmann
  0 siblings, 1 reply; 3+ messages in thread
From: Jef STEELANT (EXT) @ 2024-09-26  9:08 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 3326 bytes --]

The syslog implementation does not detect if the file descriptor of /dev/log is closed, and keeps on logging to an invalid fd.
This happens for instance when using lxc with musl libc ( see issue https://github.com/lxc/lxc/issues/4485). LXC will at a certain point close the fd of /dev/log, in the assumption that a next call to syslog will detect an EBADF when writing data, and that the log will be reopened. glibc does this, but musl does not. It would be better if syslog would either stop logging to the invalid fd, or reopen the log when s send returns EBADF.

Jef
-- This message and any attachments herein are, unless otherwise stated, confidential, intended solely for the addressees and are SoftAtHome's ownership. Any unauthorized use, reproduction or dissemination is prohibited unless formaly agreed beforehand by the sender. If you are not the intended addressee of this message, please immediately delete it and all its attachments from your computer system and notify the sender. SoftAtHome reserves the right to monitor all email communications through its networks. Any views or opinions presented are solely those of its author and do not necessarily represent those of SoftAtHome. The internet cannot guarantee the integrity of this message. SoftAtHome not shall be liable for the message if altered, changed or falsified. While we take all reasonable precautions to ensure that viruses are not transmitted via emails, we recommend that you take your own measures to prevent viruses from entering your computer system. SoftAtHome is a French Soci?t? Anonyme with a Board of Directors, having a capital of 6 450 699 Euros having its registered office located at 9-11 rue du d?barcad?re - 92700 - Colombes - France - Tel + 33 (0)1 57 66 88 88 - Fax + 33 (0)1 57 66 88 89 - RCS Nanterre B 500 440 813 - Intra-Community VAT: FR 04500440813 -- Ce message et toutes les pi?ces jointes qui y sont incluses sont, sauf indication contraire, confidentiels, destin?s uniquement aux destinataires et sont la propri?t? de SoftAtHome. Toute utilisation non autoris?e, reproduction ou diffusion est interdite, sauf accord formel pr?alable de l'exp?diteur. Si vous n'?tes pas le destinataire pr?vu de ce message, veuillez le supprimer imm?diatement ainsi que toutes ses pi?ces jointes de votre syst?me informatique et en informer l'exp?diteur. SoftAtHome se r?serve le droit de surveiller toutes les communications par e-mail via ses r?seaux. Les opinions exprim?es dans ce message sont celles de leur auteur et ne repr?sentent pas n?cessairement celles de SoftAtHome. L'Internet ne permettant pas d'assurer l'int?grit? de ce message, SoftAtHome d?cline toute responsabilit? ? ce titre, dans l'hypoth?se o? il aurait ?t? alt?r?, d?form? ou falsifi?. Par ailleurs et malgr? toutes les pr?cautions prises pour ?viter la pr?sence de virus dans nos envois, nous vous recommandons de prendre, de votre c?t?, les mesures permettant d'assurer la non-introduction de virus dans votre syst?me informatique. SoftAtHome est une Soci?t? Anonyme fran?aise ? Conseil d'Administration ayant un capital de 6 450 699 euros, dont le si?ge social est situ? au 9-11 rue du d?barcad?re - 92700 - Colombes - France - Tel + 33 (0)1 57 66 88 88 - Fax + 33 (0)1 57 66 88 89 RCS Nanterre B 500 440 813 - TVA intracommunautaire : FR 04500440813

[-- Attachment #2: Type: text/html, Size: 4776 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [musl] syslog does not detect a closed file descriptor
  2024-09-26  9:08 [musl] syslog does not detect a closed file descriptor Jef STEELANT (EXT)
@ 2024-09-26 16:42 ` Markus Wichmann
  2024-10-09 20:36   ` Rich Felker
  0 siblings, 1 reply; 3+ messages in thread
From: Markus Wichmann @ 2024-09-26 16:42 UTC (permalink / raw)
  To: musl; +Cc: Jef STEELANT (EXT)

Am Thu, Sep 26, 2024 at 09:08:59AM +0000 schrieb Jef STEELANT (EXT):
> The syslog implementation does not detect if the file descriptor of
> /dev/log is closed, and keeps on logging to an invalid fd.
> This happens for instance when using lxc with musl libc ( see issue
> https://github.com/lxc/lxc/issues/4485). LXC will at a certain point
> close the fd of /dev/log, in the assumption that a next call to syslog
> will detect an EBADF when writing data, and that the log will be
> reopened. glibc does this, but musl does not. It would be better if
> syslog would either stop logging to the invalid fd, or reopen the log
> when s send returns EBADF.

This is why you do not close FDs you do not own. The application does
not own the socket FD for the syslog; it belongs to libc. And the
application can portably request the FD be closed by calling closelog().
And it should, because that will restore the initial state in that file,
and cause the log to be opened again.

Using EBADF for anything is a bad idea in the lib, since the lib must
work with multiple threads, and in a multi-threaded process EBADF means
"you could have sent this data to the wrong FD". I think the simplest
solution is for lxc to just call closelog() before closing the other
FDs.

Ciao,
Markus

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [musl] syslog does not detect a closed file descriptor
  2024-09-26 16:42 ` Markus Wichmann
@ 2024-10-09 20:36   ` Rich Felker
  0 siblings, 0 replies; 3+ messages in thread
From: Rich Felker @ 2024-10-09 20:36 UTC (permalink / raw)
  To: Markus Wichmann; +Cc: musl, Jef STEELANT (EXT)

On Thu, Sep 26, 2024 at 06:42:20PM +0200, Markus Wichmann wrote:
> Am Thu, Sep 26, 2024 at 09:08:59AM +0000 schrieb Jef STEELANT (EXT):
> > The syslog implementation does not detect if the file descriptor of
> > /dev/log is closed, and keeps on logging to an invalid fd.
> > This happens for instance when using lxc with musl libc ( see issue
> > https://github.com/lxc/lxc/issues/4485). LXC will at a certain point
> > close the fd of /dev/log, in the assumption that a next call to syslog
> > will detect an EBADF when writing data, and that the log will be
> > reopened. glibc does this, but musl does not. It would be better if
> > syslog would either stop logging to the invalid fd, or reopen the log
> > when s send returns EBADF.
> 
> This is why you do not close FDs you do not own. The application does
> not own the socket FD for the syslog; it belongs to libc. And the
> application can portably request the FD be closed by calling closelog().
> And it should, because that will restore the initial state in that file,
> and cause the log to be opened again.
> 
> Using EBADF for anything is a bad idea in the lib, since the lib must
> work with multiple threads, and in a multi-threaded process EBADF means
> "you could have sent this data to the wrong FD". I think the simplest
> solution is for lxc to just call closelog() before closing the other
> FDs.

Yes, if you close or replace any fds belonging to the implementation
behind its back, very bad things can happen. This is an application
bug. Any attempt to mitigate it by catching EBADF here would only bury
the bug, making it so you detect it only on fairly rare race
conditions rather than always seeing it (and thereby realizing it
needs to be fixed and fixing it).


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-10-09 20:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-26  9:08 [musl] syslog does not detect a closed file descriptor Jef STEELANT (EXT)
2024-09-26 16:42 ` Markus Wichmann
2024-10-09 20:36   ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).