NetBSD Problem Report #55463
From www@netbsd.org Mon Jul 6 00:31:09 2020
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 11CD51A9213
for <gnats-bugs@gnats.NetBSD.org>; Mon, 6 Jul 2020 00:31:09 +0000 (UTC)
Message-Id: <20200706003108.1B12E1A9218@mollari.NetBSD.org>
Date: Mon, 6 Jul 2020 00:31:08 +0000 (UTC)
From: snow@datagirl.xyz
Reply-To: snow@datagirl.xyz
To: gnats-bugs@NetBSD.org
Subject: TUNGIFHEAD ioctl returns 1024 instead of 1
X-Send-Pr-Version: www-1.0
>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:/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:
(Contact us)
$NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.