--userns-block-fd can hang when given a closed descriptor

オープン 初心者向け
#826 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
c, linux

調査の方向性

まず --userns-block-fd の引数解析と、指定されたディスクリプターの読み取りとクローズを行う bubblewrap.c:3179-3180 付近のセットアップコードを確認してください。child_wait_fd と setup_finished_pipe がどのように割り当てられるかを調べてから、issue にある両方の再現手順を実行してください。セットアップが停止する前に、クローズ済みのディスクリプターがエラーで拒否されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

bubblewrap 0.13.1 accepts a closed --userns-block-fd descriptor and can reuse its number for its internal eventfd or, with --json-status-fd, its setup-completion pipe.

Both runs below hung until timeout -s KILL 20 killed them (status 137).

To reproduce:

bwrap --unshare-user --info-fd 1 --userns-block-fd 4 --ro-bind / / --proc /proc --dev /dev /bin/true 3<&- 4<&-

strace:

2865  openat(AT_FDCWD, "/proc", O_RDONLY|O_PATH) = 3
2865  eventfd2(0, EFD_CLOEXEC)          = 4
2865  clone(child_stack=NULL, flags=CLONE_NEWNS|CLONE_NEWUSER|SIGCHLD) = 2866
2866  read(4,  <unfinished ...>
2865  read(4, 0x7ffe9b5a5857, 1)        = -1 EINVAL (Invalid argument)
2865  write(4, "\1\0\0\0\0\0\0\0", 8)   = -1 EBADF (Bad file descriptor)

child_wait_fd gets descriptor 4. The parent's 1-byte read of opt_userns_block_fd fails with EINVAL. The parent closes that descriptor (bubblewrap.c:3180), which is also child_wait_fd. Its write to child_wait_fd fails with EBADF, leaving the child blocked.

With --json-status-fd:

bwrap --unshare-user --info-fd 1 --json-status-fd 2 --userns-block-fd 5 --ro-bind / / --proc /proc --dev /dev /bin/true 3<&- 4<&- 5<&- 6<&-

strace:

2939  openat(AT_FDCWD, "/proc", O_RDONLY|O_PATH) = 3
2939  eventfd2(0, EFD_CLOEXEC)          = 4
2939  pipe2([5, 6], O_CLOEXEC)          = 0
2939  clone(child_stack=NULL, flags=CLONE_NEWNS|CLONE_NEWUSER|SIGCHLD) = 2940
2940  read(4,  <unfinished ...>
2939  read(5,

opt_userns_block_fd is the read end of setup_finished_pipe (descriptor 5). The parent blocks in its read (bubblewrap.c:3179) before writing child_wait_fd. The child blocks in its read of child_wait_fd.

A patched build checks descriptors with fcntl (fd, F_GETFD) during argument parsing. Both commands returned status 1:

bwrap: Invalid fd: 4: Bad file descriptor
bwrap: Invalid fd: 5: Bad file descriptor
主要言語
C
スター
9.4k
フォーク
408
平均マージ
6日 14時間
マージ済み PR(30日)
1

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

containers/bubblewrap のほかの issue

containers/bubblewrap の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。