Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

20210405 Gophers Code Reading Party #1

Closed
hgsgtk opened this issue Apr 5, 2021 · 4 comments
Closed

20210405 Gophers Code Reading Party #1

hgsgtk opened this issue Apr 5, 2021 · 4 comments

Comments

@hgsgtk
Copy link
Contributor

hgsgtk commented Apr 5, 2021

@ Zoom, BASE BANK, Inc.

参加者

BASE / BASE BANK

Guests

  • daisuzu
  • ema

お題

fuzz test in Go

@hgsgtk
Copy link
Contributor Author

hgsgtk commented Apr 5, 2021

Zoom Chat memo

15:04:47 From Kazuki Higashiguchi to Everyone : waiwai
15:05:48 From Yoichiro Shimizu to Everyone : https://play.golang.org/p/lD5-kBCwET4
15:05:56 From Yoichiro Shimizu to Everyone : [pr] https://budougumi0617.github.io/2021/03/31/go-string-null-pointer-panic/
15:06:44 From Kazuki Higashiguchi to Everyone :

type stringStruct struct {
	str unsafe.Pointer
	len int
}

15:08:44 From Kazuki Higashiguchi to Everyone : 最近のネタ: Go 1.16.3 https://github.com/golang/go/issues?q=milestone%3AGo1.16.3+label%3ACherryPickApproved
15:10:21 From Kazuki Higashiguchi to Everyone : > 訳注:コンパイラは命令の実行順序を b = 2; a = 1; と変更してもそれを実行しているゴルーチン内で 二つの文の実行後にはa  1 b  2 が入っているので振る舞いを変更していませんさらにコンパイ ラが実行順序を変更しなくても今日の out-of-order CPU では書き込みはラインキャッシュにさえも書き込ま れずにreorder buffer と呼ばれるレジスタに両方の値が書き込まれてから後で実際のメモリへ書き込まれま その場合メモリへ先に書き込まれるのが a であることは保証されません15:11:30 From Kazuki Higashiguchi to Everyone : 身近な小ネタ https://github.com/golang/go/issues/44887 helper関数のprint bug fix
15:12:47 From Kazuki Higashiguchi to Everyone : 

