22
An efficient slab encryption using extended SASL protocol Ruo ANDO Network Security Institute, National Institute of Information and Communications Technology 暗暗暗暗暗暗暗暗暗暗暗暗暗暗暗暗暗 2016 暗 1 暗 22 暗 ( 暗 ) 4C2 シシシシシシシシシシ 11:00--12:40

SCIS 2016: An efficient slab encryption using extended SASL protocol

Embed Size (px)

Citation preview

An efficient slab encryption using extended SASL

protocol

Ruo ANDO Network Security Institute,

National Institute of Information and Communications Technology

暗号と情報セキュリティシンポジウム2016年 1月 22日 (金 )  4C2 システムセキュリティ11:00--12:40 

概要 (SASL プロトコル拡張による Slab 暗号化)■ 最近、クラウド上のデータ処理の大規模化、高速化のために Memcached をはじめとしたキャッシュシステムが導入されているがこのキャッシュレイヤーを対象として攻撃が顕在化している。■NoSQL の普及に伴い、キャッシュレイヤーを通過するデータに、購買履歴などの個人情報が対象となることが多くなっている。■ 本論文では Slab Allocator で処理されるデータの保護のために、 SASL プロトコルを拡張化した暗号化方式を提案する。■SASL は本来エンドポイントのセキュリティを確保する方式であり、また、 Slab Allocator は OS のmalloc() / free() を直接利用しない独自のメモリ管理を行うため、提案手法ではライブラリ不依存でmemcached 内のみの修正でセキュリティプロトコルを拡張する方式を実装した。■ プロトコルは SASL ( Simple Authentication Security Layer )を扱い、許容可能なシステム負荷で運用が可能なストリーム暗号を組み込むことを成功した。(CPU負荷率で1~2%、メモリ利用率で1%以下)

Memcached (very large hash table with LRU)Memcached. Memcached adopts LRU for purging older data for subsequent insertion in the case of full table entries. Not surprisingly, the size of hash table becomes very large which results in that available memory over all the servers is limited. For countermeasures, hash table can be stretched to many gigabytes.

一貫性+可用性 ( ファイルシステム暗号化)一般的な関係データベース、 LDAP 、 NFS などは一貫性と可用性しか成立しない。 2 相コミットはこれに該当。ネットワーク分断が発生した際は、片方を切り捨てる。 Amazon Relational Database Service の Multi-AZ 配備も該当。可用性+分断耐性 ( DNSSec, CryptoDB)可用性+分断耐性のケースでも、一定時間以内に一貫性を成立させるシステム(結果整合性 ; eventually consistent )は構築可能である。 Amazon SimpleDB や Apache Cassandra などがこの方式を採用している。 DNS や HTTP キャッシュなども該当。 3 種の中ではこの方式が最も障害に強い。一貫性+分断耐性 ( ??? )Apache HBase などが採用している。 HBase の場合、単一障害点がある上、ネットワーク分断に対して整合性をとる仕組みが不完全であるため、可用性が犠牲となっている。

CP(一貫性・分断耐性)型に適した暗号方式については殆ど検討されていない。

http://www.erlang-factory.com/upload/presentations/330/riak-efl.pdf

背景:キャッシュレイヤーでのセキュリティと暗号プロトコル拡張■ 近年、クラウドコンピューティングの普及などにより、分散システムを高速化するキャッシュレイヤーの導入が盛んに行われている。■ しかしながら、キャッシュは局所性を利用した性能向上を主眼としており、攻撃解析の対象になりやすく、キャッシュ上に置かれるデータの安全性については殆ど検討されていないのが現状である。■ また、キャッシュと本体システムの通信はコールバック関数を多用した非同期方式をとるため、システム的な見地から、暗号プロトコルをどのように組み合わせるか、またかは拡張するかについては殆ど考慮されないまま放置されている。CVE-2013-7291 : memcached before 1.4.17, when running in verbose mode, allows remote attackers to cause a denial of service (crash) via a request that triggers an "unbounded key print" during logging, related to an issue that was "quickly grepped out of the source tree," a different vulnerability than CVE-2013-0179 and CVE-2013-7290.

