Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp36190lqo; Thu, 9 May 2024 11:48:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVgrx2iTF/2lDo36dt32+HQY5v3+a4gPqSFbh/I0VHc8iWZU5YcR+Yj5dLz5l1gyQsVzVFH3DM5NaZLUvTZTOoJG7SeZbU8vCdk5FBNPQ== X-Google-Smtp-Source: AGHT+IGleNxH99nYcf9W8NId4DwDhlJjtxqMAESBl+PEWGlhT/YXbJvz2pDJc6FJ5zVF1Cw8ntJi X-Received: by 2002:a25:ab0e:0:b0:de0:d3af:f52f with SMTP id 3f1490d57ef6-dee4f35f8f6mr410112276.49.1715280512035; Thu, 09 May 2024 11:48:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715280512; cv=pass; d=google.com; s=arc-20160816; b=M5QFaXJKlNI4Pxztwy2eeUzfKH8W2fOkR7ap73tCRtdh4DUv3u+jgHCOrvc1kzyBUY pLNuPyjqUNPbLiA4H6CgSoJKTdWxPn34tHF6VeD+tlseH9w793yD8xqxiF8ZaJYDOFlO rCKEXwXd6TW8tTd13F1N/CSbYMM2hY6z9y+i7yXplD12cE7Q54dGharIsJz16roeQb/4 mt5wjCwGdfCXb8D9IAMcDS66a0xK6xdH7SsEM4TyoQQFk+DqYuHxLXnjoRebSfSUSwSK IKltXeIGBVytq6U91Qc8zQHXKIAZUR5i832KpHFsh4MdIyEZmuMPjexHCy4Q7Rrw9iHI nfLA== 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=yBryuhVbsX5G3JIiC63QtWbHWndrg7Hoc/s31avaLsE=; fh=foqsWdlEIB/Ag905MvnkdOGE9KnZ9SriYs9x3vygWNM=; b=KaypnC1DTKrD8NsBgI/d23Idh7LHm3MGJOxdXJvRfb4f+gwppaHdN54plxy04SWhjn eZcG1+JPyO9VZyntICVQ5lJ9PCGd3TVSt5+iaB0As9MvTG6SdnlAginzrWEW4oqfMKjK jXm4UBMpa7WhRigzOICOQfRRYtl42ewZDqgicg+mO87fRIA9lxh4oW+fQh3HuKLBrify n/nTMJAumluifP59eiG968XlU+5Tuvz+ehLddRbo7dDeRfmo1zmEi+Vd3AuLNYYjmcgV 3OdJSIRhFP/JbV4V2EckAK3IKJqhs8uineJ2KeTTmY/cueYMw2dZrja6iDVEEoX2IcSs MPHA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=AvkdCCHo; 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-174791-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174791-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 ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-43df5670f39si19377111cf.357.2024.05.09.11.48.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 11:48:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-174791-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=AvkdCCHo; 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-174791-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174791-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id C03911C20E98 for ; Thu, 9 May 2024 18:48:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 421177F492; Thu, 9 May 2024 18:48:18 +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="AvkdCCHo" 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 229A41DFC5; Thu, 9 May 2024 18:48:14 +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=1715280497; cv=none; b=jtgDA/JyJ3SEv2JKESPbg34e2uUZwOWc6Nc2c7BPtDzuyrG2xFI1dqN/nashir9Z2Zb6ocIcmtkhwU69vKSyCb7/b2G8RhCJ3TTX1/1lPxaqPMoh9nvKUjUMyjPogix7WNJrLs0rPqpv/plw3FA2vpj8BJ6dOPv3xaoJsUMkzJY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715280497; c=relaxed/simple; bh=1BSYGbRj20fcncP91U6HQrKo4dwZ7O7Jy8mAFNMP1P4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PLIUsamZq0rcZrfgLL4cXEeGQg2ttdbb3cTWV1TidGR8fP3lChflv+jhTGOSWIbax8DIhzzLggRuFlUDLM5LgZEX3WW+VQ6Y7+3V4XnJsoktbP9+7DSuybvUEB7ElmeeKSi3EVCBB4lUsd/U/SAnNFnHRKa/e76rexY2QOVntUU= 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=AvkdCCHo; 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=yBryuhVbsX5G3JIiC63QtWbHWndrg7Hoc/s31avaLsE=; b=AvkdCCHogDEzcSiyCZF9dw8g6C X0KeSZgV2EK402V6yxvAwPmbn7429/LnT4kQIi7nxgjrMtCKjnGGpe7du0estIZIR5w3Hk1HrlSrt 0VlzNB/Az8nveVmrkmhksokw4gW0Ldvvat06ZwlLp9sItdIdgbKxmV4fHVK+OvHWnu7C7yJBl1qqG 6QaayOuZ6oPROTo+d3CqRK1fjiNBagrMQywGZX/FwSz3BF3STd01IQl2p2QYE9Au+S0v7rDztXMG8 ZrqqnzGmuxYIOaM3TVvA2ro1J+NwQXnJmxFTFsjxJJpRxoJGun6kn3VYo7MNd7u38UDIV3ledqTX5 fWvGPxpw==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1s58oI-001Wl4-0D; Thu, 09 May 2024 18:48:06 +0000 Date: Thu, 9 May 2024 19:48:06 +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: <20240509184806.GS2118490@ZenIV> References: <202405081144.D5FCC44A@keescook> <202405081354.B0A8194B3C@keescook> <202405081949.0565810E46@keescook> <20240509140854.GF3620298@mit.edu> <20240509175417.GR2118490@ZenIV> 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 11:39:04AM -0700, Linus Torvalds wrote: > .. it might also actually be a good idea *IF* we were to have some > kind of "implicit cast drops bits" warning, in that the compiler for > that case wouldn't remove the upper bits calculation, but would > trigger a warning if they are non-zero. > > So there are actually potential advantages to just always apparently > doing the full 64-bit arithmetic. > > Without debug warnings, it's a no-op that the compiler will just skip. > And with some hypothetical debug flag, it would be a "you are now > losing the high bits of the time value when assigning the result to a > limited 32-bit time_t" warning. FWIW, the thing that somewhat worries me about having a helper along the lines of combine_to_u64(low, high) is that foo->splat = combine_to_u64(something, something_else); would be inviting hard-to-catch brainos - foo->splat = combine_to_u64(something_else, something); would be very hard to catch on RTFS, especially when you'd been staring at that code for a long time. Explicitly spelled out it would be obvious which goes into bits 0..31 and which in 32..64.