NetBSD Problem Report #52303

From www@NetBSD.org  Fri Jun 16 18:25:53 2017
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 "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id DFFCB7A16A
	for <gnats-bugs@gnats.NetBSD.org>; Fri, 16 Jun 2017 18:25:52 +0000 (UTC)
Message-Id: <20170616182500.C338D7A2A9@mollari.NetBSD.org>
Date: Fri, 16 Jun 2017 18:25:00 +0000 (UTC)
From: u-bc8k@aetey.se
Reply-To: u-bc8k@aetey.se
To: gnats-bugs@NetBSD.org
Subject: linux emulation: linux-brk-syscall return value is page-rounded up (?), on native linux the syscall returns the requested value
X-Send-Pr-Version: www-1.0

>Number:         52303
>Category:       kern
>Synopsis:       linux emulation: linux-brk-syscall return value is page-rounded up (?), on native linux the syscall returns the requested value
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jun 16 18:30:00 +0000 2017
>Last-Modified:  Sat Jun 17 06:15:00 +0000 2017
>Originator:     u-bc8k
>Release:        7.1
>Organization:
Aetey
>Environment:
NetBSD XXXX 7.1 NetBSD 7.1 (GENERIC.201703111743Z) amd64
>Description:
Some Linux-specific code assumes the documented behaviour of the linux-brk-syscall: the return value to be the requested address on success, otherwise the possibly previously set current value on failure, without any page size rounding.

This works both under Linux and under the Linux ABI on FreeBSD but breaks under the Linux ABI on NetBSD.

The latter seems to round up the return value to the nearest page, which is not expected.
>How-To-Repeat:
The following brk() implementation for ia32 works under Linux and under the Linux ABI on FreeBSD but breaks under the Linux ABI on NetBSD:

int brk(char *addr) {
  int res;
  res = _syscall1(__NR_brk, (int)addr);
  if (res == (int)addr) return 0;
  errno = ENOMEM;
  return -1;
}

>Fix:

>Audit-Trail:
From: u-bc8k@aetey.se
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: kern/52303: linux emulation: linux-brk-syscall return value is
 page-rounded up (?), on native linux the syscall returns the requested value
Date: Sat, 17 Jun 2017 08:11:52 +0200

 Note that a certain sbrk() implementation can use (and uses in practice)
 the result of
  _syscall1(__NR_brk, 0) 
 requesting "zero address" to find out the previously requested break
 value, not the page-aligned one.

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.