linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: David Hildenbrand <david@redhat.com>
Cc: Pu Lehui <pulehui@huaweicloud.com>,
	Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	mhiramat@kernel.org, peterz@infradead.org,
	akpm@linux-foundation.org, Liam.Howlett@oracle.com,
	vbabka@suse.cz, jannh@google.com, pfalcato@suse.de,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	pulehui@huawei.com, Andrii Nakryiko <andrii@kernel.org>,
	Jiri Olsa <jolsa@kernel.org>
Subject: Re: [RFC PATCH] mm/mmap: Fix uprobe anon page be overwritten when expanding vma during mremap
Date: Mon, 26 May 2025 19:38:45 +0200	[thread overview]
Message-ID: <20250526173845.GC4156@redhat.com> (raw)
In-Reply-To: <20250526162940.GB4156@redhat.com>

On 05/26, Oleg Nesterov wrote:
>
> On 05/25, David Hildenbrand wrote:
> >
> > On 25.05.25 11:59, Oleg Nesterov wrote:
> > >
> > >OK. But do you see any reason why uprobe_mmap() should be ever called during
> > >mremap() ?
> >
> > Only when growing a VMA: we might now cover a part with a uprobe, which we
> > have take care of.
>
> Ah, indeed, thank you...
>
> But. What if mremap() expands and moves a VMA? it seems to me that in
> this case uprobe_mmap() won't be called? I'll try to make the test-case
> to check...

It seems that I was right...

	#define _GNU_SOURCE
	#include <sys/mman.h>
	#include <linux/perf_event.h>
	#include <fcntl.h>
	#include <syscall.h>
	#include <unistd.h>
	#include <assert.h>

	#define FNAME	"FILE"
	#define ADDR (4096*16)

	int main(int argc, char *argv[])
	{
		int fd = open(FNAME, O_RDWR|O_CREAT, 0600);
		ftruncate(fd, 2*4096);

		struct perf_event_attr attr = {
			.type = 9,
			.size = 72,		// PERF_ATTR_SIZE_VER1 to include config2
			.config1 = (long)FNAME,	// uprobe_path
			.config2 = 4096,	// probe_offset
		};

		assert(syscall(__NR_perf_event_open, &attr, 0, 0, -1, 0) >= 0);

		assert(mmap((void*)ADDR, 4096, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, fd,0) == (void*)ADDR);

		int flags = 0;
		flags = MREMAP_MAYMOVE|MREMAP_FIXED;

		assert(mremap((void*)ADDR, 4096, 2*4096, flags, 2*ADDR) == (void*)(2*ADDR));

		pause();
		return 0;
	}

and
	/tmp/D# ./test &
	[1] 102
	/tmp/D# grep FILE /proc/$!/maps
	00020000-00022000 r-xp 00000000 00:15 2060                               /tmp/D/FILE

this test-case doesn't call uprobe_mmap/install_breakpoint during mremap().
I added a couple of printk's to ensure.

If I remove the

	flags = MREMAP_MAYMOVE|MREMAP_FIXED;

line above, everything works "as expected".

Oleg.


      reply	other threads:[~2025-05-26 17:39 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-21  9:25 [RFC PATCH] mm/mmap: Fix uprobe anon page be overwritten when expanding vma during mremap Pu Lehui
2025-05-21 10:25 ` David Hildenbrand
2025-05-22 14:37   ` Pu Lehui
2025-05-22 15:14     ` David Hildenbrand
2025-05-26 14:52       ` Pu Lehui
2025-05-26 15:48         ` Oleg Nesterov
2025-05-26 18:46           ` David Hildenbrand
2025-05-27 11:42             ` Lorenzo Stoakes
2025-05-27 11:44               ` Lorenzo Stoakes
2025-05-27 13:39               ` Pu Lehui
2025-05-27 13:38             ` Pu Lehui
2025-05-28  9:03               ` David Hildenbrand
2025-05-29 16:07                 ` Pu Lehui
2025-05-30  8:33                   ` David Hildenbrand
2025-05-30  8:41                     ` Lorenzo Stoakes
2025-05-30  8:50                       ` David Hildenbrand
2025-05-30  9:03                         ` Lorenzo Stoakes
2025-05-30  9:27                           ` David Hildenbrand
2025-05-30 18:09                     ` Oleg Nesterov
2025-05-30 18:34                       ` David Hildenbrand
2025-05-30 22:48                         ` Pu Lehui
2025-05-27 13:23           ` Pu Lehui
2025-05-21 13:13 ` Lorenzo Stoakes
2025-05-22 15:00   ` Pu Lehui
2025-05-22 15:18     ` Lorenzo Stoakes
2025-05-24 16:45 ` Oleg Nesterov
2025-05-24 21:45   ` David Hildenbrand
2025-05-25  9:59     ` Oleg Nesterov
2025-05-25 10:24       ` David Hildenbrand
2025-05-26 16:29         ` Oleg Nesterov
2025-05-26 17:38           ` Oleg Nesterov [this message]

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=20250526173845.GC4156@redhat.com \
    --to=oleg@redhat.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=andrii@kernel.org \
    --cc=david@redhat.com \
    --cc=jannh@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mhiramat@kernel.org \
    --cc=peterz@infradead.org \
    --cc=pfalcato@suse.de \
    --cc=pulehui@huawei.com \
    --cc=pulehui@huaweicloud.com \
    --cc=vbabka@suse.cz \
    /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;
as well as URLs for NNTP newsgroup(s).