From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 20648 invoked from network); 4 Aug 2022 14:23:31 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 4 Aug 2022 14:23:31 -0000 Received: (qmail 11610 invoked by uid 550); 4 Aug 2022 14:23:29 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 11575 invoked from network); 4 Aug 2022 14:23:28 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1659622995; bh=wCJbMGNiKG+FQWn0q3hz5Uz7Yyvp8OX4Ws0imr8OASE=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:References:In-Reply-To; b=cxcu1lmv4EeMP/aX3r0q/rnfI/+VKwCSWoItTvoK7jKeBG9tIFK7EqB9LLoSPmOqG rp0zFxlPoHVhnr7LsUOmtIeglcSiPKCBUN9kw2Vfk9L3QONlBhDplQY6r5Gau4WSl9 qMWBLR+bImLOAbS8GlGW5NqwqSPtky9pRL98DJBw= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Date: Thu, 4 Aug 2022 16:23:22 +0200 From: Markus Wichmann To: musl@lists.openwall.com Cc: Sascha Brawer Message-ID: <20220804142322.GC3042@voyager> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) X-Provags-ID: V03:K1:GVW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q 3SfucG/kOPz1DcV2jvcRbTNxvusfz/NSTgmH65y/k8gGf+lbv391FLOHVeI+Rzr37nacf1Z8m Ev4WAoohkg8RtVZsLMATl5RbTAaLMtUZRsnnzzSIJyB17hNzaZW0rHouYmw40A/7R98Kjl5U/ ldyj5d6cv5zIqjpfKVvTt6ODVBCAv6DTn8BgwAN2Rqd9t+ZYvQDrdtGJ1kzjam1kxc6R8kBUC ElfJjXo55tDaUDx1bGG9WYZJtQ3+JXKSR9RybUaQKaDhwEudFngsc7HiLPm+jmT9bkQF+IA66 iNY6RhaEC7z6h1BzdK01hl21Y1veYX3U4JDwsJQI3M2BOPknLzu/mT4uw== Subject: Re: [musl] Should fdopen() check the passed file descriptor? On Thu, Aug 04, 2022 at 02:42:49PM +0200, Sascha Brawer wrote: > Dear list > > Should musl=E2=80=99s fdopen() verify whether the passed file descriptor= refers to > an open file? > It should not. Normal musl policy for "may fail" is to just not check that. musl only implements "shall fail". In this case, using numbers that are not FDs as such is really really bad. It means the control flow is utterly br0ken. How did the program even get into a state in which a variable is supposed to be holding an FD but doesn't? It betrays a really big problem with the program if this can happen. If the program is multi-threaded (or opens files from a signal handler, which can happen since open(2) is async-signal-safe), the program might suddenly start using a file descriptor wrong. That would be an interesting problem to debug. In short, any program calling fdopen() with a number that is not guaranteed to be an open file has a logic error that needs to be fixed post-haste. Returning EBADF is really only plastering over the problem. It would be like dereferencing a pointer fresh out of malloc() and catching the SIGSEGV instead of just testing whether the pointer is 0. Ciao, Markus