From: Oleg Nesterov <oleg@redhat.com>
To: Rong Tao <rtoax@foxmail.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: Sat, 25 Nov 2023 16:56:51 +0100 [thread overview]
Message-ID: <20231125155651.GA23245@redhat.com> (raw)
In-Reply-To: <tencent_977CBF8E8CA6234A1B740A35655D5D7EAA0A@qq.com>
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;
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.
next prev parent reply other threads:[~2023-11-25 15:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-25 14:04 [PATCH] prctl: Get private anonymous memory region name Rong Tao
2023-11-25 15:56 ` Oleg Nesterov [this message]
2023-11-26 3:04 ` Rong Tao
2023-11-25 20:00 ` kernel test robot
2023-11-25 20:00 ` kernel test robot
2023-11-25 22:26 ` kernel test robot
-- strict thread matches above, loose matches on Subject: below --
2023-11-25 21: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=20231125155651.GA23245@redhat.com \
--to=oleg@redhat.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=omosnace@redhat.com \
--cc=revest@chromium.org \
--cc=rongtao@cestc.cn \
--cc=rtoax@foxmail.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.