Li Weigang File-System and Block-Layer Encryption Theory Practice and Improvement
Li Weigang File-System and Block-Layer Encryption Theory Practice and Improvement
Weigang Li
Wenqian Yu
2
2017 Storage Developer Conference. © Intel All Rights Reserved.
Data at-rest Encryption
Application-level • Flexible to define security strategy, algorithm, key
Database
Flexibility
management, etc.
Encryption
• Application dependent
eCryptfs EFS
• File based key management
File System • Transparent to application
Encryption • Support multiple users / keys
EXT4 ZFS
Hardware
Self Encrypting Drive • One Data Encryption Key (DEK) to encrypt the
(SED) whole disk, protected by Authentication Key (AK).
• Hardware based, secure key is kept in hard-drive
3
2017 Storage Developer Conference. © Intel All Rights Reserved.
Data at-rest Encryption
Application-level • Flexible to define security strategy, algorithm, key
Database
Flexibility
management, etc.
Encryption
• Application dependent
Hardware
Self-encrypting Drive • One Data Encryption Key (DEK) to encrypt the
(SED) whole disk, protected by Authentication Key (AK).
• Hardware based, secure key is kept in hard-drive
4
2017 Storage Developer Conference. © Intel All Rights Reserved.
File System Encryption
5
2017 Storage Developer Conference. © Intel All Rights Reserved.
File system encryption
Application File-system level encryption can be
implemented at different level:
Fuse-based FS in User space
syscalls Fuse Enc/Dec
user Layered FS on top of native FS
kernel
In native FS, better performance
File System Layered
Enc/Dec
Transparent to application.
Per-file encryption and key management.
Enc/Dec Native
hardware
6
2017 Storage Developer Conference. © Intel All Rights Reserved.
eCryptfs $ mount -t ecryptfs /secret /secret
Select key type to use for newly created files:
1) tspi
eCryptfs (upper)
2) openssl IV
IV
3) passphrase
eCryptfs = Enterprise 4) pkcs11-helper
(page
(pagebased)
based)
Selection: 3
Cryptographic Filesystem. Passphrase: xxx
Select cipher: xxx R
Layered file system. 1) aes: blocksize = 16; min keysize = 16; max keysize = 32
2) blowfish: blocksize = 8; min keysize = 16; max keysize = 56 N FEK Plaintext
3) des3_ede: blocksize = 8; min keysize = 24; max keysize = 24 G Page
In Linux kernel since version 4) twofish: blocksize = 16; min keysize = 16; max keysize = 32
5) cast6: blocksize = 16; min keysize = 16; max keysize = 32 Extent
2.6.19. 6) cast5: blocksize = 8; min keysize = 5; max keysize = 16
Selection [aes]: 1
Mount eCryptfs on top of a Select key bytes:
1) 16 Per page encryption
directory to protect it. 2) 32
3) 24
Un-mount eCryptfs, the files in Selection [16]: 1
Enable plaintext passthrough (y/n) [n]: Enc Enc
lower FS are encrypted and Enable filename encryption (y/n) [n]:
Attempting to mount with the following options:
un-readable. ecryptfs_unlink_sigs
ecryptfs_key_bytes=16
ecryptfs_cipher=aes
The Encrypted FEK (EFEK) is ecryptfs_sig=aa20c2d38cf280d5 FEKEK
Mounted eCryptfs
stored in the lower FS. auth-tok
EFEK Ciphertext
keyring Page
KDF
key source
Native FS (lower)
Ref: http://ecryptfs.sourceforge.net/ecryptfs.pdf
7
2017 Storage Developer Conference. © Intel All Rights Reserved.
EFS
EFS = Encrypting File
System
Filter driver layered on
top of NTFS
Source: https://technet.microsoft.com/library/bb457116.aspx#EJAA
8
2017 Storage Developer Conference. © Intel All Rights Reserved.
EFS (Cont.) Plaintext
Encryption
Combination of public key RNG FEK
(RSA) and symmetric key
encryption (3DES, AES).
Ciphertext
FEK is protected by user’s RSA
pub-key
public key. Encryption
ENC
EFEK is decrypted by user’s EFEK
9
2017 Storage Developer Conference. © Intel All Rights Reserved.
EXT4 encryption
$ mkfs -t ext4 /dev/nvme1n1
RNG $ tune2fs -O encrypt /dev/nvme1n1
IV (page based)
$ mount /dev/nvme1n1 /mnt/ext4
Plaintext $ e4crypt add_key /mnt/ext4
Page Enter passphrase (echo disabled): xxx
FEK
inode Key with descriptor [775a2062517e439c] applied to /mnt/ext4.
nonce $ keyctl list @s
2 keys in keyring:
setkey
453787240: --alswrv 0 65534 keyring: _uid.0
Enc 1024073693: --alsw-v 0 0 logon: ext4:775a2062517e439c
Enc Ciphertext
Page
In Linux kernel since version 4.1.
Per-directory Master key.
Master
key inode Per-file encryption key (FEK, derived
nonce
Key-ring from master key and nonce).
On-disk
Support AES-256-XTS.
10
2017 Storage Developer Conference. © Intel All Rights Reserved.
ZOL encryption
$ zpool create -o ashift=13 testpool /dev/..
$ zfs create -o encryption=aes-128-ccm
IV testpool/tank
R Enter passphrase for 'tank': xxx
N Salt K Plaintext Enter again: xxx
G Block $ zfs get all testpool/tank
D FEK
Master F testpool/tank encryption aes-128-ccm local
key
IV
On-disk
11
2017 Storage Developer Conference. © Intel All Rights Reserved.
Block Layer Encryption
12
2017 Storage Developer Conference. © Intel All Rights Reserved.
Block layer encryption
Encrypt everything on the disk – one
Application key for whole disk (volume).
user Hides file and directory information,
syscalls
kernel such as name and size.
File system
OS-agnostic.
Block layer
Master
Encrypt Decrypt volume volume
key
hardware Wrapped
Enc
Disk key
Password
13
2017 Storage Developer Conference. © Intel All Rights Reserved.
dm-crypt $cryptsetup luksFormat -c aes-xts-plain64 -s 512 / dev/nvme3n1
$cryptsetup luksFormat -c aes-cbc-essiv:sha256 -s 256 /
dev/nvme3n1
Are you sure? (Type uppercase yes): YES
IV
(sectorbased)
(sector based) Enter passphrase: xxx
Plaintext Verify passphrase: xxx
Sector $cryptsetup open --type luks /dev/nvme3n1 dm-crypt-disk
R
Master (512B) Enter passphrase for /dev/nvme3n1: xxx
N
key $ lsblk
G
nvme3n1 259:1 0 745.2G 0 disk
└─dm-crypt-disk 253:3 0 745.2G 0 crypt
$ mkfs -t ext4 /dev/mapper/dm-crypt-disk
$ mount /dev/mapper/dm-crypt-disk /dm-crypt-disk/
setkey $ df -T
Enc Enc /dev/mapper/dm-crypt-disk ext4 1% /dm-crypt-disk
$ umount /dm-crypt-disk
$ cryptsetup close dm-crypt-disk
14
2017 Storage Developer Conference. © Intel All Rights Reserved.
Linux Kernel Crypto API
15
2017 Storage Developer Conference. © Intel All Rights Reserved.
Linux Kernel Crypto API
Linux Kernel sub-system $ cat /proc/crypto:
Data Transform
Symmetric key ciphers: skcipher eCryptfs Ext4 …
hardware acceleration.
DMA
Crypto Hardware
16
2017 Storage Developer Conference. © Intel All Rights Reserved.
Cryptographic Hardware
Acceleration
17
2017 Storage Developer Conference. © Intel All Rights Reserved.
Security Benchmarks
Intel® QuickAssist Technology 110
100
90
80
70
60
50
40
30
20
10
0
RSA 2K IPSec SSL
Decrypt 1 Forwarding 3 WebProxy 1
(kOps/s) (Gbps) (Gbps)
99
Hadoop run time
1. NGINX* and OpenSSL* connections/second. Conducted by Intel Applications Integration Team. Claim is actual performance measurement. reduced significantly
Intel® microprocessor. Processor: Intel® Xeon® processor Scalable family with C6xxB0 ES2
Performance tests use cores from a single CPU, Memory configuration:, DDR4–2400. Populated with 1 (16 GB) DIMM per channel, total of 6 DIMMs
Intel® QuickAssist Technology driver: QAT1.7.Upstream.L.0.8.0-37 Fedora* 22 (Kernel 4.2.7) BIOS:
87
PLYDCRB1.86B.0088.D09.1606011736
3. Cloudera* 5.4.2 with Snappy* Software vs. Intel® QuickAssist Technology hardware solution. Conducted by Intel Applications Integration Team.
Claim is actual performance measurement. Intel® Xeon® processor E5-2699 v4 (56 cores enabled) 256 GB DDR4 1.6 TB NVMe SSD 1 Intel® C6xxx-based card (24x)
10 Gbps CentOS* 6.7 w/ 2.6.32 kernel Cloudera* 5.4.2
QAT driver 0.9.1 Snappy* 1.1.2 (popular, fast compression codec)
One NameNode Eight DataNodes 10 Gbps network
2- 24 Core Intel(r) Xeon Scalable Platform -SP @1.8GHz, Single (UP) Processor configuration. Intel(r) C627 PCH with crypto acceleration capability (in x16 mode) Neon City platform. DDR4 2400MHz RDIMMs 6x16GB(total
96 GB), 6 Channels, 1 x Intel® Corporation Red Rock Canyon 100GbE Ethernet Switch in the x16 PCIe slot on Socket 0. 8 cache ways allocated for DDIO.
TERASORT TIME IN MINUTES LOWER IS BETTER
Intel® QuickAssist Technology integrates hardware acceleration for compute intensive workloads
Such as Bulk Cryptography, Public Key Exchange & Compression on Intel® Architecture Platforms
18
2017 Storage Developer Conference. © Intel All Rights Reserved.
Gen 2 Intel® QuickAssist Technology with Intel® Key Protection Technology (KPT)
z
LBG KPT
Intel® C627 Chipset
with Intel® QAT
Intel® QuickAssist
Intel®
Unwrapping (Decrypt)
Technology PTT Secure
Channel
Private Key (PK) Symmetric Wrapping Key (SWK) Wrapped Private Key (WPK)
19
2017 Storage Developer Conference. © Intel All Rights Reserved.
1
Cryptographic hardware program model
Computing Wait Wait IO Synchronous:
CPU For high performance “single
Offload Complete Offload Complete
stream” accelerator
Hardware
Simple program model
Engine
Engine
Engine
async mode
20
2017 Storage Developer Conference. © Intel All Rights Reserved.
Ext4 encryption with hardware accelerator
Extent Callback Synchronous call causes
Page n performance drop!
Sequential
wakeup
Page
21
2017 Storage Developer Conference. © Intel All Rights Reserved.
ZOL encryption with hardware accelerator
FIO Sequential Write to different number of NVMe drives
22
2017 Storage Developer Conference. © Intel All Rights Reserved.
Hardware offloading cost
Intel® QAT (DH8950) offloading cost
vs. Software cost (Intel® Xeon® E5-2699 v4 )
Offloading cost:
18000 Create request descriptor
16000
Interrupt handling, response
14000
polling
Cost (CPU Cycles)
12000
10000 Hardware* offloading cost is
8000
almost consistent: ~1600-1800
6000
4000
cycles.
2000 Choose right buffer size to
0
0 2000 4000 6000 8000 10000 12000 14000 16000 18000
get best performance with
Buffer Size(Bytes) reasonable offloading cost.
qat_aes_xts xts-aes-aesni Software cost varies by buffer
Intel® microprocessor. Processor: Intel® Xeon® E5-2699 v4 @ 2.20GHz @88 HT cores, Memory
configuration:, DDR4–2400. Populated with 1 (16 GB) DIMM per channel, total of 4 DIMMs.
size.
* Intel® QuickAssist Technology DH8950, in-tree kernel driver.
Benchmark code calls Kernel Crypto API (skcipher), compute average CPU time with 1000x API calls.
Cycle count as measured at Kernel Crypto (skcipher) API for AES-XTS algorithm.
23
2017 Storage Developer Conference. © Intel All Rights Reserved.
dm-crypt with hardware acceleration
dm-crypt Page
Page(4KB)
(4KB) dm-crypt calls Kernel Crypto API for data
(for each page) Sector
512B
Sector
512B
encryption, it can integrate with a
iv iv hardware accelerator seamlessly.
When 8 sectors
all done
Sector
asynchronous call: sending 8x requests
512B
for one 4KB page in-parallel, no wait.
iv
But: offloading cost is high -
x8 x8
Encrypting a 4KB page 8x
API call Callback
Page
encryption requests.
Page(4KB)
(4KB)
Encrypting 1MB data 2048x
Kernel Crypto API Sector Sector encryption requests.
512B 512B
Driver
Sector
Submit 512B
request x8 Callback x8
24
2017 Storage Developer Conference. © Intel All Rights Reserved.
dm-crypt optimization Encrypt 8 sectors (sg_list) in a single call.
Offloading cost is reduced greatly.
Page Kernel Crypto API or accelerator hardware to
dm-crypt Page(4KB)
(4KB)
compute IV for each sector.
(for each page) Sector
512B
Sector
iv 512B Throughput (MB/s)
iv 900
Sector
512B
sg_list 800
iv 700
600
API call x1 Callback x1
500
400
Page 300
Page(4KB)
(4KB)
200
Kernel Crypto API
100
Sector Sector
Driver 512B 512B 0
w/o optimization with optimization
Submit Sector dd if=/dev/zero of=/dev/mapper/dm-c bs=1M count=10000 oflag=sync
512B
request x1 Callback x1 Note: experimental result, patch is not in upstream kernel yet.
Intel® microprocessor. Processor: Intel® Xeon® E5-2699 v4 @ 2.20GHz @88 HT cores, Memory configuration:, DDR4–2400. Populated
with 1 (16 GB) DIMM per channel, total of 4 DIMMs. 1X P3700 NVMe. Intel® QuickAssist Technology DH8950, in-tree driver in kernel
4.12
Accelerator Submit BIO
25
2017 Storage Developer Conference. © Intel All Rights Reserved.
Key Management
26
2017 Storage Developer Conference. © Intel All Rights Reserved.
Key management – keyring
keyctl
In-kernel key management and
user
retention facility:
kernel
http://man7.org/linux/man-
pages/man7/keyrings.7.html
keyring
request key
setkey
Kernel
Linux Kernel Crypto API
sub-system
27
2017 Storage Developer Conference. © Intel All Rights Reserved.
Key management - LUKS
# cryptsetup luksDump /dev/nvme3n1
LUKS header information for /dev/nvme3n1
Version: 1
Cipher name: aes
Master Disk Format Cipher mode: xts-plain64
Hash spec: sha1
key Payload offset: 4096
slot#0 MK bits:
MK digest:
512
ed 36 e3 09 00 72 ea ba 24 04 6e 11 7e 69 1a 87 5a d1 32 57
MK salt: bc 41 51 8e e0 90 65 20 70 6d ef 2f 3f 80 06 a7…
slot#2 MK iterations: 48000
UUID: 0f6c5194-b299-4f3e-9f54-17dc67a62f04
Key Slot 0: ENABLED
Iterations: 192480
Salt: 62 4b 4d 54 b1 d5 0c 44 c2 a9 a0 d3 03 36 59 78…
Key material offset: 8
slot#7 AF stripes:
Key Slot 1: DISABLED
4000
28
2017 Storage Developer Conference. © Intel All Rights Reserved.
Memory-based key management
If data encryption / decryption is done in
Enc / Dec host CPU, keys (FEK, master key,
Library private key…) have to be exposed in
memory
Cold boot (memory dump) attack
CPU
Heartbleed-like attack
Memory Possible solution
SGX Enclave
Total Memory Encryption (TME)
Debug-register-based or cache-
based key storage
29
2017 Storage Developer Conference. © Intel All Rights Reserved.
HSM-based key management
Memory
HSM = Hardware Security Module Crypto
Library
KEK = Key Encryption Key Wrapped-key
30
2017 Storage Developer Conference. © Intel All Rights Reserved.
Summary
File-system and full-disk encryption are important software
technologies to implement data-at-rest encryption solution.
Data encryption at different layer has its own pros and cons.
Data encryption software shall consider how to best utilize the
hardware crypto accelerator underneath in order to get best
performance, e.g., buffer size, sync vs. async, offloading cost, etc.
Besides data encryption, secure-key protection is even more
important for persistent data storage.
Hardware based key management is a possible solution to protect
key leakage.
31
2017 Storage Developer Conference. © Intel All Rights Reserved.
References
http://ecryptfs.sourceforge.net/ecryptfs.pdf
https://zfs.datto.com/slides/caputi.pdf
https://technet.microsoft.com/library/bb457116.aspx#EJAA
http://kernsec.org/files/lss2014/Halcrow_EXT4_Encryption.pdf
www.intel.com/content/www/us/en/embedded/technology/quickassist/overview.html
32
2017 Storage Developer Conference. © Intel All Rights Reserved.