kern/73778: linux emulation: semctl(IPC_STAT) has broken return value

Andriy Gapon avg at
Wed Nov 10 08:50:29 PST 2004

>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
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Nov 10 16:50:28 GMT 2004
>Originator:     Andriy Gapon
>Release:        FreeBSD 5.2.1-RELEASE-p11 i386
FreeBSD 4.X, 5.X
semctl with IPC_STAT command should return zero in case of success, see:

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.
write a small test program or just look at the code
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,
+		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 ---


More information about the freebsd-bugs mailing list