Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1352156pxy; Thu, 29 Apr 2021 05:27:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzNvVVOEzUDk6j8QRV0uh421AQ8hOC3fNDAgf8kWQAFFeZ2q0BWZagkTR0xj6Bq6EWmxP0 X-Received: by 2002:a63:cf55:: with SMTP id b21mr33093939pgj.126.1619699229354; Thu, 29 Apr 2021 05:27:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619699229; cv=none; d=google.com; s=arc-20160816; b=Iq1/Rzrxr7Syr5LZcOb0XNBIAa+3HqmDcF7C59Op0ZmQ7JkGPzbFEwnmSeM2V0B1wD CIFZ2HwqFfxiLalfW4rjH3vMqxxZvvBlpMH2LMxJAh57mNZ2VUFTnwlhHOlzO9GZrwwE 4CzXyAqR3cQnQCYXL8EqBAL3oTcQ3YyGocE2VdILjt7rYkMIy0VLQmxlTBjksfMSOPVJ au6cKggR1s5dXic0NMzrTp8tNlQt5APDe43o5K97n1Up0+ePNmCPZvpiPuAx1EYG0+ON wGre7wiiY+oVd/Ys+eBgcMujPD1bCK4JMC1PBFl03NfVQ0Wup4oARIYH9va3H5u3WkB1 UDTA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rlbUJqtDJSJXZ0talu2Z3XFcFBG+/7XBZRlbnxcqpi4=; b=RA7Z5U4YnQl0c17zu6l+rGvhvhTHxfk3H37GnZeBqfY30dvHHycuaUNy7OYSSubr54 p8QBOWC9IEw8PeGaRb5c/UPLl519nMk8Yi+AxPcBe+knHcUhCkkg2hAFMT7co5YSKw/l fLt2E7iW6S6riusM9C1q/mrXXJXe6omKwHr31gRu+EduiSDN99MTI3e1ds/I+AtPW9EU +hsDkT/DRHxi5Bqbr5v2kl4qdj5oDlkQizkSdbE21v1tZRRwzIAv5aF9NoJUummAiLg6 u1JuhuD48wCoI48uCgThUc2dZbex6k1JCzDDX2MfQ04KIpjbwHgGHJOQNbgqOs8Pp/Oa V3Mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fJHxKypI; 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 d19si3141695pgv.38.2021.04.29.05.26.55; Thu, 29 Apr 2021 05:27:09 -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=fJHxKypI; 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 S236635AbhD2M0d (ORCPT + 99 others); Thu, 29 Apr 2021 08:26:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:35380 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236612AbhD2M0b (ORCPT ); Thu, 29 Apr 2021 08:26:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619699144; 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: in-reply-to:in-reply-to:references:references; bh=rlbUJqtDJSJXZ0talu2Z3XFcFBG+/7XBZRlbnxcqpi4=; b=fJHxKypIf4zRRDAzpFmq8iag4rrlofSafrHIPKb5O51p3rS3mBzKV6bWzsGO667Tt5bQAV mZNvCJPdGmYDaVdaRKT8EMauK7QiALw3T1+5vjbeURBi46BO6AFthwwXUCa7VsA6rGTgJx 4Q8ynqcyP8VvdPKSaHsig/0paPuo0wg= 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-405-McSW6JEJMfKG2TeFwvbHRQ-1; Thu, 29 Apr 2021 08:25:41 -0400 X-MC-Unique: McSW6JEJMfKG2TeFwvbHRQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F1D518049FF; Thu, 29 Apr 2021 12:25:37 +0000 (UTC) Received: from t480s.redhat.com (ovpn-114-50.ams2.redhat.com [10.36.114.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id A2ABF18796; Thu, 29 Apr 2021 12:25:32 +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 v1 2/7] fs/proc/kcore: pfn_is_ram check only applies to KCORE_RAM Date: Thu, 29 Apr 2021 14:25:14 +0200 Message-Id: <20210429122519.15183-3-david@redhat.com> In-Reply-To: <20210429122519.15183-1-david@redhat.com> References: <20210429122519.15183-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Let's resturcture the code, using switch-case, and checking pfn_is_ram() only when we are dealing with KCORE_RAM. Signed-off-by: David Hildenbrand --- fs/proc/kcore.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c index 09f77d3c6e15..ed6fbb3bd50c 100644 --- a/fs/proc/kcore.c +++ b/fs/proc/kcore.c @@ -483,25 +483,36 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos) goto out; } m = NULL; /* skip the list anchor */ - } else if (!pfn_is_ram(__pa(start) >> PAGE_SHIFT)) { - if (clear_user(buffer, tsz)) { - ret = -EFAULT; - goto out; - } - } else if (m->type == KCORE_VMALLOC) { + goto skip; + } + + switch (m->type) { + case KCORE_VMALLOC: vread(buf, (char *)start, tsz); /* we have to zero-fill user buffer even if no read */ if (copy_to_user(buffer, buf, tsz)) { ret = -EFAULT; goto out; } - } else if (m->type == KCORE_USER) { + break; + case KCORE_USER: /* User page is handled prior to normal kernel page: */ if (copy_to_user(buffer, (char *)start, tsz)) { ret = -EFAULT; goto out; } - } else { + break; + case KCORE_RAM: + if (!pfn_is_ram(__pa(start) >> PAGE_SHIFT)) { + if (clear_user(buffer, tsz)) { + ret = -EFAULT; + goto out; + } + break; + } + fallthrough; + case KCORE_VMEMMAP: + case KCORE_TEXT: if (kern_addr_valid(start)) { /* * Using bounce buffer to bypass the @@ -525,7 +536,15 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos) goto out; } } + break; + default: + pr_warn_once("Unhandled KCORE type: %d\n", m->type); + if (clear_user(buffer, tsz)) { + ret = -EFAULT; + goto out; + } } +skip: buflen -= tsz; *fpos += tsz; buffer += tsz; -- 2.30.2