[BUG] system/vncviewer: `rfb_negotiate_security` never bounds the server-supplied security-type count against `sizeof(types)`, overflowing the 16-byte stack array `types[16]` (pre-auth stack buffer overflow)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 76/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- c
- 領域
- networking
調査の方向性
system/vncviewer/rfb_protocol.cから始め、特にrfb_negotiate_security()とrfb_recv_exact()を確認して、サーバーが指定した数が読み取り長としてどのように使われるかを追跡してください。rfb_discard_exact()が余分なバイトをどのように処理するか確認してください。大きすぎる数を拒否するか、types[16]の範囲外に書き込まず安全に読み捨ててください。大きすぎる数でバッファがオーバーフローせず、有効なハンドシェイクが引き続き動作すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Description / Steps to reproduce the issue
During the RFB 3.7+ security handshake the server sends a one-byte count of security types,
followed by that many type bytes. rfb_negotiate_security() reads the count straight off the
socket into a uint8_t and uses it as the length of a recv into the fixed 16-byte stack array
types[16], with no upper-bound check (only the == 0 case is special-cased).
system/vncviewer/rfb_protocol.c, rfb_negotiate_security():
521 static int rfb_negotiate_security(int sockfd, const char *password)
522 {
523 uint8_t num_types;
524 uint8_t types[16]; /* 16-byte stack buffer */
...
532 ret = rfb_recv_exact(sockfd, &num_types, 1); /* server-supplied 1..255 */
...
538 if (num_types == 0) { ... return -ECONNREFUSED; } /* ONLY the ==0 case handled */
...
551 ret = rfb_recv_exact(sockfd, types, num_types); /* SINK: writes num_types bytes */
rfb_recv_exact() writes exactly len bytes into the caller buffer:
383 static int rfb_recv_exact(int sockfd, void *buf, size_t len)
...
388 while (len > 0)
390 n = recv(sockfd, p, len, 0);
406 p += n;
407 len -= n;
So line 551 can recv up to 255 bytes into types[16], a 239-byte stack overflow of
attacker-chosen content that smashes the saved-register / return-address region of the frame.
There is no bound at all (not even a DEBUGASSERT) between the 1-byte read of num_types and
its use as the copy length.
This runs before authentication: vncviewer_main.c:191 rfb_connect() →
vncviewer_main.c:208 rfb_handshake() → rfb_protocol.c:772 rfb_negotiate_security(). A
malicious VNC server (the server a viewer connects to) or an on-path attacker injecting into the
TCP stream triggers it on the first handshake, with no credentials.
Steps:
- Build and run the vncviewer app and connect to an attacker-controlled / MITM'd VNC server.
- In the RFB 3.7+ security handshake, have the server send a security-type count of e.g.
0xff
followed by that many bytes. rfb_negotiate_security()writes those bytes pasttypes[16].
An AddressSanitizer build reports a stack-buffer-overflow WRITE past the 16-byte types array.
Expected: a count larger than the viewer's buffer is rejected or read in capped chunks.
Actual: up to 255 attacker bytes are written past types[16] on the stack, before auth.
Suggested fix: reject or clamp num_types to sizeof(types) before the recv — the viewer
only needs to know whether None / VNC Auth is offered, so it can read in capped chunks and
discard the remainder like rfb_discard_exact already does elsewhere.
On which OS does this issue occur?
[OS: Linux]
What is the version of your OS?
ubuntu 22
NuttX Version
a09fb84a9b5f274add52cc0b6d803b77d44306c1
Issue Architecture
[Arch: all]
Issue Area
[Area: Networking]
Host information
No response
Verification
- I have verified before submitting the report.
- 主要言語
- C
- スター
- 472
- フォーク
- 793
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 116
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/nuttx-apps のほかの issue
-
[FEATURE] Shrink getprime runs for OSTest対応中かも @linguini1 が 19 日前に担当しました。 オープンType: Enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
apache/nuttx-apps#3620 · コメント 6 件 · リアクション 1 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Type: Enhancement
難易度 4/5 3〜5日 初心者へのやさしさ 18/100
apache/nuttx-apps#3816 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[FEATURE] `pthread_sigqueue` testing implementation対応中かも @aryan9948 が 33 日前に担当しました。 オープンType: Enhancement
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
apache/nuttx-apps#3796 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[BUG] testing/sched/timerjitter: unexpected results under normal usage対応中かも @RogerNext が 93 日前に担当しました。 オープンType: Bug
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
apache/nuttx-apps#3634 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
[TODO] move graphics/input -> input.再び着手できるかも @cederom が 218 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
apache/nuttx-apps#3436 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
apache/nuttx-apps の issue をすべて見る
似ている issue
-
vim.filetype.match() prefixes a URL buffer name with the cwd before passing it to filetype functionsオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
メンテナーはふだん 1 日以内に返信
-
stream_curl: retry_count never resets after a successful reconnect, so long sequential streams die after 5 drops対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
mpv-player/mpv#18728 ·
メンテナーはふだん 1 日以内に返信
-
followup Prio 📌
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
cyrusimap/cyrus-imapd#6640 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 60/100
メンテナーはふだん 1 日以内に返信