From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ua1-x92a.google.com (mail-ua1-x92a.google.com [IPv6:2607:f8b0:4864:20::92a]) by sourceware.org (Postfix) with ESMTPS id 2F4913857351 for ; Thu, 29 Sep 2022 17:55:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2F4913857351 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-ua1-x92a.google.com with SMTP id i17so818591uaq.9 for ; Thu, 29 Sep 2022 10:55:32 -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=iwSlyLIAVVQRcQBSOe8CD8gabivun6sqcpasjxMrIw4=; b=NsEvSHH7wnGXeMEccMHORCrTRP5Y46UvSywPIwZYvBD9d5ivZzkcaaOaczX/E1H5U4 hPyM5iHANsPp9bR/c28SyM3kVeLCOAtCvxslE8QIGUll00GQc8rufd0wQD99F4qdCUQI 3sloVOv9ZR20DbBwIdMlu7jhE8nhqSxZ6KJt+eLjKh/dkhEL3IZI2AuTy8rWeA/ablhM ZlV39oXqfeMPNI/CVZvKmgPU4UF+gs0cZEDtuLu10ql4Ke8L7iw8yGNLqevFDKRpfCSn YyTXYs3mK7/rVNZTh6bFhVkMHyzGsvRP8aAL8qoH5rpyaU2T9N5smTaWL4JvEBcLMKO1 9VOQ== 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=iwSlyLIAVVQRcQBSOe8CD8gabivun6sqcpasjxMrIw4=; b=PpL5scey1EVMEZhTmHAmXvB4GLDyk1R80ba2KDC4VxvT1Wax5p765O1HubJPruXJ1c 3LcSvdtVEkrWA2DwN0G1jPUHwBc/AqK/hsODq9nMBVxOauDbIbW9hYFz4K+bOslcOJRF HbXIv0LdFwcxP1ZHnMUVCpws8NszS2i8hH4TgkiLs5QfMdBEeWEBxcgDTKX9IxI2Pw5/ YNFQvfvxN/kJheGO8IDuHZOh6no693oa8xFQnfaD+g08J/Qd2E1l5mW5GS2xO9oPJmmQ R1FSDQEzm6hUcu2MoVhuw5pb4fuphBt2i2JvH4LFXaKTSef137zFgwq/sZrNfR+KH/G1 JiwA== X-Gm-Message-State: ACrzQf1n+AQq0ML74eZ8F78dK+K4gP7Z+BBpVNfAMVX8VisvN1thyak0 dJeseaB57/8glUJYhRbsFnXTsAKvTS2JEaeB X-Google-Smtp-Source: AMsMyM5OfXsiJws5JdgXzYOCJP1nDtZva9zm/oLPZfPyRafXqfqa/naqGHLHJnzsty/6K5XuqMwbfg== X-Received: by 2002:a9f:37c8:0:b0:390:c1c0:70ea with SMTP id q66-20020a9f37c8000000b00390c1c070eamr2439862uaq.53.1664474131223; Thu, 29 Sep 2022 10:55:31 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:3736:f485:5f41:e13d:4b46]) by smtp.gmail.com with ESMTPSA id e199-20020a1f1ed0000000b003a4a4f943c1sm281026vke.22.2022.09.29.10.55.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Sep 2022 10:55:30 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Wilco Dijkstra , Yu Chien Peter Lin Subject: [PATCH v2] malloc: Do not clobber errno on __getrandom_nocancel (BZ#29624) Date: Thu, 29 Sep 2022 14:55:26 -0300 Message-Id: <20220929175526.2596756-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: 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 | 12 ++++++++++-- sysdeps/unix/sysv/linux/not-cancel.h | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/stdlib/arc4random.c b/stdlib/arc4random.c index e417ef624d..0a1f4b8a57 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 == -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..518f738519 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,15 @@ __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); + r = r == -1 ? -errno : r; + __set_errno (save_errno); + return 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