Black Hat Usa 2014 - Appsec: The New Page Of Injections Book Memcached Injections

背景: Third party sorftware security■ 現在、暗号化は Third-party software(第三者によるオープンスース)に依存している。Third-party software は高度に抽象化、カプセル化、そして汎用化されており、その結果、一度脆弱性が発見されると、クラスブレイク効果により被害が多数のシステムに渡り、利用者による対策が不可能なことから被害が深刻化する。■Third-party software 内の暗号プロトコルだけではなく、 Third-party software が組み込まれた通信システムのプロトコルの状態範囲を包括的把握し、適切な箇所に暗号化を施して情報の秘匿性を確保す必要が生じている。POODLE: SSLv3.0 脆弱性 (CVE-2014-3566) 「Red Hat Product Security チームは、 SSLv3 プロトコルの脆弱性 ( 通称 POODLE) について認識しており、 CVE-2014-3566 でこの問題に対応しています。 SSLv3 のすべての実装がこの問題の影響を受けます .」https://access.redhat.com/ja/node/1232403

本論文では、ライブラリ・OSを修正せずに SASL プロトコルを拡張し、 SLAB の暗号化を行う手法を提案する。

Cache security■Cross VM 攻撃• Thomas Ristenpart, Eran Tromer, Hovav Shacham, and Stefan Savage, "Hey, You, Get Off of My Cloud!

Exploring Information Leakage in Third-Party Compute Clouds, In Proceedings of CCS 2009, pages 199–212. ACM Press, Nov. 2009

• Set Associative Cache を共有している「悪意のある VM」が連続してキャッシュを叩く。キャッシュの 反応が遅れると他の VM でアクセスしていることが判る。限定した環境だが鍵漏洩の恐れがある。■Memached のセキュリティ(設定不備など)• Marco Slaviero, Lifting the Fog, BlckHat 2010   https://www.blackhat.com/html/bh-us-10/bh-us-10-

briefings.htmlエンドポイントの対策(SASL)はあるが、通信路が保護されてない、サーバの稼動位置がセキュアではない。■Memached のセキュリティ(SQLインジェクションに似た脆弱性がある)Ivan Novikov, "The New Page of Injections Book: Memcached Injections", BlachHat USA 2014

現在、これらの問題についてのシステムレベルでの根本的な対応策は提示されてない。情報漏洩を防ぐためにはプロトコルを拡張して暗号化して守る必要がある。

Slab allocator問題点1  inline 関数のインターセプトの非現実性Slab Allocator はアプリケーション特有に実装されるため、カーネル側の処理 (malloc, free のフックなど)で暗号化するには現実的ではない。

Hash Table

88 bytes 88 bytes

88 bytes

Slab Class 1

112 bytes 112 bytes

112 bytes

Slab Class 2

144 bytes 144 bytes

144 bytes

Slab Class 3

n bytes n bytes

n bytes

Slab Class n / m

Class ID

Table

#0  do_slabs_newslab (id=id@entry=1) at slabs.c:196#1  0x0000000000411ef7 in do_slabs_alloc (id=1, size=82) at slabs.c:235#2  slabs_alloc (size=size@entry=82, id=id@entry=1) at slabs.c:404#3  0x0000000000412c19 in do_item_alloc (key=0x7fffec0390a4 "keystring",nkey=9, flags=<optimized out>, exptime=0, nbytes=10,    cur_hv=0) at items.c:188

Key-Value“keystring”

問題点2 OS primitive との semantic gapSlab class 1-n は起動時に初期化され、アプリケーション固有に処理される。そのため、 OSのプリミティブ関数 (malloc, free) の操作と、 Slab Allocator の処理との間に semantic gap が生じる。

Memcached の利用例と暗号レイヤーDatabase

MySQL

http server

Memcached

Memcached

Hypervisor

SASLc

MemcachedSASLc

SASLc

https

SASLd

MemcachedCVE-2013-7291Verbose mode

Black Hat Usa 2014The New Page Of Injections Book

Confidential items (cache)

Id, SHA1(passwd)

VENOM: QEMU vulnerability (CVE-

2015-3456)

