NetBSD-Bugs archive

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

kern/55463: TUNGIFHEAD ioctl returns 1024 instead of 1



>Number:         55463
>Category:       kern
>Synopsis:       TUNGIFHEAD ioctl returns 1024 instead of 1
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jul 06 00:35:00 +0000 2020
>Originator:     snow flurry
>Release:        9.0
>Organization:
>Environment:
NetBSD patchouli 9.0 NetBSD 9.0 (GENERIC) #0: Fri Feb 14 00:06:28 UTC 2020  mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/amd64/compile/GENERIC amd64
>Description:
After setting the TUN_IFHEAD flag on a tun(4) device using the TUNSIFHEAD ioctl, the TUNGIFHEAD ioctl returns 1024 (the value of TUN_IFHEAD), not 1 as is mentioned in the tun(4) man page:

> TUNGIFHEAD  The argument should be a pointer to an int; the ioctl sets the value to one if the device is in ?multi-af? mode, and zero otherwise.

>How-To-Repeat:
Running the following C code  as root is expected to print "TUNGIFHEAD returned 1" but prints "TUNGIFHEAD returned 1024":
=====
#include <net/if_tun.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>

#define _DEV_TUN "/dev/tun0"

int main (int argc, char *argv[]) {
    int fd, res, ifheadmode = 1;

    fd = open(_DEV_TUN, O_RDWR);
    if (fd == -1) {
        perror("open() failed");
        return 1;
    }

    res = ioctl(fd, TUNSIFHEAD, &ifheadmode);
    if (res == -1) {
        perror("TUNSIFHEAD failed");
        return 1;
    }

    res = ioctl(fd, TUNGIFHEAD, &ifheadmode);
    if (res == -1) {
        perror("TUNGIFHEAD failed");
        return 1;
    }

    // should be 1
    printf("TUNGIFHEAD returned %d\n", ifheadmode);

    close(fd);

    return 0;
}
>Fix:
The following patch appears to resolve the issue:
=====
--- sys/net/if_tun.c.old	2020-07-05 14:43:15.042513460 -0700
+++ sys/net/if_tun.c	2020-07-05 14:42:29.928975123 -0700
@@ -724,7 +724,7 @@
 		break;
 
 	case TUNGIFHEAD:
-		*(int *)data = (tp->tun_flags & TUN_IFHEAD);
+		*(int *)data = ((tp->tun_flags & TUN_IFHEAD) == TUN_IFHEAD);
 		break;
 
 	case FIONBIO:



Home | Main Index | Thread Index | Old Index