Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5253099imu; Tue, 15 Jan 2019 14:08:39 -0800 (PST) X-Google-Smtp-Source: ALg8bN42DlK8eHYgu2jZWlnhlobqBz4/mRiSfs7DAQW19TonRytgUfoqGLvtJeBKRRE7ZVpt609Q X-Received: by 2002:a62:5910:: with SMTP id n16mr6219921pfb.128.1547590119086; Tue, 15 Jan 2019 14:08:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547590119; cv=none; d=google.com; s=arc-20160816; b=tIGaqrF35zhnKdDnwt9a9J+9JS3bc+ry0pKQDY+kodzyfki/hpqC5AID6d+CMbtoRO vvzw0wnkQ6OsfraIPeWkiS2ECxz27qD5Cz0nIp0iZN3bvBJ9py4wFBEpQPx8hOR7OXZx xOouLbTi3RiX0Cpwyd/SeQfwSKxc4rujXz//yPsQZ4BJDctFTQC1mJu+so/GpF0qQtat IqvDZhWnhMxCxc6g/+Al6ENhytiFw/ROZxSLoeNKrqWeb/6dMIXKT0f7MA7flZreemcF eDJqLF4xHsxf1gfePnOOXCQCT7WZD9htvKYLxEgCOvDW9b1C2EngRVWuOrjbz22YP9ge tJoA== 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=EKKVgc7FLUoyVKolIiHa8AL4JKeHNS02UtP7xUXYw0M=; b=NdmYXqf6w6v9cpWsQln2aeYOGT2Uap7bLXEpT7/oBPHv6t5g9YRF1oT10n3iZ1HqTI 34HiJ4UDhKsj+F7kfjelJcC8UNGEJTQ92qRlx+7RYu2EiDE+yZPd4yvCMxS2Euzdvu+1 UdZrwXSv6BdggyMf0rhOPIhaGIZhhxDtkieZemTmTycAyjopC3/8d0dbYAF/RkilA+uS brQF59gGHDNBX85DrF8CmRBkegCva0qXjJhkb1QtoPSWFwf7uVdpQYgR+q1LFINrhOP+ Q5ZwDo0MXonEwqInW48DY1trAWvsG67+m76QdzkEFKxP1b7zI/QjnFqP+yX0xsaCCazQ EPZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WVstXudd; 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 gn22si4090499plb.19.2019.01.15.14.08.20; Tue, 15 Jan 2019 14:08:39 -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=WVstXudd; 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 S2387848AbfAOQpq (ORCPT + 99 others); Tue, 15 Jan 2019 11:45:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:35384 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731090AbfAOQpl (ORCPT ); Tue, 15 Jan 2019 11:45:41 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 1B4A92054F; Tue, 15 Jan 2019 16:45:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547570740; bh=k8bXhqWpO5kaQ3I9FWr8R5h834By14tmBALeMGehoVg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WVstXuddeUA6CnQJY92Drnnj7ArlDJzSkIw1ED1Qw6OcqRlQ8Tl+1YRPEfOXLLjZu ACJQiomh/bf2GRneA4SRaG+pEmTer3l9HQHM2x/jK5l9GRRnurHmsI6QqfH58QRUct Sl2hyKOZeSdSDpE3jlrB5pI88C9ttWIkw5IA3nmw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jan Stancek , "Kirill A. Shutemov" , Michal Hocko , "Kirill A. Shutemov" , David Hildenbrand , Andrea Arcangeli , Andrew Morton , Linus Torvalds , Laszlo Ersek Subject: [PATCH 4.20 53/57] mm: page_mapped: dont assume compound page is huge or THP Date: Tue, 15 Jan 2019 17:36:34 +0100 Message-Id: <20190115154913.994745402@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190115154910.734892368@linuxfoundation.org> References: <20190115154910.734892368@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jan Stancek commit 8ab88c7169b7fba98812ead6524b9d05bc76cf00 upstream. LTP proc01 testcase has been observed to rarely trigger crashes on arm64: page_mapped+0x78/0xb4 stable_page_flags+0x27c/0x338 kpageflags_read+0xfc/0x164 proc_reg_read+0x7c/0xb8 __vfs_read+0x58/0x178 vfs_read+0x90/0x14c SyS_read+0x60/0xc0 The issue is that page_mapped() assumes that if compound page is not huge, then it must be THP. But if this is 'normal' compound page (COMPOUND_PAGE_DTOR), then following loop can keep running (for HPAGE_PMD_NR iterations) until it tries to read from memory that isn't mapped and triggers a panic: for (i = 0; i < hpage_nr_pages(page); i++) { if (atomic_read(&page[i]._mapcount) >= 0) return true; } I could replicate this on x86 (v4.20-rc4-98-g60b548237fed) only with a custom kernel module [1] which: - allocates compound page (PAGEC) of order 1 - allocates 2 normal pages (COPY), which are initialized to 0xff (to satisfy _mapcount >= 0) - 2 PAGEC page structs are copied to address of first COPY page - second page of COPY is marked as not present - call to page_mapped(COPY) now triggers fault on access to 2nd COPY page at offset 0x30 (_mapcount) [1] https://github.com/jstancek/reproducers/blob/master/kernel/page_mapped_crash/repro.c Fix the loop to iterate for "1 << compound_order" pages. Kirrill said "IIRC, sound subsystem can producuce custom mapped compound pages". Link: http://lkml.kernel.org/r/c440d69879e34209feba21e12d236d06bc0a25db.1543577156.git.jstancek@redhat.com Fixes: e1534ae95004 ("mm: differentiate page_mapped() from page_mapcount() for compound pages") Signed-off-by: Jan Stancek Debugged-by: Laszlo Ersek Suggested-by: "Kirill A. Shutemov" Acked-by: Michal Hocko Acked-by: Kirill A. Shutemov Reviewed-by: David Hildenbrand Reviewed-by: Andrea Arcangeli Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/mm/util.c +++ b/mm/util.c @@ -478,7 +478,7 @@ bool page_mapped(struct page *page) return true; if (PageHuge(page)) return false; - for (i = 0; i < hpage_nr_pages(page); i++) { + for (i = 0; i < (1 << compound_order(page)); i++) { if (atomic_read(&page[i]._mapcount) >= 0) return true; }