Exploit database

GH-fe45a0a486d27c36aa80e2c232873fd2

khoatran107/cve-2025-21756

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2025-21756

4 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files8
khoatran107/cve-2025-21756Revision 13a3614dbba0

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

test_unix/unix_repeat_truncated.c

C · 2,549 bytes
#include <sys/socket.h>
#include <sys/un.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>

#define SOCKET_PATH "/tmp/unix_dgram_socket"

#define SKB_MAX_ALLOC 0x3ec0 // through debugging

int main() {
	int sockfd;
	struct sockaddr_un addr;

	// Create a datagram UNIX socket
	sockfd = socket(AF_UNIX, SOCK_DGRAM, 0);
	if (sockfd == -1) {
		perror("socket");
		exit(EXIT_FAILURE);
	}

	memset(&addr, 0, sizeof(struct sockaddr_un));
	addr.sun_family = AF_UNIX;
	strncpy(addr.sun_path, SOCKET_PATH, sizeof(addr.sun_path) - 1);

	// Ensure the receiver exists
	// Create receiver socket and bind
	int recv_sock = socket(AF_UNIX, SOCK_DGRAM, 0);
	unlink(SOCKET_PATH);
	struct sockaddr_un recv_addr = addr;
	bind(recv_sock, (struct sockaddr *)&recv_addr, sizeof(recv_addr));


	// Send a datagram to the UNIX socket
	char msg[SKB_MAX_ALLOC + 0x4000];
	memset(msg, 'A', sizeof(msg));
	getchar();
	for (int i = 0; i < 5; i++) {
		*(long long*)(msg + SKB_MAX_ALLOC) = 0xcafebabedeadbe00 + i;

		if (i % 3 == 0) {
			strcpy(msg + SKB_MAX_ALLOC, "If the receive buffer is smaller than the first sk_buff, unix_dgram_recvmsg copies as much data as possible into the buffer, up to its size, and discards the excess. It returns the number of bytes copied, which is the buffer size, and the next receive call will process the next message, not the truncated part. ");
		} else if (i % 3 == 1) {
			strcpy(msg + SKB_MAX_ALLOC, "The sk_receive_queue remains a queue of complete messages. Each receive call processes one sk_buff, and truncation does not leave partial messages in the queue. The application must ensure the buffer is large enough to avoid data loss. ");
		} else {
			strcpy(msg + SKB_MAX_ALLOC, "When using Unix domain datagram sockets, the sk_receive_queue holds messages as sk_buff structures. The unix_dgram_sendmsg function enqueues these, and unix_dgram_recvmsg dequeues them for processing. If the receive buffer is smaller than the message, truncation occurs, affecting how data is handled. ");
		}
		ssize_t sent = sendto(sockfd, msg, SKB_MAX_ALLOC + 0x4000, 0,
						(struct sockaddr *)&addr, sizeof(addr));
		if (sent == -1) {
			perror("sendto");
			exit(EXIT_FAILURE);
		}
		printf("Sent %zd bytes\n", sent);
	}
	// Receive it (optional)
	for (int i = 0; i < 5; i++) {
		char buf[0x10000];
		ssize_t recv_len = recv(recv_sock, buf, SKB_MAX_ALLOC + 0x20, 0);
		buf[recv_len] = '\0';
		printf("Received: %s\n", buf + SKB_MAX_ALLOC);
	}

	close(sockfd);
	close(recv_sock);
	unlink(SOCKET_PATH);

	return 0;
}