Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp801417rwe; Wed, 31 Aug 2022 11:12:41 -0700 (PDT) X-Google-Smtp-Source: AA6agR7LNVyl8iy9eVSIlbR78VMvRXKGsfW3LngCRYGVS+sIMDlZB9qRZBDI4rHwa2mV7gOG4ags X-Received: by 2002:a17:90b:314b:b0:1fd:e5ba:3cab with SMTP id ip11-20020a17090b314b00b001fde5ba3cabmr4576475pjb.96.1661969561343; Wed, 31 Aug 2022 11:12:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661969561; cv=none; d=google.com; s=arc-20160816; b=PriX/K4oLZXlAW8Gqu+0APlnfmS+USDRxvdPpfZm185E3eP7SngPG+FukmiijuS0/w NU2iIARZ1mQ7T0GS8A+RtvzyspWp6TDrt3qYGIZ7jSrWaY1Yr5MepnuqAWBJUtC0EOsO XDEuOi/8JcN0Z3aDEFz9xR9lvIXo3T/rs7Yn/0XhkHL51Z+b/DFbKKrft260j8DshilQ 8tclFzz3hxW/OfY53vxQ1SyWPpDoO/fkQpW81bBjrCI0hhlftV8TRfMdpl8tPvZSnShL T5Xg6AC78kGRgL5cxMvww8zE3nJGDC2gQlmMrlHmbSA5wsADH/6GOMqhn+6TMrfqfdVr UBmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=VFkJurdbJUTCWb5htdv9XL8GXl+ooHeGwTuU6qvLebw=; b=E5ZS083OGGZaifx4v5f1x/Mat0VkdioIuupwnAH26wEf8B2Y+SkB8acmvoIdToienT dnS7RrQhaSI6gqBE+Y5VmflbRO2Ayx/SYEfMa8KYJy61Y4QZKRw5BkhsojcYI7KsckOO JUb9rvv9k91zFQTJDgGX3emDxb7yJCt0A9lv8MbWTfEbZvjEpVJTas535X5lNoofDBZs oiw6xwkxKilqf0AmrcYZw/Zvv6y1wxUh2YSqEMS3MqTYHm7ViUj4keqlbs8bxD8f/8yz YWXutiGsyxG/t6egCfJiwHCnzDlfXA9VMLCi6ZUfldLnro/YOezaOu8QWE/KiIu2r4uT 1s+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=VostS88K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a20-20020a631a14000000b0042a55cd3253si5337591pga.440.2022.08.31.11.12.28; Wed, 31 Aug 2022 11:12:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=VostS88K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230350AbiHaRtQ (ORCPT + 99 others); Wed, 31 Aug 2022 13:49:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231421AbiHaRtM (ORCPT ); Wed, 31 Aug 2022 13:49:12 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7B27D0756 for ; Wed, 31 Aug 2022 10:49:09 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id 145so14797139pfw.4 for ; Wed, 31 Aug 2022 10:49:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc; bh=VFkJurdbJUTCWb5htdv9XL8GXl+ooHeGwTuU6qvLebw=; b=VostS88Kk2T9x6tzKXLo0TDqNIb1gPQ3/yzR073wKLNexwMTG22DFuQ+O6EvlCnOd/ OgcP5p9wktNxFostue0wrRjsLrG7khl70oMXkKD0a01OaDu6xqWF9GcUVBxHL22V6uPZ SzGoOnicvDtJasw1c4prIQQ8Lu5uYdlCrU2WA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=VFkJurdbJUTCWb5htdv9XL8GXl+ooHeGwTuU6qvLebw=; b=M6tFHDVe0g3mIafoQrPZfHn5iX5qHeF3kRG7xE3sFp0G33OlsUQlpx2FEP6lleavnP nwIdDFPtJvPc9P5i9u6xg++cKV9utUKJt5lhNNw6SWnX9XRnbripSssgHJk0Mp9qNYxr vR/IkNQAeWNQrD/3Zu2ahxybN1qiWrbx8A1rZx09YpceIDi6MMpVMZZ3rbZX3TBZRm0S C3Plef/MTJ4Zb4kL0wWDEufEp9k1+c/VTXe444V4GZWb+FwqXj1+GkQDcTfFPN99Rvj8 QyYbTcSNR9i1RBW9clLoytlOOAkQlYqRQpra7DDSvf9GwZZqCmzuRab8K+C1Q4FseVmd 3T9w== X-Gm-Message-State: ACgBeo0hLSpBop5nOW6vumDJ+1TXciQ0BmcEaGGMBXDpmGhaiuaGb4AD pv3hgP/eIwjpkOHpGC1gbWju/A== X-Received: by 2002:a63:f011:0:b0:42c:7687:7322 with SMTP id k17-20020a63f011000000b0042c76877322mr9329970pgh.126.1661968148965; Wed, 31 Aug 2022 10:49:08 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id c8-20020a170903234800b0016d3935eff0sm10016902plh.176.2022.08.31.10.49.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 10:49:08 -0700 (PDT) Date: Wed, 31 Aug 2022 10:49:07 -0700 From: Kees Cook To: Rasmus Villemoes Cc: Gwan-gyeong Mun , Andrzej Hajda , "Gustavo A. R. Silva" , Nick Desaulniers , linux-hardening@vger.kernel.org, Daniel Latypov , Vitor Massaru Iha , linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] overflow: Allow mixed type arguments Message-ID: <202208311040.C6CA8253@keescook> References: <20220830192147.47069-1-keescook@chromium.org> <787894a0-b1b7-43c2-c509-f246f94f58f7@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <787894a0-b1b7-43c2-c509-f246f94f58f7@rasmusvillemoes.dk> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 30, 2022 at 09:52:32PM +0200, Rasmus Villemoes wrote: > On 30/08/2022 21.21, Kees Cook wrote: > > [...] > > + * *@d holds the results of the attempted addition, but is not considered > > + * "safe for use" on a non-zero return value, which indicates that the > > + * sum has overflowed or been truncated. > > I don't like that wording. It makes it sound like there's some ambiguity > or (implementation|un)-definedness involved in what the destination > holds on overflow. The gcc documentation is perfectly clear that the > result is the infinite-precision result truncated to N bits, with N > being the bitwidth of d. Hm, well, I think use of *d should be strongly discouraged on overflow. How about just adding the specifics to the end? * *@d holds the result of the attempted addition, but is not considered * "safe for use" on a non-zero return value, which indicates that the * sum has overflowed or been truncated. (*@d will contain the * infinite-precision result truncated to the bitwidth of *@d.) -- Kees Cook