Networking Forums

Networking Forums > Computer Networking > Linux Networking > Configuring portmap and rpc to listen on specific interfaces

Reply
Thread Tools Display Modes

Configuring portmap and rpc to listen on specific interfaces

 
 
Enrique Perez-Terron
Guest
Posts: n/a

 
      09-28-2004, 02:04 AM
I have written a patch to portmap that reads a config file
(/etc/portmap.conf by default) and binds to the specified interfaces
only, if the file exists and contains directives that match any
existing interfaces.

I have uploaded the patch and a source tarball to my ISP's server:

http://home.online.no/~enrio/portmap...FC2.src.tar.gz
http://home.online.no/~enrio/portmap...ict-bind.patch

The first file is the source tarball the was used by the Fedora Core
build, with all the Fedora patches applied, but without my patch. The
second file i my patch.

However, this raises a number of questions, and maybe you have more
questions that I have not thought of.

First a rationale for doing a change at all:

The version of portmap I have (Fedora Core 2) uses libwrap.so to
determine which connections it should accept. (See man 5 hosts_access.
This invention uses the same configuration files as tcp-wrapper, but
the wrapper code is run inside portmap each time there is a new
connection.) However, the code appears to do quite a bit of processing
of the incoming data before it calls the wrapper library to determine
if the request should be denied. In particular, the rpc decoding of
parameters is performed. This exposes the program to buffer overrun
attacks and whatsnot.

It is possible that the rpc code has been very thoughroughly reviewed
and audited, but I do not have any notice about it, and I guess many
others do not have it aeither. We would rather know the portmapper
does not listen on the wrong interfaces at all. Of course I have a
firewall in place, but by Murphy's law, it can fail, become
misconfigured, etc. The libwrap/hosts.{allow,deny} configuration makes
a second line of defence, but I still feel it is better to simply
check netstat -a | grep '\*:' or something similar, and verify that
nothing is listening to any ports other than the few I have had the
time and expertise to configure tightly.

Second: Is this the right way of doing it?

I have seen a couple of postings on the net advertising pathches that
allows one to specify an interface address on the command line.

Such solutions cover the majority of the small cases where there is a
local network and one linux box has a dsl connection to the world.
However, a more generic solution is required to cover the general
case, where there can be any number of interfaces.

In larger sites the configuration changes much more often than in a
home lan. The configuration is also more complex, and it is much
harder to remember all the small dependencies. If we place the
interfaces (or their IP addresses) on the command line of the daemons
in the boot scripts, it leads to a proliferation of places that have
to be updated when the configuration changes. To mitigate this, one
can write scripts that update such bits from a central configuration
database. I believe there ar a number of commercial tools that do just
that.

Such tools are generally quite expensive, and their maintainers
probably have a hard time catching up with all the software changes
they have to support. We should give some thought to what is the best
design for the case of portmap, minimising the burden both for the
maintainers of such tools and for all the others that cannot afford
the tools.

I have written my patch so that the administrator can specify
something like

# portmpa config file
bind eth0:0 192.168.0.0/24 127.0.0.0/8 some.host
another.host/255.240.0.0

and portmapper will retrieve the list of running interfaces from the
kernel, and check each of them against the list in the config file,
and connect to those interfaces that match an item in the config file.

The next question is, should this code be in portmap? Or should it
rather be moved to the rpc library? Should the same config file affect
all servers using rpc (including the kernel for NFS)? If so, should
the file have a language that allows different directives to apply to
different services?

What about network interfaces that come up after portmap has started?
Should portmap query the kernel regularly about any new interfcaes and
check them against the file?

I have no idea what will happen if someone tries to compile my patch
for another architecture. Is there someone out there with access to
other architectures that is willing to look into the issue? Also, I do
not have the required knowledge to make my patch IPV6-ready. The
portmap code I have contains some ifdef IPV6 directives, but I do not
know if it actually works.

To get the kernel interface information, the patch uses an ioctl,
SIOCGIFCONF.
It returns an array of struct ifreq, but there is no way for the
kernel to specify the size of each structure. Without IPV6 support,
the structure contains a struct sockaddr, but that structure is too
small to hold an IPV6 address. I tried to browse the kernel code for
another interface, no luck yet. Any tips?
I would rather have something portable, but quite likely that does not
exist yet.
 
Reply With Quote
 
 
 
 
Enrique Perez-Terron
Guest
Posts: n/a

 
      10-01-2004, 12:01 AM
(E-Mail Removed) (Enrique Perez-Terron) wrote in message news:<(E-Mail Removed) om>...
> I have written a patch to portmap that reads a config file
> (/etc/portmap.conf by default) and binds to the specified interfaces
> only, if the file exists and contains directives that match any
> existing interfaces.


I have now improved on the patch quite a bit.

I have adopted the ideas of Troels Arvin who posted to Red Hats's
Bugzilla a patch adding the option -l to listen on the loopback
interface only. He also had an adjustment to the init.d script, so the
portmap daemon would be started with options taken from a new file
/etc/sysconfig/portmap. This fits nicely into Red Hat's framework. I
have included his files in the new tarball. However, his changes to
the .c files and to the portmap.8 man page are superseded by mine.

I have also added an option '-b bind-spec' where 'bind-spec' is
- an interface name
- an ip address in 1.2.3.4 format
- a hostname to look up with gethostbyname()
- an ip address or a hostname followed by a netmask,
e.g 1.2.3.4/24 or www.ping.com/255.255.0.0
- 'loopback' will bind to all interfaces having the IFF_LOOPBACK
flag set
- any of the above prefixed with 'udp:' or with 'tcp:'.

To specify multiple interfaces, use multiple -b options.

Do not omit the loopback interface. Both the current Linux kernel and
the upcoming versions of the GNU C library connect to portmap through
the loopback interface. Also notice that applications linked with GNU
C library versions up to these days connect to portmap using the
primary interface, that is the first non-loopback interface listed by
the kernel, or eg. by /sbin/ifconfig.

I have uploaded a new patch to my ISP's server, and also a new tar.gz
file.

http://home.online.no/~enrio/portmap_4-patched.2.tar.gz
http://home.online.no/~enrio/portmap...t-bind.2.patch

The tar contains the source portmap_4 version with all the Red Hat
patches applied up to Fedora Core 2 portmap-4.0-59, but without my
patch. It also contains the man-pages and init-script that accompanies
the Fedora rpm.
To apply the patch, download both files, and run the following
commands:

tar zxf portmap_4-patched.2.tar.gz
cd patched-portmap_4
patch -p1 <../portmap-4.0-restrict-bind.2.patch

To build it I recommend runnging the script qbuild, it runs make with
the command line arguments that are used in the Fedora rpm build. The
script is also included in the tar file.

Regards,
Enrique
 
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
nfs portmap: server 10.122.2.37 not responding. PZ Linux Networking 0 03-12-2007 02:46 AM
Load balancing and specific interfaces John B Linux Networking 0 01-18-2007 09:21 PM
DHCP server setup on RH Linux - Not configured to listen on any interfaces! KAL Linux Networking 1 12-12-2006 10:19 AM
IP Alias & IPtables, redirecting outbound traffic out specific interfaces paul.groth@gmail.com Linux Networking 1 05-09-2006 05:45 AM
snmpd to listen to a specific IP saidev Linux Networking 1 04-27-2005 09:49 AM



1 2 3 4 5 6 7 8 9 10 11