Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1826713imm; Mon, 3 Sep 2018 10:26:35 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaVUvEzb2IIWMOKxXlYMabDjT/0a+IMGc7org36+egqL8rFyZs7WAeVBsSobvwkdo5b0uqB X-Received: by 2002:a63:946:: with SMTP id 67-v6mr18448441pgj.132.1535995595618; Mon, 03 Sep 2018 10:26:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535995595; cv=none; d=google.com; s=arc-20160816; b=P5ybvDVMNuKvsvECkdUPfrEj6+7P69pp7DYmiUJOJ1hbkiEgOKswe6y2B/OUUPB2SD QseVduuoq/V47AkessnuicTPIvYts3LjO4Kn1Qg231/d27gjU3xbY5GuxLCFbe+mSzLh t8JZMsAfILXPjnAr+eFEVe5XO3uTL6BiB2bLgc8623LwEzKSG0vBAyyucUwHbYYdpWuf LGjBK1edBY6KxEn5k6VuOdWDh7JaWPLdPRW7BkAkAgqCFJ/fhk4emNJN5TjkX/5RNBCA DpUQvaHg7LaqW9j/m9ArkOyXD8CB3U30R6MvmJXHkcfEMlci/NqAcRPHuCXxAHmoV4XL MJ9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=ia961Qcy/cfElEzHROHS3GuGYELaO03plW0mhlLr4Cg=; b=F1NNr8BBLq2f5D2Gjdsx9SUcBtUHt3jFkzANhywqB7Dw8nYIUcpnGGcNK/2UVmbHol y6TnDJcrOmAWkHr5HNMUyJgIqkPeKMCEzgnjAy4pe1itKHjFCG8XphsZBkes/rYeVPRY 21twaoHdYqtpZHqqVUx5Uhjnc8x7c/8p19THsorE0N8xoM590uUvriZ8sJZI7TkuRxZw 0K1s66LEClGFM85XRm9H/fS1q4KpQwm8+erTwU9UAZd/D9UmI4G+PCYlR2TkquFV/AqP 704U2l7pCqPYRnw7bJwLc2OYMxmBSfiilEHCG5UX0Tcqf9EMSyTdrWmqLwy6qxaPvmeD 7y1Q== 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 o9-v6si18515076pgf.331.2018.09.03.10.26.20; Mon, 03 Sep 2018 10:26:35 -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 S1730204AbeICVqC (ORCPT + 99 others); Mon, 3 Sep 2018 17:46:02 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45598 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728935AbeICVqC (ORCPT ); Mon, 3 Sep 2018 17:46:02 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 7CCA7D0A; Mon, 3 Sep 2018 17:24:54 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dominique Leuenberger , Adrian Schroeter , Vlastimil Babka , Thomas Gleixner , Andi Kleen , Michal Hocko , "H . Peter Anvin" , Linus Torvalds , Dave Hansen , Michal Hocko Subject: [PATCH 4.14 111/165] x86/speculation/l1tf: Fix overflow in l1tf_pfn_limit() on 32bit Date: Mon, 3 Sep 2018 18:56:37 +0200 Message-Id: <20180903165701.084914937@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180903165655.003605184@linuxfoundation.org> References: <20180903165655.003605184@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Vlastimil Babka commit 9df9516940a61d29aedf4d91b483ca6597e7d480 upstream. On 32bit PAE kernels on 64bit hardware with enough physical bits, l1tf_pfn_limit() will overflow unsigned long. This in turn affects max_swapfile_size() and can lead to swapon returning -EINVAL. This has been observed in a 32bit guest with 42 bits physical address size, where max_swapfile_size() overflows exactly to 1 << 32, thus zero, and produces the following warning to dmesg: [ 6.396845] Truncating oversized swap area, only using 0k out of 2047996k Fix this by using unsigned long long instead. Fixes: 17dbca119312 ("x86/speculation/l1tf: Add sysfs reporting for l1tf") Fixes: 377eeaa8e11f ("x86/speculation/l1tf: Limit swap file size to MAX_PA/2") Reported-by: Dominique Leuenberger Reported-by: Adrian Schroeter Signed-off-by: Vlastimil Babka Signed-off-by: Thomas Gleixner Acked-by: Andi Kleen Acked-by: Michal Hocko Cc: "H . Peter Anvin" Cc: Linus Torvalds Cc: Dave Hansen Cc: Michal Hocko Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/20180820095835.5298-1-vbabka@suse.cz Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/processor.h | 4 ++-- arch/x86/mm/init.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -180,9 +180,9 @@ extern const struct seq_operations cpuin extern void cpu_detect(struct cpuinfo_x86 *c); -static inline unsigned long l1tf_pfn_limit(void) +static inline unsigned long long l1tf_pfn_limit(void) { - return BIT(boot_cpu_data.x86_phys_bits - 1 - PAGE_SHIFT) - 1; + return BIT_ULL(boot_cpu_data.x86_phys_bits - 1 - PAGE_SHIFT) - 1; } extern void early_cpu_init(void); --- a/arch/x86/mm/init.c +++ b/arch/x86/mm/init.c @@ -892,7 +892,7 @@ unsigned long max_swapfile_size(void) if (boot_cpu_has_bug(X86_BUG_L1TF)) { /* Limit the swap file size to MAX_PA/2 for L1TF workaround */ - unsigned long l1tf_limit = l1tf_pfn_limit() + 1; + unsigned long long l1tf_limit = l1tf_pfn_limit() + 1; /* * We encode swap offsets also with 3 bits below those for pfn * which makes the usable limit higher. @@ -900,7 +900,7 @@ unsigned long max_swapfile_size(void) #if CONFIG_PGTABLE_LEVELS > 2 l1tf_limit <<= PAGE_SHIFT - SWP_OFFSET_FIRST_BIT; #endif - pages = min_t(unsigned long, l1tf_limit, pages); + pages = min_t(unsigned long long, l1tf_limit, pages); } return pages; }