linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Rong Tao <rtoax@foxmail.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Florent Revest <revest@chromium.org>,
	Kees Cook <keescook@chromium.org>,
	David Hildenbrand <david@redhat.com>,
	Stefan Roesch <shr@devkernel.io>,
	Andy Chiu <andy.chiu@sifive.com>,
	Josh Triplett <josh@joshtriplett.org>,
	Joey Gouly <joey.gouly@arm.com>, Miguel Ojeda <ojeda@kernel.org>,
	Ondrej Mosnacek <omosnace@redhat.com>,
	"open list:MEMORY MANAGEMENT" <linux-mm@kvack.org>,
	open list <linux-kernel@vger.kernel.org>,
	rongtao@cestc.cn
Subject: Re: [PATCH] prctl: Get private anonymous memory region name
Date: Sun, 26 Nov 2023 11:04:52 +0800	[thread overview]
Message-ID: <tencent_B96B540A71C98045E8392BED324B65E89505@qq.com> (raw)
In-Reply-To: <20231125155651.GA23245@redhat.com>


On 11/25/23 23:56, Oleg Nesterov wrote:
> On 11/25, Rong Tao wrote:
>> +static int prctl_get_vma(unsigned long opt, unsigned long addr,
>> +			 unsigned long buf, unsigned long arg)
>> +{
>> +	struct mm_struct *mm = current->mm;
>> +	const char __user *u_buf;
>> +	int error;
>> +
>> +	switch (opt) {
>> +	case PR_GET_VMA_ANON_NAME:
>> +		const struct anon_vma_name *anon_name = NULL;
>> +
>> +		u_buf = (const char __user *)buf;
>> +		error = 0;
>> +
>> +		mmap_read_lock(mm);
>> +		anon_name = madvise_get_anon_name(mm, addr);
>> +		if (!anon_name) {
>> +			mmap_read_unlock(mm);
>> +			error = -EFAULT;
> may be another error code makes sense to distinguish this case from
> the copy_to_user() failure?
>
>> +			break;
>> +		}
>> +
>> +		if (copy_to_user((char __user *)u_buf, anon_name->name,
>> +				 strlen(anon_name->name) + 1))
>> +			error = -EFAULT;
> and I guess you can simplify this code a bit,
>
> 		anon_name = madvise_get_anon_name(...);
> 		if (!anon_name || copy_to_user(...))
> 			error = -EFAULT;
Thanks a lot, I just modify the code, please review.
> 		
> 		mmap_read_unlock(mm);
> 		anon_vma_name_put(anon_name); // safe if anon_name == NULL;
>
>> +const struct anon_vma_name *madvise_get_anon_name(struct mm_struct *mm,
>> +						  unsigned long start)
>> +{
>> +	struct vm_area_struct *vma;
>> +	struct anon_vma_name *anon_name;
>> +
>> +	vma = find_vma(mm, start);
>> +	if (vma) {
>> +		anon_name = anon_vma_name(vma);
>> +		if (anon_name) {
>> +			anon_vma_name_get(anon_name);
>> +			return anon_name;
>> +		}
>> +	}
>> +
>> +	return NULL;
> Again, afaics this can be simplified,
>
> 	struct anon_vma_name *anon_name = NULL;
>
> 	vma = find_vma(mm, start);
> 	if (vma) {
> 		anon_name = anon_vma_name(vma);
> 		anon_vma_name_get(anon_name);
> 	}
>
> 	return anon_name;
>
> Oleg.
Thanks again.

Rong Tao

>



  reply	other threads:[~2023-11-26  3:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-25 14:04 Rong Tao
2023-11-25 15:56 ` Oleg Nesterov
2023-11-26  3:04   ` Rong Tao [this message]
2023-11-25 20:00 ` kernel test robot
2023-11-25 20:00 ` kernel test robot
2023-11-25 22:26 ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_B96B540A71C98045E8392BED324B65E89505@qq.com \
    --to=rtoax@foxmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=andy.chiu@sifive.com \
    --cc=catalin.marinas@arm.com \
    --cc=david@redhat.com \
    --cc=joey.gouly@arm.com \
    --cc=josh@joshtriplett.org \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ojeda@kernel.org \
    --cc=oleg@redhat.com \
    --cc=omosnace@redhat.com \
    --cc=revest@chromium.org \
    --cc=rongtao@cestc.cn \
    --cc=shr@devkernel.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox