From: Jinjiang Tu <tujinjiang@huawei.com>
To: David Hildenbrand <david@redhat.com>, <akpm@linux-foundation.org>,
<shr@devkernel.io>, <hannes@cmpxchg.org>, <riel@surriel.com>,
<wangkefeng.wang@huawei.com>, <sunnanyong@huawei.com>,
<linux-mm@kvack.org>
Subject: Re: [PATCH v2 1/2] mm/ksm: fix ksm exec support for prctl
Date: Mon, 25 Mar 2024 10:24:21 +0800 [thread overview]
Message-ID: <c376c256-54a9-4718-4595-0f165866a484@huawei.com> (raw)
In-Reply-To: <8b5e8d52-ab93-4e2e-aab7-43221f891aae@redhat.com>
在 2024/3/22 17:02, David Hildenbrand 写道:
> On 22.03.24 07:09, Jinjiang Tu wrote:
>> commit 3c6f33b7273a ("mm/ksm: support fork/exec for prctl") inherits
>> MMF_VM_MERGE_ANY flag when a task calls execve(). Howerver, it doesn't
>> create the mm_slot, so ksmd will not try to scan this task.
>>
>> To fix it, allocate and add the mm_slot to ksm_mm_head in
>> __bprm_mm_init()
>> when the mm has MMF_VM_MERGE_ANY flag.
>>
>> Fixes: 3c6f33b7273a ("mm/ksm: support fork/exec for prctl")
>> Signed-off-by: Jinjiang Tu <tujinjiang@huawei.com>
>> ---
>> fs/exec.c | 10 ++++++++++
>> include/linux/ksm.h | 13 +++++++++++++
>> 2 files changed, 23 insertions(+)
>>
>> diff --git a/fs/exec.c b/fs/exec.c
>> index ff6f26671cfc..66202d016a0a 100644
>> --- a/fs/exec.c
>> +++ b/fs/exec.c
>> @@ -67,6 +67,7 @@
>> #include <linux/time_namespace.h>
>> #include <linux/user_events.h>
>> #include <linux/rseq.h>
>> +#include <linux/ksm.h>
>> #include <linux/uaccess.h>
>> #include <asm/mmu_context.h>
>> @@ -267,6 +268,13 @@ static int __bprm_mm_init(struct linux_binprm
>> *bprm)
>> goto err_free;
>> }
>> + /*
>> + * Need to be called with mmap write lock
>> + * held, to avoid race with ksmd.
>> + */
>> + if (ksm_execve(mm))
>> + goto err_ksm;
>> +
>
> But now, would we revert what insert_vm_struct() did?
>
> We're freeing the VMA later, but we might have accounted memory.
>
>
> What would be cleaner is doing the ksm_execve() before the
> insert_vm_struct(), and then cleaning up in case insert_vm_struct()
> failed.
In fact, ksm_execve() has been called before the insert_vm_struct() in
this patch.
next prev parent reply other threads:[~2024-03-25 2:24 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-22 6:09 [PATCH v2 0/2] " Jinjiang Tu
2024-03-22 6:09 ` [PATCH v2 1/2] " Jinjiang Tu
2024-03-22 9:02 ` David Hildenbrand
2024-03-25 2:24 ` Jinjiang Tu [this message]
2024-03-25 8:33 ` David Hildenbrand
2024-03-24 0:03 ` kernel test robot
2024-03-25 5:44 ` Dan Carpenter
2024-03-25 6:33 ` Jinjiang Tu
2024-03-22 6:09 ` [PATCH v2 2/2] selftest/mm: ksm_functional_tests: extend test case for ksm fork/exec Jinjiang Tu
2024-03-22 11:43 ` David Hildenbrand
2024-03-25 2:24 ` Jinjiang Tu
2024-03-25 8:38 ` David Hildenbrand
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=c376c256-54a9-4718-4595-0f165866a484@huawei.com \
--to=tujinjiang@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=hannes@cmpxchg.org \
--cc=linux-mm@kvack.org \
--cc=riel@surriel.com \
--cc=shr@devkernel.io \
--cc=sunnanyong@huawei.com \
--cc=wangkefeng.wang@huawei.com \
/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