From patchwork Mon Jun 3 09:08:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 165588 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp4204072ili; Mon, 3 Jun 2019 02:10:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqzpW5F6lzfaEzc27W6spNV39wwg3/E5hP0N5r12LaWzSlP1YmKgRiwk2a++Gll8ckSnrawo X-Received: by 2002:a17:902:2862:: with SMTP id e89mr28690483plb.258.1559553033384; Mon, 03 Jun 2019 02:10:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559553033; cv=none; d=google.com; s=arc-20160816; b=tJwbhtFG6kLbO3t1CrWESy/SvSPOhALr/YziO6QT8nS/j+JQqalgfsmhxCUbR34uGA 3PClMRENkWasApW/QjXhm+tT//O3+FDH3i7FYRDEG9r2TVMr4LYI0NjwKk/twvuI3m2b 934GZjGUevW6057YLZPAEE0e7xilnBgBtfBQD2qd9fL0s12wZaPOcPt0wR4BWXcO4V5O MJwu+gLXTDGoo+rb4E4vTzFioADOADfyr4/D/7GmpCGOuiXxwY6oiwRLMTnu+WWkICMD zrGZZLkgij8/V1yne8iuirOjfPI9Z9r6BiAOapeMEtnkQwwlsvs8G+V0r2XBLPxl8NhA w5+w== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=RaYeXvBOuAvpwdlO0VkmXPn0ll6A5TzKYbc5ebKf9F4=; b=grKY6MGiQcvAzLottxqYutBfkgRLZ9MZWe/7pfYXamEzLyv8vkS2J7Mqk2GY+MPpyo NYP8izxcuUpO9Ug3wNtpiM59wiME0mphBeweRbJKt1FSWZmDVV+4pl0pnHfPc8gnCmFT e5o7PdAstT6aTYevuwrQ1vD0fwujTHByvcDCFNSzvIzKA0OIr4irkdYq/szO+ekFsyev H1B3VOG+CfUQaLGbUuVzt0ihIW1MZeEcJ56dF7IzBi0rIpba6tapkDP+Dv8o2P4IndUH Qu79PNllzd/pUGisDMZTelqbZueG/4gePr9Lyc4sOsR1xlI9OpwKc1S86bW3WJVRpayi s8Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lvKrkYy6; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 h9si8018453pju.85.2019.06.03.02.10.33; Mon, 03 Jun 2019 02:10:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@kernel.org header.s=default header.b=lvKrkYy6; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728115AbfFCJKc (ORCPT + 14 others); Mon, 3 Jun 2019 05:10:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:54948 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728106AbfFCJKb (ORCPT ); Mon, 3 Jun 2019 05:10:31 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 1382527E32; Mon, 3 Jun 2019 09:10:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559553030; bh=uJqMRlVgTXkqM8Df4tfYcYSfh4LY6/T02rXWYiZHRNs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lvKrkYy6tGxu+z2/lwYbdEddZ8pgpHrKgo/JXjd/wyGNGuVjH9iBxOBJacmDaDf/f MVHSFBCj3pk9Cq/jq3Uj152ksa1KpTgQtzPGT6RaTMTEYecNEbfxpQwdKUqiQZjwl+ +AFoRuOHrwSpe3EKeTN9TpCrZVRpzasybffeHuqQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Masahiro Yamada , Kees Cook , Nick Desaulniers , Nathan Chancellor Subject: [PATCH 4.19 28/32] compiler.h: give up __compiletime_assert_fallback() Date: Mon, 3 Jun 2019 11:08:22 +0200 Message-Id: <20190603090315.423148657@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190603090308.472021390@linuxfoundation.org> References: <20190603090308.472021390@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Masahiro Yamada commit 81b45683487a51b0f4d3b29d37f20d6d078544e4 upstream. __compiletime_assert_fallback() is supposed to stop building earlier by using the negative-array-size method in case the compiler does not support "error" attribute, but has never worked like that. You can simply try: BUILD_BUG_ON(1); GCC immediately terminates the build, but Clang does not report anything because Clang does not support the "error" attribute now. It will later fail at link time, but __compiletime_assert_fallback() is not working at least. The root cause is commit 1d6a0d19c855 ("bug.h: prevent double evaluation of `condition' in BUILD_BUG_ON"). Prior to that commit, BUILD_BUG_ON() was checked by the negative-array-size method *and* the link-time trick. Since that commit, the negative-array-size is not effective because '__cond' is no longer constant. As the comment in says, GCC (and Clang as well) only emits the error for obvious cases. When '__cond' is a variable, ((void)sizeof(char[1 - 2 * __cond])) ... is not obvious for the compiler to know the array size is negative. Reverting that commit would break BUILD_BUG() because negative-size-array is evaluated before the code is optimized out. Let's give up __compiletime_assert_fallback(). This commit does not change the current behavior since it just rips off the useless code. Signed-off-by: Masahiro Yamada Reviewed-by: Kees Cook Reviewed-by: Nick Desaulniers Signed-off-by: Kees Cook Signed-off-by: Nathan Chancellor Signed-off-by: Greg Kroah-Hartman --- include/linux/compiler.h | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -319,29 +319,14 @@ static inline void *offset_to_ptr(const #endif #ifndef __compiletime_error # define __compiletime_error(message) -/* - * Sparse complains of variable sized arrays due to the temporary variable in - * __compiletime_assert. Unfortunately we can't just expand it out to make - * sparse see a constant array size without breaking compiletime_assert on old - * versions of GCC (e.g. 4.2.4), so hide the array from sparse altogether. - */ -# ifndef __CHECKER__ -# define __compiletime_error_fallback(condition) \ - do { ((void)sizeof(char[1 - 2 * condition])); } while (0) -# endif -#endif -#ifndef __compiletime_error_fallback -# define __compiletime_error_fallback(condition) do { } while (0) #endif #ifdef __OPTIMIZE__ # define __compiletime_assert(condition, msg, prefix, suffix) \ do { \ - int __cond = !(condition); \ extern void prefix ## suffix(void) __compiletime_error(msg); \ - if (__cond) \ + if (!(condition)) \ prefix ## suffix(); \ - __compiletime_error_fallback(__cond); \ } while (0) #else # define __compiletime_assert(condition, msg, prefix, suffix) do { } while (0)