From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_RED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 491C6C11F67 for ; Thu, 1 Jul 2021 06:35:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CC39861422 for ; Thu, 1 Jul 2021 06:35:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC39861422 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0648A8D0295; Thu, 1 Jul 2021 02:35:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 03B4C8D028E; Thu, 1 Jul 2021 02:35:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E1E208D0295; Thu, 1 Jul 2021 02:35:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0037.hostedemail.com [216.40.44.37]) by kanga.kvack.org (Postfix) with ESMTP id BDDC38D028E for ; Thu, 1 Jul 2021 02:35:37 -0400 (EDT) Received: from smtpin37.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 70E0B180300E6 for ; Thu, 1 Jul 2021 06:35:37 +0000 (UTC) X-FDA: 78313057914.37.76E56B9 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by imf08.hostedemail.com (Postfix) with ESMTP id 6B05F3000098 for ; Thu, 1 Jul 2021 06:35:36 +0000 (UTC) Received: by mail-pj1-f49.google.com with SMTP id b14-20020a17090a7aceb029017261c7d206so243130pjl.5 for ; Wed, 30 Jun 2021 23:35:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=rqHIANMsZa6psCFHi3SNVVtKGDOM6hpfvG19pl5xZFE=; b=DETYXdO0wp8KsQF/J8KcduBVDwodGLR9GhGnV77YzV4VhAdSXalwPX/KcSMnyaXoK1 9n5veFiBxDMvGAdF8M9SDqdd03SLZBdT/pp20e0DR7/UHpGpLt5z4KnKVG9bTEItkbDd iMY2pebjnf0Xmz5rc7+eDFTm0/E/lTJ4gwMSuTNCZw60b8KiOTJVSCbfaomEr2YQoUuE t6YOlb1LX5/U6gnogYgj6Jlvu2sCzPdL5oM01eeyH1nh+nS77pSQmNcug0i0somVqP0U g7+1fAT61qyfMc9OkMwz4TMYgF8kv79ivPziiHSgjeFeCjear4r6BQ47RegLsw8MvWS8 rldA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=rqHIANMsZa6psCFHi3SNVVtKGDOM6hpfvG19pl5xZFE=; b=ud+IrxgIhEhcF8utAY+1YslFQNMYaKI9LDq78KuY1wNvWQA10Jp74H9M4ubpsDp1f5 U6JZx0WBIT3CEBYdgOXxWihDMeX0Cwh2aixcSj4m5TWTMjN6c7U63EAqXjkFArjlp7Qn wd8IfWtsRDcTzM7mbn0aeKLzDN8LxnisvI9KcXoLeev9LuN12awFUBzhLFOA3eIv34m1 IA/XTC+YrX47Rn2oiGvAubzyDJUC+EeRFxl+d1bpE7D83tfuPVXU0RD7+0EQxjZWpde8 2kRcbg5k0JWZMPr7N/86+m5D2VzOZJzb544ujAyObhYk4QAEoI1i8FEj8bRjp/P3UM7x IE4w== X-Gm-Message-State: AOAM531hVxUrTIjRu4k9NShACzAvig05+w6FEjubE0aS1685MsXZbq2C F5RlMOD6nLONqZkxfK7VLeatjQ== X-Google-Smtp-Source: ABdhPJxnkZoAlGLyOnC6LF38fGYrDCSiQdJhpfx/SRo9hkurkWBYdpMu6HBl1NRF2l4TXt7SIfM8tA== X-Received: by 2002:a17:90a:bd82:: with SMTP id z2mr21567915pjr.4.1625121335507; Wed, 30 Jun 2021 23:35:35 -0700 (PDT) Received: from [10.255.59.29] ([139.177.225.236]) by smtp.gmail.com with ESMTPSA id j19sm24687739pgm.44.2021.06.30.23.35.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 30 Jun 2021 23:35:34 -0700 (PDT) Subject: Re: [External] Re: [patch 141/192] fs/proc/kcore.c: add mmap interface To: Linus Torvalds , Andrew Morton Cc: Alexey Dobriyan , chenying.kernel@bytedance.com, Linux-MM , mm-commits@vger.kernel.org, Mike Rapoport , Muchun Song , zhouchengming@bytedance.com, duanxiongchun@bytedance.com References: <20210630184624.9ca1937310b0dd5ce66b30e7@linux-foundation.org> <20210701015441.snfkDnNcO%akpm@linux-foundation.org> From: zhoufeng Message-ID: <44be9d56-7a56-5da0-9d74-7aee421732b2@bytedance.com> Date: Thu, 1 Jul 2021 14:35:28 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=DETYXdO0; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf08.hostedemail.com: domain of zhoufeng.zf@bytedance.com designates 209.85.216.49 as permitted sender) smtp.mailfrom=zhoufeng.zf@bytedance.com X-Stat-Signature: 3fgyb6cnn53dtz6u68uh7jrwbkbnm3cu X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 6B05F3000098 X-HE-Tag: 1625121336-99803 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: =E5=9C=A8 2021/7/1 =E4=B8=8A=E5=8D=8811:32, Linus Torvalds =E5=86=99=E9=81= =93: > On Wed, Jun 30, 2021 at 6:54 PM Andrew Morton wrote: >> When we do the kernel monitor, use the DRGN >> (https://github.com/osandov/drgn) access to kernel data structures, fo= und >> that the system calls a lot. DRGN is implemented by reading /proc/kco= re. >> After looking at the kcore code, it is found that kcore does not imple= ment >> mmap, resulting in frequent context switching triggered by read. >> Therefore, we want to add mmap interface to optimize performance. >=20 > Ok, this is funky, but I'm going to drop this patch because I think > it's buggy as is. >=20 > Since >=20 >> +static int mmap_kcore(struct file *file, struct vm_area_struct *vma) >> +{ >> + size_t size =3D vma->vm_end - vma->vm_start; >=20 > Ok. >=20 > But then: >=20 >> + start =3D kc_offset_to_vaddr(((u64)vma->vm_pgoff << PAGE_SHIFT= ) - >> + ((data_offset >> PAGE_SHIFT) << PAGE_SHIFT)); >=20 > Not only is that >=20 > ((data_offset >> PAGE_SHIFT) << PAGE_SHIFT) >=20 > a very strange calculation (did you mean "data_offset & PAGE_MASK"?), > but I don't see anything that protects against underflow in that > calculation. pg_off can easily be arbitrarily small (eg zero), so that > subtraction can underflow afaik. Sorry, the calculations here are really confusing. The reason is that=20 when DRGN read /proc/kcore for ELF file header: phdr->p_offset =3D kc_vaddr_to_offset(m->addr) + data_offset; and DRGN call mmap, use phdr->p_offset passed in, I need to subtract=20 "data_offset". >=20 > So that needs a test, and return -EINVAL or whatever. > There's a problem with not judging "start". I will fix it in a v3. > But even if that is fixed, this test is entirely broken: >=20 >> + list_for_each_entry(m, &kclist_head, list) { >> + if (start >=3D m->addr && size <=3D m->size) >> + break; >> + } >=20 > No, that's wrong. >=20 Yes, this is indeed wrong, I will fix it in a v3. > You allow 'size' to be as big as 'm->size', but you do that even if > 'start' isn't 'm->start'. >=20 > The proper check would be something like >=20 > u64 end =3D start + size; >=20 > if (start >=3D m->addr && end <=3D m->addr+m->size) .. >=20 > or similar (and that should check that "start+size" hasn't overflowed). >=20 > So I see what appears to be multiple problems, and while I hand-waved > some fixes for them, those are very much "maybe something like this", > and I'm going to drop this patch. Not for 5.14. >=20 > Linus >=20