Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1921601pxb; Sun, 31 Oct 2021 03:51:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzj0xnshmxuwbRAGTjewHFK0QGyE83rynxWWnZTaGPer+Nx75zuhWVDyFuCJrNDDIYO3+tm X-Received: by 2002:a05:6638:dc6:: with SMTP id m6mr16306810jaj.48.1635677477176; Sun, 31 Oct 2021 03:51:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635677477; cv=none; d=google.com; s=arc-20160816; b=SWOPjLqXUFft+fbZrTeTZW+3s2SDW5TmQJ+j3lPbOEctIlBbaDztLMUqzOdK7yuQnQ zeoUs5Hglacu/eNUNLEoPRkkFNGUWMmIfyi1ceQroVnPMfxZQ6WrerNQq5DQFwghYdjN jlT9nqA1x1nMABa2AVHEtuzcZx4no6MIZu/LqnDzffzT7dpyg00pwZBrvz9lHOwk22ZF aDcqbDMFfmlDhQPgs/M22yGtg7KfMHk3tOwtYGw0IV4z53T66ER2WPmlRBZBE0qhDSRr /CTPXwBo650UUg4PJK+4hCyBU4GxGPwwVEGtz3pIAnYXokJvs08cTY+DMvfnnDz2e7Ib CZKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=DNWvsFbfU10vRjJNl5pSfOnAk5Kzreg9TVT24RK+pJQ=; b=g93Fw7pwjfSZ4f4VAt0hKshxhqDruiLkI/CLuLqrmkp3RzdtzQBaKJyNa6iLCfCJWp iK/4x9k4Z3P7gPTPma5V3YF2TFCLLyBiYbwxodDCumv+2jHoP4T85yMiYSZ848gDdyOa Rj+02mKjIFKqRPMy1TyrrhXj9riwb1D4JGM1AjelqjhrcTkf93QGtP0bo/vYVj2JMG1z TULFilnS8oKM26anedacYaLSshxqhWqdYIEQmjZnS2hYbLD2ENAC9HbdUuIIqbKk3NTW QpiBVpvyeEEUY6COl3pwtpWIanyDM0+bInY0xxrYI4fpTqIytRaNLscq+2XyF59QXszM OjSw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x8si14517567ilu.60.2021.10.31.03.51.00; Sun, 31 Oct 2021 03:51:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230046AbhJaKwg (ORCPT + 99 others); Sun, 31 Oct 2021 06:52:36 -0400 Received: from dcvr.yhbt.net ([64.71.152.64]:46804 "EHLO dcvr.yhbt.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229638AbhJaKwg (ORCPT ); Sun, 31 Oct 2021 06:52:36 -0400 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 5789E1F953; Sun, 31 Oct 2021 10:50:04 +0000 (UTC) Date: Sun, 31 Oct 2021 10:50:04 +0000 From: Eric Wong To: Sargun Dhillon 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 Subject: Re: epoll may leak events on dup Message-ID: <20211031105004.GA12092@dcvr> References: <20211030100319.GA11526@ircssh-3.c.rugged-nimbus-611.internal> <20211031073923.M174137@dcvr> <20211031095355.GA15963@ircssh-3.c.rugged-nimbus-611.internal> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20211031095355.GA15963@ircssh-3.c.rugged-nimbus-611.internal> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sargun Dhillon wrote: > On Sun, Oct 31, 2021 at 07:39:23AM +0000, Eric Wong wrote: > > CRIU? Checkpoint/Restore In Userspace? > > Sargun Dhillon 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.