Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2557190pxa; Mon, 17 Aug 2020 12:40:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxuBzIupas7O6QpeT+SPZyYk3Q68ILbs9aVPDkRTpz1XQHLmWp9vQGUurkdSohrZ6ho4Y59 X-Received: by 2002:a17:907:1183:: with SMTP id uz3mr16502833ejb.216.1597693245981; Mon, 17 Aug 2020 12:40:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597693245; cv=none; d=google.com; s=arc-20160816; b=FYXkdCx+KwE39G/LAbZb8pHrOHOwVQ3UCVdp2/DnVcxIYMaHwXpaaKXHbfdEQDHRB+ oJ5mObnVJZroCKW0EQqygIDrQeVSUkvj7a1YLjMREbGqBTgnghVPG17oM/R7GZ6W2ZQJ Bt8AQ9V3l4mYkI2Fmmepxc7H7wL38fk98fuhLBeHq7q+LbybbB1xeXQme+ChiCzJtanf z7bTkHie5Btui5JBh044+LH2G8IO0t4/dVmE6ayt+7rrBuDKEqZg6dBRwiiTe4V8O7l8 V+0F/tYvhGUuweQDomuR7PjZKdBiaHavzT6GtmU8L9UmyxW5GJ6SeZTkRTX6nfZyFlIg redw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:to:from:date :dkim-signature; bh=uSda/maq1kyFlmgdc9lPucbhxB4Rs/n3Ulbz/u//5ko=; b=KgyBl2lMPe/NzVOhtVe8AmYpvCpv/tcURs5Or6vxIyfUKnsQ94bMS7uyPdjN+zCl1o 0iNH6qhNl1QLqeykiuPpw77BPRWVC5dPrzJ0KxDb2L/R4ZwSTHqWmRGxAR1lQjSJRjrB /MN3wBdbykO0J6Nnlla/L0OGaP1rjLRW+KiIqGrR9mzlPW8upvOx2Jqs7xWHyEAqtO8a HAzDx3ZWz0FBi6xhihFVEgHW297ZPmMkWVMz1W5HQ5xkujaKU4YQICoxCPe8doKjZY1V v70cTfjG/7VjQSIH3jTKHw6/rwtSpUct90+t7aB1oPOwd3RAToFkJll+LxM54GRocGZR Z2PA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=E+bxGWQ4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p22si11683192eds.169.2020.08.17.12.40.23; Mon, 17 Aug 2020 12:40:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=E+bxGWQ4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1732401AbgHQTg6 (ORCPT + 99 others); Mon, 17 Aug 2020 15:36:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732395AbgHQTgy (ORCPT ); Mon, 17 Aug 2020 15:36:54 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 697B9C061342 for ; Mon, 17 Aug 2020 12:36:54 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id d188so8731385pfd.2 for ; Mon, 17 Aug 2020 12:36:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=uSda/maq1kyFlmgdc9lPucbhxB4Rs/n3Ulbz/u//5ko=; b=E+bxGWQ4aloHMCGvC/C88Lm/LjqBzqUeliCrcozBEZMRKbyg+1uq3MbJHRL+u+fAgy rcfLJVPQZ9kKIBkXB0xoAGLmBb+lgoPAZlnS4ffebwSge6AqZOPLud4MtAVsUxyNCwLs 808/MgaEYfc7LQRe31GlclDrcC3duq6vYQwQ4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=uSda/maq1kyFlmgdc9lPucbhxB4Rs/n3Ulbz/u//5ko=; b=cYvyQ3wEtEjw55G6zrs5eoUmzfl9vam13HoOGUNuWegUalp1MnA7Ny1FErbdupXsw1 K3lVvxnVgdvjD99aRqdH0ixYXgIeCHEdNLhR/cyJ+6nJaJP3V7zK0Lc76AvwdvcG0ox1 6aQZXZwpGaaaXHEg/E6I4dq/NVXv/9V+e0vtsmXZmop7Kb77nn5edvKtsKqmv7Nkq2mK V1TKAMKyi8A/tYLr7dOrpd3lmcAi56StxXo7WpmA9GBjIlowG0oZs8SGZx/QTC0Q3q/Y eMQabnMGjce548MtPX+MOBM1vA6F1tqVsmXCJDKw6IQlcMY3LsH2FHNSwA5ZJJWp3bXf z57A== X-Gm-Message-State: AOAM532U4zNA2Dv3fo763R5MU43ppyrqEdtx6ekuoHJea3ZjJUgfWw4L jar2wBRordCIangBst/Kf3TrcQ== X-Received: by 2002:a65:63ca:: with SMTP id n10mr11219632pgv.252.1597693014022; Mon, 17 Aug 2020 12:36:54 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id g4sm19415044pjh.32.2020.08.17.12.36.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Aug 2020 12:36:52 -0700 (PDT) Date: Mon, 17 Aug 2020 12:36:51 -0700 From: Kees Cook To: dsterba@suse.cz, Rasmus Villemoes , "Gustavo A. R. Silva" , Jason Gunthorpe , Leon Romanovsky , Matthew Wilcox , linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com Subject: Re: [PATCH v2] overflow: Add __must_check attribute to check_*() helpers Message-ID: <202008171235.816B3AD@keescook> References: <202008151007.EF679DF@keescook> <20200817090854.GA2026@twin.jikos.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200817090854.GA2026@twin.jikos.cz> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 17, 2020 at 11:08:54AM +0200, David Sterba wrote: > On Sat, Aug 15, 2020 at 10:09:24AM -0700, Kees Cook wrote: > > +static inline bool __must_check __must_check_overflow(bool overflow) > > +{ > > + return unlikely(overflow); > > How does the 'unlikely' hint propagate through return? It is in a static > inline so compiler has complete information in order to use it, but I'm > curious if it actually does. It may not -- it depends on how the compiler decides to deal with it. :) > In case the hint gets dropped, the fix would probably be > > #define check_add_overflow(a, b, d) unlikely(__must_check_overflow(({ \ > typeof(a) __a = (a); \ > typeof(b) __b = (b); \ > typeof(d) __d = (d); \ > (void) (&__a == &__b); \ > (void) (&__a == __d); \ > __builtin_add_overflow(__a, __b, __d); \ > }))) Unfortunately not, as the unlikely() ends up eating the __must_check attribute. :( -- Kees Cook