Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1346242ybp; Thu, 17 Oct 2019 11:23:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqxfCwti9Bb/JJgEpZ11tQRziTeeweYYIik9J7SygB9WNwNJci0IXK3GbktJbty4uMlYR6kR X-Received: by 2002:a17:906:154a:: with SMTP id c10mr4688344ejd.238.1571336588926; Thu, 17 Oct 2019 11:23:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571336588; cv=none; d=google.com; s=arc-20160816; b=CuQEIxtXZLt6rVH3ayqJiwZuoJTrPuPWTwHmGY7n44Vy0+hPufn7rkr2nbSdPOUZja 0lXrzslcWhfKSgU7wsr4hG+5POewB6hQm0ImfTLjt6/f/OioW7sCcOVRb0RIBVM1OzRC b8qVyrdKmiytp/AnY+pDSO8NWt8HEmjaZhLUapBjh3wDyWW3K31BJlW0Y3FQOdHZeoCx jKYD1kT53G6Rt6WleMcwEIKWYGp4PHc2tKVKmsdiV2w8+MRxIPWqd0DQj7V3LxJPGF// MJxbkQ+Ws+PQk20ABFtYWKBautFqbHLNKmTwZEPS61Sgwn6K8k/3M3gcg7Ptxr6O2yaa KPwQ== 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=BVP2apyCFMlxnIe8raBE2rDGHUPws5xXKkcGESwNJDA=; b=AuEw5ucByJW2L92M7nkOoLTKzfWc1Eny3Ik1SWDJIsXtYk0PvZ00JmhknCyIrNAjJo vo+IPFoE3i1ypze80oCb2/G+efEER/ovfz7xugE2Acj6x4WUSv5L1aaLEusPhrTHvcjs NHNAH5NJP+PJRekA824lQF8DOwkPrGlaOzML8cVmcA2ho/g7nQ/o5rVhiwVydsEMX8XS PIaI7vUzBrUi2NZvQcvL7dAsOl70pMyQFwfdADde+MinpuB3O3Pw7Zh1cTLwm8Of2Yxk ZfddleQeasg25DYOX/v3VWyRBPa2FKyp0MLQ18JXreOw/DCxVefHCdXNjAJHZ3A3R0r5 e2QA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Y/2N1j8P"; 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 d1si1961062eds.148.2019.10.17.11.22.45; Thu, 17 Oct 2019 11:23:08 -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; dkim=pass header.i=@kernel.org header.s=default header.b="Y/2N1j8P"; 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 S2438955AbfJPWBH (ORCPT + 99 others); Wed, 16 Oct 2019 18:01:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:55104 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438646AbfJPV7u (ORCPT ); Wed, 16 Oct 2019 17:59:50 -0400 Received: from localhost (unknown [192.55.54.58]) (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 8556921E6F; Wed, 16 Oct 2019 21:59:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571263189; bh=VKHQfKbsgnFdOJ/vCWv509LB8R6iwIp/yFnQDFa6zDc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y/2N1j8PxCVkrRlRgHR9mmwgYoXycrr1mBP9HyCA4ZG4tuaWph1EXa2mhIZwJJGfx Mliq3qnyD+odoY907tl76fVvO3kzXyL6Ae4VEkrfjzNJCJt2NenLNNUmdoKfRtlpOO c5YtaB/VIlCJr+WmwSP/9xHuN0LjYvE+znGhdRPc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qian Cai , Heiko Carstens , Christian Borntraeger , Michal Hocko , "Kirill A. Shutemov" , Vasily Gorbik , Alexander Duyck , Andrew Morton , Linus Torvalds Subject: [PATCH 5.3 077/112] mm/page_alloc.c: fix a crash in free_pages_prepare() Date: Wed, 16 Oct 2019 14:51:09 -0700 Message-Id: <20191016214904.226946438@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191016214844.038848564@linuxfoundation.org> References: <20191016214844.038848564@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: Qian Cai commit 234fdce892f905cbc2674349a9eb4873e288e5b3 upstream. On architectures like s390, arch_free_page() could mark the page unused (set_page_unused()) and any access later would trigger a kernel panic. Fix it by moving arch_free_page() after all possible accessing calls. Hardware name: IBM 2964 N96 400 (z/VM 6.4.0) Krnl PSW : 0404e00180000000 0000000026c2b96e (__free_pages_ok+0x34e/0x5d8) R:0 T:1 IO:0 EX:0 Key:0 M:1 W:0 P:0 AS:3 CC:2 PM:0 RI:0 EA:3 Krnl GPRS: 0000000088d43af7 0000000000484000 000000000000007c 000000000000000f 000003d080012100 000003d080013fc0 0000000000000000 0000000000100000 00000000275cca48 0000000000000100 0000000000000008 000003d080010000 00000000000001d0 000003d000000000 0000000026c2b78a 000000002717fdb0 Krnl Code: 0000000026c2b95c: ec1100b30659 risbgn %r1,%r1,0,179,6 0000000026c2b962: e32014000036 pfd 2,1024(%r1) #0000000026c2b968: d7ff10001000 xc 0(256,%r1),0(%r1) >0000000026c2b96e: 41101100 la %r1,256(%r1) 0000000026c2b972: a737fff8 brctg %r3,26c2b962 0000000026c2b976: d7ff10001000 xc 0(256,%r1),0(%r1) 0000000026c2b97c: e31003400004 lg %r1,832 0000000026c2b982: ebff1430016a asi 5168(%r1),-1 Call Trace: __free_pages_ok+0x16a/0x5d8) memblock_free_all+0x206/0x290 mem_init+0x58/0x120 start_kernel+0x2b0/0x570 startup_continue+0x6a/0xc0 INFO: lockdep is turned off. Last Breaking-Event-Address: __free_pages_ok+0x372/0x5d8 Kernel panic - not syncing: Fatal exception: panic_on_oops 00: HCPGIR450W CP entered; disabled wait PSW 00020001 80000000 00000000 26A2379C In the past, only kernel_poison_pages() would trigger this but it needs "page_poison=on" kernel cmdline, and I suspect nobody tested that on s390. Recently, kernel_init_free_pages() (commit 6471384af2a6 ("mm: security: introduce init_on_alloc=1 and init_on_free=1 boot options")) was added and could trigger this as well. [akpm@linux-foundation.org: add comment] Link: http://lkml.kernel.org/r/1569613623-16820-1-git-send-email-cai@lca.pw Fixes: 8823b1dbc05f ("mm/page_poison.c: enable PAGE_POISONING as a separate option") Fixes: 6471384af2a6 ("mm: security: introduce init_on_alloc=1 and init_on_free=1 boot options") Signed-off-by: Qian Cai Reviewed-by: Heiko Carstens Acked-by: Christian Borntraeger Acked-by: Michal Hocko Cc: "Kirill A. Shutemov" Cc: Vasily Gorbik Cc: Alexander Duyck Cc: [5.3+] Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/page_alloc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1174,11 +1174,17 @@ static __always_inline bool free_pages_p debug_check_no_obj_freed(page_address(page), PAGE_SIZE << order); } - arch_free_page(page, order); if (want_init_on_free()) kernel_init_free_pages(page, 1 << order); kernel_poison_pages(page, 1 << order, 0); + /* + * arch_free_page() can make the page's contents inaccessible. s390 + * does this. So nothing which can access the page's contents should + * happen after this. + */ + arch_free_page(page, order); + if (debug_pagealloc_enabled()) kernel_map_pages(page, 1 << order, 0);