Index | Thread | Search

From:
"Theo de Raadt" <deraadt@openbsd.org>
Subject:
Re: snmpd closefrom
To:
Alexander Bluhm <bluhm@openbsd.org>, tech@openbsd.org
Date:
Tue, 09 Apr 2024 07:33:58 -0600

Download raw body.

Thread
Claudio Jeker <cjeker@diehard.n-r-g.com> wrote:

> On Tue, Apr 09, 2024 at 02:13:30PM +0200, Alexander Bluhm wrote:
> > Hi,
> > 
> > fstat output shows that snmpd_metrics uses file descriptors 0, 1,
> > 2 for regular communication.  This should not happen as any output
> > to stderr would interfere with other data.
> > 
> > stdin, stdout, stderr are reserverd.  They should point to a terminal
> > or /dev/null.  Redirects to other files is also fine.  But closing
> > and then opening some files or sockets to 0, 1, 2 is not allowed.
> > 
> > The closefrom(1) in snmpd is the culprit.  With closefrom(4)
> > descriptors 0, 1, 2 are /dev/null, 3 is a socketpair shared with
> > the parent, and higher numbers are used for other files.
> > 
> > ok?
> 
> Why call closefrom() in the first place? If the code used O_CLOEXEC etc
> there would be no need for that. snmpd_backend() is called once from
> main() in the setup code so it feels strange to need closefrom() there.

   ^^^  Yep.  It smells.