エンドポイント(SASL) と通信路(https) を暗号化する方法はあるが、その間が抜けている。

POODLE: SSLv3 脆弱性 (CVE-2014-3566)

Slab 暗号化でのプロトコル拡張制約• ライブラリは変更できない。•そのままでは SASL は使えない•カーネルなど、低レベルのレイヤからの変更は不可能。→ Memcached 内の変更のみで Slab 暗号化を行う必要がある。

Memcached

SASL

Slab Allocator

Memory System

https

Malloc / Free

Application Layer

Library Layer

Kernel Layer

連動(変数共有)不可能

フック不可能

drive_machine

event_handler

conn_new

update_eventitem_remove

Item_free

try_read_command

complete_nreadout_string

try_read_network

complete_nread_binary

store_item

get_item

Basic State Transition of Memcached

item_link

Binary Protocol Substates

trigger

Request handler

Commit

Binary protocolstates

ASYNCASYNC

ASYNC

外部入力からの状態遷移

Encryption Phase はRequest Handler (赤)に組み込む

consequence

内部更新からの状態遷移

Extension Target: Memcached and Binary Protocolenum bin_substates { bin_no_state, bin_reading_set_header, bin_reading_cas_header, bin_read_set_value, bin_reading_get_key, bin_reading_stat, bin_reading_del_header, bin_reading_incr_header, bin_read_flush_exptime, bin_reading_sasl_auth, bin_reading_sasl_auth_data, bin_reading_touch_key,};header.h

drive_machine

event_handler update_event

complete_nread

nread_binary store_item

item_link

nread_ascii

Dispatch_event

SASL mechs

nread_binaryKey

Excahnge

Key Excahnge

Substate to be modified

Substate to be appdended

①Entering binary protocol

②Enterint SASL protocol

プロトコル拡張のポイント① 認証手順が入るとバイナリプロトコルにスイッチし、テキストプロトコルには戻らない。② バイナリプロトコルとSASLプロトコルの入り口となる状態を見つけ、修正・拡張する。

SASL_Client_Start

Check Return

Get Requested Data

SASL Client StepFree SASL Context

Send Selected SASL Mechanism and

Data

Get Selected SASL Mechanism and

Data

Call Server Start

Send LIST MECHs

Request LIST MECHs

Free SASL Context

Server Action

Client Action

Simple Security Authentication Layer

Loop of Third-party Software:サーバライブラリとクライアントで共有される手順(拡張・修正不可能)

SASL protocol header (RFC 4422)

#0 process_bin_complete_sasl_auth (c=0x7ffff00261c0) at memcached.c:1727#1 0x0000000000408e85 in complete_nread_binary (c=0x7ffff00261c0) at memcached.c:2265#2 0x000000000040b7f1 in complete_nread (fd=<value optimized out>, which=<value optimized out>, arg=0x7ffff00261c0) at memcached.c:2296#3 drive_machine (fd=<value optimized out>, which=<value optimized out>, arg=0x7ffff00261c0) at memcached.c:3979#4 event_handler (fd=<value optimized out>, which=<value optimized out>, arg=0x7ffff00261c0) at memcached.c:4193#5 0x00007ffff7dd6b44 in event_base_loop () from /usr/lib64/libevent-1.4.so.2#6 0x00000000004109ed in worker_libevent (arg=0x62ee50) at thread.c:385#7 0x00000034496079d1 in start_thread () from /lib64/libpthread.so.0#8 0x0000003448ee8b6d in clone () from /lib64/libc.so.6

0x7fffe80263ed: "root"0x7fffe80263f2: "root"0x7fffe80263f7: "memcached"0x7fffe8026401: ""0x7fffe8026402: ""Continuing.この部分を援用してストリーム暗号の鍵交換に使う。

drive_machine

event_handler

conn_new

update_event

try_read_command

complete_nread

complete_nread_binary

SASL and Memcached (Event handler-> drive_machine -> binary protocol -> SASL )

SASL_LIST_DATA

SASL_AUTH_STEP

SASL_LIST_MECHs

store_item

Binary Protocol Substates

