Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

ioctl_tiocsctty passes the address of a zero instead of the documented 0 argument

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

メンテナーはふだん 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):

https://github.com/bytecodealliance/rustix/blob/1e2954a46ecffa6b30426ad7b1833b226530dcf4/src/process/ioctl.rs#L13

but the argument adapter passes the address of a stack-local 0u32:

https://github.com/bytecodealliance/rustix/blob/1e2954a46ecffa6b30426ad7b1833b226530dcf4/src/process/ioctl.rs#L45-L47

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

環境構築

はじめの一歩

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

bytecodealliance/rustix のほかの issue

bytecodealliance/rustix の issue をすべて見る

似ている issue

Rust の issue をもっと見る

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

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