endoli / endoli/javascriptcore.rs

Unsoundness: `JSValue` (and others) can outlive the `Context`

オープン
#38 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

主要言語
Rust
スター
54
フォーク
4
PR マージ指標
30日以内にマージされた PR はありません

説明

Hi,

JSValue, JSObject and others are not restricted in the lifetime, therefore are able to outlive the Context, in the best case just crashing the program and in the worst case causing a use-after-free.

The following script reproduces the problem and leads to a segfault (due to an safety check in jsc itself):

use javascriptcore::*;

fn main() {
    let v;
    {
        let ctx = JSContext::default();
        v = evaluate_script(&ctx, "'Hello' + ' ' + 'World'", None, "test.js", 1)
            .expect("Failed to evaluate script");
        println!("Value: {:?}", v.as_string());
    }
    println!("Value: {:?}", v.as_string());
}

Typically, you would add PhantomData to add a phantom lifetime. However, you already hold a raw pointer to the context in these structs and the context should be a widespread object in many real-world users of your bindings, ref-counting the context in Rust with Arc might be the best option.

Kind Regards
Tim

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

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

調査の方向性

issue 内の Rust 再現コードから始め、JSContext、JSValue、JSObject、evaluate_script の定義を追跡してください。Context のスコープ終了後に use-after-free が発生することを確認し、そのうえで lifetime-safe な所有権アプローチを決定して文書化してください。再現コードが Context の破棄後に値へアクセスできず、関連する安全性の動作がテストでカバーされていれば完了です。

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

評価

技術スタック
javascript, rust
領域
tooling
issue の種類
バグ
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

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

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