All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Frysinger <vapier@gentoo.org>
To: nfs@lists.sourceforge.net
Cc: Neil Brown <neilb@suse.de>
Subject: Re: Does mountd/statd really need to listen on a privileged port??
Date: Thu, 12 Apr 2007 21:09:03 -0400	[thread overview]
Message-ID: <200704122109.04535.vapier@gentoo.org> (raw)
In-Reply-To: <200704122055.12223.vapier@gentoo.org>


[-- Attachment #1.1: Type: text/plain, Size: 511 bytes --]

On Thursday 12 April 2007, Mike Frysinger wrote:
> if that's true, then we could at least rewrite the socket code to bind to
> ports that do not appear in /etc/services (via getservbyport()) ... that'd
> allow admins to easily prevent things like mountd/statd from hijacking
> reserved ports ...

actually, it can be done regardless of how the socket is obtained ... attached 
is a function i wrote to address this issue but didnt get around to 
integrating into packages

what do you think ?
-mike

[-- Attachment #1.2: Type: application/pgp-signature, Size: 827 bytes --]

[-- Attachment #2: bindresport.c --]
[-- Type: text/x-csrc, Size: 1457 bytes --]

#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>

/* Allocate a privileged port that is not reserved according to
 * the /etc/services database.  This allows the user to reserve
 * mark ports as "taken" by updating that file rather than having
 * a ton of packages install a ton of little files that somehow
 * magically get accumulated to reserve ports ...
 * http://bugs.gentoo.org/77810
 *
 * We do this recursively so that we dont have to worry about the
 * libc rebinding the same privileged port over and over again.
 * We keep all the sockets open until we find one we're happy
 * with and we keep it.
 */
int bind_unreserved_port(int domain, int type, char *protocol)
{
	int s;
	struct servent *serv;
	struct sockaddr_in saddr;
	socklen_t slen;

	/* allocate a socket */
	s = socket(domain, type, 0);
	if (s < 0)
		return s;

	/* attempt to bind to port */
	if (bindresvport(s, (struct sockaddr_in *) 0) != 0)
		goto err_close;

	/* make sure we only bind to non-reserved ports */
	if (getsockname(s, (struct sockaddr *)&saddr, &slen) != 0)
		goto err_close;

	serv = getservbyport(saddr.sin_port, protocol);
	if (serv != NULL) {
		/* this port is listed in /etc/services, so let's try again */
		int punt_socket = s;
		s = bind_unreserved_port(domain, type, protocol);
		close(punt_socket);
	}

	/* awesome, got ourselves a decent port */
	return s;

err_close:
	close(s);
	return -1;
}

[-- Attachment #3: Type: text/plain, Size: 345 bytes --]

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

[-- Attachment #4: Type: text/plain, Size: 140 bytes --]

_______________________________________________
NFS maillist  -  NFS@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nfs

  reply	other threads:[~2007-04-13  1:08 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-12 22:05 Does mountd/statd really need to listen on a privileged port?? Neil Brown
2007-04-13  0:05 ` Trond Myklebust
2007-04-16  1:03   ` Neil Brown
2007-04-13  0:55 ` Mike Frysinger
2007-04-13  1:09   ` Mike Frysinger [this message]
2007-04-13  1:39   ` Neil Brown
2007-04-13  2:04     ` Mike Frysinger
2007-04-17 10:14     ` Olaf Kirch
2007-04-17 11:12       ` Mike Frysinger
2007-04-16 18:13 ` Steve Dickson
2007-04-17 10:08   ` Olaf Kirch
2007-04-17 11:21     ` Mike Frysinger
2007-04-17 11:32       ` Olaf Kirch
2007-04-18  7:14     ` Neil Brown
2007-04-19  0:46       ` Neil Brown
2007-04-19  1:21         ` Javier Fernández-Sanguino Peña
2007-04-20  3:04           ` Portmap - was " Neil Brown
2007-04-20  6:49             ` Olaf Kirch
2007-04-20  8:02               ` Neil Brown
2007-04-20 13:27                 ` Olaf Kirch
2007-04-20 19:18             ` Steve Dickson
2007-04-23  4:03               ` Neil Brown
2007-04-23  6:31                 ` Neil Brown
2007-04-23 13:43                   ` Steve Dickson
2007-04-24  0:56                     ` Neil Brown
2007-04-24 17:13                       ` Steve Dickson
2007-04-23 13:28                 ` Steve Dickson
2007-04-23 23:09                   ` Neil Brown
2007-04-24  6:43                     ` Olaf Kirch
2007-04-24  7:24                       ` Neil Brown
2007-04-24 15:15                         ` Talpey, Thomas
2007-04-24 15:31                           ` Talpey, Thomas
2007-04-24  7:08                     ` Olaf Kirch
2007-04-24 15:10                       ` Steve Dickson
2007-04-24 16:10                       ` Christoph Hellwig
2007-04-24 17:04                         ` Steve Dickson
2007-04-24 17:17                           ` Christoph Hellwig
2007-04-24 17:52                             ` Steve Dickson
2007-04-24 19:09                               ` Peter Åstrand
2007-04-24 20:26                                 ` Steve Dickson
2007-04-24 20:36                                   ` Peter Staubach
2007-04-25 11:56                                     ` Olaf Kirch
2007-04-25 15:44                                       ` Peter Staubach
2007-04-25 20:14                                         ` Olaf Kirch
2007-04-26  6:32                                           ` Neil Brown
2007-04-26  8:59                                             ` Olaf Kirch
2007-04-26 13:03                                               ` Peter Staubach
2007-05-02  4:22                                                 ` Ian Kent
2007-04-27 15:07                                               ` Olaf Kirch
2007-04-27 15:18                                                 ` Christoph Hellwig
2007-04-27 17:07                                                   ` Olaf Kirch
2007-04-29 23:32                                                 ` Steve Dickson
2007-04-26  7:52                                     ` Aurélien Charbon
2007-04-25  8:57                                   ` Peter Åstrand
2007-04-25  8:56                               ` Olaf Kirch
2007-04-25  9:58                                 ` Christoph Hellwig
2007-04-25 13:22                                   ` Steve Dickson
2007-04-25 14:10                                     ` Olaf Kirch
2007-04-25 14:42                                       ` Christoph Hellwig
2007-04-26 14:30                                         ` Peter Åstrand
2007-04-25 14:37                                     ` Christoph Hellwig
2007-04-25 13:39                                 ` Steve Dickson
2007-04-26 22:22                                 ` Steve Dickson
2007-04-27  2:22                                   ` J. Bruce Fields
2007-04-27  6:20                                   ` Olaf Kirch
2007-04-27 14:01                                     ` Peter Staubach
2007-04-27 14:09                                       ` Christoph Hellwig
2007-04-27 14:21                                         ` Peter Staubach
2007-04-27 14:37                                           ` Christoph Hellwig
2007-04-29 23:39                                           ` Steve Dickson
2007-04-27 16:49                                       ` Olaf Kirch
2007-04-27 17:06                                         ` Peter Staubach
2007-04-27 17:04                                       ` Olaf Kirch
2007-04-27 17:34                                         ` Peter Staubach
2007-05-04 18:52                                     ` Steve Dickson
2007-04-24 14:38                     ` Steve Dickson
2007-04-19 15:15         ` Steve Dickson
2007-04-19 15:21           ` J. Bruce Fields
2007-04-19 15:42             ` Steve Dickson
2007-04-19 15:50               ` J. Bruce Fields
2007-04-19 16:36                 ` Steve Dickson
2007-04-19 22:50                   ` Anibal Monsalve Salazar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200704122109.04535.vapier@gentoo.org \
    --to=vapier@gentoo.org \
    --cc=neilb@suse.de \
    --cc=nfs@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.