Skip to content

io: make sure we don't close stdio fds

Filip Hejsek qemu-devel 3 versions – In review

Get series with b4
b4 am [email protected] change-id 20261012-fix-stdio-close-98864055d473

Versions newest first

  1. v3 Latest2 patches 3 repliesIn review
  2. v22 patches 2 repliesSuperseded
  3. v12 patches 2 repliesSuperseded

Changes in v3 from the cover letter

- Add documentation changes
- Link to v2: https://lore.kernel.org/qemu-devel/[email protected]

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2char-stdio: avoid closing stdio fdschardev/char-stdio.c+15 -11 reply
2/2io: report a warning when a file channel is created from a stdio fdinclude/io/channel-file.h io/channel-file.c+14 -41 reply

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchMarc-André LureauDaniel P. Berrangé
SeriesR-b
1/2R-b
2/2R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 0/2] io: make sure we don't close stdio fds

The stdio chardev currently closes the stdin and stdout fds when it is destroyed. This means that, assuming char0 is a stdio chardev, invoking the HMP command

chardev-change char0 null

will cause QEMU to run with descriptors 0 and 1 closed. That's not a great situation, as:
- the stdio chardev cannot be recreated
- code assuming fds 0 and 1 are open will misbehave
- the fds 0 and 1 will get assigned to newly opened files, possibly causing them to be confused for actual stdin/stdout

The fist patch fixes the problem by duplicating the fds before they get passed to qio_channel_file_new_fd(), the second patch adds a warning that is printed when qio_channel_file_new_fd() is called with a stdio fd and modifies the documentation of that function to say that passing stdio descriptors is incorrect.

Changes in v3:
- Add documentation changes
- Link to v2: https://lore.kernel.org/qemu-devel/[email protected]

Changes in v2:
- Code style fixes
- Set *errp when dup fails
- Link to v1: https://lore.kernel.org/qemu-devel/[email protected]

---
Filip Hejsek (2):
char-stdio: avoid closing stdio fds
io: report a warning when a file channel is created from a stdio fd

 chardev/char-stdio.c      | 16 +++++++++++++++-
 include/io/channel-file.h | 12 ++++++++----
 io/channel-file.c         |  6 ++++++
 3 files changed, 29 insertions(+), 5 deletions(-)

---
base-commit: 7e8d3c7fc460fe7cd28a3e423d7466fa292bc269
change-id: 20261012-fix-stdio-close-98864055d473

Best regards,

Signature · 1 line
Filip Hejsek <[email protected]>