All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: Sargun Dhillon <sargun@sargun.me>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	viro@zeniv.linux.org.uk, akpm@linux-foundation.org,
	willy@infradead.org, arnd@kernel.org,
	Willem de Bruijn <willemb@google.com>
Subject: Re: epoll may leak events on dup
Date: Sun, 31 Oct 2021 10:50:04 +0000	[thread overview]
Message-ID: <20211031105004.GA12092@dcvr> (raw)
In-Reply-To: <20211031095355.GA15963@ircssh-3.c.rugged-nimbus-611.internal>

Sargun Dhillon <sargun@sargun.me> wrote:
> On Sun, Oct 31, 2021 at 07:39:23AM +0000, Eric Wong wrote:
> > CRIU?  Checkpoint/Restore In Userspace?
> > Sargun Dhillon <sargun@sargun.me> wrote:
> > 
> Right, in CRIU, epoll is restored by manually cloning the FDs to the
> right spot, and re-installing the events into epoll. This requires:
> 0. Getting the original epoll FD
> 1. Fetching / recreating the original FD
> 2. dup2'ing it to right spot (and avoiding overwriting the original epoll FD)
> 3. EPOLL_CTL_ADD'ing the FD back in.

OK, am I understanding it's something like:

	int tmp_fd = epoll_create1(...);
	if (tmp_fd != orig_epfd) {
		dup2(tmp_fd, orig_epfd);
		close(tmp_fd);
	}

	for (/* loop over original FDs: */) {
		tmp_fd = socket(...);
		if (tmpfd != orig_sfd) {
			dup2(tmp_fd, orig_sfd);
			close(tmp_fd);
		}
		epoll_ctl(orig_epfd, EPOLL_CTL_ADD, orig_sfd, ...);
	}

Is that close to what CRIU is doing?
In no place does tmp_fd end up in the epoll rbtree, there.
Everything is keyed w/ orig_sfd and it's underlying file.

      reply	other threads:[~2021-10-31 10:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-30 10:03 epoll may leak events on dup Sargun Dhillon
2021-10-31  7:39 ` Eric Wong
2021-10-31  9:53   ` Sargun Dhillon
2021-10-31 10:50     ` Eric Wong [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=20211031105004.GA12092@dcvr \
    --to=e@80x24.org \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sargun@sargun.me \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willemb@google.com \
    --cc=willy@infradead.org \
    /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.