Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp680648pxj; Fri, 14 May 2021 12:57:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2sqmnBi2J8RIaFYJ8Vdy35L9MP0d953CuaLOibSRZrzr3n/DHrvNzf/P++VUisVPYgIFy X-Received: by 2002:a02:1c81:: with SMTP id c123mr46217052jac.42.1621022265701; Fri, 14 May 2021 12:57:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621022265; cv=none; d=google.com; s=arc-20160816; b=bJpcT+i1bLl6Vi8sNPU0/XGmy/OP80qA1ep6w6EnrHq27loko1gNCmwznl2AdjMsuH fn3YQYXSnD1K64zOuJGKTMCgfVKFPwJTWMfgLjQGaqTkyXU8pWX2I7aq1GrE1HGvbzCq Dtfq6eZ1xfLNzV1cOqGH96UsmaQQ/ORsqMSm8Uor3aHi4h3etpEHBOf+R21EHZjBfbYm xigM4FRvbvu127wrGdEcLcStNqc7EtdMv6rgWu29q82InjSx0p+++iTXlBEGlN8+gqic 0jGFv1xtJyLOBo6BhPK8ASbhLCg5tZBvkR3DBMrCMJd+lE6F10fvbJpU3ygPtxI7wOLh lnFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Ht2wahpr6SjLNp0fKa1tB4u5N0RuDTYUAiljNoyrPYg=; b=DulKoCeCislZnMwJkcCuFMP4Ac185UPn9iA49eVUzInYjP41ymPDum61tpd5/hA2rv xGKOmHkvanQWTcWr5HZdXv35Fhyh61O2fp+qviq5QSJY5Jrz7F7mmPPpzYl1dUKTCs8i HG0QYyFLufPDmcMUCAil/sb9ylIv3xImclOTmkpd8WLQyzhz30t+3PNvRCZS1dXjt2c1 YCNaMrnk6bEkNeI3wNEbJOCTJGNqgvgdZGhDbGVkf2ssgKnoJen+wKiJvmW/E8x+V80u QpdaTrbRKKKaNBAejspV2lcci/9I1ouqVyXZpSeN8MYnLssyW0cU6pB3kqYH/6rbCQAr AnQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JPmayByR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q4si8243826jas.111.2021.05.14.12.57.33; Fri, 14 May 2021 12:57:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JPmayByR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231654AbhENRYW (ORCPT + 99 others); Fri, 14 May 2021 13:24:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:32044 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234871AbhENRYV (ORCPT ); Fri, 14 May 2021 13:24:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621012989; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Ht2wahpr6SjLNp0fKa1tB4u5N0RuDTYUAiljNoyrPYg=; b=JPmayByRcJ9EneuBAe56eVvunA9G/WxesgTq3UWqkt0wi/x+CXpMcfKk0kfUqiBX0SUmuu Wp2hlEbapqgIwaOMRReSyyCTbyM6Uf7a3kmlXMFWpiqWSY48uP8aIif4o8PtsyM8ugdIB2 alK0iira77VoO8REl47l0Hw/ucE3uwc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-166-bsPGuG-lMOKE43HnSNtgxA-1; Fri, 14 May 2021 13:23:06 -0400 X-MC-Unique: bsPGuG-lMOKE43HnSNtgxA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C25181005D47; Fri, 14 May 2021 17:23:03 +0000 (UTC) Received: from t480s.redhat.com (ovpn-114-113.ams2.redhat.com [10.36.114.113]) by smtp.corp.redhat.com (Postfix) with ESMTP id 87E821971B; Fri, 14 May 2021 17:22:48 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: David Hildenbrand , Andrew Morton , "Michael S. Tsirkin" , Jason Wang , Alexey Dobriyan , Mike Rapoport , "Matthew Wilcox (Oracle)" , Oscar Salvador , Michal Hocko , Roman Gushchin , Alex Shi , Steven Price , Mike Kravetz , Aili Yao , Jiri Bohac , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Naoya Horiguchi , linux-hyperv@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 0/6] fs/proc/kcore: don't read offline sections, logically offline pages and hwpoisoned pages Date: Fri, 14 May 2021 19:22:41 +0200 Message-Id: <20210514172247.176750-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Looking for places where the kernel might unconditionally read PageOffline() pages, I stumbled over /proc/kcore; turns out /proc/kcore needs some more love to not touch some other pages we really don't want to read -- i.e., hwpoisoned ones. Examples for PageOffline() pages are pages inflated in a balloon, memory unplugged via virtio-mem, and partially-present sections in memory added by the Hyper-V balloon. When reading pages inflated in a balloon, we essentially produce unnecessary load in the hypervisor; holes in partially present sections in case of Hyper-V are not accessible and already were a problem for /proc/vmcore, fixed in makedumpfile by detecting PageOffline() pages. In the future, virtio-mem might disallow reading unplugged memory -- marked as PageOffline() -- in some environments, resulting in undefined behavior when accessed; therefore, I'm trying to identify and rework all these (corner) cases. With this series, there is really only access via /dev/mem, /proc/vmcore and kdb left after I ripped out /dev/kmem. kdb is an advanced corner-case use case -- we won't care for now if someone explicitly tries to do nasty things by reading from/writing to physical addresses we better not touch. /dev/mem is a use case we won't support for virtio-mem, at least for now, so we'll simply disallow mapping any virtio-mem memory via /dev/mem next. /proc/vmcore is really only a problem when dumping the old kernel via something that's not makedumpfile (read: basically never), however, we'll try sanitizing that as well in the second kernel in the future. Tested via kcore_dump: https://github.com/schlafwandler/kcore_dump v1 -> v2: - Dropped "mm: rename and move page_is_poisoned()" - "fs/proc/kcore: don't read offline sections, logically offline pages ..." -- Add is_page_hwpoison() in page-flags.h along with a comment - "mm: introduce page_offline_(begin|end|freeze|thaw) to ..." -- s/unfreeze/thaw/ -- Add a comment to PageOffline documentation in page-flags.h - "virtio-mem: use page_offline_(start|end) when setting PageOffline()" -- Extend patch description - "fs/proc/kcore: use page_offline_(freeze|thaw)" -- Simplify freeze/thaw logic - Collected acks/rbs Cc: Andrew Morton Cc: "Michael S. Tsirkin" Cc: Jason Wang Cc: Alexey Dobriyan Cc: Mike Rapoport Cc: "Matthew Wilcox (Oracle)" Cc: Oscar Salvador Cc: Michal Hocko Cc: Roman Gushchin Cc: Alex Shi Cc: Steven Price Cc: Mike Kravetz Cc: Aili Yao Cc: Jiri Bohac Cc: "K. Y. Srinivasan" Cc: Haiyang Zhang Cc: Stephen Hemminger Cc: Wei Liu Cc: Naoya Horiguchi Cc: linux-hyperv@vger.kernel.org Cc: virtualization@lists.linux-foundation.org Cc: linux-fsdevel@vger.kernel.org Cc: linux-mm@kvack.org David Hildenbrand (6): fs/proc/kcore: drop KCORE_REMAP and KCORE_OTHER fs/proc/kcore: pfn_is_ram check only applies to KCORE_RAM fs/proc/kcore: don't read offline sections, logically offline pages and hwpoisoned pages mm: introduce page_offline_(begin|end|freeze|thaw) to synchronize setting PageOffline() virtio-mem: use page_offline_(start|end) when setting PageOffline() fs/proc/kcore: use page_offline_(freeze|thaw) drivers/virtio/virtio_mem.c | 2 ++ fs/proc/kcore.c | 67 ++++++++++++++++++++++++++++++------- include/linux/kcore.h | 3 -- include/linux/page-flags.h | 22 ++++++++++++ mm/util.c | 40 ++++++++++++++++++++++ 5 files changed, 118 insertions(+), 16 deletions(-) base-commit: 6efb943b8616ec53a5e444193dccf1af9ad627b5 -- 2.31.1