Article View: net.bugs.2bsd
Article #3342.9 BSD socket() syscall bug (and fix)
From: David L. Stevens
Date: Thu, 16 Oct 1986 02:36
Date: Thu, 16 Oct 1986 02:36
62 lines
2753 bytes
2753 bytes
Index: /usr/src/sys/sys/ipc.c 2.9BSD (with ISR mods)
Description:
When creating a socket, the syscall can leave a file structure
that claims to be a socket, but has no socket structure pointer
in f_socket. This results in a bus error when the file is closed,
from within a program or on exit.
Repeat-By:
Call socket() with a protocol that isn't supported; when there
are no mbufs available; or any time when socreate() will fail.
Then fork() and exit. This will result in a kernel mode bus error
and a panic().
Fix:
The problem is that socket() tries to get rid of the file reference
by setting the reference count to 0. A fork will increment this
and then there is an unusable file structure that will be closed
on exit. Since the FSOCKET bit is set, soclose() will be called
and it blindly tries to dereference f_socket.
The fix is to simply not mark the file structure as a
socket unless socreate() succeeds. The reference count trick
works fine as long as soclose() isn't called.
*** BROKEN /usr/src/sys/sys/ipc.c Wed Oct 15 21:09:00 1986
--- FIXED /usr/src/sys/sys/ipc.c Tue Oct 14 14:01:49 1986
***************
*** 100,106
}
if ((fp = falloc()) == NULL)
return;
! fp->f_flag = FSOCKET|FREAD|FWRITE;
if (uap->asp && copyin((caddr_t)uap->asp, (caddr_t)&sp, sizeof (sp)) ||
uap->asa && copyin((caddr_t)uap->asa, (caddr_t)&sa, sizeof (sa))) {
u.u_error = EFAULT;
--- 100,106 -----
}
if ((fp = falloc()) == NULL)
return;
! fp->f_flag = FREAD|FWRITE;
if (uap->asp && copyin((caddr_t)uap->asp, (caddr_t)&sp, sizeof (sp)) ||
uap->asa && copyin((caddr_t)uap->asa, (caddr_t)&sa, sizeof (sa))) {
u.u_error = EFAULT;
***************
*** 110,115
uap->asp ? &sp : 0, uap->asa ? &sa : 0, uap->options);
if (u.u_error)
goto bad;
fp->f_socket = so;
return;
bad:
--- 110,116 -----
uap->asp ? &sp : 0, uap->asa ? &sa : 0, uap->options);
if (u.u_error)
goto bad;
+ fp->f_flag |= FSOCKET;
fp->f_socket = so;
return;
bad:
--
+-DLS (dls@j.cc.purdue.edu)
Technical Details
Message-ID:
<2325@j.cc.purdue.edu>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!seismo!columbia!rutgers!princeton!allegra!ulysses!mhuxr!mhuxt!houxm!ihnp4!inuxc!pur-ee!j.cc.purdue.edu!dlsShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!columbia!rutgers!princeton!allegra!ulysses!mhuxr!mhuxt!houxm!ihnp4!inuxc!pur-ee!j.cc.purdue.edu!dls From: dls@j.cc.purdue.edu (David L. Stevens) Newsgroups: net.bugs.2bsd Subject: 2.9 BSD socket() syscall bug (and fix) Message-ID: <2325@j.cc.purdue.edu> Date: Wed, 15-Oct-86 22:36:08 EDT Article-I.D.: j.2325 Posted: Wed Oct 15 22:36:08 1986 Date-Received: Thu, 16-Oct-86 23:09:20 EDT Reply-To: dls@j.cc.purdue.edu.UUCP (David L. Stevens) Organization: PUCC Unix Group Lines: 62 Keywords: kernel mode bus error, bogus file structure