From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vk1-xa29.google.com (mail-vk1-xa29.google.com [IPv6:2607:f8b0:4864:20::a29]) by sourceware.org (Postfix) with ESMTPS id 4774E385C41C for ; Thu, 29 Sep 2022 19:28:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4774E385C41C 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-xa29.google.com with SMTP id g27so1203020vkl.3 for ; Thu, 29 Sep 2022 12:28:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date; bh=ZkAxPp2UtGIe/hHPqni0XRmKeaAb5qSImKaEURNG2n0=; b=knpMHpK6wNXCzpWBNLgkmWEFUXGR+wysjCEsLZnUV9+/Zm1hfZ4QZA2p98MHBRv9II bpVRj3MPDiEk4z78IDoB5nVL/xS41tITccoc2MjxlLIeU0VeGe9zI6crLvv5FGFvj7Qe RI2Z8OvNUc2Lp2C054D3yMgxwNF5lu3ZD0I6zDvmt3VbI1BuEC9TbnxS7fylMOnXuDCJ WXRAyRQ2hAp4QSpz0VP23oEkE98oTmy5TIV6Xxi4D+lbjf6DTZPTxMhvMz8UpvHyq9Qh eZqyCt/XRKOoLY3w5V4O6ChaEdokQCiDHdqOS7Ua1KY6Gb1umsEcLzg16qPOUWl+bOu9 RSFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date; bh=ZkAxPp2UtGIe/hHPqni0XRmKeaAb5qSImKaEURNG2n0=; b=0VeYG7kjMtJI/0OcbejUZA9QJhRt6rU9EpI4cjo324mrD2pynPkwNbzULOKWHKsmmC wG0iYAx5vqpgBLGgWTnR+MdZzN/zLBUMwodsOzgqMRSu5FFK49qYiTFVA8tKBxX1b+AB scfhfCeSvn6Mxi0rmAxb/7L6mC+I4rTSiVgxOCcPv2+G0sHddyKOuy8AUZhI8EWoGqXT 88pQX0bCF835XSGxi/d4/sKgwWP/s9Z4vrhDO9RMeAt5T0MeM3KOpVFGqfSdbaF4LnZl DI2TDrC0IkfUiiigWyjDR4JviXBHKKyO4Vzh61zipygfkLqhghFO6o3MSwwspeNiK+ba UCHg== X-Gm-Message-State: ACrzQf2L3Xhz2Gi/d/uu7+WcIPISvcwm5nFEs2P0/BSQ0UfTNXRVyLOB 7KTX/Tei+WRpp2+tZNHlq9nu3yRBU0rw1jBv X-Google-Smtp-Source: AMsMyM4YK/jtnbKLjduqS1PACm87JaGpS9/YWC66QmuKdWwIQkldr3gwQj4qrNR2UJt0ZJG3NE0dpQ== X-Received: by 2002:ac5:c4d6:0:b0:3a3:7ffe:2753 with SMTP id a22-20020ac5c4d6000000b003a37ffe2753mr2493926vkl.9.1664479681464; Thu, 29 Sep 2022 12:28:01 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:3736:f485:5f41:e13d:4b46]) by smtp.gmail.com with ESMTPSA id y7-20020a1f3207000000b003a30e5de061sm395088vky.47.2022.09.29.12.28.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Sep 2022 12:28:01 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Wilco Dijkstra , Yu Chien Peter Lin Subject: [PATCH v3 2/2] malloc: Do not clobber errno on __getrandom_nocancel (BZ #29624) Date: Thu, 29 Sep 2022 16:27:56 -0300 Message-Id: <20220929192756.3310704-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220929192756.3310704-1-adhemerval.zanella@linaro.org> References: <20220929192756.3310704-1-adhemerval.zanella@linaro.org> 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 | 2 +- sysdeps/mach/hurd/not-cancel.h | 12 ++++++++++-- sysdeps/unix/sysv/linux/not-cancel.h | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/stdlib/arc4random.c b/stdlib/arc4random.c index 960a38f295..c126c601bf 100644 --- a/stdlib/arc4random.c +++ b/stdlib/arc4random.c @@ -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..5d2d2b4b8a 100644 --- a/sysdeps/mach/hurd/not-cancel.h +++ b/sysdeps/mach/hurd/not-cancel.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -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 cf35c8bfc9..93615de681 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 ssize_t __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