Reentrant TriggerState

Entering State

Returning State Loop of client-to-server-library

Event_handler ( 非同期)Driver_machine ( 核ステートマシン)Complete_nread ( プロトコルスイッチ)

drive_machine

event_handler

conn_new

update_event

try_read_command

complete_nread

complete_nread_binary

RC4_key_exchange

bin_list_sasl_mechs

Decryption of user/passwd

Shared varibaleRC4 key

Extension 1: Inserting new state (Key Exchange)

SASL Loop

Binary Protocol Transitions

Entering state 2(SASL protocol)

Entering state 1(Binary protocol) SASL loop に入る前にプロトコル種別と鍵を確認する

drive_machine

event_handler

conn_new

update_event

try_read_command

complete_nread

complete_nread_binary

Handling ID and Password

SASL_LIST_DATA

SASL_AUTH_STEP

SASL_LIST_MECHs

store_item

Binary Protocol Substates

Reentrant TriggerState

Entering State

Returning State

Loop of Third-party Software修正不可能

プロトコル拡張のポイント① システムが Third-party software(SASLライブラリ)のループに入ると、サーバソフトウェアでの修正は不可能になる。② ループに入る前の条件分岐( switch-case) の直前の case の関数を修正する。

Extention 2:Inserting new state (ID and password)

#0 process_bin_complete_sasl_auth (c=0x7ffff00261c0) at memcached.c:1727#1 0x0000000000408e85 in complete_nread_binary (c=0x7ffff00261c0) at memcached.c:2265#2 0x000000000040b7f1 in complete_nread (fd=<value optimized out>, which=<value optimized out>, arg=0x7ffff00261c0) at memcached.c:2296#3 drive_machine (fd=<value optimized out>, which=<value optimized out>, arg=0x7ffff00261c0) at memcached.c:3979#4 event_handler (fd=<value optimized out>, which=<value optimized out>, arg=0x7ffff00261c0) at memcached.c:4193#5 0x00007ffff7dd6b44 in event_base_loop () from /usr/lib64/libevent-1.4.so.2#6 0x00000000004109ed in worker_libevent (arg=0x62ee50) at thread.c:385#7 0x00000034496079d1 in start_thread () from /lib64/libpthread.so.0#8 0x0000003448ee8b6d in clone () from /lib64/libc.so.6

0x7fffe80263ed: "root"0x7fffe80263f2: "root"0x7fffe80263f7: "memcached"0x7fffe8026401: ""0x7fffe8026402: ""Continuing.

drive_machine

complete_nread_binary(c)

process_bin_complete_sasl_auth(c)

event_handler

#0 process_bin_complete_sasl_auth (c=0x7ffff00261c0) at memcached.c:1727#1 0x0000000000408e85 in complete_nread_binary (c=0x7ffff00261c0) at memcached.c:2265どちらの状態を修正しても暗号化は可能。システム負荷率などの副作用については調査中

修正候補の状態*2

do_store_item

do_item_get_nocheck

do_item_get_nodeleted

do_item_remove

do_store_replace

do_item_link

accoc_insert

do_item_update

Item_link_q

assoc_find

hash

item_free

item_unlink

Item_delete_lock_over

complete_nread_binary

store_item

drive_machinecomplete_nread

Handling key-value itemsDelete

Store

Prepare

Extention 3:Inserting new state (Items Encyrption) #0 do_store_item (it=0x7ffff7f07f70, comm=2, c=0x6b6170, hv=238646833)

at memcached.c:2307#1 0x00000000004147a5 in store_item (item=0x7ffff7f07f70, comm=2, c=0x6b6170) at thread.c:607#2 0x0000000000405ad1 in complete_update_bin (c=0x6b6170) at memcached.c:1170#3 0x00000000004087bf in complete_nread_binary (c=0x6b6170) atmemcached.c:2241#4 0x000000000040893d in complete_nread (c=0x6b6170) at memcached.c:2296#5 0x000000000040db1a in drive_machine (c=0x6b6170) at memcached.c:3979#6 0x000000000040e604 in event_handler (fd=34, which=2, arg=0x6b6170)at memcached.c:4193#7 0x00007ffff7ba6254 in event_base_loop () from /usr/lib/x86_64-linux-gnu/libevent-2.0.so.5of #8 0x0000000000413fbd in worker_libevent (arg=0x636af0) at thread.c:385#9 0x00007ffff755cb50 in start_thread () from /lib/x86_64-linux-gnu/libpthread.so.0#10 0x00007ffff72a695d in clone () from /lib/x86_64-linux-gnu/libc.so.6#11 0x0000000000000000 in ?? ()$5 = 0x2 <Address 0x2 out of bounds>

