Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp803997ybl; Wed, 4 Dec 2019 11:09:42 -0800 (PST) X-Google-Smtp-Source: APXvYqzPJvQzEhbnLGEw04d/tZXDlEQ/4doMIMS9g72dhE1OK6dTPxQcW02SCejBrPzx1Nd5Irp6 X-Received: by 2002:a05:6830:1f4b:: with SMTP id u11mr3712770oth.60.1575486582293; Wed, 04 Dec 2019 11:09:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575486582; cv=none; d=google.com; s=arc-20160816; b=0KsKu1/lzhsQ6ISE5GwxfWnpUsD5qSIBctNqaWBO/c2pktmA0WNrt8SFtAS2+IYNx/ 1ZEc7Epcddd7c8G/j+rj7ZkTf2493WG+QdjltBdPCSEieFI/bI77VmQLr0CuuSlNBDZt v9rH304vfJTWMqu6vmfMzGXZGSGpqdrNZzU/UCMVTAT8HhFlYfcNhcQf3mHxwhx6/GLE TFm46ivdTqDujnCK2e++lF5fnD2JUNJ+C/GFo3z5cxL1LhO4cAzfztUOB3ZUTnnKi1EY KH83dCIqKUKxt7Z3bAi+nlJGvrOOQcpRDNK2YxkyXdQgYqFJF8GE4g3l+oZrp2rCCCCu qH/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=2qcn3ykK+1cU9+Ykjh04i0Y2t3JQqNEuDmngFpx/KmA=; b=bZ6FmzlatLJrRrRS931J0/rjI/sSi1faGyPicgaK942OvTgOZQlQOpyy6WG/tBmnNz 3k4YYHgY59uWFlC5L6Q9ZfWEsvnUv2UIszyLh1ADHodvwjZK6ZVtohXiw9ykfEL5+Bcp q8GYgW4twzNl8XsvpR3oqrsojOsLyE04jgIdkV8AEjrys2UcBSVkGTCa3wd+TMbAhg/u Ua/GSxdx+Izu5XJsKgE6URp4ACJvZcvVjAQWb5d4WnyLVx9WE0jQW2V/dYIO0F2gNDMn feshzgJmKqVumI8nTH59EbkQUFjfipfiE6070emB0Ewqg+8KQNEP7VGkXiR6janK/p1I Qxvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lDCZe4hy; 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 y6si3517919otq.74.2019.12.04.11.09.29; Wed, 04 Dec 2019 11:09:42 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=lDCZe4hy; 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 S1730184AbfLDSHV (ORCPT + 99 others); Wed, 4 Dec 2019 13:07:21 -0500 Received: from mail.kernel.org ([198.145.29.99]:56910 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730737AbfLDSHS (ORCPT ); Wed, 4 Dec 2019 13:07:18 -0500 Received: from localhost (unknown [217.68.49.72]) (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 B090020675; Wed, 4 Dec 2019 18:07:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575482837; bh=XOT+X/DKPEi5dZaEYS+gn3/ARlU0Jl/JFo1hv2SUL3U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lDCZe4hy0JCCggl8/0GCLeCOzypJVFbuslUzE/g2dK6VGwl+WezOCZDLlpJ/F3evA A4o3KRqKGUKc/D3GGib2pNjvhXo5UtONfceY4Cv0tcHn51CIdaUzh9oUxg0ylsusvX SGsaFj3zoGVSpqtGbo/776hpMoKHie289ENqS+lo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vlastimil Babka , Sasha Levin Subject: [PATCH 4.14 155/209] mm, gup: add missing refcount overflow checks on s390 Date: Wed, 4 Dec 2019 18:56:07 +0100 Message-Id: <20191204175334.154600538@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204175321.609072813@linuxfoundation.org> References: <20191204175321.609072813@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vlastimil Babka The mainline commit 8fde12ca79af ("mm: prevent get_user_pages() from overflowing page refcount") was backported to 4.14.y stable as commit 04198de24771. The backport however missed that in 4.14, there are several arch-specific gup.c versions with fast gup implementations, so these do not prevent refcount overflow. This stable-only commit fixes the s390 version, and is based on the backport in SUSE SLES/openSUSE 4.12-based kernels. The remaining architectures with own gup.c are sparc, mips, sh. It's unlikely the known overflow scenario based on FUSE, which needs 140GB of RAM, is a problem for those architectures, and I don't feel confident enough to patch them. Signed-off-by: Vlastimil Babka Signed-off-by: Sasha Levin --- arch/s390/mm/gup.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/s390/mm/gup.c b/arch/s390/mm/gup.c index 05c8abd864f1d..9bce54eac0b07 100644 --- a/arch/s390/mm/gup.c +++ b/arch/s390/mm/gup.c @@ -39,7 +39,8 @@ static inline int gup_pte_range(pmd_t *pmdp, pmd_t pmd, unsigned long addr, VM_BUG_ON(!pfn_valid(pte_pfn(pte))); page = pte_page(pte); head = compound_head(page); - if (!page_cache_get_speculative(head)) + if (unlikely(WARN_ON_ONCE(page_ref_count(head) < 0) + || !page_cache_get_speculative(head))) return 0; if (unlikely(pte_val(pte) != pte_val(*ptep))) { put_page(head); @@ -77,7 +78,8 @@ static inline int gup_huge_pmd(pmd_t *pmdp, pmd_t pmd, unsigned long addr, refs++; } while (addr += PAGE_SIZE, addr != end); - if (!page_cache_add_speculative(head, refs)) { + if (unlikely(WARN_ON_ONCE(page_ref_count(head) < 0) + || !page_cache_add_speculative(head, refs))) { *nr -= refs; return 0; } @@ -151,7 +153,8 @@ static int gup_huge_pud(pud_t *pudp, pud_t pud, unsigned long addr, refs++; } while (addr += PAGE_SIZE, addr != end); - if (!page_cache_add_speculative(head, refs)) { + if (unlikely(WARN_ON_ONCE(page_ref_count(head) < 0) + || !page_cache_add_speculative(head, refs))) { *nr -= refs; return 0; } -- 2.20.1