Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1330647rdb; Wed, 24 Jan 2024 11:34:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IHGLH3HHzR+0ZJmTWbbFVoKblxzY0dB/sFk8+R5DqlKv2a/qxQWk+ggoGnVKWlR9X2UIcrP X-Received: by 2002:a05:6214:1d0c:b0:686:ae74:10a7 with SMTP id e12-20020a0562141d0c00b00686ae7410a7mr1678191qvd.119.1706124863423; Wed, 24 Jan 2024 11:34:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706124863; cv=pass; d=google.com; s=arc-20160816; b=i+pPN3Mcl07VBrKbuV8PwYQBCZOzxIiJqvsmcfOBlu4FkxHMwjfns7GZPTnQogtqON S8jmtcNh5bcudqYuerinZv0idA74Kf0FTa2hu1mVad4i6TVw4e+AuI4YXCtlF9m7zdwi dq4OxiUv4gJ8qqSDI/8sP6tDxl2ip42u87RTdhvSG76UC5ChMyOK9PSedZXZXsVgzh/e QeToYJoObBr4zOmMBK91cEJiz9Yo2M5JgJQw1ql6QJ/q2cOgTuF862COo9NbAtb/p97R /y5tUoAJhjjCC+yDxaqygLROR4AZ8g+NXfQb6g60aFzYcmVzKjl8zUdTDSQrLuqPYU8H mN+A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:references:in-reply-to:subject:cc:to:dkim-signature :dkim-signature:from; bh=FAg534iwdS91fkdcXs5EMfhsi34lrsD1PSWyXPhB5Ok=; fh=3MhxYlNEiPkzMq6IEzf4YjuTsse8clcCGHGYdsI+L9c=; b=vbmEQsOS9EfFACx9nJCKh73m48MH70zVH+7i6EIAo371ASJEObHdBesEez/nvpro6q UUFZJWqgnEGirjwl/SOiTTKeFOFDqeveJAbP3RjN5nHFIbeTYaIWma8Yon9rhiMIJ9tM Ej7nVrui21RqIWHujhDW4gXaP3N1F6xCf/Q/FQYbTUoBIgwyQP1aWPwwts2DZVSaziV8 5rZLzfPKgssdsgssJlY51DLFwps4H4JXrxtrvGJruacTR8XMWjwV8oyF/uQBD61hTLvI nUy4dHr1YMapAkQLaNtGVr7QMJxIFDWVNd+RM0DjNuJUE2WBseUNy47VbEjyS54Cd7Q6 CrKw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=0J7DdVlj; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-37597-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37597-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id v6-20020a0ce1c6000000b0068183ea228esi11148316qvl.312.2024.01.24.11.34.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 11:34:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37597-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=@linutronix.de header.s=2020 header.b=0J7DdVlj; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-37597-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37597-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de 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 313881C21F56 for ; Wed, 24 Jan 2024 19:34:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 66AD0132C30; Wed, 24 Jan 2024 19:34:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="0J7DdVlj"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="58F68lhJ" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 2EDBA132C20; Wed, 24 Jan 2024 19:34:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706124855; cv=none; b=bNgNtQmlC8NH61F6KULXbTmJX5ySsmUnJxN9aB6Z2n5jCWktJN1oXM3drTwi+hyFzJ9yYtjofupGboONCDyv50H6zEOUzili9Ks8va0RIHl6CFAnBk48gKjkx821kSaarFnBTSIedM77eZVI6Eq1fesPM4yb8lm3Uio5gQcuIH4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706124855; c=relaxed/simple; bh=GYJFXfXsIOPeYbximf1oUJWFqHQl+GwEjV9Ni5wP+aI=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=Dreadp43JZc57WBVTqDUKPyRn6+h/Uoh/h78RJotFdxPJHiaAnx2LioujTTnThGtF/lX7/Hu6qBXdFCm9Vck8ILlTpHCa0SF6tSczXhrj5EA/7LuHe2npSwnMoj3sL8pdEx9rjPig0vu8wxDCOavqygfborik2Sx8G8upvUCizI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=0J7DdVlj; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=58F68lhJ; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706124852; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=FAg534iwdS91fkdcXs5EMfhsi34lrsD1PSWyXPhB5Ok=; b=0J7DdVljP8JzWt5Vt3UVPXhNxvShFJTnmQ+om8AydJjMB1tBLUj5foOh9xkkOjWVUnnRk0 HAGF0VndthdlWYK3fYrehQhRpGC9gCF+g4PPbsx0cGMHrRK9mPfvlP763tf86ZYqM9wmaY fFMivweskdhGOFmlrASRLLhc2XEv7DCGl9xBse+GyGPc4yXXPkttctqjAm7GcnH06Pzszf cNCqGAPnXcS/nZI35xTK+zFiioFXZiDwamSOfoSyQOub6GPEZgjnkA13vllMdmKIwJ6D+e 9tDfRJ3610hqVmE78wRZRa1ZS6QbDvCsoIMQTd4He0JbNqw7LJxuugQ9yHBvEQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706124852; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=FAg534iwdS91fkdcXs5EMfhsi34lrsD1PSWyXPhB5Ok=; b=58F68lhJ9TrKiArwgXOJMl6V5qF2nE+HAOpa9PicsDQDPZiMMfTSX2bUtRXbIIAADOMM8v PFQnYw/vtKQnjWCA== To: Kees Cook , linux-hardening@vger.kernel.org Cc: Kees Cook , John Stultz , Stephen Boyd , "Gustavo A. R. Silva" , Bill Wendling , Justin Stitt , linux-kernel@vger.kernel.org Subject: Re: [PATCH 75/82] timekeeping: Refactor intentional wrap-around test In-Reply-To: <20240123002814.1396804-75-keescook@chromium.org> References: <20240122235208.work.748-kees@kernel.org> <20240123002814.1396804-75-keescook@chromium.org> Date: Wed, 24 Jan 2024 20:34:11 +0100 Message-ID: <87sf2mjzkc.ffs@tglx> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain On Mon, Jan 22 2024 at 16:27, Kees Cook wrote: > In an effort to separate intentional arithmetic wrap-around from > unexpected wrap-around, we need to refactor places that depend on this > kind of math. One of the most common code patterns of this is: > > VAR + value < VAR > > Notably, this is considered "undefined behavior" for signed and pointer > types, which the kernel works around by using the -fno-strict-overflow > option in the build[1] (which used to just be -fwrapv). Regardless, we > want to get the kernel source to the position where we can meaningfully > instrument arithmetic wrap-around conditions and catch them when they > are unexpected, regardless of whether they are signed[2], unsigned[3], > or pointer[4] types. > > Refactor open-coded wrap-around addition test to use add_would_overflow(). > This paves the way to enabling the wrap-around sanitizers in the future. > > Link: https://git.kernel.org/linus/68df3755e383e6fecf2354a67b08f92f18536594 [1] > Link: https://github.com/KSPP/linux/issues/26 [2] > Link: https://github.com/KSPP/linux/issues/27 [3] > Link: https://github.com/KSPP/linux/issues/344 [4] > Cc: John Stultz > Cc: Thomas Gleixner > Cc: Stephen Boyd > Signed-off-by: Kees Cook Reviewed-by: Thomas Gleixner