Page MenuHomeFreeBSD

Make stdio cancel-safe.
ClosedPublic

Authored by kib on Jun 17 2017, 11:54 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Apr 28, 11:58 PM
Unknown Object (File)
Sun, Apr 21, 5:09 PM
Unknown Object (File)
Apr 7 2024, 7:34 PM
Unknown Object (File)
Apr 7 2024, 7:32 AM
Unknown Object (File)
Feb 21 2024, 1:05 PM
Unknown Object (File)
Feb 1 2024, 1:20 AM
Unknown Object (File)
Dec 20 2023, 8:18 AM
Unknown Object (File)
Oct 17 2023, 12:02 AM

Details

Summary

If used with fopen(3)/fdopen(3)-ed FILEs, stdio accurately uses non-cancellable internal versions of the functions, i.e. it seems to be fine with regard to cancellation. But if the funopen(3) and f{r,w}open(3) functions were used to open the FILE, and corresponding user functions create cancellation points (they typically have no other choice), then stdio code at least leaks FILE' lock.

The change installs cleanup handler which unlocks FILE. Some minimal restructuring of the code was required to make it use common return place to satisfy hand-rolled pthread_cleanup_pop() requirements.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

I've applied this to my mpd server (libc rebuilt and reinstalled) and restarted my tests. Hope it won't crash :-)

My tests show no problems with this patch applied. It seems this is required for net/mpd5 to run stable, it hits lock leak in the stdio otherwise: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=186114#c83

vangyzen added a subscriber: vangyzen.

Do fseek() and fseeko() need to use FLOCKFILE_CANCELSAFE() also? They call _fseeko() -> __sflush(), which is likely a cancellation point.

This revision is now accepted and ready to land.Jun 28 2017, 2:14 PM
kib edited edge metadata.

Use safe locking around fseeko.

This revision now requires review to proceed.Jun 28 2017, 2:56 PM
This revision is now accepted and ready to land.Jun 28 2017, 3:18 PM
This revision was automatically updated to reflect the committed changes.