From mboxrd@z Thu Jan 1 00:00:00 1970 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=-7.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=no 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 C07B0C43461 for ; Thu, 3 Sep 2020 21:47:14 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 716C420639 for ; Thu, 3 Sep 2020 21:47:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="AO6gkprq"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="EFlB8L34" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 716C420639 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=SvqHn0WQa6uqT+/0P/Ab3skuqNmoKlrpOne88AC6gzQ=; b=AO6gkprq+9srYU5umjN9OYusx Bsu5Rg5qpFD7J1jzy/KTYR027sKjSgrjbjassBZN7PkhgyckuTOW8GOWiDLI+8nMek6sRY4q40G1a +7ZXzYL+5eXd6qQ3MVCmH/8tduaCt6QjfSuciAhsBU4CN1bPPAvgHi0U8H1rK6bpr7b40v81FlyOS UYMuBhW/h7ul/qmmwaC+RCWma8ndO99VqwO+z8IRnsOBvdbpIDA3mje6tAumdW8bSS3xu5USdMxhc b1UsogCD3P+gO6r9M5vQsZ2LlThEvg7FyZTUbb+62r9JEaw3lRn1xm+BTN48TmS/r6m3rw2jX9C7G ZIFG7Yj5A==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kDx3R-0002f9-0T; Thu, 03 Sep 2020 21:46:01 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kDx3N-0002dQ-MH for linux-arm-kernel@lists.infradead.org; Thu, 03 Sep 2020 21:45:58 +0000 Received: by mail-pg1-x543.google.com with SMTP id v15so3169471pgh.6 for ; Thu, 03 Sep 2020 14:45:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=88UAUo6RYF27MUEaYZE9R7HTuO6mGUyasahfv8EZhB8=; b=EFlB8L3484X2NUQ2w9kQvBk3L+1RDvCzNz+1QFX1Nm3dCNte5YHScmXG1pqmo0J2+E C6Clco3P/dWY6iT/m+OtQJLLVltMdhY68a4RYVvEYy7d7wz05uOxuTBRrPhAf9vZulwq OT1t8R0KPmtqqUOLIMHdbCPWYgvYCgeGDAsFI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=88UAUo6RYF27MUEaYZE9R7HTuO6mGUyasahfv8EZhB8=; b=j8GDQrAmUwpLKFXAwyL0xr7AWfG9U5bnA6uHa+dVnw/FWAHeey9MBUuuDz550E6WoI 43nOuZA0VmzgHz74bNOjlPxnKGS1LqpAHLkZ8S2acDePtYyook7cdvT6pJbfKw8zYNJP VksxkoELAj1ovjqZhSS8NNf6X7dD2XFFycNCYs+A/TXDYgs1HG1CQBeofPTsTiKv+OFA cr0vA6nYmYC5fO3bsBEbFIdTbWnYLERblFuB4E2sbpByLXPv+ZpgMEyQJu8EFGzKsD21 lPofJnyPbzHTWWlBXSU+fblsiCwvf/AzpUBD6M5o8ZpQCc9pu/6scKevSJxKqdeTcqYW m5bA== X-Gm-Message-State: AOAM532Zq9VCZ4+9ptMTrchWLWENV8Wne7yhe9xFphUMcMVVXOTShGx6 SFxc7H0+GggYuw03NPnHhrb0rw== X-Google-Smtp-Source: ABdhPJyg0lgZlgBi8/Irq6grlvy58EaMpaSg/pdagWK+0tWzLnV3KOczUO8JKY6Ln9M1KxRZgEWLVw== X-Received: by 2002:a17:902:7b83:: with SMTP id w3mr6022860pll.28.1599169555661; Thu, 03 Sep 2020 14:45:55 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id t20sm4165589pgj.27.2020.09.03.14.45.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 14:45:54 -0700 (PDT) Date: Thu, 3 Sep 2020 14:45:54 -0700 From: Kees Cook To: Sami Tolvanen Subject: Re: [PATCH v2 02/28] x86/asm: Replace __force_order with memory clobber Message-ID: <202009031445.807B55E@keescook> References: <20200624203200.78870-1-samitolvanen@google.com> <20200903203053.3411268-1-samitolvanen@google.com> <20200903203053.3411268-3-samitolvanen@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200903203053.3411268-3-samitolvanen@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200903_174557_755561_8354491C X-CRM114-Status: GOOD ( 25.45 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, x86@kernel.org, "Paul E. McKenney" , kernel-hardening@lists.openwall.com, Peter Zijlstra , Greg Kroah-Hartman , Masahiro Yamada , linux-kbuild@vger.kernel.org, Nick Desaulniers , linux-kernel@vger.kernel.org, Steven Rostedt , clang-built-linux@googlegroups.com, Arvind Sankar , linux-pci@vger.kernel.org, Will Deacon , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Sep 03, 2020 at 01:30:27PM -0700, Sami Tolvanen wrote: > From: Arvind Sankar > > The CRn accessor functions use __force_order as a dummy operand to > prevent the compiler from reordering CRn reads/writes with respect to > each other. > > The fact that the asm is volatile should be enough to prevent this: > volatile asm statements should be executed in program order. However GCC > 4.9.x and 5.x have a bug that might result in reordering. This was fixed > in 8.1, 7.3 and 6.5. Versions prior to these, including 5.x and 4.9.x, > may reorder volatile asm statements with respect to each other. > > There are some issues with __force_order as implemented: > - It is used only as an input operand for the write functions, and hence > doesn't do anything additional to prevent reordering writes. > - It allows memory accesses to be cached/reordered across write > functions, but CRn writes affect the semantics of memory accesses, so > this could be dangerous. > - __force_order is not actually defined in the kernel proper, but the > LLVM toolchain can in some cases require a definition: LLVM (as well > as GCC 4.9) requires it for PIE code, which is why the compressed > kernel has a definition, but also the clang integrated assembler may > consider the address of __force_order to be significant, resulting in > a reference that requires a definition. > > Fix this by: > - Using a memory clobber for the write functions to additionally prevent > caching/reordering memory accesses across CRn writes. > - Using a dummy input operand with an arbitrary constant address for the > read functions, instead of a global variable. This will prevent reads > from being reordered across writes, while allowing memory loads to be > cached/reordered across CRn reads, which should be safe. > > Signed-off-by: Arvind Sankar In the primary thread for this patch I sent a Reviewed tag, but for good measure, here it is again: Reviewed-by: Kees Cook -- Kees Cook _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel