Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp15759lqo; Thu, 9 May 2024 11:08:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWOOYypodPPTRGbi4LXSGqzzVC+fvaga5QIBtcSjt2MK+QU1jCHPQjDbQw9QDvqHnIZqijYARCxhc3NXpCTu4x+GFU07iPxB5nmIhC6fg== X-Google-Smtp-Source: AGHT+IE6CRy/fyPdWoU/vymtUuko7cnugUrmLBQpdXqWQ2zTnL8lbLquDwyfTQ4r1aq9xIYO9R23 X-Received: by 2002:a17:90a:4307:b0:2b5:4ee8:e5e8 with SMTP id 98e67ed59e1d1-2b6cc758bb5mr228394a91.16.1715278124380; Thu, 09 May 2024 11:08:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715278124; cv=pass; d=google.com; s=arc-20160816; b=JdRsYYrteXQdzmiSx8n39kiZ9XCb9SAI6IDKy1fvTxLcH7jaerf17Qb+VrMv5TG0HG Nq5H12aP9mx2q6LSgSgKkm9geJ+9omMmWatLVBVjgPooq+mmS4JSGeNzIl6aZyzblMBC 3ixTXpJAQma55uZOa+I4YJICLbCsCiIboCPUkyJPVjwaM0KTndfjFHyaUVcnpT1nrhme uBViBfpIEvi6TJ9fgtKy8LnbUl+3JQgxZM9jMcTNwhtzxxUGgvTJKmNvbIKNUgsWaLyP flVMwkKv0tswIUW6ys5y7lI0LDJUBQ4RrIWeQX9TbRjYyITSTaulIMeehZBBWL6pitMB jiBA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=2M1QRjYBDT1Zd0NqfbgFR5skSig9YZV6L8U7l1RklbU=; fh=benXImr7Ti5FIYD/vBsW+lrLyCMCFOiEhMsMuFCzgQ0=; b=J4/ZaQR69u0//VBzApOuZ08gw0IogYpn1dpcTKjrIB7dEumGVKbjnE8Nm+k008n9GT 6ba9+2BMm8vlWKBtxNKnzfJGQmBrGBvpuVO6QO703vaeUaY1mFe/Nb/7Bo8oztYrOu2L 7fRcdUmyPX2xJuXwmEZqlz40eYU54SkidFgjprLyO9rZZcKn20+lQ7/fk+GOYe2OHdQE pXqpKSZW0wpmXn1NUPdcpVvbdUNRaDZIcW913SvNQq92K8Ed7UgC4ZvVsC8fpC0yZyTF 6ZoA8pKizc4tWauGRQ6/tyqvoVu7guBjH1w+cHHNpytpiMgkJ4yD4SAG3iKAOAKnLn8C gvuQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=IwKBi4r0; arc=pass (i=1 spf=pass spfdomain=linuxfoundation.org dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-174752-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174752-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2b670f5b24dsi1969371a91.70.2024.05.09.11.08.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 11:08:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-174752-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=IwKBi4r0; arc=pass (i=1 spf=pass spfdomain=linuxfoundation.org dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-174752-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174752-linux.lists.archive=gmail.com@vger.kernel.org" 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 D1CFC2839B6 for ; Thu, 9 May 2024 18:08:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 59C1D7711A; Thu, 9 May 2024 18:08:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="IwKBi4r0" Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 39DCA6EB62 for ; Thu, 9 May 2024 18:08:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715278115; cv=none; b=ahPnasSyDgCBICQDPLqrW0iIyQQeAcGW5Sa0N7JstMJv9606msQsOYwj39CwQO4DzVCV+TZ8sCaj7Qts357lWhhAIT0mx1pbG3t6XLdSCf3tABkprsXX/Ug4iTOsF8n1g24H1HB7YB3DLsKY+BKMBCFH+Cw2hrw6/DeLrnTXPs0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715278115; c=relaxed/simple; bh=B/fLZgJ1kMx5q/e/aqEvOH6JUgyuZ+Q/2hXPHkpLqEo=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=lsQYiIM4ahhLLpOrV1N/+HpK8zjd6IGZIN/Jyi7C9GkW9UOIPZsqIYXKjo5VcUCX2f+Wk3qxoHmQVOBhv2SpEqOHDshWjARjH7WrjXzDkZhG08ZMR2BjUTWPmoj4LLH1l6aK9qlD28eAdcFl6vqhMkeBHtESRv2HNP8vn1c2KO8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org; spf=pass smtp.mailfrom=linuxfoundation.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=IwKBi4r0; arc=none smtp.client-ip=209.85.218.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linuxfoundation.org Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a599eedc8eeso313376166b.1 for ; Thu, 09 May 2024 11:08:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1715278110; x=1715882910; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=2M1QRjYBDT1Zd0NqfbgFR5skSig9YZV6L8U7l1RklbU=; b=IwKBi4r0DT2bnZC3xar/In+2PnJV7LJaN1eie2qTgFhmDjRZ13MDTwKaDCw2FlhKMT wwNbiuEaH7IrVbrtP2rxP8+MXmSzpEV8h7HUpEfKF7llk8CHCwCGUfLGpm+IOkLEsLtD m7mF+qBviPAQYt3g6aeryOJQXsw/bG3uFgHYc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715278110; x=1715882910; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2M1QRjYBDT1Zd0NqfbgFR5skSig9YZV6L8U7l1RklbU=; b=g2g1WqzkjdfQk7xa+LwS8o9GW5DsavLYipdVrQ6jZ9oSnkEjcJB89WUA7e/sEliKU3 rK0AhXqC/kfDshE6W3eROXsoS6dMl7SANNPTy5eobfP50aD7ELBrJZyrCtGeXogbE5AE obbpvg8k3EPhQrTrrXyGtqGd83AtJZGSw0puaI4HD+dnIgXecyX51a+Gxk/6Ne9xWZ8g CZJNb7JkRxvhgswqjJtc/Du7T3ti0xPEA+fHzij33QzGAgQPKY5F15/QeOqQZ0QGSCvM wNZCONNz4cXGmrRGQtAAPZnKt0Qrte0AZ9c/tn1akKmVIEEi2IXoqmvKBpQPKomPPdhE tY7A== X-Forwarded-Encrypted: i=1; AJvYcCU+DxJGOdSHBgt6tesuPYk9GT245F2QbTIUieN4pwxSJ+sbS2+PvnMXEnBNOBjHJxF7nRFwLYImaSpWpUrSk1ANnCrqiLVRRsd8QvSq X-Gm-Message-State: AOJu0YyNQNGBkyds3g9iQiBoxP2WYD+vV3WfQSxlTYasGCOce/Rx7gae es5twJOaRhAGfREDWLHBmDtV/weyLDb/WwCFwGBZGGVdZd3uhnkfEw3j9d/zblfMb0SDvQZs2VW XPfM= X-Received: by 2002:a17:906:81cf:b0:a59:a7b7:2b8e with SMTP id a640c23a62f3a-a5a2d5853b3mr20622066b.29.1715278110313; Thu, 09 May 2024 11:08:30 -0700 (PDT) Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com. [209.85.218.54]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5a1781c269sm97927266b.38.2024.05.09.11.08.29 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 09 May 2024 11:08:29 -0700 (PDT) Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a599eedc8eeso313369966b.1 for ; Thu, 09 May 2024 11:08:29 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCVU/j6t7zuskBMvoTtg9kg4DTwGHbt6fWbioDj4NpsdPxPenpSTg4mYd2+2YOoyTP2/urhmdRv5PRLwHllJbXDY6falD0NbtcRSAgQy X-Received: by 2002:a17:907:1118:b0:a59:c5c2:a320 with SMTP id a640c23a62f3a-a5a2d581b19mr26210766b.23.1715278109328; Thu, 09 May 2024 11:08:29 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <202404291502.612E0A10@keescook> <202405081144.D5FCC44A@keescook> <202405081354.B0A8194B3C@keescook> <202405081949.0565810E46@keescook> <20240509140854.GF3620298@mit.edu> <20240509175417.GR2118490@ZenIV> In-Reply-To: <20240509175417.GR2118490@ZenIV> From: Linus Torvalds Date: Thu, 9 May 2024 11:08:12 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC] Mitigating unexpected arithmetic overflow To: Al Viro 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 Content-Type: text/plain; charset="UTF-8" On Thu, 9 May 2024 at 10:54, Al Viro wrote: > > 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. Casting to 'T' is probably a clearer option but doesn't work very well in a helper functions that may not know what the final type is. Any half-way decent compiler will end up optimizing away the shifts and adds for the high bits because they see the assignment to 'all_bits'. There's no point in generating high bits that just get thrown away. Linus