Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4568409ybi; Tue, 11 Jun 2019 08:44:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqxYUmVmxDkJJ1A+e8e5Ku5Zz8L/3U97djE075XIPpqVhFiboI09MW3E5drjaH/1S1BMvcR/ X-Received: by 2002:a63:c104:: with SMTP id w4mr20872530pgf.125.1560267875125; Tue, 11 Jun 2019 08:44:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560267875; cv=none; d=google.com; s=arc-20160816; b=Y2C6gQdiWVo26KATnnXmA+CTFtIE1+ZGvuyvBizNrdYGe5ujJ8LEshyJQ7eK4uK36/ D3JNcde51GO4mQ8/N01gbi9Bo4YMXgIvsqSFauM69EU/RDjUDa+duf/Lxc5TtiZ3dLwG UZ7/x6xcUR16cjH6xKvMHToRO2V/6ucLkrwYf2jYq0q3vU9FnFkFKWMKLgJ0txHAF6TS kK8OwnIOOBozPdgx8w6+L5zU1KSrlBS2Se8w6fgpcFmX9qxvFUuT2B2lEduXZc2xbr/k maH7wDkbnBFsBmiUJeHx4Af/YtG9l9PZWtqevPzHri0n/2tzMT+z1nOHczBVTZQBtyVu yAaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from; bh=Li2jwk+M5wRSwEaBIj0OeiaL73U0bvLoYE32NHlt8KQ=; b=i6lsedIub67SMc4lxIrK6wibUg3mYv7wb5v2WfZyxpRu/Zuzhdwzo4evl8Tu4YR94S iz7yyiAtIiBddlziSwSpAqs1jpcVevvvpKXiFEtkTU0xVSwS9gmy60ijndlzptknoqHm vCJNVOyc9yFCRsA9Hzr5e+aatAzfKz5a+mkWUjMOM6cGpodjBkTq0dX4YPQDI7a7V5xS moKirHEkltHJ6w9WI33DaHI+lIIlcltvr+7C4CKCaaqbzhBjoczYODSz0zWVfyU2CBJs Fu7OYQKJqU/cC2J7pg2LAixTdVyYfccRKhIksxFjxyuLf59eYr9DzKAI8HXlq84+SLdy ehQw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y10si279536pgj.585.2019.06.11.08.44.20; Tue, 11 Jun 2019 08:44:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391681AbfFKOza (ORCPT + 99 others); Tue, 11 Jun 2019 10:55:30 -0400 Received: from mx2.suse.de ([195.135.220.15]:52670 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388925AbfFKOz1 (ORCPT ); Tue, 11 Jun 2019 10:55:27 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 1FC56ABD2; Tue, 11 Jun 2019 14:55:26 +0000 (UTC) From: Roman Penyaev Cc: Roman Penyaev , Andrew Morton , Al Viro , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 12/14] epoll: support mapping for epfd when polled from userspace Date: Tue, 11 Jun 2019 16:54:56 +0200 Message-Id: <20190611145458.9540-13-rpenyaev@suse.de> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190611145458.9540-1-rpenyaev@suse.de> References: <20190611145458.9540-1-rpenyaev@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org User has to mmap user_header and user_index vmalloce'd pointers in order to consume events from userspace. Also we do not let any copies of vma on fork(). Signed-off-by: Roman Penyaev Cc: Andrew Morton Cc: Al Viro Cc: Linus Torvalds Cc: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- fs/eventpoll.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/fs/eventpoll.c b/fs/eventpoll.c index e42ddf580556..c5db15c5f8b0 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c @@ -1426,11 +1426,47 @@ static void ep_show_fdinfo(struct seq_file *m, struct file *f) } #endif +static int ep_eventpoll_mmap(struct file *filep, struct vm_area_struct *vma) +{ + struct eventpoll *ep = vma->vm_file->private_data; + size_t size; + int rc; + + if (!ep_polled_by_user(ep)) + return -ENOTSUPP; + + size = vma->vm_end - vma->vm_start; + if (!vma->vm_pgoff && size > ep->header_length) + return -ENXIO; + if (vma->vm_pgoff && ep->header_length != (vma->vm_pgoff << PAGE_SHIFT)) + /* Index ring starts exactly after the header */ + return -ENXIO; + if (vma->vm_pgoff && size > ep->index_length) + return -ENXIO; + + /* + * vm_pgoff is used *only* for indication, what is mapped: user header + * or user index ring. Sizes are checked above. + */ + if (!vma->vm_pgoff) + rc = remap_vmalloc_range_partial(vma, vma->vm_start, + ep->user_header, size); + else + rc = remap_vmalloc_range_partial(vma, vma->vm_start, + ep->user_index, size); + if (likely(!rc)) + /* No copies for forks(), please */ + vma->vm_flags |= VM_DONTCOPY; + + return rc; +} + /* File callbacks that implement the eventpoll file behaviour */ static const struct file_operations eventpoll_fops = { #ifdef CONFIG_PROC_FS .show_fdinfo = ep_show_fdinfo, #endif + .mmap = ep_eventpoll_mmap, .release = ep_eventpoll_release, .poll = ep_eventpoll_poll, .llseek = noop_llseek, -- 2.21.0