Received: by 10.213.65.68 with SMTP id h4csp1090043imn; Sun, 18 Mar 2018 14:15:49 -0700 (PDT) X-Google-Smtp-Source: AG47ELsFqkjFqve/2My/LBqfH1YIIikxdcOLL8lmsUMzlJ19LtBg0BCkC+DeewiZn1xP2PRSyMbs X-Received: by 10.99.112.25 with SMTP id l25mr7510323pgc.412.1521407749849; Sun, 18 Mar 2018 14:15:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521407749; cv=none; d=google.com; s=arc-20160816; b=C/KN2uKByqZkxdqW4ZXB5ETgev0hcv9WehynASddOrmuSeGwwM0YS/vuR/DSs9hkiS Bpi5oNeDwU0IrYHpRs/Sfo8ePgAJFFg/bgNyDjtZ44BIzDc+HhWNF1E0Jymrcfhr1EZs e+K+MrlHO0jw/oVl3PSCqndcGHnw7ShAs1jKz9iVw2OHjlORwhsmomraHX7Nqy4lkd1f ip1YKpScY5gNZ8p79QIOJkeCHDmkNxUhqIBvWxF7FNOly5NcEwpaWSC+LHG//KNMB7MQ CfTej3SAPDjbLWMWjy34CHVRE5p5WEPFoqMleKLz37TkB4lomAjOxtljT65zZ8oTDCZG euHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=9rij1HjYbCVwhDDnJiidP7Z+G1WLgSilLi2QdoJiobU=; b=CDeTRT5WN9pgYb3V4azn6cpqEzyxpetSK7TY+5rxjrPrnJxyEWfB+Fb7+xsfsziWIx E55gaLrqzMcZ5YzbgQ8O66DgJ8q9f9ksnNf7XzrlWoVXskR7LBsLdnfp3kE5Kri7AKWV R/MNS/l+hDybC1k1k2vQve4RLdqbh5OnQyauL5y9urrJHPpuEg4PUTsc5BuhlsgClrca uHxG4jqjszigR4ZMGVQQr5BCe9b3KFh4e/Jtw13s8Mto/GkeRbnOsV97RwG9jWiNaP7a CZtekVbIXNIpxdkQvpTlFHDZ0klH9P7lk3Bwn4GIGWxTieqenVHQCbiNFSFFHQEmsc3N 4G/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=E/heuBlP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l7-v6si5263653plg.82.2018.03.18.14.15.25; Sun, 18 Mar 2018 14:15:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=E/heuBlP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754313AbeCRVNh (ORCPT + 99 others); Sun, 18 Mar 2018 17:13:37 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:39156 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754406AbeCRVNc (ORCPT ); Sun, 18 Mar 2018 17:13:32 -0400 Received: by mail-wm0-f68.google.com with SMTP id f125so3596776wme.4 for ; Sun, 18 Mar 2018 14:13:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=9rij1HjYbCVwhDDnJiidP7Z+G1WLgSilLi2QdoJiobU=; b=E/heuBlP4uj1w7z8RSrjh8zDgxlYJHgco7dZs1iUjxEOS2y0ww9o8YHSE72BWmnDEy NsBrNGIVWyXlOyyKe4fvXBHcApayV8KmNnc2tgnHHsV+JeG9oU3qfJvx2SvHE/kooDiA A82iyQ54rfhpmWqyVSDsFaskBU8gwYg03i0FM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=9rij1HjYbCVwhDDnJiidP7Z+G1WLgSilLi2QdoJiobU=; b=lm0hDYZo0YndcdQMPTEyE38YQ4hsxns3JXHW0vgnWmZ0sV730y7Ljy+oKIfIXu8O1L Bw4T3/ReMBodB2vgqRdzYW/yYJ0U/xAnLBY4GQ5ELxbxE94Tx/9f6d/SIBoiIkEVvXPC IokLDALYLNYWKn0hEVRDTxFOZsTUGxjkbnE0jz58FKkXe3ZWR33kCzeqG1jNz95pAw6u DI8MWw81wx6jWVrvUzI2HOvoD2zN3IpkW1zDiy6tJd5tvtv7SZg4MofKosCrh1cJ/Brr vHZJa4PYtV678MuppL6aYPJH49FfeRYAeA4dtuVv+DR6VYHSmpU561/14QnwfpVax1uC hmgw== X-Gm-Message-State: AElRT7FQXqQng17K0DLA5Ue9DxoWlLEvHtYX+Otw5qhTtgc9BIlA+hLX GtoPMrYxo/I7x92br7UcNSNUU8g8Hz+KJQ== X-Received: by 10.80.172.229 with SMTP id x92mr11157032edc.252.1521407611491; Sun, 18 Mar 2018 14:13:31 -0700 (PDT) Received: from [192.168.0.189] (dhcp-5-186-126-104.cgn.ip.fibianet.dk. [5.186.126.104]) by smtp.gmail.com with ESMTPSA id d22sm7619996eda.70.2018.03.18.14.13.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Mar 2018 14:13:30 -0700 (PDT) Subject: Re: [PATCH v5 0/2] Remove false-positive VLAs when using max() To: Linus Torvalds , Kees Cook Cc: Al Viro , Florian Weimer , Andrew Morton , Josh Poimboeuf , Rasmus Villemoes , Randy Dunlap , Miguel Ojeda , Ingo Molnar , David Laight , Ian Abbott , linux-input , linux-btrfs , Network Development , Linux Kernel Mailing List , Kernel Hardening References: <1521174359-46392-1-git-send-email-keescook@chromium.org> <20180316175502.GE30522@ZenIV.linux.org.uk> From: Rasmus Villemoes Message-ID: <42b4342b-aefc-a16a-0d43-9f9c0d63ba7a@rasmusvillemoes.dk> Date: Sun, 18 Mar 2018 22:13:28 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018-03-17 19:52, Linus Torvalds wrote: > On Sat, Mar 17, 2018 at 12:27 AM, Kees Cook wrote: >> >> Unfortunately my 4.4 test fails quickly: >> >> ./include/linux/jiffies.h: In function ‘jiffies_delta_to_clock_t’: >> ./include/linux/jiffies.h:444: error: first argument to >> ‘__builtin_choose_expr’ not a constant > > Ok, so it really looks like that same "__builtin_constant_p() doesn't > return a constant". > > Which is really odd, but there you have it. Not really. We do rely on builtin_constant_p not being folded too quickly to a 0/1 answer, so that gcc still generates good code even if the argument is only known to be constant at a late(r) optimization stage (through inlining and all). So unlike types_compatible_p, which can obviously be answered early during parsing, builtin_constant_p is most of the time a yes/no/maybe/it's complicated thing. Sure, when the argument is just a literal or perhaps even any kind of ICE, gcc can fold it to "yes", and I think it does (though the details of when and if gcc does that can obviously be very version-dependent, which may be some of what we've seen). But when it's not that obvious, gcc leaves it in the undetermined state. That's not good enough for builtin_choose_expr, because even the type of the resulting expression depends on that first argument, so that really must be resolved early. So to have some kind of builtin_constant_p control a builtin_choose_expr, it would need to be a "builtin_ice_p" or "builtin_obviously_constant_p" that would always be folded to 0/1 as part of evaluating ICEs. So I don't think there's any way around creating a separate macro for use with compile-time constants. Rasmus