flawopen.com/Teardowns/cve-2024-26585-linux-tls-zerocopy-use-after-free

● CVE-2024-26585 · CVSS 4.7 · मध्यम
सुरक्षा अनुसंधान · FlawOpen

तकनीकी विश्लेषण: CVE-2024-26585: Linux Kernel TLS Subsystem Use-After-Free Teardown

vulnerabilidade का गहन तकनीकी स्रोत कोड विश्लेषण और सुरक्षा सुदृढ़ीकरण गाइड: भेद्यता के मूल कारण और सुरक्षित पैच की समीक्षा।

💡 आसान भाषा में (ELI5)

सरल भौतिक उपमा द्वारा समझें: Imagine you order a meal for delivery. The chef starts cooking, but you call and cancel the order. Because the kitchen staff wasn't notified properly, the delivery driver picks up an empty plate, drives to a new customer's house, and serves them whatever was left on the counter, contaminating the new customer's food.

इस पेज के मुख्य शब्द

Kernel TLS (kTLS)
Linux kernel facility to perform symmetric TLS encryption/decryption directly inside the network socket layer for maximum throughput.
Zero-Copy Networking
Transmitting data directly from application buffers to the network card without intermediate CPU memory copying.
Asynchronous Crypto (aead_request)
Offloading cryptographic AES-GCM operations to asynchronous hardware accelerators.
Slab Corruption
Corrupting Linux kernel slab cache structures (kmalloc-512), destabilizing kernel execution.

मूल कारण विश्लेषण (Root Cause)

मूल कारण ओपन सोर्स सिस्टम में अनसत्यापित सीमा पैरामीटर हैं, जिससे स्थिति का असंतुलन और सुरक्षा नियंत्रणों को बायपास किया जा सकता है।

हमले का चरण-दर-चरण प्रवाह

Step 1

हमला चरण: Open kTLS Socket

तकनीकी शोषण तंत्र और निष्पादन विवरण: The attacker creates a TLS socket and enables kernel encryption offload via setsockopt(TCP_ULP, "tls").

Step 2

हमला चरण: Submit Asynchronous Zero-Copy Payload

तकनीकी शोषण तंत्र और निष्पादन विवरण: The attacker sends data using MSG_ZEROCOPY, queuing pages for hardware crypto.

Step 3

हमला चरण: Abrupt Socket Teardown

तकनीकी शोषण तंत्र और निष्पादन विवरण: The attacker closes the socket before the crypto accelerator completes its async callback.

Step 4

मेमोरी करप्शन(Kernel Memory Corruption)

तकनीकी शोषण तंत्र और निष्पादन विवरण: The cleanup handler frees memory pages that the delayed hardware callback subsequently overwrites.

सोर्स कोड: कमज़ोर बनाम सुरक्षित कार्यान्वयन

कमज़ोर कार्यान्वयन
// VULNERABLE: net/tls/tls_sw.c before patch
static void tls_encrypt_done(void *data, int err) {
    struct tls_context *ctx = data;
    struct tls_sw_context_tx *ctx_tx = tls_sw_ctx_tx(ctx);

    // ROOT CAUSE:
    // Asynchronous completion callback assumes socket context is still locked!
    // If the socket was closed while crypto was in flight, ctx_tx is already freed!
    clear_bit(TLS_TX_SYNC_MORE, &ctx_tx->tx_bitmask);
    tls_free_open_rec(ctx);
}
सुरक्षित और सुदृढ़ फ़िक्स
// SECURE: net/tls/tls_sw.c patch
static void tls_encrypt_done(void *data, int err) {
    struct tls_context *ctx = data;
    
    // 1. Verify context reference counter before dereferencing context pointers
    if (!refcount_inc_not_zero(&ctx->refcount)) {
        return; // Socket is already dying, abort callback safely!
    }
    
    struct tls_sw_context_tx *ctx_tx = tls_sw_ctx_tx(ctx);
    clear_bit(TLS_TX_SYNC_MORE, &ctx_tx->tx_bitmask);
    tls_free_open_rec(ctx);
    
    // 2. Drop reference cleanly
    refcount_dec(&ctx->refcount);
}

इंजीनियरिंग और सिस्टम सुरक्षा चेकलिस्ट

स्रोत