Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp244650rdb; Mon, 22 Jan 2024 19:51:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IHbNuGo/ckEtyMX7CPOcbNq8sS7/a9BC2OBGQ6Y1SIhk9DX8kDmxu7QWdN2DQyhGgVXdlkU X-Received: by 2002:a05:6e02:971:b0:361:ac8c:9f7e with SMTP id q17-20020a056e02097100b00361ac8c9f7emr6998462ilt.61.1705981904337; Mon, 22 Jan 2024 19:51:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705981904; cv=pass; d=google.com; s=arc-20160816; b=KIZnj7yH8NAINS185yr/jP+or1B1HCywOW0lBdaXPsC7nvCFmI3Bjt4LYYnjv9Usqn LBFjN4QNJzuWrPUq7FUgBOsco3lGZbjN2AuCj6H6i7I7qXYkc9gmCOk4PbkhFX58CzG0 ksQsgTYD1c8VoX3a1PzVQO7AC8C1+lPoVTEg4Rkqj0wvZL1oeMbYURG1ennTxw3IpBFL 2SLR8qnA26AWDIl9VuTdsLKIODVlNHPmdZ+hgGKrO8dhWy8A9NpHPvdCa+HgKVRMFc5p k+hWX1Dz2rt9VSQOeTStSw3FUuuKY+h82H6ca1Kh0CtOgBkWfGzI7lJSi8IMSmQGwX8U Z4xg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:references:in-reply-to :user-agent:subject:cc:to:from:date:dkim-signature; bh=EJSvHxAZAdlpVApMaX7oA5mXz6/ivaiHXBiNqf5e76I=; fh=nBZm1dvAdwdkRMP1e874MhniwaY/G//Tn55uSQRtvi4=; b=dl68TbSUqS+232TS0Yq4193LIEMdxbQkplzz0dp4o0H/XgzLQChcbvFZRN3HVYCMAZ 8/RHiaQH96Pda3W6zQH39j2oGeYLM8sf2lg+b88PK3Q3WCURDTPzLwVl321C57PQe1pU s3QXrfHKoNQYRdnx8JSqLLrsJg/J5lURgZuW3ZKyJ1ZvcayVYlZtK1na7MDcRmepD8/4 nN1XAmT+lk58DiaB0lEHaYDQriT/W4oacrinoRjxJrcxB5zT1F6/VpbIJ5Zqni9HL7/P e6S582ODEKzA81GLOVETxAWGdKplzo3vfGg8stySVSpWsz7BhHyAVUi7jQbGbNrKjBgm sfUw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Wng2Ly9p; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-1545-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-crypto+bounces-1545-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id r16-20020a635d10000000b005cf1b03d5bdsi9112170pgb.124.2024.01.22.19.51.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 19:51:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto+bounces-1545-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Wng2Ly9p; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-1545-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-crypto+bounces-1545-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 628E9B24B5C for ; Tue, 23 Jan 2024 03:29:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 398EB15C6; Tue, 23 Jan 2024 03:29:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Wng2Ly9p" X-Original-To: linux-crypto@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 E2B7A10F1; Tue, 23 Jan 2024 03:29:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705980584; cv=none; b=KD7Fnge+T9POJvAV8qAKe6sx92HBtT8JmbeIorRg4KP7mBmGdiTT+JCIrJqT4MRxC2GiGlCqCW1H3DBGErzk2orKr3LaLYGalpQk+kJPDFgMT3nwDOd/CwbU96FlZoFLNXs6I2urnXRju2kOHr2SLaov3F9i/MeN71pfR+2WhL0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705980584; c=relaxed/simple; bh=U1v5qrYKbV+f+R8OtytsdZNiZAtmV31IrDUJJyID3bk=; h=Date:From:To:CC:Subject:In-Reply-To:References:Message-ID: MIME-Version:Content-Type; b=Q0YmV5gDg3VwcxQlxqdemhPnPEavoW7fR8gLM5xm078rlHPS7xP/tmnOZocVehg/pCwyaxkUZrpZEsLhM65GL54MzofCKmiwjqND1gVjiXb+0xdY2pL+vuEDBDSTEJFvGwDty4Jq17wiysMICq8W5OQ5Bw/45aDnVB/Ik/pHEGQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Wng2Ly9p; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A2CEC433C7; Tue, 23 Jan 2024 03:29:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705980583; bh=U1v5qrYKbV+f+R8OtytsdZNiZAtmV31IrDUJJyID3bk=; h=Date:From:To:CC:Subject:In-Reply-To:References:From; b=Wng2Ly9p0gJUrUy0fOD4sFGGZ3A/c+t4sAUY6sRcNyedhhhAQEuGsBs991gjlQhWi L9W34O7F9D6wLVxhLculzkedvobKw3ENzJv1JQTt2VBpihomaaGQWcWBbsYybwdIJF ig5KyQrCJqCLjUKrpQep0GrdUC5rmFXzYY056mFzRum+NFP1zAAHW6lCBRRBozSmzS IKrxbZ/KFH/jeSI4AjmRfZwnEkxStHujgD3WpURC8HreGp2IRC4gaNEfbGxo/7AosX j93RdCdt5BGaL7DtelBesGtRUoWStsloAYet8odRBsaEEjZhqLKLRgsDIy8/b6GhYk f7F7CMQMRIVtw== Date: Mon, 22 Jan 2024 19:29:42 -0800 From: Kees Cook To: Eric Biggers , Kees Cook CC: linux-hardening@vger.kernel.org, Herbert Xu , "David S. Miller" , Aditya Srivastava , Randy Dunlap , linux-crypto@vger.kernel.org, "Gustavo A. R. Silva" , Bill Wendling , Justin Stitt , linux-kernel@vger.kernel.org Subject: Re: [PATCH 46/82] crypto: Refactor intentional wrap-around test User-Agent: K-9 Mail for Android In-Reply-To: <20240123030745.GA1097@sol.localdomain> References: <20240122235208.work.748-kees@kernel.org> <20240123002814.1396804-46-keescook@chromium.org> <20240123030745.GA1097@sol.localdomain> Message-ID: Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On January 22, 2024 7:07:45 PM PST, Eric Biggers w= rote: >Just to double check, you really intend to forbid *unsigned* integer wrap= around? >This patch's commit message focuses on signed, and barely mentions unsign= ed=2E >The actual code changes in this patch only deals with unsigned=2E I don't mean to forbid wrap-around; we just need to annotate it=2E I can s= ee how this commit log didn't do a great job explaining this=2E I hope the = cover letter is more sensible: https://lore=2Ekernel=2Eorg/linux-hardening/20240122235208=2Ework=2E748-ke= es@kernel=2Eorg/ >Also, what's the motivation for addressing the 'x + y < x' case but not o= ther >cases in the same file? It's a code pattern we could find easily=2E It's working from the instance= s found via Coccinelle earlier in the series: https://lore=2Ekernel=2Eorg/linux-hardening/20240123002814=2E1396804-5-kee= scook@chromium=2Eorg/ > For example, the le128_add() function which this patch >modifies has two other intentional wraparounds, which this patch doesn't = touch=2E For dedicated wrapping functions we can mark them with __unsigned_wrap: https://lore=2Ekernel=2Eorg/linux-hardening/20240123002814=2E1396804-6-kee= scook@chromium=2Eorg/ >Also, the le128_sub() function just below le128_add() is very similar but= does >wraparound in the other direction=2E That's 6 cases in 20 lines of code,= but this >patch only addresses 1=2E And of course, lots of other crypto code relie= s on >unsigned wraparounds too, which this patch overlooks=2E =20 Right -- finding these kinds of things is where a lot of time will be spen= t in the future, I suspect=2E :) > So I'm a bit confused >about the point of this patch=2E If we really wanted to explicitly annot= ate all >the intentional wraparounds in a particular piece of code, so that the co= de can >be run with the corresponding sanitizer enabled, wouldn't it be necessary= to >actually test the code with that sanitizer enabled to find all the cases? Yes, but there's a lot of code to test -- I'm trying to get the first step= s done=2E And then once the sanitizers are in good shape, the fuzzers can g= rind=2E (I'm trying to add some parallelism to this project; this code patt= ern was known so I figured we could address it now=2E) -Kees --=20 Kees Cook