From patchwork Mon Nov 6 13:27:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1860161 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=WifGkwAM; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SPBxf1sHzz1yQL for ; Tue, 7 Nov 2023 00:28:22 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 79AF9385800A for ; Mon, 6 Nov 2023 13:28:19 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x734.google.com (mail-qk1-x734.google.com [IPv6:2607:f8b0:4864:20::734]) by sourceware.org (Postfix) with ESMTPS id 5DA6A385559B for ; Mon, 6 Nov 2023 13:27:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5DA6A385559B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5DA6A385559B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::734 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699277252; cv=none; b=lEU+nuX63DtVR18J0Bbihgr3qjb7Tmo8AEa52Kik0jaSxVCXbtf4Tew9RZMLKw8In4ZnK+sfhJ0ay0URcBzrcwNforyXreallwfV2/smhRG7t/dPhctbtBYds7jLOzZzLM1U95YCxmMU4mKpfR0uNR6f4WuxYNFewH6QkfGEkcY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699277252; c=relaxed/simple; bh=X2wiZ3laELaKsR0jgcmuy/E0a1j+Y6CXbQpJCpc45wA=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=RMjyHTp7jjV6bDqBb2l+uBKVItW8iBTNy+z7HBJWvOC2Tm8x9HiqFRWZQSE1whgMsLQmqz7v789jvq29Js/rsQdu7q85EElIicRuD2NSpBEHIg5vmLRnBnuAa8p0yysOcLqppI1cgSFlSPxBvZfR9D/VK4ro0e+o9P4GqBofvFg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qk1-x734.google.com with SMTP id af79cd13be357-778a108ae49so443638985a.0 for ; Mon, 06 Nov 2023 05:27:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699277250; x=1699882050; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=6jWpJtYgU4AupWiGBpR3CkeP70iQINh300sZdk4guoA=; b=WifGkwAMX5L+/YTGt8N2SnozNgSfctejJamS8LZFA+DSlNdLEubA6XtIru+CGsUAnj f3djEtFhUI93gBu0GHTQG6hmPTfSRBUHd8+wtYAJZrl5f4s8PSdNVTd7vdOe0mIQryfw 1OyjdiTA29y3IVAPeUwRIrnRYCCiw1r1S38/w9kgPsc9mFUc+9TpOxbUdAGag8+hXVfb msL45+OyiaJ3D/VKlRYBffTjKP1DGP4Lrs1y6MAP4sXxxPSOR6hQsxwddlT38QBPJs80 PypQeTWafFRj1ZTsX3vF2blJdaICiJ+xOYupoI8jiav+mWrZGOtviVNl4ViwQvk/60O1 lgnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699277250; x=1699882050; 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:message-id:reply-to; bh=6jWpJtYgU4AupWiGBpR3CkeP70iQINh300sZdk4guoA=; b=pTWfVXcqoqK9ZmWCGP2jfIIOX/PRhsNpheCy4beLxzq5jSPLtChOjg+U4ejq4hgQjN OuCb+u4hp8rZ4tI5BgoNOP5+reMWpHlaCosrRG0uTosNUYZmZDYLHON5Rq+qhKJTXxOL NajuU0zypL89yO4z//wbvpJPpWRGFT7QsKpcv+kW7EM8evF8zg1Y+u6iaQMpfhTuXcBR iWEFjG7GzXgX0LrVTyWE6+KMJaG32SDWATR2gcYOzQVoh2cAY9VCZM/ndMdt5uXqu+4t UI322Ha5/p3836bti3Tp46ay3dZPr/nOaZsCneJ+/3S2XX443D4r3IYD1D/zx2pqwsDe Gk0A== X-Gm-Message-State: AOJu0Yx7aoPIWwtAGt/NFD+uLaPjuOxmjEVvcRE5dyG5Ym8BZxHtG6M4 nnLJr5XlIW8Q/NWK4cJBtBtqxLUPE60QYn+fhO0AoA== X-Google-Smtp-Source: AGHT+IENiQo2/xuwSrvuvrWxd7WVMJZJDMhueZ1oQggUbC/NLgaNC6nrbg1rbaE9PtZNHqC5LmoMVw== X-Received: by 2002:a05:620a:4095:b0:76c:ae1f:201e with SMTP id f21-20020a05620a409500b0076cae1f201emr15580845qko.27.1699277250303; Mon, 06 Nov 2023 05:27:30 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c0:a715:c1a0:7281:6384:2ee9]) by smtp.gmail.com with ESMTPSA id k3-20020a05620a142300b0076f12fcb0easm3272722qkj.2.2023.11.06.05.27.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 05:27:29 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org, Bruno Haible Subject: [PATCH v2 7/7] hppa: Fix undefined behaviour in feclearexcept (BZ 30983) Date: Mon, 6 Nov 2023 10:27:13 -0300 Message-Id: <20231106132713.953501-8-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231106132713.953501-1-adhemerval.zanella@linaro.org> References: <20231106132713.953501-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 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, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org From: Bruno Haible The expression (excepts & FE_ALL_EXCEPT) << 27 produces a signed integer overflow when 'excepts' is specified as FE_INVALID (= 0x10), because - excepts is of type 'int', - FE_ALL_EXCEPT is of type 'int', - thus (excepts & FE_ALL_EXCEPT) is (int) 0x10, - 'int' is 32 bits wide. The patched code produces the same instruction sequence as previosuly. Reviewed-by: Carlos O'Donell --- sysdeps/hppa/fpu/fclrexcpt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sysdeps/hppa/fpu/fclrexcpt.c b/sysdeps/hppa/fpu/fclrexcpt.c index 055fb04ccc..46caf39ec1 100644 --- a/sysdeps/hppa/fpu/fclrexcpt.c +++ b/sysdeps/hppa/fpu/fclrexcpt.c @@ -26,7 +26,7 @@ feclearexcept (int excepts) /* Get the current status word. */ __asm__ ("fstd %%fr0,0(%1)" : "=m" (s.l) : "r" (&s.l) : "%r0"); /* Clear all the relevant bits. */ - s.sw[0] &= ~((excepts & FE_ALL_EXCEPT) << 27); + s.sw[0] &= ~(((unsigned int) excepts & FE_ALL_EXCEPT) << 27); __asm__ ("fldd 0(%0),%%fr0" : : "r" (&s.l), "m" (s.l) : "%r0"); /* Success. */