Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2872241pxa; Mon, 17 Aug 2020 23:30:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVhUjDcAX4Cs4mcXzRGWewnZbFDV+k93f8IjL9UWK08R4orvuc93C+Aw9x6RPc2kEZ5OXS X-Received: by 2002:a17:906:fa15:: with SMTP id lo21mr19177890ejb.42.1597732244102; Mon, 17 Aug 2020 23:30:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597732244; cv=none; d=google.com; s=arc-20160816; b=iM5V0vvS+zzln0ly9zUt8XsPplw9FQ4hIYdRnOViRLi9WiGKFq1aXgxf10iRmS3XkR IaWXMtcAXu14cJNmPwGPgOrP4GgXDtz3HXxK84tYIzIm4SEm4edc8ohgyDqu3zCmQqhd XLKR9Uqvwg5PnAgCh8gX9QsBQOjqd5+0WKoZnauXWHBmCNlDIc2+/bpvARcxjZT6natp fJPJd1Tb4DJeCqynzWpQk7W49sJtj7ecyUHMt2IOfTJ27UIwpMhAt4mo1qX5idCbSlHt hVXgU3lfoCKGM0M5AEueKidHdhNdx6BATQOJuQ48iL0Mj1g5AHEPzxU/x65r+euHB+Sx 4YzQ== 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:cc:to:from:date :dkim-signature; bh=9kgMEFLS93x20ZWZn2Z8BrL3Yk9qHlmcbMWzZcP/RIQ=; b=NM4Q8gPBCkkYm8Try8P/+nvvKF8x7FPCowyfg9mYauzEc33SLvsTAe8vm9ePBmw2kR 8UadMjlbOZtJV60GZ/zL3eS/j85Ju87Bt+dUAi/8IyCzYaZdAay5uzfPJRJr4TtCyoNi JgNyMoOFv+f93ck5LQqNXgV4ZM2wJJGOH6JPBqtjqqfays0zTyGKJHOxG7ISJal5pZLj d83kwWMMqgNEbuyGYrLTHw9eA4Qs864gMUk2Y4geuwWDYz2J67KOLiRWzNWiQObM4LwV 2NwxOfu9SVx9gRcTRT4HRjhr9Bau9NniM6JLW+VctOeTQxPlV/WUBMvlFrBcHcPBSHiz 8f4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DQMzmJqM; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ks26si12670090ejb.90.2020.08.17.23.30.20; Mon, 17 Aug 2020 23:30:44 -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=@kernel.org header.s=default header.b=DQMzmJqM; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726599AbgHRG1l (ORCPT + 99 others); Tue, 18 Aug 2020 02:27:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:48966 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726403AbgHRG1l (ORCPT ); Tue, 18 Aug 2020 02:27:41 -0400 Received: from localhost (unknown [213.57.247.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D95FE20829; Tue, 18 Aug 2020 06:27:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597732060; bh=6sam980i8nu2tM59pReLKjc8Vd78afzBLEkduMMs5Oo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DQMzmJqMKAa/Q6GxxrH0+XkN6TZlv//VGpLUEmUtSUjDnuqpR0j1T4LYqbXzwMv5+ HzmM+kZtwVlSJFq2jbFzpHcTckaAUVnOUk7eBNxZQ4RHN43yUTgewxLj6YQv+5NvcT QtCLtIyHvOFB/yS2uTmzSMm2/kEYhojin+3MPMAw= Date: Tue, 18 Aug 2020 09:27:36 +0300 From: Leon Romanovsky To: Kees Cook Cc: dsterba@suse.cz, Rasmus Villemoes , "Gustavo A. R. Silva" , Jason Gunthorpe , 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: <20200818062736.GL7555@unreal> References: <202008151007.EF679DF@keescook> <20200817090854.GA2026@twin.jikos.cz> <202008171235.816B3AD@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202008171235.816B3AD@keescook> 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 12:36:51PM -0700, Kees Cook wrote: > 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 theory yes, in practice, the compilers will ignore this macro. And if you success to force compiler to use this macro, it won't give any real performance advantage. We (RDMA) tried very hard to see any performance gain by instrumenting code with likely/unlikely in our performance critical data path both in user space and kernel. The performance results were statistically equal. If you are interested, we had a very intense discussion about it when likely/unlikely can still be usable (hint random input). https://lore.kernel.org/linux-rdma/20200807160956.GO4432@unreal Thanks > > > 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