```go
package main_test

import (
	"testing"
)

func TestHelper(t *testing.T) {
	helperA(t)
}

func helperA(t *testing.T) {
	t.Helper()

	t.Run("subtest", func(t *testing.T) {
		t.Helper()
		t.Fatal("fatal error message")
	})
}

15:16:23 From Yoichiro Shimizu to Everyone : https://golangweekly.com/issues/356
15:16:45 From Yoichiro Shimizu to Everyone : https://go.libhunt.com/newsletter
15:17:40 From Kazuki Higashiguchi to Everyone : https://searchsecurity.techtarget.com/definition/fuzz-testing
15:17:47 From Kazuki Higashiguchi to Everyone : > ファズテスト(ファジング)とは、ソフトウェアやOS、ネットワークのコーディングエラーやセキュリティ上の抜け穴を発見するための品質保証技術である。ファズテストでは、ファズと呼ばれる大量のランダムなデータをテスト対象に入力し、クラッシュさせることを試みます。脆弱性が発見された場合は、ファザーと呼ばれるソフトウェアツールを使用して、潜在的な原因を特定することができます。ファズテストは、1989年にウィスコンシン大学のBarton Miller氏によって開発されました。
15:18:31 From Kazuki Higashiguchi to Everyone : http://pages.cs.wisc.edu/~bart/
15:18:38 From Yoichiro Shimizu to Everyone : https://ymotongpoo.hatenablog.com/entry/2020/12/19/225831
15:18:44 From Yoichiro Shimizu to Everyone : https://youtu.be/bbjEJ-lq2EY
15:19:44 From Takashi Matsuyuki to Everyone : golang/go#44551 (comment)
15:19:44 From Yoichiro Shimizu to Everyone : https://docs.google.com/presentation/d/1JymtbbDcMvmn_359v-TxmIpzLGrG3iYXG0Gg6RJduTI/edit#slide=id.g9b9ee6b788_0_449
15:20:29 From Yoichiro Shimizu to Everyone : https://future-architect.github.io/articles/20201211/
15:20:55 From Takashi Matsuyuki to Everyone : https://go.googlesource.com/proposal/+/master/design/draft-fuzzing.md
15:21:26 From Kazuki Higashiguchi to Everyone : Systems built with Go must be secure and resilient. Fuzzing can help with this, by allowing developers to identify and fix bugs, empowering them to improve the quality of their code. However, there is no standard way of fuzzing Go code today, and no out-of-the-box tooling or support. This proposal will create a unified fuzzing narrative which makes fuzzing a first class option for Go developers.
15:22:55 From Kazuki Higashiguchi to Everyone : > In Rust, cargo-fuzz allows for fuzzing of structured data in addition to raw bytes, allowing for even more flexibility with authoring fuzz targets.
15:23:11 From Kazuki Higashiguchi to Everyone : https://fitzgeraldnick.com/2020/01/16/better-support-for-fuzzing-structured-inputs-in-rust.html
15:24:00 From Kazuki Higashiguchi to Everyone : https://github.com/dvyukov/go-fuzz
15:25:02 From Kazuki Higashiguchi to Everyone : > It is possible that there are existing FuzzX functions in yyy_test.go
15:25:49 From Kazuki Higashiguchi to Everyone : https://ejje.weblio.jp/content/corpus
15:25:53 From Kazuki Higashiguchi to Everyone : > (文書などの)集成、集積、全集、(資料の)総体、集成資料、(人・動物の)死体
15:26:18 From Kazuki Higashiguchi to Everyone : https://chromium.googlesource.com/chromium/src/+/66.0.3359.158/testing/libfuzzer/efficient_fuzzer.md
15:26:25 From Kazuki Higashiguchi to Everyone : > Seed corpus is a set of valid and interesting inputs that serve as starting points for a fuzzer. If one is not provided, a fuzzer would have to guess these inputs from scratch, which can take an indefinite amount of time depending of the size of inputs.
15:26:42 From Kazuki Higashiguchi to Everyone : > ァザーの出発点となる、有効で興味深い入力のセットのことです。
15:27:18 From Kazuki Higashiguchi to Everyone : https://go.googlesource.com/proposal/+/master/design/draft-fuzzing.md#seed-corpus
15:27:21 From Kazuki Higashiguchi to Everyone : Seed corpus
15:29:31 From Yoichiro Shimizu to Everyone : Fuzzにわたすのは普通のテストコードみたいに書ける
15:32:38 From Yoichiro Shimizu to Everyone : https://go.googlesource.com/proposal/+/master/design/draft-fuzzing.md#custom-generators
15:32:55 From Kazuki Higashiguchi to Everyone : Fuzzingなくてつらいね事例 by とんぷーさん
15:32:56 From Kazuki Higashiguchi to Everyone : https://go.googlesource.com/go/+/refs/tags/go1.15.1/src/encoding/json/decode_test.go#409
15:33:04 From Yoichiro Shimizu to Everyone : カスタムジェネレータを使うと入力制御して制御できる
15:36:51 From Kazuki Higashiguchi to Everyone : https://old.reddit.com/r/golang/comments/hvpr96/design_draft_first_class_fuzzing/
15:39:36 From Takashi Matsuyuki to Everyone : > The arguments to f.Add(...) and the fuzzing arguments in the f.Fuzz function must be the same type within the target,
15:39:44 From Takashi Matsuyuki to Everyone : https://go.googlesource.com/proposal/+/master/design/draft-fuzzing.md#fuzz-target
15:39:48 From Takashi Matsuyuki to Everyone : まあそうだよねって内容
15:42:33 From Kazuki Higashiguchi to Everyone : > The seed corpus is the user-specified set of inputs to a fuzz target which will be run by default with go test. These should be composed of meaningful inputs to test the behavior of the package, as well as a set of regression inputs for any newly discovered bugs identified by the fuzzing engine. This set of inputs is also used to “seed” the corpus used by the fuzzing engine when mutating inputs to discover new code coverage. A good seed corpus can save the mutation engine a lot of work (for example adding a new key type to a key parsing function).
15:43:01 From Kazuki Higashiguchi to Everyone : ミューテーションエンジンの作業の軽減っていう意図が書いておりました
15:46:23 From Ren Ogaki to Everyone : テストケースの作り方のまとめ的な記事
15:46:24 From Ren Ogaki to Everyone : https://www.synopsys.com/blogs/software-security/fuzzing-test-cases-not-all-random/
15:48:26 From Kazuki Higashiguchi to Everyone : https://medium.com/a-journey-with-go/go-fuzz-testing-in-go-deb36abc971f
15:48:41 From Yoichiro Shimizu to Everyone : https://talks.golang.org/2015/dynamic-tools.slide#1
15:48:42 From Kazuki Higashiguchi to Everyone : https://www.youtube.com/watch?v=a9xrxRsIbSU&t=459s
15:49:36 From Kazuki Higashiguchi to Everyone : 読んでいた記事
15:49:37 From Kazuki Higashiguchi to Everyone : https://medium.com/a-journey-with-go/go-fuzz-testing-in-go-deb36abc971f
15:51:36 From Kazuki Higashiguchi to Everyone : https://deeeet.com/writing/2015/12/21/go-fuzz/
15:53:55 From Kazuki Higashiguchi to Everyone : http://www.jaist.ac.jp/~kshirai/lec/i223/11.pdf
15:56:10 From Kazuki Higashiguchi to Everyone : https://llvm.org/docs/LibFuzzer.html
15:56:24 From Kazuki Higashiguchi to Everyone : > a library for coverage-guided fuzz testing
15:56:57 From Kazuki Higashiguchi to Everyone : > LibFuzzer is in-process, coverage-guided, evolutionary fuzzing engine.
15:58:16 From Kazuki Higashiguchi to Everyone : > The fuzzer generates random mutations based around the sample inputs in the current corpus. If a mutation triggers execution of a previously-uncovered path in the code under test, then that mutation is saved to the corpus for future variations.
15:58:20 From Kazuki Higashiguchi to Everyone : ファザーは、現在のコーパスにあるサンプル入力に基づいて、ランダムな変異を生成します。もし、ある変異がテスト対象のコードで以前に発見されなかったパスを実行するきっかけとなった場合、その変異は将来のバリエーションのためにコーパスに保存されます。
15:58:31 From Kazuki Higashiguchi to Everyone : なるほど、だからVCSにcommitするべきなのか
15:59:17 From Kazuki Higashiguchi to Everyone : golang/go#44551 (comment)
15:59:21 From Kazuki Higashiguchi to Everyone : > AFL/libfuzzer really focus on iteration speed, but there are other approaches like symbolic execution which are slow, but generate new coverage (more or less) by definition on each iteration. Less fast million monkeys; more like applied model checking using heavy-weight SMT/SAT solvers. Most research, and some products, pair the two together. I know for a fact Mayhem and Mechanical Phish did this in the cyber grand challenge, for instance.
15:59:31 From Kazuki Higashiguchi to Everyone : libfuzzerだ
16:00:22 From Yoichiro Shimizu to Everyone : https://docs.google.com/presentation/d/1JymtbbDcMvmn_359v-TxmIpzLGrG3iYXG0Gg6RJduTI/edit#slide=id.ga06611cbef_0_1
16:00:28 From Yoichiro Shimizu to Everyone : https://future-architect.github.io/articles/20201211/
16:01:03 From Kazuki Higashiguchi to Everyone : AFL/libfuzzer: 繰り返しの速度に重点、シンボリック実行 symbolic execution はまた違うやりかた
16:01:11 From Kazuki Higashiguchi to Everyone : 様々なfuzz testがあるんだぁ
16:01:17 From Kazuki Higashiguchi to Everyone : めちゃ楽しいなこれは
16:01:54 From Kazuki Higashiguchi to Everyone : > using heavy-weight SMT/SAT solvers => symbolic execution

@hgsgtk
Copy link
Contributor Author

hgsgtk commented Apr 5, 2021

@hgsgtk 感想

fuzz test さまざまな方法があるとしってテンションが上った

AFL/libfuzzer: 繰り返しの速度に重点、シンボリック実行 symbolic execution はまた違うやりかた

golang/go#44551 (comment)

AFL/libfuzzer really focus on iteration speed, but there are other approaches like symbolic execution which are slow, but generate new coverage (more or less) by definition on each iteration. Less fast million monkeys; more like applied model checking using heavy-weight SMT/SAT solvers. Most research, and some products, pair the two together. I know for a fact Mayhem and Mechanical Phish did this in the cyber grand challenge, for instance.

libfuzzer

libfuzzer: https://llvm.org/docs/LibFuzzer.html

libFuzzer – a library for coverage-guided fuzz testing.

tutorial: https://github.com/google/fuzzing/blob/master/tutorial/libFuzzerTutorial.md

AFL

https://github.com/google/AFL

American Fuzzy Lop is a brute-force fuzzer coupled with an exceedingly simple but rock-solid instrumentation-guided genetic algorithm. It uses a modified form of edge coverage to effortlessly pick up subtle, local-scale changes to program control flow.

symbolic-execution-fuzzing

https://blog.code-intelligence.com/using-symbolic-execution-fuzzing#:~:text=Symbolic%20execution%20is%20a%20software,formulae)%20during%20the%20program%20execution.&text=Once%20a%20path%20terminates%20due,path%20condition%20for%20concrete%20values.

Symbolic execution is a software testing technique that substitutes the normal inputs into a program (e.g. numbers) through symbolic values (formulae) during the program execution.

@budougumi0617
Copy link
Contributor

@budougumi0617 サマリ&感想

お題: testing: add fuzz test support

golang/go#44551

以下の理由よりfuzz testについていろいろググってみた。

  • まだ実装コードはない
  • そもそもfuzz testについて明るくない

fuzz test

ファジングについてはとんぷーさんのブログ記事・登壇資料などを参考にした。

fuzz testではひたすら自動生成した入力を与えて、クラッシュするまでテストを繰り返す。

// クラッシュするかしないか、ではなく「特定の性質」を定義してアウトプットを検証するfuzz testの上位系をPBTというらしい

しかし、fuzz testはただの「ランダムテスト」ではない。fuzz testの入力は単純な自動生成ではなく、エンジンを利用して作成される。
プロポーザルで作成を予定されているエンジンはcoverage-guided fuzzing engine。

https://go.googlesource.com/proposal/+/master/design/draft-fuzzing.md#fuzzing-engine-and-mutator

A new coverage-guided fuzzing engine, written in Go, will be built. This fuzzing engine will be responsible for using compiler instrumentation to understand coverage information, generating test arguments with a mutator, and maintaining the corpus.

つまり、fuzz testを繰り返すなかでテスト対象のカバレッジを計測しながら有用なテストケースを生成する。作成された有用なテストケースは「コーパス」として保存される。
新しく作るテストは既存のコーパスを元に生成されるので、コーパスが蓄積されればされるほど質のよいテストケースが生成される(と思われる)。
コーパスがあれば「強くてnew game状態でfuzz testを開始」できるので、VCSにコミットしておくのが望ましい。

感想

思ったより仕組みが奥深くて多分コードからいきなり読んでも何しているのかわからなそうだった。
mutation engineの概念を知り、コードを理解するだけでもかなり難しそうなイメージ。
なので、まずfuzzingの概要についてざっくり理解するアプローチができてよかった。
あまりfuzzingしている話を聞いたことがないけれど、これからのデファクトになるんだろうか。かなりマシンパワーと実行時間を必要とする気がするので、CIで夜中実行しておいて、朝クラッシュしていたら直してみる、みたいなことになるのかな?

// ランニングテストは柴田さんが昔からやっているので、それをイメージした。

余談

個人的には、最近読んでいる英語独習法という本でもコーパスを用いた知識の構築を説明していたので、予想外のところでconnect the dotsして面白かった。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants