lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Tue, 22 Jan 2019 12:46:55 +0100
From:   Roman Penyaev <rpenyaev@...e.de>
To:     Linus Torvalds <torvalds@...ux-foundation.org>
Cc:     Andrew Morton <akpm@...ux-foundation.org>,
        Davidlohr Bueso <dbueso@...e.de>,
        Jason Baron <jbaron@...mai.com>,
        Al Viro <viro@...iv.linux.org.uk>,
        "Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>,
        Andrea Parri <andrea.parri@...rulasolutions.com>,
        linux-fsdevel <linux-fsdevel@...r.kernel.org>,
        Linux List Kernel Mailing <linux-kernel@...r.kernel.org>
Subject: Re: [RFC PATCH v2 02/13] epoll: introduce user structures for polling
 from userspace

On 2019-01-21 22:34, Linus Torvalds wrote:
> So I'm not entirely convinced, but I guess actual numbers and users
> might convince me otherwise.
> 
> However, a quick comment:
> 
> On Tue, Jan 22, 2019 at 9:15 AM Roman Penyaev <rpenyaev@...e.de> wrote:
>> 
>> +struct epoll_uitem {
>> +       __poll_t ready_events;
>> +       struct epoll_event event;
>> +};
> 
> This really ends up being a horrible data structure.
> 
> struct epoll_event is declared as
> 
>     struct epoll_event {
>             __poll_t events;
>             __u64 data;
>     } EPOLL_PACKED;
> 
> and __poll_t is "unsigned". So on pretty much all 64-bit architectures
> except for x86-64 (which sets that packed attribute), you have a
> packing hole there in between the events and the data, and "struct
> epoll_event" has 8-byte alignment.
> 
> Now, in "struct epoll_uitem", you end up having *another* packing hold
> in between "ready_events" and "struct epoll_event".
> 
> So this data structure that has 16 bytes of actual data, ends up being
> 24 bytes in size.
> 
> Again, x86-64 happens to be the exception to this, but that's a random
> small implementation detail, not a design thing.
> 
> I think "struct epoll_event" was badly designed to begin with to have
> this issue, but it shouldn't then be an excuse to make things even
> worse with this array of "struct epoll_uitem" things.
> 
> Hmm?

Ha! Yes, you are right.  Eyes see "packed" and brain responds
"ok, this is 12 bytes, + 4 for ready_events = 16, perfect".
I have not paid any attention to how actually this EPOLL_PACKED is
defined.  Not nice at all.  I will unfold the structure like this:

/*
  * Item, shared with userspace.  Unfortunately we can't embed 
epoll_event
  * structure, because it is badly aligned on all 64-bit archs, except
  * x86-64 (see EPOLL_PACKED).  sizeof(epoll_uitem) == 16
  */
struct epoll_uitem {
	__poll_t ready_events;
	__poll_t events;
	__u64 data;
};

Also BUILD_BUG_ON(sizeof(epoll_uitem) != 16) somewhere in alloc won't
hurt.

--
Roman


Powered by blists - more mailing lists