From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from hall.aurel32.net (hall.aurel32.net [IPv6:2001:bc8:30d7:100::1]) by sourceware.org (Postfix) with ESMTPS id A838F3858022 for ; Mon, 24 Oct 2022 18:58:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A838F3858022 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=aurel32.net Authentication-Results: sourceware.org; spf=none smtp.mailfrom=aurel32.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=aurel32.net ; s=202004.hall; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date: Subject:Cc:To:From:Content-Type:From:Reply-To:Subject:Content-ID: Content-Description:In-Reply-To:References:X-Debbugs-Cc; bh=0wBqSAXyFO4ldAy2luxFmKpV5l2g2FHEhAQioLSgckE=; b=Y9fjPGybf8P0cCh+IrPThsLgLy VBRMAyouL1EmYfKW5RsB/XxItS/qXzeidRNWmo2r0Ha0QPhSsbhmUgRETq9HVxdtZzMni9eLjFu80 /mWhl5IAANKUijxSpZE9/qBBFj75v3/+1S0rCin3W+pFK9MUTL+ZZ6Tno0HhW8C2T/sx2mCoewG4n woW0WjMHhDg0iMdZ70s5jtSn55gOE1cHwDdwqZH1cJPy9n+LqEOrDmVpx3G2IUAsPHm6f0X9VkROW zGz7DdBrBIJPo1mlVv//ReF5okzSkikjF4iiXu/7/q0t5sbrNlMh1JZP/1iuu2BwxLRtvAdSIxE2g wRkje6LA==; Received: from [2a01:e34:ec5d:a741:8a4c:7c4e:dc4c:1787] (helo=ohm.rr44.fr) by hall.aurel32.net with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1on2eY-00Dyq9-G2; Mon, 24 Oct 2022 20:58:26 +0200 Received: from aurel32 by ohm.rr44.fr with local (Exim 4.96) (envelope-from ) id 1on2eY-007IRk-0H; Mon, 24 Oct 2022 20:58:26 +0200 From: Aurelien Jarno To: libc-stable@sourceware.org Cc: Aurelien Jarno , Tulio Magno Quites Machado Filho Subject: [COMMITTED 2.36] Avoid undefined behaviour in ibm128 implementation of llroundl (BZ #29488) Date: Mon, 24 Oct 2022 20:58:18 +0200 Message-Id: <20221024185818.1739179-1-aurelien@aurel32.net> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_PASS,SPF_NONE,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: Detecting an overflow edge case depended on signed overflow of a long long. Replace the additions and the overflow checks by __builtin_add_overflow(). Reviewed-by: Tulio Magno Quites Machado Filho (cherry picked from commit 2b5478569e72ee4820a6e163d306690c9c0eaf5e) --- NEWS | 2 ++ sysdeps/ieee754/ldbl-128ibm/s_llroundl.c | 21 +++++++++------------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/NEWS b/NEWS index a6da588c85..8c60d3dc8d 100644 --- a/NEWS +++ b/NEWS @@ -33,6 +33,8 @@ The following bugs are resolved with this release: [29485] Linux: Terminate subprocess on late failure in tst-pidfd [29490] alpha: New __brk_call implementation is broken [29463] math/test-float128-y1 fails on x86_64 + [29488] test-ibm128-llround fails on ppc64el when built with gcc-12 and -O2 + or higher [29528] elf: Call __libc_early_init for reused namespaces [29537] libc: [2.34 regression]: Alignment issue on m68k when using [29539] libc: LD_TRACE_LOADED_OBJECTS changed how vDSO library are diff --git a/sysdeps/ieee754/ldbl-128ibm/s_llroundl.c b/sysdeps/ieee754/ldbl-128ibm/s_llroundl.c index d85154e73a..d8c0de1faf 100644 --- a/sysdeps/ieee754/ldbl-128ibm/s_llroundl.c +++ b/sysdeps/ieee754/ldbl-128ibm/s_llroundl.c @@ -66,38 +66,35 @@ __llroundl (long double x) /* Peg at max/min values, assuming that the above conversions do so. Strictly speaking, we can return anything for values that overflow, but this is more useful. */ - res = hi + lo; - - /* This is just sign(hi) == sign(lo) && sign(res) != sign(hi). */ - if (__glibc_unlikely (((~(hi ^ lo) & (res ^ hi)) < 0))) + if (__glibc_unlikely (__builtin_add_overflow (hi, lo, &res))) goto overflow; xh -= lo; ldbl_canonicalize (&xh, &xl); - hi = res; if (xh > 0.5) { - res += 1; + if (__glibc_unlikely (__builtin_add_overflow (res, 1, &res))) + goto overflow; } else if (xh == 0.5) { if (xl > 0.0 || (xl == 0.0 && res >= 0)) - res += 1; + if (__glibc_unlikely (__builtin_add_overflow (res, 1, &res))) + goto overflow; } else if (-xh > 0.5) { - res -= 1; + if (__glibc_unlikely (__builtin_add_overflow (res, -1, &res))) + goto overflow; } else if (-xh == 0.5) { if (xl < 0.0 || (xl == 0.0 && res <= 0)) - res -= 1; + if (__glibc_unlikely (__builtin_add_overflow (res, -1, &res))) + goto overflow; } - if (__glibc_unlikely (((~(hi ^ (res - hi)) & (res ^ hi)) < 0))) - goto overflow; - return res; } else -- 2.35.1