NetBSD Problem Report #54266

From martin@aprisoft.de  Mon Jun  3 13:49:31 2019
Return-Path: <martin@aprisoft.de>
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 096597A15D
	for <gnats-bugs@gnats.NetBSD.org>; Mon,  3 Jun 2019 13:49:31 +0000 (UTC)
Message-Id: <20190603134921.8A8B45CC7A5@emmas.aprisoft.de>
Date: Mon,  3 Jun 2019 15:49:21 +0200 (CEST)
From: martin@NetBSD.org
Reply-To: martin@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: strange -m32 bug?
X-Send-Pr-Version: 3.95

>Number:         54266
>Category:       lib
>Synopsis:       strange -m32 bug?
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jun 03 13:50:00 +0000 2019
>Last-Modified:  Mon Jun 03 19:35:01 +0000 2019
>Originator:     Martin Husemann
>Release:        NetBSD 8.99.42
>Organization:
The NetBSD Foundation, Inc.
>Environment:
System: NetBSD seven-days-to-the-wolves.aprisoft.de 8.99.42 NetBSD 8.99.42 (GENERIC) #274: Fri May 31 07:45:03 CEST 2019 martin@seven-days-to-the-wolves.aprisoft.de:/work/src/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:

I ran into a very strange "COMPAT_NETBSD32" issue (but actually I am pretty
sure it is not the kernel at fault).


>How-To-Repeat:

cd /var/tmp
dd if=/dev/zero of=disk.img seek=6g count=1
vnconfig -c vnd0 disk.img

then compile the program below, once with -m32 and once without.

Run both binaries with "vnd0" as argument and watch the number of total
sectors being clamped:

 # cc -Wall -I /work/src/sbin/fsck -O2 test.c /work/src/sbin/fsck/partutil.c -lprop -l util
 # ./a.out vnd0
disk vnd0:
        sec size: 512
        total secs: 6442450944
 # cc -m32 -Wall -I /work/src/sbin/fsck -O2 test.c /work/src/sbin/fsck/partutil.c -lprop -l util
 # ./a.out vnd0
disk vnd0:
        sec size: 512
        total secs: 4294967295

The implementation relies on the kernel copying out the disk geometry 
dictionary, and you can inspect that via drvctl -p vnd0, and compare it
to the output of a 32bit drvctl binary - which is the same. This is why
I think the kernel is doing the proper thing, but I have a hard time seing
where the difference in userland comes from.

The code works fine on a real i386 machine.

--8<--
/*
 * Compile with:
 *  cc -Wall -I /usr/src/sbin/fsck -O2 test.c /usr/src/sbin/fsck/partutil.c -lprop -lutil
 */

#include <stdlib.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/disk.h>
#include <fcntl.h>
#include <util.h>
#include <errno.h>
#include <unistd.h>
#include "partutil.h"

int
get_disk_geom(const char *disk, struct disk_geom *d)
{
	char buf[1024];
	int fd, error;

 	if ((fd = opendisk(disk, O_RDONLY, buf, sizeof(buf), 0)) == -1)
		return 0;

	error = getdiskinfo(disk, fd, NULL, d, NULL);
	close(fd);
	if (error < 0) {
		errno = error;
		return 0;
	}
	return 1;
}

int
main(int argc, char **argv)
{
	struct disk_geom geo;

	if (argc != 2) {
		fprintf(stderr, "usage: %s (disk)\n", argv[0]);
		return 1;
	}

	if (get_disk_geom(argv[1], &geo))
		printf("disk %s:\n\tsec size: %u\n\ttotal secs: %" PRIu64 "\n",
		    argv[1], geo.dg_secsize, geo.dg_secperunit);

	return 0;
}
-->8--

>Fix:
totally puzzled - no idea.

>Audit-Trail:
From: "K. Schreiner" <ks@ub.uni-mainz.de>
To: <gnats-bugs@netbsd.org>
Cc: 
Subject: Re: lib/54266: strange -m32 bug?
Date: Mon, 3 Jun 2019 16:57:42 +0200

 On Mon, Jun 03, 2019 at 01:50:00PM +0000, martin@NetBSD.org wrote:
 >
 > [...]
 > I ran into a very strange "COMPAT_NETBSD32" issue (but actually I am pretty
 > sure it is not the kernel at fault).
 > [...]

 > disk vnd0:
 >         sec size: 512
 >         total secs: 4294967295
 Hm, 4294967295=4G-1 - overflow somewhere?

 Kurt

From: christos@zoulas.com (Christos Zoulas)
To: gnats-bugs@netbsd.org, lib-bug-people@netbsd.org, 
	gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, martin@NetBSD.org
Cc: 
Subject: Re: lib/54266: strange -m32 bug?
Date: Mon, 3 Jun 2019 15:32:55 -0400

 On Jun 3,  3:00pm, ks@ub.uni-mainz.de ("K. Schreiner") wrote:
 -- Subject: Re: lib/54266: strange -m32 bug?

 |  Hm, 4294967295=4G-1 - overflow somewhere?

 The 32 bit code uses the disklabel code which has only 32 bits for
 secperunit, because it does not support the geometry ioctl used in
 the 64 bit code.

 christos

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.