From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vk1-xa32.google.com (mail-vk1-xa32.google.com [IPv6:2607:f8b0:4864:20::a32]) by sourceware.org (Postfix) with ESMTPS id A48423858D39 for ; Thu, 29 Sep 2022 16:45:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A48423858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-vk1-xa32.google.com with SMTP id b15so978524vkp.2 for ; Thu, 29 Sep 2022 09:45:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date; bh=cy43f+OvRi9fNBf9+YtXVOc9024bZDn1Vsxlc60sYvk=; b=hxj/z7c2/RXmPX0r28ZlqL+yQKKhZEB+znRuV/rDPB2KmsTVt5tNG1gzJLWXlbwGmF KRqhVjGOV1BlseCdR7mnQuntJ0VsnKIcerRrqOcellOeLqQ+TVZY3Q0uKURLG2zLbYyD SgomvZ70TgbfoHZm1IHhCVGNaaeShq59xPit1TPkdP2rS9Gwtn+T1svEwgYoE0wWCixU e/MQ3W+GfhTJNkmEFe18LhsyD8EQVgJhb0ftppr3Gv8pkipRCMwDyHOqtH6gpR1UosXy jOV1MSsXhgTj17ZeLVEvIn/y6oSCIoZttUREcr0o9xTnUxmfN2LqvdO1DI3jcSDL0j1x 4Xzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date; bh=cy43f+OvRi9fNBf9+YtXVOc9024bZDn1Vsxlc60sYvk=; b=c49cLRSJzgudfqVJvMQG32R+1e73nf0n5XLN+/Y+zRIFVxhe7u3n50qfkP1e7Hg7ZX LmlhyOt4U7Ffk4iHl8ZYzzf6l2vYPlB/yCGiI4OeEzfaEaBrLuUgmG3f4cy9cwmdXfwC vqWAtAbvS7EOYvJfF9wcp/wZ3NVbdNnFcyry3oMKXLHCSsgzqsB7mVZMoqtfp6Fou2fO tgm/yJqcH23Ol4HG34WAgWLmygJEE3Sa9bL7LxaUL/lq4ejuYiiJMnHFDGcyYzSGS0gd 7+a6kJO9p9+RIzvjKVTTl1nU718dM9NTGMysVzd8mnJPOfwDQEccGvFOWcvT8gHAraXs HLfQ== X-Gm-Message-State: ACrzQf22Sp5rCQDcR2bu9XVP/+IknBk8IpbNB9OS7P/PULWmdcP6Itmc oeCWaaRDHR46PWxq61zGfgXT2Dhshsys5R2a X-Google-Smtp-Source: AMsMyM7XlzeZSwLrnvy5Hn1ugZQeqGooKdrOBN9rXSl6UB5bq54TtVo2bSdIkyIt9equOqN94mtTrA== X-Received: by 2002:a05:6122:1781:b0:3a3:9de2:1d7c with SMTP id o1-20020a056122178100b003a39de21d7cmr2130326vkf.19.1664469913785; Thu, 29 Sep 2022 09:45:13 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:3736:f485:5f41:e13d:4b46]) by smtp.gmail.com with ESMTPSA id p16-20020a056102201000b0039ae99e4723sm1820584vsr.17.2022.09.29.09.45.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Sep 2022 09:45:13 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Wilco Dijkstra , Yu Chien Peter Lin Subject: [PATCH] malloc: Do not clobber errno on __getrandom_nocancel (BZ#29624) Date: Thu, 29 Sep 2022 13:45:10 -0300 Message-Id: <20220929164510.3454281-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,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: I am not sure if changing thread cache initialization to not use getrandom syscall will add much, on recent kernel getrandom should fast (although still a syscall) and I am not sure of the performance implications. --- Use INTERNAL_SYSCALL_CALL instead of INLINE_SYSCALL_CALL. This requires emulate the semantic for hurd call (so __arc4random_buf uses the fallback). Checked on x86_64-linux-gnu. --- stdlib/arc4random.c | 4 ++-- sysdeps/mach/hurd/not-cancel.h | 11 +++++++++-- sysdeps/unix/sysv/linux/not-cancel.h | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/stdlib/arc4random.c b/stdlib/arc4random.c index e417ef624d..20886e0445 100644 --- a/stdlib/arc4random.c +++ b/stdlib/arc4random.c @@ -34,7 +34,7 @@ void __arc4random_buf (void *p, size_t n) { static int seen_initialized; - size_t l; + int l; int fd; if (n == 0) @@ -51,7 +51,7 @@ __arc4random_buf (void *p, size_t n) n -= l; continue; /* Interrupted by a signal; keep going. */ } - else if (l < 0 && errno == ENOSYS) + else if (l < 0 && l == -ENOSYS) break; /* No syscall, so fallback to /dev/urandom. */ arc4random_getrandom_failure (); } diff --git a/sysdeps/mach/hurd/not-cancel.h b/sysdeps/mach/hurd/not-cancel.h index ae58b734e3..f2cb9b60ba 100644 --- a/sysdeps/mach/hurd/not-cancel.h +++ b/sysdeps/mach/hurd/not-cancel.h @@ -27,6 +27,7 @@ #include #include #include +#include /* Non cancellable close syscall. */ __typeof (__close) __close_nocancel; @@ -75,8 +76,14 @@ __typeof (__fcntl) __fcntl_nocancel; #define __fcntl64_nocancel(...) \ __fcntl_nocancel (__VA_ARGS__) -#define __getrandom_nocancel(buf, size, flags) \ - __getrandom (buf, size, flags) +static inline int +__getrandom_nocancel (void *buf, size_t buflen, unsigned int flags) +{ + int save_errno = errno; + int r = __getrandom (buf, buflen, flags); + __set_errno (save_errno); + return r == -1 ? -save_errno : r; +} #define __poll_infinity_nocancel(fds, nfds) \ __poll (fds, nfds, -1) diff --git a/sysdeps/unix/sysv/linux/not-cancel.h b/sysdeps/unix/sysv/linux/not-cancel.h index a263d294b1..00ab75a405 100644 --- a/sysdeps/unix/sysv/linux/not-cancel.h +++ b/sysdeps/unix/sysv/linux/not-cancel.h @@ -71,7 +71,7 @@ __writev_nocancel_nostatus (int fd, const struct iovec *iov, int iovcnt) static inline int __getrandom_nocancel (void *buf, size_t buflen, unsigned int flags) { - return INLINE_SYSCALL_CALL (getrandom, buf, buflen, flags); + return INTERNAL_SYSCALL_CALL (getrandom, buf, buflen, flags); } static inline int -- 2.34.1