Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp3154699lqo; Wed, 15 May 2024 00:58:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXiWCGgU+Ilv8pYsj4eNjSsev/kp+ZP8lrAUGYahm3PlgRzvCni88ifPJVaUPdjEWmtA5+p0xLDNIWAqcaL5rnPS2juNo70dP3PdUCAqg== X-Google-Smtp-Source: AGHT+IGDRKN8nkppOn7ITMmcYEcQZZiLA7/gzrhraH3iz1+kDxRa7yJpMx6NjQoMJoF0aTYvP2xJ X-Received: by 2002:a05:6214:5f02:b0:6a0:a9dc:b117 with SMTP id 6a1803df08f44-6a1680bf323mr173862386d6.0.1715759882486; Wed, 15 May 2024 00:58:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715759882; cv=pass; d=google.com; s=arc-20160816; b=xdxjD+FbJw3uOLPDlCM3vfQ+ItUYH7fMPVUeLyySCnrzXGvRISvNtP0ag+/qdflX9O XOHICAqD01sxScpmyPdjy046e1bkMVGUg/apRNNmlOwxHOTTjJ3PkixV2RqOlgwdSWIf u7vxIL2PPFEak9UOa0ZZYaN68m51heWmK2p+45xZ6e/6uL3XWd9EXkXQjaF/XsTOYvf1 wQZiiOvF7dPM7vNQ34gt1p/nAbVArzYA/mTBL325giezbqH1A9/35QemidZUOJh62WNS m8jlLP8Wi/HNMAhoNKGeKv3K/lAoyoZqKFNJnIHxOBgUw/f1Ec93GXz6+alw7OB85iaj 4CDQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=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=EVMjXvYoWu9duYh304Rm/ZLOEAMOJGnAs/As64ANNG8=; fh=kQ7HhUFwhb9nqukW1qynT86Dxj+S2/7AsT4MaSauL4M=; b=vO/vhE9+sIylraPVASKKEiKZt+G0mN/ZyAO7Nr4tWBC/0lBvQsHlb0IkG0S7a43nnf BM8wIuZlkLuxOgJ1vkwuPeRsWqbU4dJQ4NvUAWLaeh7J9gbJZAMzjBbzzDjT7J09i2T6 8AHXAZhMdv13bH2QCXMgcfPK65SY2nkjvo+0U7YtVMfSJyz6eOoUCO+AGcd+Ph7HJMMN yEKMLteS0imOMgwmdYKZrd9APiKqIJ+By6NtJPMn3OzslebvX31y8PWsPepnRAaUS+c3 Bmg/paBg4oPjoEKbGB+vqj/magyy/92iWyAqpv27pxN5EA9d8qpFK2+/MU0dFSLtX246 bCag==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="MZil/YLZ"; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-179617-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179617-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 6a1803df08f44-6a15f2f36c2si135369966d6.515.2024.05.15.00.58.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 00:58:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-179617-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="MZil/YLZ"; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-179617-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179617-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 32AD01C20F12 for ; Wed, 15 May 2024 07:58:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0B4AB4CE13; Wed, 15 May 2024 07:57:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="MZil/YLZ" Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 376884CB2E; Wed, 15 May 2024 07:57:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715759870; cv=none; b=UrIMNWpG16yp+7ceaP9kcHUB7w58vqjX4h7uPCUjtWqSThT5knPO2aBGmscO3CaUVy54KZ0QoqKunYm4yAs2lFjo1tW1pxFaaeV0bXFaHn1VaPRC9L4F7zHxA0ZLzyxXau1lFM3IN0wThtP3vlG+YlsaM3Xf5dHdJpwPwBzT4pg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715759870; c=relaxed/simple; bh=Z/lRFMon1x6t5IgwQK1lijm0gQDnovjnOQHfgmMkPMw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=aWJw/ynJfZQc8anL5+E5T31QXssnUEXd8XfQrOAKcyUGoF2nNbxFQ7LfVqVvXR/HChTaS9hr+QjSqP+WOl32RVi6vA9moM9SqkyyUe5huQmfR2MKAfLblgg5dqMVb5bS7F/G87Vc5dkzZsR6WTIO/Kz1MSuiFdBMHL6bOxg2ADk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=MZil/YLZ; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=EVMjXvYoWu9duYh304Rm/ZLOEAMOJGnAs/As64ANNG8=; b=MZil/YLZtZbxcwu9zxQwWqU/no FsJod91Q2GIeY0p9N68dmcq5o7/HloU8fCADGnfFGR8QT+iJJb5OBTw334/PF1eKpbJJ2Q2a10EZA EZagCuaq/y9hVOs6uWdWEMoUmfnLm0WkpxJdNqmHxUKuWZ3BLjmNV+bOFkYPF8mJ6Vp6uEIdeQRwi MzJaP8h/5ntJd6/mbyYvI5xCt4prSAMqbhPakulwAPJQtA3+aCGPXodVnX0kn/mZsAcWN/0AvBetR 9c2+qGOmc9Jz7WPF7zeGbljGp4kS9f8ogDFr5/oix6M3692dOekp4m541m3lXgIGeluXV5te6uxaI T/w0fuLg==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s79WD-0000000A4ao-0ebj; Wed, 15 May 2024 07:57:45 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id C8FAA30068B; Wed, 15 May 2024 09:57:44 +0200 (CEST) Date: Wed, 15 May 2024 09:57:44 +0200 From: Peter Zijlstra To: Linus Torvalds Cc: Kees Cook , Justin Stitt , 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: <20240515075744.GZ40213@noisy.programming.kicks-ass.net> References: <202404291502.612E0A10@keescook> <202405081144.D5FCC44A@keescook> <202405081354.B0A8194B3C@keescook> 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: On Wed, May 08, 2024 at 04:47:25PM -0700, Linus Torvalds wrote: > Now, another thing to do might be to treat assignments (and again, > implicit casts) to 'size_t' specially. In most compilers (certainly in > gcc), "size_t" is a special type. > > Now, in the kernel, we don't actually use __builtin_size_t (the kernel > started out with a very standalone type system, and I think it > actually predated gcc's __builtin_size_t or maybe I just wasn't aware > of it). But we certainly _could_ - or we could at least use some > special marked type for our own 'size_t'. So I've been arguing that since unsigned (and signed too when -fwrapv) have well defined wrapping semantics and people rely on them, you cannot go around and assume that wrapping is bad. You're arguing much the same. I've proposed that Kees instead adds a type qualifier to explicitly mark no-overflow / no-wrap types. That way __buildin_size_t is no longer magical, and it along with all the other __builtin_*_overflow() muck can go away. You'd end up with things like: typedef nowrap unsigned int __kernel_size_t; or perhaps: nowrap int idx = j * sizeof(foo); etc. To indeed annotate these baby steps, without making code needlessly ugly with all these __builtin_*_overflow() wrappers.