Project

General

Profile

Bug #12908

epoll should exclude normal files/directories

Added by Patrick Mooney 4 months ago. Updated 4 months ago.

Status:
Closed
Priority:
Normal
Category:
kernel
Start date:
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:

Description

Upstreaming OS-5941 from SmartOS:

When comparing epoll behavior on Linux to SmartOS/LX, a difference was found in what epoll supports vs poll(2). While poll(2) will happily operate on files and directories, epoll_ctl() excludes both:

Linux:

open("poll.c", O_RDONLY)                = 3
epoll_create1(0)                        = 4
epoll_ctl(4, EPOLL_CTL_ADD, 3, {EPOLLIN|EPOLLOUT, {u32=3, u64=18020514542911491}}) = -1 EPERM (Operation not permitted)
poll([{fd=3, events=POLLIN|POLLOUT}], 1, 0) = 1 ([{fd=3, revents=POLLIN|POLLOUT}])

open(".", O_RDONLY|O_DIRECTORY)         = 3
epoll_create1(0)                        = 4
epoll_ctl(4, EPOLL_CTL_ADD, 3, {EPOLLIN|EPOLLOUT, {u32=3, u64=18020514542911491}}) = -1 EPERM (Operation not permitted)
poll([{fd=3, events=POLLIN|POLLOUT}], 1, 0) = 1 ([{fd=3, revents=POLLIN|POLLOUT}])

SmartOS:
open("poll.c", O_RDONLY)                = 3
epoll_create1(0)                        = 4
epoll_ctl(4, EPOLL_CTL_ADD, 3, {EPOLLIN|EPOLLOUT, {u32=3, u64=3}}) = 0
poll([{fd=3, events=POLLIN|POLLOUT}], 1, 0) = 1 ([{fd=3, revents=POLLIN|POLLOUT}])

open(".", O_RDONLY|O_DIRECTORY)         = 3
epoll_create1(0)                        = 4
epoll_ctl(4, EPOLL_CTL_ADD, 3, {EPOLLIN|EPOLLOUT, {u32=3, u64=3}}) = 0
poll([{fd=3, events=POLLIN|POLLOUT}], 1, 0) = 1 ([{fd=3, revents=POLLIN|POLLOUT}])

On a PI with this wad, I tested non-epoll /dev/poll (and poll(2)) against normal files to ensure that their behavior hadn't changed. It all performed as expected with poll/devpoll resulting in proper events and epoll rejecting the request with EPERM.

History

#1

Updated by Electric Monk 4 months ago

  • Gerrit CR set to 762
#2

Updated by Patrick Mooney 4 months ago

Without the fix, the epoll test suite notes problems for the file and dir tests:

test_dir        0       TFAIL: 0 != -1
test_dir        1       TFAIL: 0 != 1
test_file       0       TFAIL: 0 != -1
test_file       1       TFAIL: 2 != 1

With the fix, they are clean:

test_dir        0       TPASS
test_dir        1       TPASS
test_file       0       TPASS
test_file       1       TPASS

#3

Updated by Patrick Mooney 4 months ago

This has been in SmartOS (and OmniOSce) since 2017

#4

Updated by Electric Monk 4 months ago

  • Status changed from In Progress to Closed
  • % Done changed from 0 to 100

git commit 87bfe94c15340e9846f25201fa63446ac956d845

commit  87bfe94c15340e9846f25201fa63446ac956d845
Author: Patrick Mooney <pmooney@pfmooney.com>
Date:   2020-07-06T15:35:08.000Z

    12908 epoll should exclude normal files/directories
    Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
    Reviewed by: Robert Mustacchi <rm@joyent.com>
    Approved by: Dan McDonald <danmcd@joyent.com>

Also available in: Atom PDF