242f5d
commit f326d68d762edf4b0e9604daa446b6f8ca25725a
242f5d
Author: Mark Wielaard <mark@klomp.org>
242f5d
Date:   Sun Jul 26 22:40:22 2020 +0200
242f5d
242f5d
    epoll_ctl warns for uninitialized padding on non-amd64 64bit arches
242f5d
    
242f5d
    struct vki_epoll_event is packed on x86_64, but not on other 64bit
242f5d
    arches. This means that on 64bit arches there can be padding in the
242f5d
    epoll_event struct. Seperately the data field is only used by user
242f5d
    space (which might not set the data field if it doesn't need to).
242f5d
    
242f5d
    Only check the events field on epoll_ctl. But assume both events
242f5d
    and data are both written to by epoll_[p]wait (exclude padding).
242f5d
    
242f5d
    https://bugs.kde.org/show_bug.cgi?id=422623
242f5d
242f5d
diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c
242f5d
index 5b5b7eee6..929a4d9af 100644
242f5d
--- a/coregrind/m_syswrap/syswrap-linux.c
242f5d
+++ b/coregrind/m_syswrap/syswrap-linux.c
242f5d
@@ -2099,8 +2099,29 @@ PRE(sys_epoll_ctl)
242f5d
          SARG1, ( ARG2<3 ? epoll_ctl_s[ARG2] : "?" ), SARG3, ARG4);
242f5d
    PRE_REG_READ4(long, "epoll_ctl",
242f5d
                  int, epfd, int, op, int, fd, struct vki_epoll_event *, event);
242f5d
-   if (ARG2 != VKI_EPOLL_CTL_DEL)
242f5d
-      PRE_MEM_READ( "epoll_ctl(event)", ARG4, sizeof(struct vki_epoll_event) );
242f5d
+   if (ARG2 != VKI_EPOLL_CTL_DEL) {
242f5d
+      /* Just check the events field, the data field is for user space and
242f5d
+         unused by the kernel.  */
242f5d
+      struct vki_epoll_event *event = (struct vki_epoll_event *) ARG4;
242f5d
+      PRE_MEM_READ( "epoll_ctl(event)", (Addr) &event->events,
242f5d
+                    sizeof(__vki_u32) );
242f5d
+   }
242f5d
+}
242f5d
+
242f5d
+/* RES event records have been written (exclude padding).  */
242f5d
+static void epoll_post_helper ( ThreadId tid, SyscallArgs* arrghs,
242f5d
+                                SyscallStatus* status )
242f5d
+{
242f5d
+   vg_assert(SUCCESS);
242f5d
+   if (RES > 0) {
242f5d
+      Int i;
242f5d
+      struct vki_epoll_event **events = (struct vki_epoll_event**)(Addr)ARG2;
242f5d
+      for (i = 0; i < RES; i++) {
242f5d
+         /* Assume both events and data are set (data is user space only). */
242f5d
+         POST_FIELD_WRITE(events[i]->events);
242f5d
+         POST_FIELD_WRITE(events[i]->data);
242f5d
+      }
242f5d
+   }
242f5d
 }
242f5d
 
242f5d
 PRE(sys_epoll_wait)
242f5d
@@ -2111,13 +2132,12 @@ PRE(sys_epoll_wait)
242f5d
    PRE_REG_READ4(long, "epoll_wait",
242f5d
                  int, epfd, struct vki_epoll_event *, events,
242f5d
                  int, maxevents, int, timeout);
242f5d
+   /* Assume all (maxevents) events records should be (fully) writable. */
242f5d
    PRE_MEM_WRITE( "epoll_wait(events)", ARG2, sizeof(struct vki_epoll_event)*ARG3);
242f5d
 }
242f5d
 POST(sys_epoll_wait)
242f5d
 {
242f5d
-   vg_assert(SUCCESS);
242f5d
-   if (RES > 0)
242f5d
-      POST_MEM_WRITE( ARG2, sizeof(struct vki_epoll_event)*RES ) ;
242f5d
+   epoll_post_helper (tid, arrghs, status);
242f5d
 }
242f5d
 
242f5d
 PRE(sys_epoll_pwait)
242f5d
@@ -2130,15 +2150,14 @@ PRE(sys_epoll_pwait)
242f5d
                  int, epfd, struct vki_epoll_event *, events,
242f5d
                  int, maxevents, int, timeout, vki_sigset_t *, sigmask,
242f5d
                  vki_size_t, sigsetsize);
242f5d
+   /* Assume all (maxevents) events records should be (fully) writable. */
242f5d
    PRE_MEM_WRITE( "epoll_pwait(events)", ARG2, sizeof(struct vki_epoll_event)*ARG3);
242f5d
    if (ARG5)
242f5d
       PRE_MEM_READ( "epoll_pwait(sigmask)", ARG5, sizeof(vki_sigset_t) );
242f5d
 }
242f5d
 POST(sys_epoll_pwait)
242f5d
 {
242f5d
-   vg_assert(SUCCESS);
242f5d
-   if (RES > 0)
242f5d
-      POST_MEM_WRITE( ARG2, sizeof(struct vki_epoll_event)*RES ) ;
242f5d
+   epoll_post_helper (tid, arrghs, status);
242f5d
 }
242f5d
 
242f5d
 PRE(sys_eventfd)
242f5d
commit b74f9f23c8758c77367f18368ea95baa858544cb
242f5d
Author: Mark Wielaard <mark@klomp.org>
242f5d
Date:   Tue Aug 18 23:58:55 2020 +0200
242f5d
242f5d
    Fix epoll_ctl setting of array event and data fields.
242f5d
    
242f5d
    Fix for https://bugs.kde.org/show_bug.cgi?id=422623 in commit ecf5ba119
242f5d
    epoll_ctl warns for uninitialized padding on non-amd64 64bit arches
242f5d
    contained a bug. A pointer to an array is not a pointer to a pointer to
242f5d
    an array. Found by a Fedora user:
242f5d
    https://bugzilla.redhat.com/show_bug.cgi?id=1844778#c10
242f5d
242f5d
diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c
242f5d
index 0850487e9..3f488795a 100644
242f5d
--- a/coregrind/m_syswrap/syswrap-linux.c
242f5d
+++ b/coregrind/m_syswrap/syswrap-linux.c
242f5d
@@ -2115,11 +2115,11 @@ static void epoll_post_helper ( ThreadId tid, SyscallArgs* arrghs,
242f5d
    vg_assert(SUCCESS);
242f5d
    if (RES > 0) {
242f5d
       Int i;
242f5d
-      struct vki_epoll_event **events = (struct vki_epoll_event**)(Addr)ARG2;
242f5d
+      struct vki_epoll_event *events = (struct vki_epoll_event*)(Addr)ARG2;
242f5d
       for (i = 0; i < RES; i++) {
242f5d
          /* Assume both events and data are set (data is user space only). */
242f5d
-         POST_FIELD_WRITE(events[i]->events);
242f5d
-         POST_FIELD_WRITE(events[i]->data);
242f5d
+         POST_FIELD_WRITE(events[i].events);
242f5d
+         POST_FIELD_WRITE(events[i].data);
242f5d
       }
242f5d
    }
242f5d
 }