From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from Atcsqr.andestech.com (60-248-80-70.hinet-ip.hinet.net [60.248.80.70]) by sourceware.org (Postfix) with ESMTPS id AFD8C3858C50 for ; Thu, 29 Sep 2022 08:34:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AFD8C3858C50 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=andestech.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=andestech.com Received: from mail.andestech.com (ATCPCS16.andestech.com [10.0.1.222]) by Atcsqr.andestech.com with ESMTP id 28T8XwkJ003712 for ; Thu, 29 Sep 2022 16:33:58 +0800 (+08) (envelope-from peterlin@andestech.com) Received: from atcfdc88.andestech.com (10.0.15.120) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.498.0; Thu, 29 Sep 2022 16:33:58 +0800 From: Yu Chien Peter Lin To: CC: , , Yu Chien Peter Lin Subject: [PATCH] malloc: Fix clobbered errno when getrandom failed [BZ #29624] Date: Thu, 29 Sep 2022 16:33:52 +0800 Message-ID: <20220929083352.11890-1-peterlin@andestech.com> X-Mailer: git-send-email 2.34.1.390.g2ae0a9cb82 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.0.15.120] X-DNSRBL: X-MAIL:Atcsqr.andestech.com 28T8XwkJ003712 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_STATUS,RDNS_DYNAMIC,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: The patch resets errno when getrandom syscall failed, which will result in errno clobbered at statically linked program startup. This scenario is possible if getrandom is called by tcache_key_initialize when crng is not ready thus EAGAIN is returned. Fixes bug 29624. Signed-off-by: Yu Chien Peter Lin --- malloc/malloc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/malloc/malloc.c b/malloc/malloc.c index 953183e956..21f2bf5431 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -3140,6 +3140,7 @@ tcache_key_initialize (void) #if __WORDSIZE == 64 tcache_key = (tcache_key << 32) | random_bits (); #endif + __set_errno(0); } } -- 2.34.1