From patchwork Wed Jun 3 23:32:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 215404 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83235C433E3 for ; Wed, 3 Jun 2020 23:33:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B2AC207D0 for ; Wed, 3 Jun 2020 23:33:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="UstK7WLa" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726884AbgFCXdI (ORCPT ); Wed, 3 Jun 2020 19:33:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726516AbgFCXcX (ORCPT ); Wed, 3 Jun 2020 19:32:23 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B290C0085C6 for ; Wed, 3 Jun 2020 16:32:20 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id fs4so258150pjb.5 for ; Wed, 03 Jun 2020 16:32:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/wgSseUcyTd9Drk76fcV4j2VbriV8jy/HYEGQ0NYaFk=; b=UstK7WLaEjDWaKH3+++ddeAXtqpiyFxQfl0O2lazw1LzLA/AjfOlogFybdXuhuVdpb rFJfQt4LgPRAzCjKoGukk2COBz4+5z1QncnyZ/CR0mBbgUwuOWUYwdicuZEexScuGgS/ olVZGdjTE/8GbLwCvMROC7gFScCzYDYjU2Bl8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/wgSseUcyTd9Drk76fcV4j2VbriV8jy/HYEGQ0NYaFk=; b=gZDh26MIrlHNvjaI7CbIvP404zeHvugRcBNUjO1mcD9ZehGgQ2Q6ivo9LzRwFNq8n3 +Lg9To+tvWjR2q9iAglDUsJn6bjsHIVKG57nkaoCvHuQbXn3aztykNT1AfsclEo/xFNf eK4tAAv2Xu0dO4z5N41RWSazK2/s6gJzE0KjvTCkZQyXt/2tH3iyID0AfbRDGDMPLGQV W/YO+T/YGAjgAkRo4hedUk1ffKiW485MRm/GFKgbKSzSK6LhTcIF1RnbAPoW36l4SyQL WacS5pKYS5kK3vEiIg98sqc13MgP1pEfwyZtOsPM5wMMk+jzM1Ew+L0y4U2JUXg89TpB iu7g== X-Gm-Message-State: AOAM531RkXcxyaB9P8sYFrT4nXdoTdZ3GPQnTV+VHsWH12BQHx6laqur Qhl25tgAgFJuOfqhj0N4vbVpZA== X-Google-Smtp-Source: ABdhPJx0hlq73lYT8fOS+tXn65Ai8YEmL5/PSXJN4dJgAWJCbi3pNRJVeupDCakZZ2YluWv4rvJ6+A== X-Received: by 2002:a17:902:b706:: with SMTP id d6mr2149275pls.304.1591227139667; Wed, 03 Jun 2020 16:32:19 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id k19sm2867022pfg.153.2020.06.03.16.32.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2020 16:32:16 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Linus Torvalds , Miguel Ojeda , Alexander Potapenko , Joe Perches , Andy Whitcroft , x86@kernel.org, drbd-dev@lists.linbit.com, linux-block@vger.kernel.org, b43-dev@lists.infradead.org, netdev@vger.kernel.org, linux-wireless@vger.kernel.org, linux-ide@vger.kernel.org, linux-clk@vger.kernel.org, linux-spi@vger.kernel.org, linux-mm@kvack.org, clang-built-linux@googlegroups.com Subject: [PATCH 10/10] compiler: Remove uninitialized_var() macro Date: Wed, 3 Jun 2020 16:32:03 -0700 Message-Id: <20200603233203.1695403-11-keescook@chromium.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200603233203.1695403-1-keescook@chromium.org> References: <20200603233203.1695403-1-keescook@chromium.org> MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Using uninitialized_var() is dangerous as it papers over real bugs[1] (or can in the future), and suppresses unrelated compiler warnings (e.g. "unused variable"). If the compiler thinks it is uninitialized, either simply initialize the variable or make compiler changes. As recommended[2] by[3] Linus[4], remove the macro. [1] https://lore.kernel.org/lkml/20200603174714.192027-1-glider@google.com/ [2] https://lore.kernel.org/lkml/CA+55aFw+Vbj0i=1TGqCR5vQkCzWJ0QxK6CernOU6eedsudAixw@mail.gmail.com/ [3] https://lore.kernel.org/lkml/CA+55aFwgbgqhbp1fkxvRKEpzyR5J8n1vKT1VZdz9knmPuXhOeg@mail.gmail.com/ [4] https://lore.kernel.org/lkml/CA+55aFz2500WfbKXAx8s67wrm9=yVJu65TpLgN_ybYNv0VEOKA@mail.gmail.com/ Suggested-by: Linus Torvalds Signed-off-by: Kees Cook --- include/linux/compiler-clang.h | 2 -- include/linux/compiler-gcc.h | 6 ------ tools/include/linux/compiler.h | 2 -- tools/virtio/linux/kernel.h | 2 -- 4 files changed, 12 deletions(-) diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h index 790c0c6b8552..019f444b500b 100644 --- a/include/linux/compiler-clang.h +++ b/include/linux/compiler-clang.h @@ -5,8 +5,6 @@ /* Compiler specific definitions for Clang compiler */ -#define uninitialized_var(x) x = *(&(x)) - /* same as gcc, this was present in clang-2.6 so we can assume it works * with any version that can compile the kernel */ diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h index d7ee4c6bad48..ac3e29ae32de 100644 --- a/include/linux/compiler-gcc.h +++ b/include/linux/compiler-gcc.h @@ -58,12 +58,6 @@ (typeof(ptr)) (__ptr + (off)); \ }) -/* - * A trick to suppress uninitialized variable warning without generating any - * code - */ -#define uninitialized_var(x) x = x - #ifdef CONFIG_RETPOLINE #define __noretpoline __attribute__((__indirect_branch__("keep"))) #endif diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h index 180f7714a5f1..29cbb73f2ae0 100644 --- a/tools/include/linux/compiler.h +++ b/tools/include/linux/compiler.h @@ -108,8 +108,6 @@ # define noinline #endif -#define uninitialized_var(x) x = *(&(x)) - #include /* diff --git a/tools/virtio/linux/kernel.h b/tools/virtio/linux/kernel.h index 6683b4a70b05..1e14ab967c11 100644 --- a/tools/virtio/linux/kernel.h +++ b/tools/virtio/linux/kernel.h @@ -109,8 +109,6 @@ static inline void free_page(unsigned long addr) const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) -#define uninitialized_var(x) x = x - # ifndef likely # define likely(x) (__builtin_expect(!!(x), 1)) # endif