From patchwork Wed Oct 18 13:08:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Liebler X-Patchwork-Id: 1850805 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=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=rKXhOlo0; 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 4S9WR36Sxwz20Zj for ; Thu, 19 Oct 2023 00:09:51 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C5BB23857B9B for ; Wed, 18 Oct 2023 13:09:49 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id A7AE63858D33 for ; Wed, 18 Oct 2023 13:09:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A7AE63858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A7AE63858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697634582; cv=none; b=wwd6Wbl1WsWD1uyxhDlbjWc8X7rLCdf7SAXeOaMqO2Ko1C2iN5h7sdFOroKKq6BO1oTVfX5nLUQeR9Ndt3XXNhjGoWUDt8qJ4t2OlfwMrR9tnyJp4078FXgqGKEM9eh9M1mYhdRfcNml5YXQ2+aQluOwLYYOTIAX9LV5LUms/zE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697634582; c=relaxed/simple; bh=v6o71J54OhQzFpydKhPHw2SCJezht/PSYmlfoxj5Uao=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=N3xfQ+QoXvSshGGAIoagzg0cD+q8tjTUDGyDPyozP2MnsQgPkO+NtZQ0N7fluiyX1Sf/2mLysDLDepO2Ku9lfFcCOYLpXSRHZqhD5wNhcKpEgRkI27zceneqH56l+evWwmYxp6zpkdlfSF/It4jMPGMkLj+N3ahB0Rk7qm2fWdg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0353726.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39ID7Oh7030119 for ; Wed, 18 Oct 2023 13:09:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=pp1; bh=IgPADK3KCnvNa55Ocv4Rr+si4vusQVa+rxLlnAa/lxU=; b=rKXhOlo0Hyo2GkugsabIY2AVWwKV0qGzo/Nmg3qVVRNa0MPRcXgY72eFPA3/IIs2kafl jPRI++dSQam9yy+3RJQheyk0hRjpiwotwpy7moW/uQcCX6ITVkMMadCQexNGRZRGTJd4 Xf3rdTSG5o7cskreudFfhiIajlfEgkds8KXZpt+SB6xuCzWGCfwgxMiRREkdjsK/LqNb LtybwhvWcq8McwS0FFf6xi0tU+P9ZnNelrMvvj9oFso4dBCWg0BRX7rB9RCJoY5YiJKU SNtAx2rCMNYAKLC0pXon/BZBbmbkgRBmTmO9hAUF39OxCGht57OM5vSPXBK6JNpzeAkR oA== Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3ttfyar3rp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 18 Oct 2023 13:09:38 +0000 Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 39IBumn4019900 for ; Wed, 18 Oct 2023 13:08:44 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3tr811r3gs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 18 Oct 2023 13:08:44 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 39ID8fmq12386950 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 18 Oct 2023 13:08:41 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9C15220040; Wed, 18 Oct 2023 13:08:41 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7F3A720043; Wed, 18 Oct 2023 13:08:41 +0000 (GMT) Received: from a35lp69.lnxne.boe (unknown [9.152.108.100]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 18 Oct 2023 13:08:41 +0000 (GMT) From: Stefan Liebler To: libc-alpha@sourceware.org Cc: Stefan Liebler Subject: [PATCH] s390: Fix undefined behaviour in feenableexcept, fedisableexcept [BZ #30960] Date: Wed, 18 Oct 2023 15:08:40 +0200 Message-ID: <20231018130840.3249206-1-stli@linux.ibm.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: v_qinSkIY2OFP4kynatwWHVb6tVj1Rsu X-Proofpoint-ORIG-GUID: v_qinSkIY2OFP4kynatwWHVb6tVj1Rsu X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-18_11,2023-10-18_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 adultscore=0 lowpriorityscore=0 mlxlogscore=652 impostorscore=0 mlxscore=0 spamscore=0 clxscore=1015 priorityscore=1501 malwarescore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310180109 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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 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 If feenableexcept or fedisableexcept gets excepts=FE_INVALID=0x80 as input, we have a signed left shift: 0x80 << 24 which is not representable as int and thus is undefined behaviour according to C standard. This patch casts excepts as unsigned int before shifting, which is defined. For me, the observed undefined behaviour is that the shift is done with "unsigned"-instructions, which is exactly what we want. Furthermore, I don't get any exception-flags. After the fix, the code is using the same instruction sequence as before. --- sysdeps/s390/fpu/fedisblxcpt.c | 3 ++- sysdeps/s390/fpu/feenablxcpt.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/sysdeps/s390/fpu/fedisblxcpt.c b/sysdeps/s390/fpu/fedisblxcpt.c index 728f103f43..84b2c5e64a 100644 --- a/sysdeps/s390/fpu/fedisblxcpt.c +++ b/sysdeps/s390/fpu/fedisblxcpt.c @@ -26,7 +26,8 @@ fedisableexcept (int excepts) _FPU_GETCW (temp); old_exc = (temp & FPC_EXCEPTION_MASK) >> FPC_EXCEPTION_MASK_SHIFT; - new_flags = (temp & (~((excepts & FE_ALL_EXCEPT) << FPC_EXCEPTION_MASK_SHIFT))); + new_flags = (temp & (~(((unsigned int) excepts & FE_ALL_EXCEPT) + << FPC_EXCEPTION_MASK_SHIFT))); _FPU_SETCW (new_flags); return old_exc; diff --git a/sysdeps/s390/fpu/feenablxcpt.c b/sysdeps/s390/fpu/feenablxcpt.c index 0807e610a2..76d25316f4 100644 --- a/sysdeps/s390/fpu/feenablxcpt.c +++ b/sysdeps/s390/fpu/feenablxcpt.c @@ -26,7 +26,8 @@ feenableexcept (int excepts) _FPU_GETCW (temp); old_exc = (temp & FPC_EXCEPTION_MASK) >> FPC_EXCEPTION_MASK_SHIFT; - new_flags = (temp | ((excepts & FE_ALL_EXCEPT) << FPC_EXCEPTION_MASK_SHIFT)); + new_flags = (temp | ((unsigned int) (excepts & FE_ALL_EXCEPT) + << FPC_EXCEPTION_MASK_SHIFT)); _FPU_SETCW (new_flags); return old_exc;