Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp218790imm; Tue, 28 Aug 2018 21:05:32 -0700 (PDT) X-Google-Smtp-Source: ANB0VdawQlu8oWRd/U5/87QfsACrW4e7IwVjvVKnJ17YDJxbEycTiHbOVVVaR7CN965Mes4vZ/48 X-Received: by 2002:aa7:831b:: with SMTP id t27-v6mr4153957pfm.81.1535515532567; Tue, 28 Aug 2018 21:05:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535515532; cv=none; d=google.com; s=arc-20160816; b=HDBQZ8Wfsd1ep3Yi2jHOEvfLAvsWr1zlfleCUQA6JZLc4Z3+tcYt/WhOEhpLmwXeFM SOnjjVEgwAOZ1IrPMpMEI5svFM9BE4q5TVoVObA+niVWyvpeA+55UAogDnl84I3FcyLt LzuUamF1K4pkl3NWNrESESSwk4N6GOwJwbM05sVJUh7K0shA50uNkuqVpgUNKyay3L8X zIRcS4CKkyU51Q4ziL+Q8A261AvxXwZzcd8elYxIiEu/wxofE9GFCPSU2iWIkgQhhX/Z hClk/bs32enp6XEbWrhLhyOrDNbWtxY79FigkOy/rj1+RYcz5z0CINmM5CLpBRefaV1N fyXQ== 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:arc-authentication-results; bh=aoK8Cpedx3UY5GRnkw81dMF5cym8ukRyr1Oi2yIcmcE=; b=rqD3txmmvswCplt7+l71RWawyjw4cCww/qsl9n8EL+vDrhdFDAQiv2OjZ8c7oxDw1B fKtduVUXxXmmVxH0MNBsZQpMrtdkLeAshJ5c5P2HFRbkpBdqhSsKxW6ATGVmkPw5PAw8 m+UVoICiSmj8GG/TiqmQJDKBnFrGzApQFc2XBS+S0Myj0Xb0+HuCZpLkUvL2Kn6fUe3k rQJcfoifaDtHQVIXTJ0+TNw+zMdMv8GsTi8zMCrgyKgHZPR+tBfDSLW4kjVVQ/0zwmTY SVcqCd2cJimJ+Lroiw0k4kD6P1gvflYIifUHU+KnslFad0N4qnr8V4ecivBUX92pdmBk l00A== 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 71-v6si2729331pfa.305.2018.08.28.21.05.17; Tue, 28 Aug 2018 21:05:32 -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 S1727449AbeH2H7B (ORCPT + 99 others); Wed, 29 Aug 2018 03:59:01 -0400 Received: from nautica.notk.org ([91.121.71.147]:43596 "EHLO nautica.notk.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726857AbeH2H7A (ORCPT ); Wed, 29 Aug 2018 03:59:00 -0400 Received: by nautica.notk.org (Postfix, from userid 1001) id 7C870C009; Wed, 29 Aug 2018 06:04:10 +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 Subject: [PATCH] proc/kcore: fix invalid memory access in multi-page read optimization Date: Wed, 29 Aug 2018 06:04:07 +0200 Message-Id: <1535515447-21167-1-git-send-email-asmadeus@codewreck.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <20180828105959.GA29204@nautica> References: <20180828105959.GA29204@nautica> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The 'm' kcore_list item can 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 Fixes: bf991c2231117 ("proc/kcore: optimize multiple page reads") Signed-off-by: Dominique Martinet --- I guess now I'm looking at bf991c2231117 again that it would be slightly more efficient to remove the !m check and initialize m to point to kclist_head like this: m = list_entry(&kclist_head, struct kcore_list, list); but it feels a bit forced to me; deferring the choice to others. fs/proc/kcore.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c index ad72261ee3fe..50036f6e1f52 100644 --- a/fs/proc/kcore.c +++ b/fs/proc/kcore.c @@ -451,7 +451,8 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos) * If this is the first iteration or the address is not within * the previous entry, search for a matching entry. */ - if (!m || start < m->addr || start >= m->addr + m->size) { + if (!m || &m->list == &kclist_head || start < m->addr || + start >= m->addr + m->size) { list_for_each_entry(m, &kclist_head, list) { if (start >= m->addr && start < m->addr + m->size) -- 2.17.1