OPNsense - FreeBSD source
Find a file
Bill Paul 4c45fb08aa Correct a bug in the 'allow arbitrary number of socket descriptors' changes
made to the RPC code some months ago. The value of __svc_fdsetsize is being
calculated incorrectly.

Logically, one would assume that __svc_fdsetsize is being used as a
substitute for FD_SETSIZE, with the difference being that __svc_fdsetsize
can be expanded on the fly to accomodate more descriptors if need be.
There are two problems: first, __svc_fdsetsize is not initialized to 0.
Second, __svc_fdsetsize is being calculated in svc.c:xprt_registere() as:

                __svc_fdsetsize = howmany(sock+1, NFDBITS);

This is wrong. If we are adding a socket with index value 4 to the
descriptor set, then __svc_fdsetsize will be 1 (since fds_bits is
an unsigned long, it can support any descriptor from 0 to 31, so we
only need one of them). In order for this to make sense with the
rest of the code though, it should be:

                __svc_fdsetsize = howmany(sock+1, NFDBITS) * NFDBITS;

Now if sock == 4, __svc_fdsetsize will be 32.

This bug causes 2 errors to occur. First, in xprt_register(), it
causes the __svc_fdset descriptor array to be freed and reallocated
unnecessarily. The code checks if it needs to expand the array using
the test: if (sock + 1 > __svc_fdsetsize). The very first time through,
__svc_fdsetsize is 0, which is fine: an array has to be allocated the
first time out. However __svc_fdsetsize is incorrectly set to 1, so
on the second time through, the test (sock + 1 > __svc_fdsetsize)
will still succeed, and the __svc_fdset array will be destroyed and
reallocated for no reason.

Second, the code in svc_run.c:svc_run() can become hopelessly confused.
The svc_run() routine malloc()s its own fd_set array using the value
of __svc_fdsetsize to decide how much memory to allocate. Once the
xprt_register() function expands the __svc_fdset array the first time,
the value for __svc_fdsetsize becomes 2, which is too small: the resulting
calculation causes the code to allocate an array that's only 32 bits wide
when it actually needs 64 bits. It also uses the valuse of __svc_fdsetsize
when copying the contents of the __svc_fdset array into the new array.
The end result is that all but the first 32 file descriptors get lost.

Note: from what I can tell, this bug originated in OpenBSD and was
brought over to us when the code was merged. The bug is still there
in the OpenBSD source.

Total nervous breakdown averted by: Electric Fence 2.0.5
1997-10-14 21:50:17 +00:00
bin Style police: keep a variable list in alphabetical order, and add 1997-10-13 09:36:05 +00:00
contrib This commit was generated by cvs2svn to compensate for changes in r30411, 1997-10-14 18:17:11 +00:00
crypto PR: bin/771 and bin/1037 are resolved by this change 1997-10-08 03:14:34 +00:00
etc Sheesh! Who's put a non-comment comment into this file? 1997-10-14 16:08:11 +00:00
games Remove bogus declaration of calloc() that broke the build. Test, folks, 1997-09-26 06:25:42 +00:00
gnu Makefile for contributed version of awk. 1997-10-14 18:32:38 +00:00
include Reinsert telnet.h into the list of files installed into include/arpa/ 1997-10-03 18:10:35 +00:00
kerberos5 Fix a break in the includes where the build blows chunks if it is 1997-10-02 15:03:23 +00:00
kerberosIV Correct the MAKE_EBONES macro --> MAKE_KERBEROS4 1997-10-03 06:37:35 +00:00
lib Correct a bug in the 'allow arbitrary number of socket descriptors' changes 1997-10-14 21:50:17 +00:00
libexec Store temporary files in /var/tmp instead /tmp. This should avoid 1997-10-11 22:05:44 +00:00
lkm Make the blank screen saver work with MDA and CGA. The fade and green 1997-10-04 04:24:18 +00:00
release Add a new startup variables menu for tweaking rc.conf variables in more 1997-10-14 18:17:35 +00:00
sbin Do not account the tape change time for ETA estimations. 1997-10-12 14:09:13 +00:00
secure Staticise a variable. 1997-10-08 07:02:48 +00:00
share Improve my hack from rev 1.6 of displayq.c, and make the TCP 1997-10-14 16:01:02 +00:00
sys Reset the flag right away, could catch a bogon someday. 1997-10-14 18:51:07 +00:00
tools Do not suppress the first 5 lines of updated ports. 1997-10-04 12:20:16 +00:00
usr.bin Add the primaries -mmin, -amin, -cmin to find, similar to the GNU find. 1997-10-13 21:06:22 +00:00
usr.sbin Add a new startup variables menu for tweaking rc.conf variables in more 1997-10-14 18:17:35 +00:00
COPYRIGHT This is the official 4.4 Lite copyright. 1994-09-11 07:53:28 +00:00
Makefile Do not use -B in initial build of "make". It doesn't exist in 2.1.x. 1997-10-10 13:02:36 +00:00
README Note that /etc is not installed by world target either. 1997-08-09 14:36:20 +00:00

This is the top level of the FreeBSD source directory.  This file
was last revised on: $Id: README,v 1.10 1997/02/23 09:18:39 peter Exp $

For copyright information, please see the file COPYRIGHT in this
directory (additional copyright information also exists for some
sources in this tree - please see the specific source directories for
more information).

The Makefile in this directory supports a number of targets for
building components (or all) of the FreeBSD source tree, the most
commonly used one being ``world'', which rebuilds and installs
everything in the FreeBSD system from the source tree except the
kernel and the contents of /etc.  Please see the top of the Makefile
in this directory for more information on the standard build targets
and compile-time flags.

Building a kernel with config(8) is a somewhat more involved process,
documentation for which can be found at:
   http://www.freebsd.org/handbook/kernelconfig.html
And in the config(8) man page.

The sample kernel configuration files reside in the sys/i386/conf
sub-directory (assuming that you've installed the kernel sources), the
file named GENERIC being the one used to build your initial installation
kernel.  The file LINT contains entries for all possible devices, not
just those commonly used, and is meant more as a general reference
than an actual kernel configuration file (a kernel built from it
wouldn't even run).


Source Roadmap:
---------------
bin		System/User commands.

contrib		Packages contributed by 3rd parties.

eBones		Kerberos package - NOT FOR EXPORT!

etc		Template files for /etc

games		Amusements.

gnu		Various commands and libraries under the GNU Public License.
		Please see gnu/COPYING* for more information.

include		System include files.

lib		System libraries.

libexec		System daemons.

lkm		Loadable Kernel Modules.

release		Release building Makefile & associated tools.

sbin		System commands.

secure		DES and DES-related utilities - NOT FOR EXPORT!

share		Shared resources.

sys		Kernel sources.

tools		Utilities for regression testing and miscellaneous tasks.

usr.bin		User commands.

usr.sbin	System administration commands.


For information on synchronizing your source tree with one or more of
the FreeBSD Project's development branches, please see:

  http://www.freebsd.org/handbook/synching.html