Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3520221rdh; Mon, 27 Nov 2023 17:03:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IGVeOfgvCu8DMwVu/GAwQNHdESMzevTEKjyM705qTM+b+nVL4TZZzd8hAHDCpnPmR74bJvT X-Received: by 2002:a05:6820:827:b0:58d:974b:5056 with SMTP id bg39-20020a056820082700b0058d974b5056mr4759589oob.1.1701133386860; Mon, 27 Nov 2023 17:03:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701133386; cv=none; d=google.com; s=arc-20160816; b=I2OJY6Y/OKBF9KiGaVekaBxPfnL7UMurVUx/usiJ5UxIgr3LfHkUghMsnGnkyB4nqQ AozFYSbG9zu0MBSPHPlEsVoDHouf8WVkhjLrPJ5Bam9xlAEJNi6hUiXAwbaIZHRLbTPb z81nhMzhwh0SXuZ1y5wtJs398rxyRuWUmdbiTad86p5WUjQn85HC4LLHwqhWoyF/k0o1 12AqHIqUP4SddPeSK51Vup14FNFaTLpgNysh1E4HKes2QXVkduf+l0KBaDcUEwoudoKH nuUUXKSextl0ATWK3/JNGC4d9dhNCLhUAn0sZc8b82dlZa/Temh4GxhKK5RWkxhuZI78 TLkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=gYIr0fLGl0A0yMUGkiXP9kYqWmnfeW6NULr2PpdUPrs=; fh=7fjqlJ5QF4cB5+9oL/+kncg0gZBgP5k2ACw8jZIMOXc=; b=V61hVq8ANr5BwGXIor+Nj2ipR9QAmioNFkdiilKEDZFOisXVtBbcCq8DKPKonvTzDO YMUlTLf0D+SCdbvphBqf7EOHfsdS4r4FJJfYl/x3eOppJvHNqq6B8+njEbNvckyMcXnZ CPoQospa0WTvZjbV08+kDMP0FpL9zq8gyj3ttbCC66kvr45/r0bhV3cBOBIhMdd7JEHS hmiyTn+0u2edJlkXaNFFm1PD5f2r79e+H4pwLwE0DaRhDCtt9MWRRHTvyab7l++4jsx8 gnaL6eFqDo6ODH1JkZSC9IavgOJSki+a6YfTef4LthltWD0AuRG6v66c/5X0s4UMv9yt fwww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=CZjEcZjU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id k10-20020a056820016a00b0058d34ee402fsi3744583ood.10.2023.11.27.17.03.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 17:03:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=CZjEcZjU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id A69D480A7E57; Mon, 27 Nov 2023 17:03:05 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229879AbjK1BCw (ORCPT + 99 others); Mon, 27 Nov 2023 20:02:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229576AbjK1BCv (ORCPT ); Mon, 27 Nov 2023 20:02:51 -0500 Received: from out203-205-221-233.mail.qq.com (out203-205-221-233.mail.qq.com [203.205.221.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 561C1C2 for ; Mon, 27 Nov 2023 17:02:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1701133366; bh=gYIr0fLGl0A0yMUGkiXP9kYqWmnfeW6NULr2PpdUPrs=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=CZjEcZjUxqGAzw+vIpTgyfIQIAX3MaTpmswwcHJF/zHbI+noMygCDBDMJA4VftPZN yPaq//cNLQ1HB3nnrcSdxK3yPYEuYxfD7C01CCn374jaK2CsRds9y75lfSXzN3A6pM d68cjoPmtnk4eoXUa+J+U+z81bSk/QVGKk/e8ZgE= Received: from [10.56.52.5] ([39.156.73.12]) by newxmesmtplogicsvrsza10-0.qq.com (NewEsmtp) with SMTP id A9882EF; Tue, 28 Nov 2023 09:02:41 +0800 X-QQ-mid: xmsmtpt1701133361t39mf7s0h Message-ID: X-QQ-XMAILINFO: OaoBA5NOFC/jOVj7yUQgbw3gi+1HeI4r6RzUUXcFdsuuF0M9wglOSEJSLO6sAw wuVnc7r9ylrhXP5QDntpHtKoSIeqiZ5P/u/eMwNCf42EezroieDc4+ZJ0aCI3LPsTygcc0vcz90u 2Uh/buCN5I1biC3suEs3+fjyxVew9eDOAXVpwbD3AApc8mN3oaRFhZz8Kp0n/7DftREPnYKsfO2G XMMVMryq7mRpOJWLo7NHxGt0ycYjxjExE8pCysiqMKaekewlyxebbQvjo6P+7NpaNDQlxmhpIfMB W2WnUoy4/8Knc9WmIaeniT1WsHJjbt2OlYkNMRuCxpk89f1c327ZPJ/CZpayaoN1xAHas8buAw01 NzHCii/yU+DKGrEwGW+mp99t6W3KUXRcR1ST9tCfWtZ4VIj5waDGhPmCy9QQiQqBgGQ+Z3WXsyDR GaO2RU2q/JdCpWFjZXrZHnPAMvvUi1nYOA9rxsU92WoqRSpimqj1GrpRALRqT8Z0f9yWvfMpbc4w u1jcAGTsPQ9eNMWuaH/5lnY1T2FUa/fTvfT4AmbHpuG6Qa1lkqBJ1Z3tpIC6JJeMQFzNtUIsNy/e H0WNjrqIyBaMBdk7bP0dKpJNj9KSq/SdgmfBy6NaxzukSrFeIGkOyYdkXU7echOiF3q6QEGbc0EU X2eynoOJzC9lp2cqEQS7qI38slQXXj4AD71CMYwAMExOx7uJRQG6glf9tGLKVPSUUjQHLuX+Czmp yMOxfRh555Qqq7fRkaZn7xpUITrBFRwjI8iqPq+8b6VkuZC/YWrPmOtVtkBHMuywwboEwPGc/bBY jwsW83iZCNchHC3FxaMSAAO1w+Kf25tAz4A9TLS18ouWGEjdwUlptABC/McXc36gal1ZsA2qeS8W JVZ2meVBTrjQNYKCNTnFX7l058D5JZE5QbR2HAqOH2Xj1XKmjjEh+B9EFJr/enIP6xspQUeHdnjT bzgRyAyVF2cggCpxiUC8HdnFcRmz0r6gu1FLIf7cez3/LTDdP3GQ== X-QQ-XMRINFO: M/715EihBoGSf6IYSX1iLFg= X-OQ-MSGID: Date: Tue, 28 Nov 2023 09:02:40 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] prctl: Get private anonymous memory region name To: David Hildenbrand , Oleg Nesterov Cc: Andrew Morton , Catalin Marinas , Kees Cook , Florent Revest , Josh Triplett , Andy Chiu , Joey Gouly , Stefan Roesch , Greg Kroah-Hartman , Ondrej Mosnacek , Miguel Ojeda , "open list:MEMORY MANAGEMENT" , open list , rongtao@cestc.cn References: <20231126135644.GA7199@redhat.com> Content-Language: en-US From: Rong Tao In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=3.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_MUA_MOZILLA, FREEMAIL_FROM,HELO_DYNAMIC_IPADDR,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,RDNS_DYNAMIC,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: *** X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 27 Nov 2023 17:03:05 -0800 (PST) On 11/27/23 22:52, David Hildenbrand wrote: > On 26.11.23 14:56, Oleg Nesterov wrote: >> On 11/26, Rong Tao wrote: >>> >>> then the PR_GET_VMA interface should be provided accordingly, >>> which is necessary, as the userspace program usually wants to know what >>> VMA name it has configured for the anonymous page. >> >> I don't really understand the use-case for PR_GET_VMA ... >> > > Can't we simply read "/proc/PID/maps" and just have that information > from there? Thank you, David. The relationship between PR_GET_VMA and /proc/PID/maps is like the relationship between PR_GET_NAME and /proc/PID/comm. Obviously, both methods can obtain the corresponding name. However, prctl(2) can be obtained directly from the code level, while reading proc is not so convenient and efficient. Moreover, reading proc is more like bash command line, rather than C code. > > Also, I don't understand the exact use case, that should be clarified > -- especially, why the existing way is insufficient. > For use-case, in fact, I now want to develop a user-mode patch tool and need to map the patch file to the target process(Use ptrace(2) and pread/pwrite("/proc/self/mem")). I initially used shared files     00400000-00401000 r--p 00000000 08:00 241933181 /home/sda/git-repos/upatch/tests/hello/hello     00401000-00402000 r-xp 00001000 08:00 241933181 /home/sda/git-repos/upatch/tests/hello/hello     00402000-00403000 r--p 00002000 08:00 241933181 /home/sda/git-repos/upatch/tests/hello/hello     00403000-00404000 r--p 00002000 08:00 241933181 /home/sda/git-repos/upatch/tests/hello/hello     00404000-00405000 rw-p 00003000 08:00 241933181 /home/sda/git-repos/upatch/tests/hello/hello     01136000-01157000 rw-p 00000000 00:00 0 [heap]     7f21472c0000-7f21472c2000 rw-p 00000000 00:00 0     7f21472c2000-7f21472e8000 r--p 00000000 103:03 3705 /usr/lib64/libc.so.6     7f21472e8000-7f2147448000 r-xp 00026000 103:03 3705 /usr/lib64/libc.so.6     7f2147448000-7f2147496000 r--p 00186000 103:03 3705 /usr/lib64/libc.so.6     7f2147496000-7f214749a000 r--p 001d3000 103:03 3705 /usr/lib64/libc.so.6     7f214749a000-7f214749c000 rw-p 001d7000 103:03 3705 /usr/lib64/libc.so.6     7f214749c000-7f21474a6000 rw-p 00000000 00:00 0     7f21474be000-7f21474bf000 rwxs 00000000 00:27 7794 /tmp/upatch/62984/map_files/patch-FKSYTp   <<     7f21474bf000-7f21474c0000 rwxs 00000000 00:27 7793 /tmp/upatch/62984/map_files/patch-KFaQNU <<     7f21474c0000-7f21474c1000 r--p 00000000 103:03 3702 /usr/lib64/ld-linux-x86-64.so.2     7f21474c1000-7f21474e8000 r-xp 00001000 103:03 3702 /usr/lib64/ld-linux-x86-64.so.2     7f21474e8000-7f21474f2000 r--p 00028000 103:03 3702 /usr/lib64/ld-linux-x86-64.so.2     7f21474f2000-7f21474f4000 r--p 00031000 103:03 3702 /usr/lib64/ld-linux-x86-64.so.2     7f21474f4000-7f21474f6000 rw-p 00033000 103:03 3702 /usr/lib64/ld-linux-x86-64.so.2     7ffec158b000-7ffec15ad000 rw-p 00000000 00:00 0 [stack]     7ffec15cf000-7ffec15d3000 r--p 00000000 00:00 0 [vvar]     7ffec15d3000-7ffec15d5000 r-xp 00000000 00:00 0 [vdso]     ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsyscall] However, this is obviously not the best approach, I want to use anonymous pages instead,     7f21474be000-7f21474bf000 rwxp 00000000 00:27 7794 [anon:patch1]     7f21474bf000-7f21474c0000 rwxp 00000000 00:27 7793 [anon:patch2] I hope to use the address to directly obtain the vma name, which is "patch1". This is very convenient in the program without parsing /proc/PID/maps in the source code. Thanks again. Rong Tao