Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp7959imm; Wed, 5 Sep 2018 13:58:49 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYQi/nR3DNrRMRYgi9musUH7Vd8IxUaKwwGAFhd2w8F2kpIG+z7uw21HlYs7ryNGxQqtMIE X-Received: by 2002:a63:2d05:: with SMTP id t5-v6mr38504449pgt.403.1536181129256; Wed, 05 Sep 2018 13:58:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536181129; cv=none; d=google.com; s=arc-20160816; b=PluMWq44Fkq42uNC7yEY1lhMpdAdQtB7jDp8VhrOK10bxMVnDEUYzU9SHJ89KNhv+7 scsTuiTcl7Gy84sZpQedGKkmywUEfKXgSYmSH6DVhsLt3TxNikLAJnFLxMxMsAwJUvyZ fI7lvEyPTpfVgE09jLOo+QRm4J+IX0j0G7lXfaSBeKePZ+sdewr/NC+FaT0FQZyv/9S4 JAUpOnG/weng7MruZzdUHjzyGTAxpWoA4k/lgDWBsLAVpKd5AkFrhEUTuM1R8Ec3gxKg m9xUEGOAr9eFdx78nd/osPyxqfW5Mjn5QMCjlRdJkRBk9Ep9+07T3JLFIEEjIjGkBuaJ yOeA== 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 :references:in-reply-to:message-id:subject:cc:to:from:date; bh=Ks5HsWMqy3iDGltdFGusT77pR5H7UaVpG8Hkm/yl5gk=; b=vvsxvAYny9tjxerQ9uefC5SbAhwoW+7Pc7QPvlzKiBmaKOJdBjTCpS//iYHReujdX7 RloA96AIhNlu4iiEDf7dvvE7aThqfoUMQi47OWbbJokxUtbNnQ71PIA/+Bmb+NVg3nnF lrxUmjwMaGUq61ddVJRKq2uR4MbZz06R3xfxYR2nSdiRCjfA0Cm4ji2kXRXBvMCnai2N 4J7gfP1/LSlarMNsPiRC2NOHaXNBYUEICtq2uxiiAItEJsfYiXHJEzVXzYLsMGzcwsq/ ZwAonNmgyzCYz2tanQsy83jZ9xwPId91ynJpHb09za9oyM9+y5AU/pbVHS1fAiPsh1Jw EV2w== ARC-Authentication-Results: i=1; mx.google.com; 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 az1-v6si2785927plb.513.2018.09.05.13.58.32; Wed, 05 Sep 2018 13:58:49 -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; 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 S1727604AbeIFB3O (ORCPT + 99 others); Wed, 5 Sep 2018 21:29:14 -0400 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 Received: from akpm3.svl.corp.google.com (unknown [104.133.8.65]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 4D583FA1; Wed, 5 Sep 2018 20:57:18 +0000 (UTC) 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> X-Mailer: Sylpheed 3.6.0 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 */ _