ioctl_tiocsctty passes the address of a zero instead of the documented 0 argument
メンテナーはふだん 11 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 68/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- linux, rust
調査の方向性
バグは src/process/ioctl.rs にあります。文書化された呼び出しは13行目にあり、45〜47行目の引数アダプタがスタック上のローカル変数 0u32 のアドレスを、値0の代わりに渡しています。まずそのアダプタと ioctl_tiocsctty のドキュメントコメントを読み、次にissueのstraceによる再現手順を実行して不正な引数を確認してください。完了の条件は、アダプタがリテラル0を渡すこと、コメントが ioctl_tty(2) を参照すること、そしてstraceの出力に TIOCSCTTY, 0 が表示されることです。
索引モデルが issue の本文から書いたものです。
説明
rustix::process::ioctl_tiocsctty is documented as performing ioctl(fd, TIOCSCTTY, 0):
but the argument adapter passes the address of a stack-local 0u32:
Linux from 2.6.12 requires the third arg to be exactly 1 for the option to steal the terminal, and only uses that arg anyway when CAP_SYS_ADMIN. On BSDs the arg is ignored. The Linux manpage says to use 0 otherwise; the comment in the code has tty_ioctl(4) but that's since been renamed to ioctl_tty(2) and TIOCSCTTY(2const) has the detail:
Make the given terminal the controlling terminal of the
calling process. The calling process must be a session
leader and not have a controlling terminal already. For
this case, arg should be specified as zero.
If this terminal is already the controlling terminal of a
different session group, then the ioctl fails with EPERM,
unless the caller has the CAP_SYS_ADMIN capability and arg
equals 1, in which case the terminal is stolen, and all
processes that had it as controlling terminal lose it.
From kernel source:
static int tiocsctty(struct tty_struct *tty,
struct file *file, int arg)
{
// ...
if (tty->ctrl.session) {
if (arg == 1 && capable(CAP_SYS_ADMIN)) {
session_clear_tty(tty->ctrl.session);
} else {
ret = -EPERM;
goto unlock;
}
}
// ...
}
This isn't unsafe exactly, but it's still confusing. Also, it might be worth exposing the steal variant.
Tiny repro:
#!/usr/bin/env -S cargo +nightly -Zscript
---cargo
package.edition = "2024"
dependencies.rustix = { version = "1.1.5", features = ["process"] }
---
fn main() {
let _ = rustix::process::ioctl_tiocsctty(std::io::stdin());
}
With strace:
$ ./repro.rs >/dev/null # compile
$ sudo strace -e ioctl ~/.cargo/build/*/*/target/debug/repro # run with CAP_SYS_ADMIN
ioctl(0, TIOCSCTTY, -527932840) = -1 ENOTTY (Inappropriate ioctl for device)
The return may vary and isn't relevant: -527932840 is an address and is neither 0 nor 1, the two permitted values. A silver lining is that it's also impossible for arg to be 1 under the current code, so it's technically harmless.
- 主要言語
- Rust
- スター
- 2.1k
- フォーク
- 308
- 平均マージ
- 14日 5時間
- マージ済み PR(30日)
- 5
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
bytecodealliance/rustix のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
bytecodealliance/rustix#1706 · コメント 1 件 ·
メンテナーはふだん 11 日以内に返信
-
net feature alone fails to compile in 1.1.5: sockopt uses crate::timespec, which net does not gate in再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
bytecodealliance/rustix#1689 · コメント 3 件 ·
メンテナーはふだん 11 日以内に返信
-
Wrong flag used for (set_)ipv6_multicast_hops対応中かも @RajaBabu15 が 63 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
bytecodealliance/rustix#1660 ·
メンテナーはふだん 11 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
bytecodealliance/rustix#1635 ·
メンテナーはふだん 11 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
bytecodealliance/rustix#1068 ·
メンテナーはふだん 11 日以内に返信
bytecodealliance/rustix の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
dependencies effort:low flow:chore rust
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
jaroslawherod/micold-ai-ide#875 ·
メンテナーはふだん 1 日以内に返信
-
priority: low
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
storytold/photocraft#6286 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Four problem loader browser tests fail on Windows対応中かも @Patriciaath999 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
Kazakh (kk_KZ) and Georgian (ka_GE) system locales get English instead of the shipped translationsオープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信