Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3098266imm; Tue, 4 Sep 2018 15:37:11 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdbv1arZtRWbpWiFLFVCDXLQpaUGvX+RmpWyxkERYC0wv00JKYeY8zfbENCme0wCdeaAiAwv X-Received: by 2002:a17:902:8541:: with SMTP id d1-v6mr36090060plo.81.1536100631470; Tue, 04 Sep 2018 15:37:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536100631; cv=none; d=google.com; s=arc-20160816; b=jBqe7NpQj0exmCy3Lzxy0hBS6mRNmj48jPsDE6hvys674g5ed6J0OHBcWbmQXXBirq r46yW9jt+CMH+tQ+Bn+HNeoQwnZOmlTdZf/B1AX2slnzETtfJ/GWhewW2+fErZxnWXaT cK+bi3mRKdhsNYdB+VRnxaJPXSDIBRKQBvQJIqDDID2CM407+gaGuoCcsYCNUGEj/qNk 8iBoCp+UTw5xF4J5abq4DUUQRqOrKpWzgkM9rHAeL03YsC3TQ4vCztRnJCbTPoN0RcGm gNZD5fgw2SVsiOEA3diYOZFvy1U1ICH9W2YE6Kfncv6x522+JP8pOtTqOZaBKkTdByV0 oSdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=GXOuy3i///UoZPB1u5w93sl1OnINvmBmrPEU+G7sOHA=; b=hxEK7WaQRN5N7PiUp31a10QrDphStstbbLIDV/klNbkkjtny1BL4ErEMVcO2vQn2ah qyktathjPrtQRMLoaShi/VefIsAqNbdYAXQXjLZdfIw2cQhl4z20IK03wcADgCuT/0Sk 1iyX1+1UfsMo3ssxJ2gqACuymdnPeyHxr3Ljc4TNsZb103chxDPFDXEc5F8kj2dpTB4I Hjj/p8sX2LifI4q2ubG3zEYbjDUfunUHNDFvmFiVv9OnQS7oWxM1WFZFRWugut+Hm7SN x6fVzXC9A5rh2KylD6bQBdLVRRZQQ0IRy1+O+mMqlHvOSTd/rmGFKNkJECTeCVu7IGej 3e4A== 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 t3-v6si33499plj.413.2018.09.04.15.36.56; Tue, 04 Sep 2018 15:37:11 -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 S1727195AbeIEDDD (ORCPT + 99 others); Tue, 4 Sep 2018 23:03:03 -0400 Received: from nautica.notk.org ([91.121.71.147]:33794 "EHLO nautica.notk.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726422AbeIEDDD (ORCPT ); Tue, 4 Sep 2018 23:03:03 -0400 Received: by nautica.notk.org (Postfix, from userid 1001) id 98F79C009; Wed, 5 Sep 2018 00:35:50 +0200 (CEST) From: Dominique Martinet To: Omar Sandoval , Andrew Morton Cc: Dominique Martinet , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Alexey Dobriyan , Eric Biederman , James Morse , Bhupesh Sharma , kernel-team@fb.com, Dominique Martinet Subject: [PATCH v2] proc/kcore: fix invalid memory access in multi-page read optimization Date: Wed, 5 Sep 2018 00:35:45 +0200 Message-Id: <1536100545-26905-1-git-send-email-asmadeus@codewreck.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1535515447-21167-1-git-send-email-asmadeus@codewreck.org> References: <1535515447-21167-1-git-send-email-asmadeus@codewreck.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dominique Martinet 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. Fixes: bf991c2231117 ("proc/kcore: optimize multiple page reads") Signed-off-by: Dominique Martinet --- fs/proc/kcore.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c index ad72261ee3fe..578926032880 100644 --- 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 */ -- 2.17.1