Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp293647rdb; Mon, 22 Jan 2024 22:38:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IGxHehgk2Lnp/mHq88NXrtH/ig7mjIyiVUkmYGwf8aI80bNSi1xbGkozAJa0L6DkXCBeitu X-Received: by 2002:a05:6871:5221:b0:210:9856:d518 with SMTP id ht33-20020a056871522100b002109856d518mr1251050oac.33.1705991911490; Mon, 22 Jan 2024 22:38:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705991911; cv=pass; d=google.com; s=arc-20160816; b=aztBRDfxVevTam5HvWkEu2Wuia6o/XEiEH6GU6ZUOhb7HTDWTX77+YnqQga1eMQM3S JtV6q7E8Z5m8k/J8+yMv6XCW0ZIt3reKiTl4I+7rfUzwUGZVzpHkZVZUZTtoARAE3PHB DcbZQTLTzZQLG4bpGNj6n3GNU88PKPiTiEYlBNEIh0fSs37CphcCEE6NjXWzxbK+s5qw 27fZqyixkhHMN/ml0GmFhe/meyvn+V9xPvCzdtZrlXbZO0iVJtqirTIrOImDvGhLW4A6 VgVNUjrGzwJt8GLGzGzcraeNp7ukEodgQU3XwzAjEx2GyFTHwkbfuRoC7Nd5kpkGHDqa eMbg== 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:dkim-signature:date; bh=01K6hhKUL+Sc+Jb58aaPmHOz1bS6cOEKCuruEFUUrOE=; fh=24y3+lECGV3Sutde5o9KC8o3nYLoh3u50ch3JjSDnqU=; b=gEqIwmqNYBV+kJLvBYLsh6v6XPmdKUm3YpF9H+yZfjBjei5pvMTXcOeq8PFX2HdHKr fltxTjRF2GJGXNRsqD4xZMP44JMxaLBp7kOJD5WyKaQMfzVfmOknbbb5pXu+8F7Pf6cp i/BLV3mVZDdg171UiF84R3Y/H+/NJIegqgaOnGbpCqR6kp6HTb6jw2lcvDftbj/Bqk/q i6TbLwKwlCjPCcjignfSn1WINtnmB71Yik4cH6cAOaPjYXTP5OzXavBRdEuZ3g7JPQre 4FlU1dzlbKLHQlv0WB4uXUJBVbvepPGN/w/6j1C6gh54N8BJRUogui6mO7QSmyuNV4JR b4UA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=st8wChQU; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-34797-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34797-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id m5-20020a656a05000000b0057d7cff25besi9612010pgu.829.2024.01.22.22.38.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 22:38:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34797-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.dev header.s=key1 header.b=st8wChQU; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-34797-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34797-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 CBFE2286B06 for ; Tue, 23 Jan 2024 06:37:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1D1725026A; Tue, 23 Jan 2024 06:36:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="st8wChQU" Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.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 05E69524C9; Tue, 23 Jan 2024 06:36:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705991818; cv=none; b=EhG9Fw8L9gOzFerLSdN7GzuBeurzCIvux2n96oxm0J5NBaA35viNd9sEWZp26lcNRCq9nmlGsO7yArJqOHfpsdknjzIQtgxeLMo3122kxC/B/Q/KJFylFwihDOxexqKNRubaQVQ9phYrejfGLqR9+oVHK3sQLk1BUa0m2cqrTEs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705991818; c=relaxed/simple; bh=4H939JIw9hVAR20By/afcYObJs+WyUMyRp+bhFZXd68=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=R290a9yVymsMWvJU8RSoO2bLewcFkkvrrjzSQG01NbY2m51p/dc+PwyFzjvGTCP231hWIXTkn+LbZHRFobtNqF0EyzPHqRJAdgeKCR225SHQzWQZnEJzXaxpAwkNHkzHLyBBOBG30KuyLDX2t82zbr8Qmp8aOpRVHKeM5F81j74= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=st8wChQU; arc=none smtp.client-ip=95.215.58.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Date: Tue, 23 Jan 2024 01:36:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1705991813; 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=01K6hhKUL+Sc+Jb58aaPmHOz1bS6cOEKCuruEFUUrOE=; b=st8wChQUf53vwUZ1mf79dNKOmUC6ZPpWkl6h7VsQr1Ltkya77anVULDEfxLEb8VRzEBlIm 5M5vyeyYHTZtP6tADRfRXWjRuPgBh9z/B9Cf+l/MVsGIuGVDtt88+n0KSotCewjj1sWLm3 Dl4bjgMhMRZQc5tJWD/M/59mn24h7Kg= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: Kees Cook Cc: linux-hardening@vger.kernel.org, Brian Foster , linux-bcachefs@vger.kernel.org, "Gustavo A. R. Silva" , Bill Wendling , Justin Stitt , linux-kernel@vger.kernel.org Subject: Re: [PATCH 42/82] bcachefs: Refactor intentional wrap-around test Message-ID: References: <20240122235208.work.748-kees@kernel.org> <20240123002814.1396804-42-keescook@chromium.org> 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: <20240123002814.1396804-42-keescook@chromium.org> X-Migadu-Flow: FLOW_OUT On Mon, Jan 22, 2024 at 04:27:17PM -0800, 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: Kent Overstreet > Cc: Brian Foster > Cc: linux-bcachefs@vger.kernel.org > Signed-off-by: Kees Cook Acked-by: Kent Overstreet