Linux TLS
Linux TLS
2025/01/19 Pumpkin 🎃
1
Outline
• Overview
• Vulnerability
2
Overview
3
Overview
4
https://blog.salrashid.dev/articles/2022/kernel_tls/
Overview
tcp_prot
IPPROTO_TCP Protocol
(struct proto)
inet_stream_ops
SOCK_STREAM Type
(struct proto_ops)
inet_family_ops
AF_INET Family
(struct net_proto_family)
5
Overview
tcp_prot
IPPROTO_TCP Protocol
(struct proto)
inet_stream_ops
SOCK_STREAM Type
(struct proto_ops)
inet_family_ops
AF_INET Family
(struct net_proto_family)
6
Overview
tls_prots
tcp_prot
IPPROTO_TCP Protocol
(struct proto)
inet_stream_ops
tls_proto_ops
SOCK_STREAM Type
(struct proto_ops)
inet_family_ops
AF_INET Family
(struct net_proto_family)
7
sk_proto tcp_prot
tx_lock
sk
struct tls_context
(ULP) tls_prots [TLS_NUM_PROTS] [TLS_NUM_CONFIG] [TLS_NUM_CONFIG]
icsk->icsk_ulp_data TX RX
TLS_BASE TLS_BASE
sk_prot
IPv4
sk_socket
X TLS_SW X TLS_SW
struct sock
(Protocol) IPv6
TLS_HW TLS_HW
sk
struct socket
(Type)
8
Overview
cipher type AES_GCM_128
TLS vers. TLS_1_2
struct KEY 0123…DEF
tls_sw_context_tx IV 12345678
SALT SALT
… …
struct tls_context
cipher type …
TLS vers. …
KEY …
struct
IV …
tls_sw_context_rx
SALT …
… …
9
Overview
10
Overview
Send packets
Encrypt packets
on TCP
TLS socket
Receive packets
Decrypt packets
on TCP
11
Overview
Send packets
Encrypt packets
on TCP
TLS socket
Receive packets
Decrypt packets
on TCP
12
Overview
13
Overview
14
Overview
15
Overview
• Algorithm
• Implementation of a speci c cryptographic operation, such as AES,
SHA-256, or HMAC
• Template
• Constructing more complex cryptographic transformations by combining or
layering simpler algorithms
16
fi
Overview
• Instance
• Instantiation of a cryptographic template, where speci c algorithms and
parameters have been con gured
• Spawn
• Create a linkage or dependency between cryptographic instances and
algorithms
17
fi
fi
Built-in Created
Spawn
Built-in Created
A
ctr templ gcm templ
Instance instance instance
cra_name[ ] “gcm(aes)”
cra_driver_name[ ] “gcm_base(ctr(aes-
generic),ghash-generic)”
cra_list
instances
cra_ ags
crypto_gcm_tmpls
(struct crypto_template)
list
20
fl
Overview
21
fi
Thread-A Thread-B
Find “gcm(aes)”
aes
md5
Global variable
22
Thread-A Thread-B
Not found
Find “gcm(aes)”
aes
md5
Global variable
23
Thread-A Thread-B
Find “gcm(aes)”
aes
Global variable
24
Thread-A Thread-B
Find “gcm(aes)”
aes
Dispatch probing
Global variable
25
Thread-A Thread-B
Find “gcm(aes)”
aes
…
1. Template name = “gcm”
2. Cipher name = “aes” “cryptomgr_probe”
26 Global variable
Thread-A Thread-B
Find “gcm(aes)”
aes
…
1. Template name = “gcm”
2. Cipher name = “aes” “cryptomgr_probe”
gcm(aes)
Dispatch probing Find template
seqiv
Global variable
gcm
27 Global variable
Overview
1 packet
Send packets
Encrypt packets
on TCP
TLS socket
28
Overview
2 packets
Send packets
Encrypt packets
on TCP
29
Overview
N packets
Send packets
Encrypt packets
on TCP
Send packets
Encrypt packets
on TCP
30
Overview
CR
YP
TO
_A
LG
_AS
YN
C
31
Overview
Send packets
Encrypt packets
on TCP
Send packets
Encrypt packets
on TCP
32
Overview
Vendor speci c drivers
33
fi
Overview
• Cryptd
• Enabled when the CONFIG_CRYPTO_CRYPTD compile option is set
• A crypto daemon which converts an arbitrary synchronous crypto algorithm
into an asynchronous algorithm that runs in a kthread
34
Overview
• Cryptd
• Enabled when the CONFIG_CRYPTO_CRYPTD compile option is set
• A crypto daemon which converts an arbitrary synchronous crypto algorithm
into an asynchronous algorithm that runs in a kthread
• Used as a template
35
Thread-A Thread-B
Find “cryptd(XXX)”
aes
…
1. Template name = “cryptd”
2. Cipher name = “XXX” “cryptomgr_probe”
cryptd
36 Global variable
Thread-A Thread-B
Find “cryptd(XXX)”
aes
…
1. Template name = “cryptd”
2. Cipher name = “XXX” “cryptomgr_probe”
cryptd
37 Global variable
Thread-A Thread-B
Find “cryptd(XXX)”
aes
…
1. Template name = “cryptd”
2. Cipher name = “XXX” “cryptomgr_probe”
cryptd(XXX)
Dispatch probing Find template
seqiv
Global variable
gcm
cryptd
Same as the original algorithm (XXX in here) but with asynchronous mode enabled
38 Global variable
Overview
• But how?
39
Overview
• AF_ALG
• Interface to kernel crypto API
• Algorithm probing with user-provided algorithm name
40
Thread-B
Thread-A
(cryptd_queue_worker)
Encrypt a packet
Pending queue
41
Thread-B
Thread-A
(cryptd_queue_worker)
Encrypt a packet
Encqueue request
(Cryptd)
Pending queue
42
Thread-B
Thread-A
(cryptd_queue_worker)
Encrypt a packet
Encqueue request
(Cryptd)
Wakeup worker !!
Pending queue
43
Thread-B
Thread-A
(cryptd_queue_worker)
Encrypt a packet
Encqueue request
(Cryptd)
Return
Pending queue
44
Thread-B
Thread-A
(cryptd_queue_worker)
Encrypt a packet
Encqueue request
(Cryptd)
Pending queue
45
Vulnerability
46
Vulnerability
CVE-2024-26800
CVE-2024-26582
CVE-2024-26584
CVE-2024-26585
CVE-2024-26583
47
Vulnerability
CVE-2024-26800
CVE-2024-26582
CVE-2024-26584
CVE-2024-26585
CVE-2024-26583
48
Vulnerability
CVE-2024-26583
49
Thread-B
Thread-A
(cryptd_queue_worker)
50
Thread-B
Thread-A
(cryptd_queue_worker)
notify
Finish
51
Thread-B
Thread-A
(cryptd_queue_worker)
Continue Finish
Exit
52
Thread-B
Thread-A
(cryptd_queue_worker)
wait_for_completion()
Continue complete()
Finish
Exit
53
Thread-B
Thread-A
(cryptd_queue_worker)
Continue Finish
Timer or something
Exit
54
Thread-B
Thread-A
(cryptd_queue_worker)
Continue Finish
Timer or something
Exit
55
Thread-B
Thread-A
(cryptd_queue_worker)
Continue Finish
Timer or something
Exit Exit
56
Thread-B
Thread-A
(cryptd_queue_worker)
Continue Finish
Timer or something
Exit Exit
57
Thread-B
Thread-A
(cryptd_queue_worker)
Continue Finish
Exit Exit
58
Thread-B
Thread-A
(cryptd_queue_worker)
Continue Finish
Exit Exit
59