From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.linuxfoundation.org ([140.211.169.12]:58894 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727069AbeIFB3O (ORCPT ); Wed, 5 Sep 2018 21:29:14 -0400 Date: Wed, 5 Sep 2018 13:57:17 -0700 From: Andrew Morton To: Dominique Martinet Cc: Omar Sandoval , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Alexey Dobriyan , Eric Biederman , James Morse , Bhupesh Sharma , kernel-team@fb.com Subject: Re: [PATCH v3] proc/kcore: fix invalid memory access in multi-page read optimization Message-Id: <20180905135717.ff763b34c4a3f1ca500d715b@linux-foundation.org> In-Reply-To: <1536100702-28706-1-git-send-email-asmadeus@codewreck.org> References: <1536100545-26905-1-git-send-email-asmadeus@codewreck.org> <1536100702-28706-1-git-send-email-asmadeus@codewreck.org> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Wed, 5 Sep 2018 00:38:22 +0200 Dominique Martinet wrote: > The 'm' kcore_list item could point to kclist_head, and it is incorrect to > look at m->addr / m->size in this case. > There is no choice but to run through the list of entries for every address > if we did not find any entry in the previous iteration > > Reset 'm' to NULL in that case at Omar Sandoval's suggestion. > > ... > > --- a/fs/proc/kcore.c > +++ b/fs/proc/kcore.c > @@ -464,6 +464,7 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos) > ret = -EFAULT; > goto out; > } > + m = NULL; > } else if (m->type == KCORE_VMALLOC) { > vread(buf, (char *)start, tsz); > /* we have to zero-fill user buffer even if no read */ lgtm. Let's add a nice little why-were-doing-this? --- a/fs/proc/kcore.c~proc-kcore-fix-invalid-memory-access-in-multi-page-read-optimization-v3-fix +++ a/fs/proc/kcore.c @@ -464,7 +464,7 @@ read_kcore(struct file *file, char __use ret = -EFAULT; goto out; } - m = NULL; + m = NULL; /* skip the list anchor */ } else if (m->type == KCORE_VMALLOC) { vread(buf, (char *)start, tsz); /* we have to zero-fill user buffer even if no read */ _