2308 item *old_it = do_item_get(key, it->nkey, hv);$6 = 0x7ffff7f07fa8 "abcI 0 6\r\nvalue2\r\nroot"Continuing.

do_store_itemdo_item_get_n

ocheck

do_item_get_nodeleted

complete_nread_binary

store_item

complete_nread# global -t itemitem memcached.h 353

struct conn

struct item

ExperimentWe compiled our sys- tem on Linux 2.6.32-358.18.1.el6.x86_64. Proposed system is hosted on Intel Xeon E312xx with 2.5 GHZ clock.

1 2 3 4 5 6 7 8 9 1011 12131415 161718 192021 2223 242526 27282930 313233 343536 373839 404142728000

729000

730000

731000

732000

733000

734000

735000

736000 memory 利用率 (per sec)

encryptionno encryption no encryption

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 2941.5

42

42.5

43

43.5

44

44.5

45

45.5

46

46.5

CPU 負荷率( idle time, per sec)

encyrption no encyption

Memcached (very large hash table with SLAB一貫性+可用性 ( ファイルシステム暗号化)一般的な関係データベース、 LDAP 、 NFS などは一貫性と可用性しか成立しない。 2 相コミットはこれに該当。ネットワーク分断が発生した際は、片方を切り捨てる。 Amazon Relational Database Service の Multi-AZ 配備も該当。可用性+分断耐性 ( DNSSec, CryptoDB)可用性+分断耐性のケースでも、一定時間以内に一貫性を成立させるシステム(結果整合性 ; eventually consistent )は構築可能である。 Amazon SimpleDB や Apache Cassandra などがこの方式を採用している。 DNS や HTTP キャッシュなども該当。 3 種の中ではこの方式が最も障害に強い。一貫性+分断耐性 ( ??? )Apache HBase などが採用している。 HBase の場合、単一障害点がある上、ネットワーク分断に対して整合性をとる仕組みが不完全であるため、可用性が犠牲となっている。

CP(一貫性・分断耐性)型に適した暗号方式については殆ど検討されていない。

http://www.erlang-factory.com/upload/presentations/330/riak-efl.pdf

本論文の結論(実装面から):ハッシュテーブルの状態遷移を解析し、 Key-Value に SLAB ID が割り当てられる直前に暗号化する文字列のポインタを視点として chunk の長さの分だけストリーム暗号をかけることで、システム負荷またプログラム修正量ともに効率的な処理を達成できる。

まとめ (SASL プロトコル拡張による Slab 暗号化)■ 最近、クラウド上のデータ処理の大規模化、高速化のために Memcached をはじめとしたキャッシュシステムが導入されているがこのキャッシュレイヤーを対象として攻撃が顕在化している。■NoSQL の普及に伴い、キャッシュレイヤーを通過するデータに、購買履歴などの個人情報が対象となることが多くなっている。■ 本論文では Slab Allocator で処理されるデータの保護のために、 SASL プロトコルを拡張化した暗号化方式を提案する。■SASL は本来エンドポイントのセキュリティを確保する方式であり、また、 Slab Allocator は OS のmalloc() / free() を直接利用しない独自のメモリ管理を行うため、提案手法ではライブラリ不依存でmemcached 内のみの修正でセキュリティプロトコルを拡張する方式を実装した。■ プロトコルは SASL ( Simple Authentication Security Layer )を扱い、許容可能なシステム負荷で運用が可能なストリーム暗号を組み込むことを成功した。(CPU負荷率で1~2%、メモリ利用率で1%以下)