From patchwork Thu Sep 29 08:33:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu-Chien Peter Lin X-Patchwork-Id: 58137 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 94B1C385829B for ; Thu, 29 Sep 2022 08:34:19 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org 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: 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 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 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yu Chien Peter Lin , ycliang@andestech.com, alankao@andestech.com Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 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); } }