user: parseLine silently ignores uid/gid conversion errors, malformed ids parse as 0
まだ誰も着手していません。
評価
調査の方向性
user/user.go の parseParts から始め、ParsePasswdFilter と ParseGroupFilter が解析済み ID をどのように公開しているかを追跡します。issue にある不正形式および範囲外の例を再現し、そのうえで、選択された動作が変換エラーを返すことなのか、無効なエントリをスキップすることなのかを判断します。呼び出し元が無効な ID と正当な uid 0 の値を区別できれば完了です。
索引モデルが issue の本文から書いたものです。
説明
parseParts in user/user.go parses numeric fields with the conversion error discarded:
case *int:
// "numbers", with conversion errors ignored because of some misbehaving configuration files.
*e, _ = strconv.Atoi(string(p))
https://github.com/moby/sys/blob/d6b812df97ee7e0c1e16437fd4d1fa61738427db/user/user.go#L82
Two consequences for consumers that resolve container users from an image's /etc/passwd or /etc/group:
- A malformed id field parses as 0. The line
evil:x:not-a-uid:10::/:/bin/shproducesUser{Name: "evil", Uid: 0}, so looking up that user silently yields root. The caller can't detect this, since uid 0 is also a perfectly legitimate value. - An id past the int range saturates instead of erroring. On 32-bit platforms
4294967296comes back as 2147483647 with no error, so the caller can't range-check it either.
Context: containerd/containerd#13797 added bounds checks on ids resolved from image user databases, but both cases above are invisible to that check because the value has already been collapsed by the time ParsePasswdFilter/ParseGroupFilter return. @fuweid suggested fixing this at the parser level (https://github.com/containerd/containerd/pull/13797#discussion_r3867287873).
I understand the error was dropped deliberately to tolerate misbehaving config files, but for the id fields specifically the failure mode is "arbitrary string becomes root", which seems worth surfacing. Happy to send a PR, either returning an error from the parse functions when an id field doesn't parse, or skipping such entries, whichever direction you prefer.
- 主要言語
- Go
- スター
- 102
- フォーク
- 62
- 平均マージ
- 6分
- マージ済み PR(30日)
- 2
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
moby/sys のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
-
devices: ignore .incus-mounts in GetDevices対応中かも @SashaMIT が 7 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
-
[userns-remap] Bug: ToHost incorrectly maps non-root container UID to root when it collides with RootPair対応中かも @okhowang が 74 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 50/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 74/100
似ている issue
-
effort:high model:sonnet phase:3 type:docs
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
OffchainLabs/nitro#4771 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
BurntSushi/toml#530 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 7 日以内に返信