NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/53103: linux emulation of sendto(2) broken (testcase included)

>Number:         53103
>Category:       lib
>Synopsis:       linux emulation of sendto(2) broken (testcase included)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Mar 16 15:40:00 +0000 2018
>Originator:     Timo Buhrmester
>Release:        8.0_BETA
NetBSD 8.0_BETA NetBSD 8.0_BETA (KIWIKERN) #0: Fri Mar 16 01:29:50 CET 2018 amd64
linux-emulated sendto(2) fails with EFAULT in a situation where the native sendto(2) succeeds.

Ultimate failure is in 'copyin', got there via
sockargs via
do_sys_sendmsg_so via
do_sys_sendmsg from

Testcase below
The below program takes two arguments, an IP address and a port number, and sends a UDP datagram containing "hello world\n" to said address/port using sendto(2)

Compile it on a 64bit Linux machine (Debian 9 in my case) 
and try to run it under NetBSD's Linux emulation, sendto(2) will fail.
Compile on NetBSD and run natively, it succeeds.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <unistd.h>

#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>

#define MSG "hello world\n"

main(int argc, char **argv)
        if (argc != 3) {
                fprintf(stderr, "Usage: %s <ip4addr> <port>\n", argv[0]);

        struct sockaddr_storage ss;
        struct sockaddr_in *sa = (struct sockaddr_in *)&ss;

        struct in_addr ia;
        int r = inet_pton(AF_INET, argv[1], &ia);
        if (r != 1) {

        sa->sin_family = AF_INET;
        sa->sin_addr = ia;
        sa->sin_port = htons(atoi(argv[2]));

        int s = socket(AF_INET, SOCK_DGRAM, 0);

        ssize_t st = sendto(s, MSG, strlen(MSG), 0, (struct sockaddr *)sa, sizeof *sa);
        fprintf(stderr, "sendto: returned %zd, expected %zu\n", st, strlen(MSG));


Home | Main Index | Thread Index | Old Index