Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp861316pxj; Fri, 14 May 2021 18:55:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvSU70P3l1jrwTXjpC4cKbspLkkV+4PBExuxNsbzCqp7QAf1kYQvjnn6OrEY6LgBN9fMBr X-Received: by 2002:a50:afa3:: with SMTP id h32mr1935605edd.202.1621043750100; Fri, 14 May 2021 18:55:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621043750; cv=none; d=google.com; s=arc-20160816; b=UpnwphGBl91RuQh5ali6/MhvMHhosoUO+FeW8I9Yt14jWOzqWACffPUBPdvrz2+rTf +OaaAJtbQS0hQcDAT9tVdq+Pxa7zUhdI3JbdXRD01k1Nm1PdELm3zR5KFeP4u4bUG4+z E9zz7lpMLnkuBh57UpcvbzXTjl0NUb9msYd45KxQ0d0HlF993w9zG9Uxn34qfW02wow6 qp5PPB9GYkoUPbF13siBiDvDJDot9PAJaO22xjgu9fQSQOgoDVack8Sa5nAMChA1OIqZ Ea6SCclVTaRI49tGkLYgdzmFe9UKo2p32iNn5YHI4aQOFobG0k/3FOkiADoe7EuHfw0G wrUw== 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=CeyyYgXMaIv1KkLK2Mxpk2s8iuflkxKOKdYcMCECEco=; b=E/m/MqxGsulk0mmOGn4FznS+US9FYe5oI2w8GuBsFMheo3L6jW1ZDZ1vKWjBWJORua Ioh+luur8QqoxpJ6IFKU318W9OkR7MRUjQM1L3yAEMGcWJJsChQ85h9EnoK5TbQs+UxE wBoCv0AOTpKov65wlr4xq1MJKfmii8i88EdNieYESziCStO1dKClhi/AMh/S70ZV/21Q 5Htovw46itsgDNNJTOgJ9jns9lH8HvGreCiDCpeOtphsDYh46p+Paww3g4obALUIcJ3p x/cDFhgp0tz7b9CDxWXxBSlw/E6BgY6LXHxTgOTbUuhS1WzT04mlWwRhNHwJ7qzltAMl Ns/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=h7nEeqQw; 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 bv8si7765873ejb.377.2021.05.14.18.55.27; Fri, 14 May 2021 18:55:50 -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=h7nEeqQw; 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 S235113AbhENRYo (ORCPT + 99 others); Fri, 14 May 2021 13:24:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:55752 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235101AbhENRYn (ORCPT ); Fri, 14 May 2021 13:24:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621013011; 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=CeyyYgXMaIv1KkLK2Mxpk2s8iuflkxKOKdYcMCECEco=; b=h7nEeqQwCW1ub5i6tGx6CMyORlkPCSg5gZ/ffOeJbSh9XV8urXK7UAJJEQHvggCgErcJjj RmUZIlDQrX/7B4In2kZawJH/7TX/dayYceRkNq0opemoK1/AnRp0hXqkQ+jOPKzh95lGAv Y8GNx3nosTjUjGOXhmLR7Mjl7J4ZfnQ= 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-326-DoFLkz1YPr-E5fxCEaU49Q-1; Fri, 14 May 2021 13:23:29 -0400 X-MC-Unique: DoFLkz1YPr-E5fxCEaU49Q-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 8BFDA107ACCA; Fri, 14 May 2021 17:23:26 +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 671681A868; Fri, 14 May 2021 17:23:11 +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, Mike Rapoport Subject: [PATCH v2 2/6] fs/proc/kcore: pfn_is_ram check only applies to KCORE_RAM Date: Fri, 14 May 2021 19:22:43 +0200 Message-Id: <20210514172247.176750-3-david@redhat.com> In-Reply-To: <20210514172247.176750-1-david@redhat.com> References: <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 Let's resturcture the code, using switch-case, and checking pfn_is_ram() only when we are dealing with KCORE_RAM. Reviewed-by: Mike Rapoport 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.31.1