Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp99913lqo; Thu, 9 May 2024 13:59:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV2nKmQRde6svL7Lbleudwm8rcjnm0kfW2X23zlAqaMutVoszH3SRvMYzcK15NpDuocINbn2wSKjqtF0OfKh+cJAl6NnDqunKRnvQ/2UQ== X-Google-Smtp-Source: AGHT+IFecPvUtAw4X/aBKldgXlgLFLaYAajdRMrM5LTbFVzQ12cVt2lMEstw2Pr+eexZmqvhCMI2 X-Received: by 2002:a05:6a20:5607:b0:1af:b4f4:e73 with SMTP id adf61e73a8af0-1afd14746d4mr5434404637.21.1715288372184; Thu, 09 May 2024 13:59:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715288372; cv=pass; d=google.com; s=arc-20160816; b=XGyRO+KJ+iGF4gcoUxuEP3BrcVdpMXDohYcr7GGqSG59EIhbo+ii23MYqLjCn5wPOV Or0uxoF+YugGqcjwWjxKmhou+pABZaNVPNCwV5fXKZDsQnw+b197ar23r4MuHz4tp0x5 ypLnz6aNYl7v255WDDkEfBv9nSvaKrAVs/N/tbCjNXDwYamP2jnFdzBic3191c81U2Dq w5THSa/aAVs5A+TCsDmCBVLgNUsr7c03z5ZXXPfcadGEtQrC1WXral31gaT/1Hoiet1D 9SCV67SmZxyib48ABBQ+9FhUAuDtxgFQgkuBGzeYI84XJQWQ9dRx4Jl1TQtQilPz0lQd DqfA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date:dkim-signature; bh=od3CEJrhje5agF/aqQd6TctGDFUrEkaEPS1ndedOerw=; fh=foqsWdlEIB/Ag905MvnkdOGE9KnZ9SriYs9x3vygWNM=; b=rJEsCak2XtfKeT/zTDsZv18jyh7XSa7GvcOcqif9HNloCTSLl22vrs0asv5afs1r5J IHQ3VnG+bTWClKK9JX8rN3G8UsPYgwhJ8rer6yVxnoBtddxKk+9/9QI7MQ7/+4w++ZTG CkW88tbD1UGgMBpoCKU+8mp6Pa9WVfeKc9VEwFNfYThUbVLk800QNnfzc0BwjoZxc4Hh q6PReLK6Z2XTDSF28E2XihBsfnglbM81onLYueWwsPw1z2FS24rLfBBDoYI4kjrBvolO 657wUZKmqDo0gEd/5yfpLlBskISGZ/J9hTgoSTgxO3lElDRR0vQ14wmSDTuFC/fCTRyr zq2A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=SoOzZCic; arc=pass (i=1 dkim=pass dkdomain=linux.org.uk dmarc=pass fromdomain=zeniv.linux.org.uk); spf=pass (google.com: domain of linux-kernel+bounces-174748-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174748-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-63411902e5asi2149321a12.570.2024.05.09.13.59.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 13:59:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-174748-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=SoOzZCic; arc=pass (i=1 dkim=pass dkdomain=linux.org.uk dmarc=pass fromdomain=zeniv.linux.org.uk); spf=pass (google.com: domain of linux-kernel+bounces-174748-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174748-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 096E62834B2 for ; Thu, 9 May 2024 17:54:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8FC21770FC; Thu, 9 May 2024 17:54:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="SoOzZCic" Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 499131A2C35; Thu, 9 May 2024 17:54:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715277272; cv=none; b=lF/FEjSrvfX9VnTOCaRsmx8T9M9v2RSex30R1DF573mJJIFcmE0rt5DPKcIEWcF1NXDIAbTBjquI0aeCTmHFfmAmOsHXtM2IDajE7jOkVmD411ak8GSvrcpF/9I4jcfFg6/E/g4txeqT43Hkb9rtUWJPBEqFL/uXGz6kV2zwRzQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715277272; c=relaxed/simple; bh=+bcJRbV4GT1PA6vhESJmH/6HNcsCAh4o5jrInzigEjg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=YwYT9zxNLXZI1DRi+JTgnJAqnaBvw7g0+xMsvqGDwogQemk/LY/FE6MHs4R/pXqXF0dlo64AZM/DkX1tCz3pkElVZpgOFd4tkcTPXU4OLnSeEbtN1CezGlIv8OPuykenN7bCc0FKvmOUTGhQUoonL9tmj+VXuBUZmSoBXoHS6so= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b=SoOzZCic; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=od3CEJrhje5agF/aqQd6TctGDFUrEkaEPS1ndedOerw=; b=SoOzZCicszp7wfFaYTZ73pqT4b B/kbl5+6HK5VMkd/ulc83gBc8GGY3ZzioOR9NDem1mogYcfBzTE+2hBHekJtUgPZ1TYsdnQwsDMZv 5V6HBevZQHt2dTW8MEM5jrmkvy++Ujxb6SS0TDep+m+xUZHu+XnQiLr6ndWXAQfdY3EU4ZpHiYf9K LeKTqq4hp2rKFLI09XDzmbc7PSCV8FiP2SsS7fVJAfesEadKI1RkFEWrh1IoIDYn7L925Bmxvx4GU TT60rXqDwO4KZgkUKJDEDysdTCFguOnxzIlImaSo9mkjuVvtkhySG7F7Prh9s0FNMsrDIQK5TYm7h Dr0PHwtQ==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1s57yD-001QjS-37; Thu, 09 May 2024 17:54:18 +0000 Date: Thu, 9 May 2024 18:54:17 +0100 From: Al Viro To: Linus Torvalds Cc: Theodore Ts'o , Kees Cook , Justin Stitt , Peter Zijlstra , Mark Rutland , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [RFC] Mitigating unexpected arithmetic overflow Message-ID: <20240509175417.GR2118490@ZenIV> References: <202404291502.612E0A10@keescook> <202405081144.D5FCC44A@keescook> <202405081354.B0A8194B3C@keescook> <202405081949.0565810E46@keescook> <20240509140854.GF3620298@mit.edu> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Al Viro On Thu, May 09, 2024 at 08:38:28AM -0700, Linus Torvalds wrote: > Going the other way is similar: > > all_bits = low_bits + ((u64) high_bits << 16) << 16); > > and again, the compiler will recognize this idiom and do the right > thing (and if 'all_bits' is only 32-bit, the compiler will optimize > the high bit noise away). Umm... That would make sense if it was all_bits = low_bits + ((T) high_bits << 16) << 16); with possibly 32bit T. But the way you wrote that (with u64) it's pointless - u64 _can_ be shifted by 32 just fine.