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=-3.3 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 9836 invoked from network); 13 Jun 2022 17:09:05 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 13 Jun 2022 17:09:05 -0000 Received: (qmail 7223 invoked by uid 550); 13 Jun 2022 17:09:03 -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 7186 invoked from network); 13 Jun 2022 17:09:02 -0000 Date: Mon, 13 Jun 2022 13:08:49 -0400 From: Rich Felker To: Waldek Kozaczuk Cc: musl@lists.openwall.com Message-ID: <20220613170849.GG7074@brightrain.aerifal.cx> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] netlink.c: missing handling of EAGAIN and EWOULDBLOCK On Mon, Jun 13, 2022 at 11:41:57AM -0400, Waldek Kozaczuk wrote: > Hi, > > Very recently we implemented minimal rnetlink support on OSv side which > allowed us to finally switch to the netlink-based implementation of > getifaddrs() and if_nameindex(). > > However, I noticed that the function __netlink_enumerate() in > https://github.com/ifduyue/musl/blob/master/src/network/netlink.c uses > MSG_DONTWAIT flag when calling recv() which may fail with EAGAIN or > EWOULDBLOCK and there is no error/retry handling for that. I actually saw > both functions fail occasionally on OSv. > > One way to fix is to add missing error handling. But another simpler > solution is to stop using MSG_DONTWAIT altogether and force recv() to > block. In other words, the line: > > r = recv(fd, u.buf, sizeof(u.buf), MSG_DONTWAIT); > > should change to: > > r = recv(fd, u.buf, sizeof(u.buf), 0); > > For time being we are applying a header trick on OSv side to re-define > MSG_DONTWAIT as 0 when compiling those specific musl sources. Thanks! I'll try to track this down. One concern is that I'm not sure how MSG_DONTWAIT is supposed to interact with "short reads" -- is it needed (for netlink) to prevent blocking when some data has been read but there is still buffer space for more? On a related issue, I'm pretty sure the netlink API doesn't allow for partial reads with some data remaining buffered on the kernel side, but we should probably verify that too. Rich