mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Cc: Tastky <tastky@gmail.com>
Subject: Re: nfs-utils broken with musl: "select: Bad file descriptor"
Date: Tue, 18 Aug 2015 16:51:44 -0400	[thread overview]
Message-ID: <20150818205144.GM32742@brightrain.aerifal.cx> (raw)
In-Reply-To: <20150818191810.GA18417@port70.net>

On Tue, Aug 18, 2015 at 09:18:10PM +0200, Szabolcs Nagy wrote:
> * Felix Janda <felix.janda@posteo.de> [2015-08-18 20:20:14 +0200]:
> 
> > Rich Felker wrote:
> > > On Tue, Aug 18, 2015 at 06:50:54PM +0200, Tastky wrote:
> > > > Just checked with said include and everything recompiled.
> > > > Unfortunately the same error persists.
> > > > 
> > > > Running OpenWrt's command
> > > > /usr/sbin/rpc.statd -p 32778 -o 32779 -F
> > > > manually (following the script's prior steps, ofc) results in a loop of:
> > > > 
> > > > sm-notify: Version 1.3.2 starting
> > > > sm-notify: Already notifying clients; Exiting
> > > > 
> > > > With strace: http://pastebin.com/raw.php?i=9ypUbmsp
> > > 
> > > From the strace, I see that a nonsensical fd #105 is in the fd_set
> > > readfds that comes from SVC_FDSET. I don't know where the latter is
> > > defined or modified.
> > 
> > It is defined in system.h (now hopefully) to be svc_fdset, which seems
> > to be defined as a global variable by the rpc headers.
> > 
> 
> i think this call goes wrong:
> 
> http://git.linux-nfs.org/?p=steved/nfs-utils.git;a=blob;f=utils/statd/rmtcall.c;hb=HEAD#l56
> 
> it loops for 100 iterations and if all ports are used
> according to getservbyport then it FD_SET(sockfd, &SVC_FDSET);
> with some random high sockfd (eg. 105) that is closed.
> 
> ...so should getservbyport fail there?
> 
> (according to strace it tries ports 883 to 982)

I think the application's expectation is that it fail rather than
returning a decimal-string-only service entity. However it looks like
the code is written to handle the case where all 100 iterations fail
to get an anonymous port. The problem seems to be that, when the loop
stops due to hitting the iteration count rather than exiting with
break, i has already been incremented past the last tmp_socket slot,
so the close loop closes the fd that they actually want to use, later
causing EBADF. This is purely an application bug, but it happens not
to get noticed if getservbyport fails anywhere along the way, which
they expect to happen in the usual case.

Rich


  reply	other threads:[~2015-08-18 20:51 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-18  2:30 Tastky
2015-08-18  3:00 ` Rich Felker
2015-08-18 16:50   ` Tastky
2015-08-18 17:49     ` Rich Felker
2015-08-18 18:07       ` Tastky
2015-08-18 18:08         ` Tastky
2015-08-18 18:20       ` Felix Janda
2015-08-18 19:18         ` Szabolcs Nagy
2015-08-18 20:51           ` Rich Felker [this message]
2015-08-19  9:34           ` Natanael Copa
2015-08-19  1:05 Chuck Lever

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=20150818205144.GM32742@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    --cc=tastky@gmail.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).