NetBSD Problem Report #53273

From soda@sra.co.jp  Thu May 10 02:41:00 2018
Return-Path: <soda@sra.co.jp>
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 B38517A1F7
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 10 May 2018 02:41:00 +0000 (UTC)
Message-Id: <20180510021928.40C6B16D4FC1@srapc2586.sra.co.jp>
Date: Thu, 10 May 2018 11:19:28 +0900 (JST)
From: soda@NetBSD.org
Reply-To: soda@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: sem_init() with pshared=1 does not actually work
X-Send-Pr-Version: 3.95

>Number:         53273
>Category:       lib
>Synopsis:       sem_init() with pshared=1 does not actually work
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu May 10 02:45:00 +0000 2018
>Last-Modified:  Thu May 10 13:30:01 +0000 2018
>Originator:     SODA Noriyuki
>Release:        NetBSD 7.1.2
>Organization:
the NetBSD project
>Environment:
System: NetBSD alec 7.1.2 NetBSD 7.1.2 (GENERIC.201803151611Z) amd64
Architecture: x86_64
Machine: amd64
>Description:

if sem_t is created by sem_init(*, 1, *), the sem_t has to be sharable
between processes, even if the processes don't share virtual memory space.
but our implemention doesn't satisfy this requirement.

>How-To-Repeat:

maya@ found this problem by trying to enable the multi-process feature
of recent firefox.

>Fix:

change the definition of sem_t from an opaque pointer to an actual struct
just like other UNIXes.
e.g.

Solaris 9:
typedef struct {
	/* this structure must be the same as sema_t in <synch.h> */
	uint32_t	sem_count;	/* semaphore count */
	uint16_t	sem_type;
	uint16_t	sem_magic;
	upad64_t	sem_pad1[3];	/* reserved for a mutex_t */
	upad64_t 	sem_pad2[2];	/* reserved for a cond_t */
}	sem_t;


FreeBSD-current:
struct _sem {
	__uint32_t	_magic;
	struct _usem2	_kern;
	__uint32_t	_padding;	/* Preserve structure size */
};
typedef	struct _sem	sem_t;


Linux:
typedef union
{
  char __size[__SIZEOF_SEM_T];
  long int __align;
} sem_t;

>Audit-Trail:
From: SODA Noriyuki <soda@NetBSD.org>
To: gnats-bugs@NetBSD.org
Cc: lib-bug-people@netbsd.org,
    gnats-admin@netbsd.org,
    netbsd-bugs@netbsd.org
Subject: Re: lib/53273: sem_init() with pshared=1 does not actually work
Date: Thu, 10 May 2018 12:04:54 +0900

 >>>>> On Thu, 10 May 2018 02:45:00 +0000 (UTC), soda@NetBSD.org said:

 > change the definition of sem_t from an opaque pointer to an actual struct
 > just like other UNIXes.

 Or, just using kernel semid as sem_t may be an option,
 although I'm not sure whether that causes any problem or not.

 But jmcneill@ pointed out that macOS is using such implementation.
 i.e.
 typedef int sem_t;

From: SODA Noriyuki <soda@NetBSD.org>
To: gnats-bugs@NetBSD.org,
    lib-bug-people@netbsd.org,
    gnats-admin@netbsd.org,
    netbsd-bugs@netbsd.org
Cc: 
Subject: Re: lib/53273: sem_init() with pshared=1 does not actually work
Date: Thu, 10 May 2018 12:34:10 +0900

 >>>>> On Thu, 10 May 2018 12:04:54 +0900, SODA Noriyuki <soda@NetBSD.org> said:

 > Or, just using kernel semid as sem_t may be an option,
 > although I'm not sure whether that causes any problem or not.

 Currently what ksem_init() returns is just a file descriptor,
 and that cannot be shared between processes.
 So, not only library, but also kernel has to be changed too.
 Thus, the "lib/" category of this PR seems wrong. ;-)

From: coypu@sdf.org
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: lib/53273: sem_init() with pshared=1 does not actually work
Date: Thu, 10 May 2018 13:29:08 +0000

 for context, the program to use this API and suffer hard from its
 brokenness is firefox which crashes often at runtime.
 There was some attempt to patch it in pkg/51966 which shouldn't
 have helped (it's for multiprocess, so pthread is no good) but
 seemed like it did.

 commenting in www/firefox/distinfo:
 -SHA1 (patch-ipc_glue_CrossProcessSemaphore.h) = 778a569887d8ad082abc2fa2fe89a0a943e84d64
 -SHA1 (patch-ipc_glue_CrossProcessSemaphore__posix.cpp) = 3052338871447cedaeafe8369afe82233183c884
 +#SHA1 (patch-ipc_glue_CrossProcessSemaphore.h) = 778a569887d8ad082abc2fa2fe89a0a943e84d64
 +#SHA1 (patch-ipc_glue_CrossProcessSemaphore__posix.cpp) = 3052338871447cedaeafe8369afe82233183c884

 Will make it crash very quickly from lack of locking.

>Unformatted:
 -current has same problem, too

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.