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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A766C00144 for ; Wed, 27 Jul 2022 01:49:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA4EE6B0071; Tue, 26 Jul 2022 21:49:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D06FB8E0002; Tue, 26 Jul 2022 21:49:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B80808E0001; Tue, 26 Jul 2022 21:49:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 9E5B16B0071 for ; Tue, 26 Jul 2022 21:49:31 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7C60AC091F for ; Wed, 27 Jul 2022 01:49:31 +0000 (UTC) X-FDA: 79731197742.04.CECADB4 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf08.hostedemail.com (Postfix) with ESMTP id 6FB9D160098 for ; Wed, 27 Jul 2022 01:49:30 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4LsxTp1984zkXkg; Wed, 27 Jul 2022 09:46:54 +0800 (CST) Received: from [10.174.177.76] (10.174.177.76) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 27 Jul 2022 09:49:26 +0800 Subject: Re: [bug report] mm/hugetlb: possible data leak with huge pmd sharing To: Mike Kravetz CC: Linux-MM , linux-kernel , Andrew Morton , Muchun Song References: <025b3ea6-4b26-f091-5464-0eef5aac7719@huawei.com> <2ec4cd05-5b3a-cd5c-7785-5a7236804bef@huawei.com> From: Miaohe Lin Message-ID: <9d670229-4bbf-a33b-ba80-73fc33c9bac3@huawei.com> Date: Wed, 27 Jul 2022 09:49:25 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.76] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658886571; a=rsa-sha256; cv=none; b=0Pc6DZGb/KmIArG3ZDdt2GSJFrTZDgOrWeJON4uO630RSH78eYriV3n2I+VcPDcsvRhxNE KyFenGKF+NtxtnzqDHO9ZmNKjeftnb81L89vxbifKKbT66HOM/VZpDT3vw2bVlm53B+4Co MEnDp4GA1GfNMCzSeA7bWTXjXUgiI7o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658886571; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yXtpgr4RgG1WbxjUfjozv10xwqIP9Tiy/miGFXCramc=; b=msxGkKaGKunECM0xl6l2pv1Cox6WdZEiieLkUj/GMNIV2VyhwhTQ2rKTVYU1t3qWAJ/9Om 7FG8Fk0qeOzaFe9LZ8p9e7iWzfuWJkrdBh+PKWy+U1ttqSnG4XqmROdkrDoE7E+CkFEQwr LAQ8mLYbh43DyCgiKJ1DdWITe/4Ik1c= X-Stat-Signature: phsz5bxndfrz8wxzdn1goirktreffopk X-Rspamd-Queue-Id: 6FB9D160098 X-Rspam-User: Authentication-Results: imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspamd-Server: rspam12 X-HE-Tag: 1658886570-994033 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: On 2022/7/27 1:18, Mike Kravetz wrote: > On 07/26/22 15:14, Miaohe Lin wrote: >> On 2022/7/26 2:35, Mike Kravetz wrote: >>> On 07/25/22 17:07, Miaohe Lin wrote: >>>> Hi all: >>>> When I investigate the mm/hugetlb code, I found there's a possible data leak issue >>>> with huge pmd sharing. Thank about the below scene: >>>> >>>> 1. Process A and process B shares huge pmd page.(vm_flags: VM_MAYSHARE but !VM_SHARED) >>> >>> Thanks, >>> >>> I often get confused about the setting of VM_MAYSHARE and VM_SHARED. When >>> you throw in the possibility of shared and anonymous, then I struggle a bit >>> more. At one time did an audit to get the meaning clear in my mind, but still >>> struggle with the meanings. >>> >>> Is it possible to have VM_MAYSHARE and !VM_SHARED on a hugetlb vma? I only >>> took a quick look and could not find a way for this to happen. But, I> could have easily missed something. >> >> Thanks for your reply. It's possible to have VM_MAYSHARE and !VM_SHARED on a hugetlb vma >> with below code snippet: >> >> ... >> fd = open("/root/huge/hugepagefile", O_CREAT | O_RDONLY, 0755); >> if (fd < 0) { >> perror("Open failed"); >> exit(1); >> } >> >> addr = mmap(0, 32UL*1024*1024, PROT_READ, MAP_SHARED, fd, 0); >> ... >> >> cat /proc//smaps: >> >> 400000000000-400002000000 r--s 00000000 00:2f 153780886 /root/huge/hugepagefile >> Size: 32768 kB >> KernelPageSize: 2048 kB >> MMUPageSize: 2048 kB >> ... >> VmFlags: rd mr me ms de ht >> >> /* sh: VM_SHARED, mw: VM_MAYWRITE, ms:VM_MAYSHARE */ >> >> So vm_flags is VM_MAYSHARE but !VM_SHARED. >> >> But in this case, it's readonly. So the above scene won't happen. Sorry for make noise. >> > > No worries! And, thank you for looking at the pmd sharing code. In concept > the functionality is simple. However, details and edge cases make things > complicated. > > If you are interested in the pmd sharing code, more eyes on this proposal > would be appreciated. Yes, thanks for your hard work. ;) > > https://lore.kernel.org/linux-mm/20220706202347.95150-1-mike.kravetz@oracle.com/ >