Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 10 Nov 2004 18:44:08 +0200 (EET)
From:      Andriy Gapon <avg@icyb.net.ua>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   kern/73778: linux emulation: semctl(IPC_STAT) has broken return value
Message-ID:  <200411101644.iAAGi8Mf018363@oddity.topspin.kiev.ua>
Resent-Message-ID: <200411101650.iAAGoSb0087045@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         73778
>Category:       kern
>Synopsis:       linux emulation: semctl(IPC_STAT) has broken return value
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Nov 10 16:50:28 GMT 2004
>Closed-Date:
>Last-Modified:
>Originator:     Andriy Gapon
>Release:        FreeBSD 5.2.1-RELEASE-p11 i386
>Organization:
>Environment:
System:
FreeBSD 4.X, 5.X
	
>Description:
semctl with IPC_STAT command should return zero in case of success, see:
semctl(2)
http://www.opengroup.org/onlinepubs/009695399/functions/semctl.html

because of a bug in linux_semctl() a positive value is returned:
td_retval is assigned a value for both LINUX_IPC_STAT and LINUX_SEM_STAT

this breaks some linux applications with error check "semctl() != 0",
while applications with error check "semctl() < 0" remain happy.
among affected applications is IBM MQ / WEMPS.
	
>How-To-Repeat:
write a small test program or just look at the code
	
>Fix:
apply the following patch
	

--- ipc.patch begins here ---
--- /usr/src/sys/compat/linux/linux_ipc.c.orig	Mon Nov  8 19:10:48 2004
+++ /usr/src/sys/compat/linux/linux_ipc.c	Tue Nov  9 20:00:56 2004
@@ -532,8 +532,11 @@
 		error = __semctl(td, &bsd_args);
 		if (error)
 			return error;
-		td->td_retval[0] = IXSEQ_TO_IPCID(bsd_args.semid,
+		if(bsd_args.cmd == SEM_STAT)
+			td->td_retval[0] = IXSEQ_TO_IPCID(bsd_args.semid,
 							unptr->buf->sem_perm);
+		else
+			td->td_retval[0] = 0;
 		bsd_to_linux_semid_ds(unptr->buf, &linux_semid);
 		return (linux_semid_pushdown(args->cmd & LINUX_IPC_64,
 		    &linux_semid, (caddr_t)args->arg.buf));
--- ipc.patch ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200411101644.iAAGi8Mf018363>