Received: by 10.213.65.68 with SMTP id h4csp833080imn; Tue, 20 Mar 2018 17:07:08 -0700 (PDT) X-Google-Smtp-Source: AG47ELsj/DAP0oXIzwBBRDkoRdsAKGW27kVEdGJpgjfwBQGH002FVGNpl4VFgxAhldp8lYvcODqA X-Received: by 10.99.109.142 with SMTP id i136mr13428431pgc.306.1521590828843; Tue, 20 Mar 2018 17:07:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521590828; cv=none; d=google.com; s=arc-20160816; b=askz3ghCtUpybP/sydB9iaXaU3GCEhjlzqdAZErJR2V99/s02i/J3OuTPMD9U54wQy eCQ/DRICkGzEfNtc9GGoGw3MqdlWic+Xcd9usOiVR/P4N6v1TU4Yc9Xk+iOhLpQ6W+3l B6VI74OwUdwm5pZyZNBhWJj+Mtlyw8el2yG/9x6Sg1+Y/GUo6K+CSX+wSgGDor5gQtdY 1Ibz2flbJCJc1oLk0qW1ZsundyA1kyd7JAD0Iae1cPGuuOCyUwx3VF+CjaVigLYJHylJ vXp1FJBnpwRF8jU9jrb8+RTYgLEpxfxaTC3wFDdzT9NyVhTt1Q3KbkuKdfNZpY+yh4/p uz1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=8MjA7ARsmdvsfLsKYmuZ3Y6MsuucOKxT1VXIA3Rhdqk=; b=SOFHnV7nIbVC9H/unfg3S9hZ1LiOfeCYJIgMEPqYzFnmuXssmaf43CM5o1LPIZ2gPf IFCvqOMeVLBcuAFzZfi+nEizgM/gClX9Oak8Ti0ll5Hexu/5pJT8yaKUzo47063zEJa0 vBtpnzubNegBSGe+ywUj49WtJJ2i4qA1JnX3jzoNWFt1vO+W2earILZS6/+VouXcMShw WAP07cmRaolj9wuqHdfRwYFGsEU/3CVMNhG62Qq/MkfW9Q3MZoFaZPBwK3ENzs6Ejcjl 8fgMflocKSOydb2G/T9G9o/MIUHhAsy3oQ1EIhiQeRnw6cwVrFJW60cCEqbQK1FFb938 yPnQ== ARC-Authentication-Results: i=1; mx.google.com; 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 o2-v6si2557205plk.457.2018.03.20.17.06.54; Tue, 20 Mar 2018 17:07:08 -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; 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 S1751581AbeCUAFx (ORCPT + 99 others); Tue, 20 Mar 2018 20:05:53 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:38014 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751018AbeCUAFw (ORCPT ); Tue, 20 Mar 2018 20:05:52 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.87 #1 (Red Hat Linux)) id 1eyRG0-0005FD-Sa; Wed, 21 Mar 2018 00:05:32 +0000 Date: Wed, 21 Mar 2018 00:05:32 +0000 From: Al Viro To: Linus Torvalds Cc: Kees Cook , 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 Subject: Re: [PATCH v5 0/2] Remove false-positive VLAs when using max() Message-ID: <20180321000532.GC30522@ZenIV.linux.org.uk> References: <1521174359-46392-1-git-send-email-keescook@chromium.org> <20180316175502.GE30522@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 20, 2018 at 04:26:52PM -0700, Linus Torvalds wrote: > On Tue, Mar 20, 2018 at 4:23 PM, Linus Torvalds > wrote: > > > > Hmm. So thanks to the diseased mind of Martin Uecker, there's a better > > test for "__is_constant()": > > > > /* Glory to Martin Uecker */ > > #define __is_constant(a) \ > > (sizeof(int) == sizeof(*(1 ? ((void*)((a) * 0l)) : (int*)1))) > > > > that is actually *specified* by the C standard to work, and doesn't > > even depend on any gcc extensions. > > Well, it does depend on 'sizeof(*(void *)X)' being 1 and the compiler > not complaining about it, and that sizeof(int) is not 1. > > But since we depend on those things in the kernel anyway, that's fine. It also depends upon "ICE for null pointer constant purposes" having the same extensions as "ICE for enum purposes", etc., which is not obvious. Back in 2007 or so we had a long thread regarding null pointer constants in sparse; I probably still have notes from back then, but that'll take some serious digging to find ;-/ What's more, gcc definitely has odd extensions. Example I remember from back then: extern unsigned n; struct { int x : 1 + n - n; } y; is accepted. Used to be quietly accepted with -Wpedantic -std=c99, even, but that got fixed - with -Wpedantic it does, at least, warn. What is and what is not recognized is fairly random - 1 + n - n + 1 + n - n is recognized as "constant", 1 + n + n + 1 - n - n is not. Of course, neither is an ICE.