NetBSD Problem Report #56549

From wiz@yt.nih.at  Tue Dec 14 15:39:49 2021
Return-Path: <wiz@yt.nih.at>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_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 CA82F1A9239
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 14 Dec 2021 15:39:48 +0000 (UTC)
Message-Id: <20211214153943.E2B541CB6ABD@yt.nih.at>
Date: Tue, 14 Dec 2021 16:39:43 +0100 (CET)
From: Thomas Klausner <wiz@NetBSD.org>
Reply-To: Thomas Klausner <wiz@NetBSD.org>
To: gnats-bugs@NetBSD.org
Subject: consecutive sem_open() do not return the same address
X-Send-Pr-Version: 3.95

>Number:         56549
>Category:       kern
>Synopsis:       consecutive sem_open() do not return the same address
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Dec 14 15:40:00 +0000 2021
>Originator:     Thomas Klausner
>Release:        NetBSD 9.99.92
>Organization:

>Environment:


Architecture: x86_64
Machine: amd64
>Description:
sem_open(3) claims:

     If the same name argument is given to multiple calls to
     sem_open() by the same process without an intervening call to
     sem_close(), the same address is returned each time.

This is not happening.
>How-To-Repeat:
Try multiple sem_open calls, see that they return different values.

Index: t_sem.c
===================================================================
RCS file: /cvsroot/src/tests/lib/librt/t_sem.c,v
retrieving revision 1.5
diff -u -r1.5 t_sem.c
--- t_sem.c	14 May 2020 08:34:19 -0000	1.5
+++ t_sem.c	14 Dec 2021 15:38:47 -0000
@@ -313,6 +313,31 @@
 	(void)sem_unlink("/sem_c");
 }

+ATF_TC_WITH_CLEANUP(sem_open_address);
+ATF_TC_HEAD(sem_open_address, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Validate that multiple sem_open calls "
+	    "return the same address");
+}
+ATF_TC_BODY(sem_open_address, tc)
+{
+	sem_t *sem, *sem2, *sem3;
+	sem = sem_open("/sem_d", O_CREAT | O_EXCL, 0777, 0);
+	ATF_REQUIRE(sem != SEM_FAILED);
+	sem2 = sem_open("/sem_d", O_CREAT | O_EXCL, 0777, 0);
+	ATF_REQUIRE(sem2 == SEM_FAILED && errno == EEXIST);
+	sem3 = sem_open("/sem_d", 0);
+	ATF_REQUIRE(sem3 != SEM_FAILED);
+	ATF_REQUIRE(sem == sem3);
+	ATF_REQUIRE_EQ(sem_close(sem3), 0);
+	ATF_REQUIRE_EQ(sem_close(sem), 0);
+	ATF_REQUIRE_EQ(sem_unlink("/sem_d"), 0);
+}
+ATF_TC_CLEANUP(sem_open_address, tc)
+{
+	(void)sem_unlink("/sem_d");
+}
+
 ATF_TP_ADD_TCS(tp)
 {

@@ -320,6 +345,7 @@
 	ATF_TP_ADD_TC(tp, child);
 	ATF_TP_ADD_TC(tp, pshared);
 	ATF_TP_ADD_TC(tp, invalid_ops);
+	ATF_TP_ADD_TC(tp, sem_open_address);

 	return atf_no_error();
 }
Fails with:
tc-end: 1639496081.591387, sem_open_address, failed, t_sem.c:331: sem == sem3 not met

>Fix:
Not provided.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(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.