You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2020/04/09 18:07:05 UTC

[trafficserver] branch 9.0.x updated (4392aff -> 2615a27)

This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a change to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git.


    from 4392aff  s3_auth_v4: multiple same name fields signing fix
     new d71e0cd  Updated ink_rwlock to be a real reader writer lock
     new dd43043  Use default rwlock attributes on initialize
     new 2615a27  Fix migrate use after free (#6578)

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 include/tscore/ink_rwlock.h      |  54 ++++++++++-------
 iocore/net/UnixNetVConnection.cc |  12 ++--
 src/tscore/ink_rwlock.cc         | 121 +++------------------------------------
 3 files changed, 50 insertions(+), 137 deletions(-)


[trafficserver] 03/03: Fix migrate use after free (#6578)

Posted by zw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit 2615a2792d38ff6f6fe41c01ec2a5f91c236d941
Author: Susan Hinrichs <sh...@yahoo-inc.com>
AuthorDate: Thu Apr 9 09:24:47 2020 -0500

    Fix migrate use after free (#6578)
    
    Co-authored-by: Susan Hinrichs <sh...@verizonmedia.com>
    (cherry picked from commit 7e58f90c51c86cf222bcf11e91e6d963a6ef440c)
---
 iocore/net/UnixNetVConnection.cc | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/iocore/net/UnixNetVConnection.cc b/iocore/net/UnixNetVConnection.cc
index bb67fd5..ab068f3 100644
--- a/iocore/net/UnixNetVConnection.cc
+++ b/iocore/net/UnixNetVConnection.cc
@@ -1384,29 +1384,31 @@ UnixNetVConnection::migrateToCurrentThread(Continuation *cont, EThread *t)
   // Go ahead and remove the fd from the original thread's epoll structure, so it is not
   // processed on two threads simultaneously
   this->ep.stop();
-  this->do_io_close();
 
   // Create new VC:
+  UnixNetVConnection *netvc = nullptr;
   if (save_ssl) {
     SSLNetVConnection *sslvc = static_cast<SSLNetVConnection *>(sslNetProcessor.allocate_vc(t));
     if (sslvc->populate(hold_con, cont, save_ssl) != EVENT_DONE) {
       sslvc->do_io_close();
       sslvc = nullptr;
     } else {
+      // Update the SSL fields
       sslvc->set_context(get_context());
     }
-    return sslvc;
-    // Update the SSL fields
+    netvc = sslvc;
   } else {
-    UnixNetVConnection *netvc = static_cast<UnixNetVConnection *>(netProcessor.allocate_vc(t));
+    netvc = static_cast<UnixNetVConnection *>(netProcessor.allocate_vc(t));
     if (netvc->populate(hold_con, cont, save_ssl) != EVENT_DONE) {
       netvc->do_io_close();
       netvc = nullptr;
     } else {
       netvc->set_context(get_context());
     }
-    return netvc;
   }
+  // Do not mark this closed until the end so it does not get freed by the other thread too soon
+  this->do_io_close();
+  return netvc;
 }
 
 void


[trafficserver] 01/03: Updated ink_rwlock to be a real reader writer lock

Posted by zw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit d71e0cd2b01fcefa378920609179ad4beff5bef8
Author: Bryan Call <bc...@apache.org>
AuthorDate: Tue Mar 31 09:29:55 2020 -0700

    Updated ink_rwlock to be a real reader writer lock
    
    (cherry picked from commit 3aeb0db4cd93197c4dd1dca734c9262555975d55)
---
 include/tscore/ink_rwlock.h |  54 ++++++++++++-------
 src/tscore/ink_rwlock.cc    | 123 ++++----------------------------------------
 2 files changed, 45 insertions(+), 132 deletions(-)

diff --git a/include/tscore/ink_rwlock.h b/include/tscore/ink_rwlock.h
index 5b3dcb3..c2938e3 100644
--- a/include/tscore/ink_rwlock.h
+++ b/include/tscore/ink_rwlock.h
@@ -29,23 +29,37 @@
 
 #pragma once
 
-#include "tscore/ink_mutex.h"
-#include "tscore/ink_thread.h"
-
-#define RW_MAGIC 0x19283746
-
-struct ink_rwlock {
-  ink_mutex rw_mutex;      /* basic lock on this struct */
-  ink_cond rw_condreaders; /* for reader threads waiting */
-  ink_cond rw_condwriters; /* for writer threads waiting */
-  int rw_magic;            /* for error checking */
-  int rw_nwaitreaders;     /* the number waiting */
-  int rw_nwaitwriters;     /* the number waiting */
-  int rw_refcount;
-};
-
-int ink_rwlock_init(ink_rwlock *rw);
-int ink_rwlock_destroy(ink_rwlock *rw);
-int ink_rwlock_rdlock(ink_rwlock *rw);
-int ink_rwlock_wrlock(ink_rwlock *rw);
-int ink_rwlock_unlock(ink_rwlock *rw);
+#include "tscore/ink_error.h"
+#include <pthread.h>
+
+typedef pthread_rwlock_t ink_rwlock;
+
+void ink_rwlock_init(ink_rwlock *rw);
+void ink_rwlock_destroy(ink_rwlock *rw);
+
+static inline void
+ink_rwlock_rdlock(ink_rwlock *rw)
+{
+  int error = pthread_rwlock_rdlock(rw);
+  if (unlikely(error != 0)) {
+    ink_abort("pthread_rwlock_rdlock(%p) failed: %s (%d)", rw, strerror(error), error);
+  }
+}
+
+static inline void
+ink_rwlock_wrlock(ink_rwlock *rw)
+{
+  int error = pthread_rwlock_wrlock(rw);
+  if (unlikely(error != 0)) {
+    ink_abort("pthread_rwlock_wrlock(%p) failed: %s (%d)", rw, strerror(error), error);
+  }
+}
+
+static inline void
+ink_rwlock_unlock(ink_rwlock *rw)
+{
+  int error = pthread_rwlock_unlock(rw);
+  if (unlikely(error != 0)) {
+    ink_abort("pthread_rwlock_unlock(%p) failed: %s (%d)", rw, strerror(error), error);
+  }
+}
diff --git a/src/tscore/ink_rwlock.cc b/src/tscore/ink_rwlock.cc
index 1d44876..c181858 100644
--- a/src/tscore/ink_rwlock.cc
+++ b/src/tscore/ink_rwlock.cc
@@ -24,131 +24,30 @@
 #include "tscore/ink_config.h"
 #include "tscore/ink_rwlock.h"
 
+static pthread_rwlockattr_t attr;
+
 //-------------------------------------------------------------------------
 // ink_rwlock_init
 //
 // Note: This should be called only once.
 //-------------------------------------------------------------------------
-int
+void
 ink_rwlock_init(ink_rwlock *rw)
 {
-  ink_mutex_init(&rw->rw_mutex);
-
-  ink_cond_init(&rw->rw_condreaders);
-  ink_cond_init(&rw->rw_condwriters);
-  rw->rw_nwaitreaders = 0;
-  rw->rw_nwaitwriters = 0;
-  // coverity[missing_lock]
-  rw->rw_refcount = 0;
-  rw->rw_magic    = RW_MAGIC;
-
-  return 0;
+  int error = pthread_rwlock_init(rw, &attr);
+  if (unlikely(error != 0)) {
+    ink_abort("pthread_rwlock_init(%p) failed: %s (%d)", rw, strerror(error), error);
+  }
 }
 
 //-------------------------------------------------------------------------
 // ink_rwlock_destroy
 //-------------------------------------------------------------------------
-
-int
+void
 ink_rwlock_destroy(ink_rwlock *rw)
 {
-  if (rw->rw_magic != RW_MAGIC) {
-    return EINVAL;
-  }
-  if (rw->rw_refcount != 0 || rw->rw_nwaitreaders != 0 || rw->rw_nwaitwriters != 0) {
-    return EBUSY;
-  }
-
-  ink_mutex_destroy(&rw->rw_mutex);
-  ink_cond_destroy(&rw->rw_condreaders);
-  ink_cond_destroy(&rw->rw_condwriters);
-  rw->rw_magic = 0;
-
-  return 0;
-}
-
-//-------------------------------------------------------------------------
-// ink_rwlock_rdlock
-//-------------------------------------------------------------------------
-
-int
-ink_rwlock_rdlock(ink_rwlock *rw)
-{
-  if (rw->rw_magic != RW_MAGIC) {
-    return EINVAL;
-  }
-
-  ink_mutex_acquire(&rw->rw_mutex);
-
-  /* give preference to waiting writers */
-  while (rw->rw_refcount < 0 || rw->rw_nwaitwriters > 0) {
-    rw->rw_nwaitreaders++;
-    ink_cond_wait(&rw->rw_condreaders, &rw->rw_mutex);
-    rw->rw_nwaitreaders--;
-  }
-  rw->rw_refcount++; /* another reader has a read lock */
-
-  ink_mutex_release(&rw->rw_mutex);
-
-  return 0;
-}
-
-//-------------------------------------------------------------------------
-// ink_rwlock_wrlock
-//-------------------------------------------------------------------------
-
-int
-ink_rwlock_wrlock(ink_rwlock *rw)
-{
-  if (rw->rw_magic != RW_MAGIC) {
-    return EINVAL;
-  }
-
-  ink_mutex_acquire(&rw->rw_mutex);
-
-  while (rw->rw_refcount != 0) {
-    rw->rw_nwaitwriters++;
-    ink_cond_wait(&rw->rw_condwriters, &rw->rw_mutex);
-    rw->rw_nwaitwriters--;
+  int error = pthread_rwlock_destroy(rw);
+  if (unlikely(error != 0)) {
+    ink_abort("pthread_rwlock_destroy(%p) failed: %s (%d)", rw, strerror(error), error);
   }
-  rw->rw_refcount = -1;
-
-  ink_mutex_release(&rw->rw_mutex);
-
-  return 0;
-}
-
-//-------------------------------------------------------------------------
-// ink_rwlock_unlock
-//-------------------------------------------------------------------------
-
-int
-ink_rwlock_unlock(ink_rwlock *rw)
-{
-  if (rw->rw_magic != RW_MAGIC) {
-    return EINVAL;
-  }
-
-  ink_mutex_acquire(&rw->rw_mutex);
-
-  if (rw->rw_refcount > 0) {
-    rw->rw_refcount--; /* releasing a reader */
-  } else if (rw->rw_refcount == -1) {
-    rw->rw_refcount = 0; /* releasing a reader */
-  } else {
-    ink_abort("invalid refcount %d on ink_rwlock %p", rw->rw_refcount, rw);
-  }
-
-  /* give preference to waiting writers over waiting readers */
-  if (rw->rw_nwaitwriters > 0) {
-    if (rw->rw_refcount == 0) {
-      ink_cond_signal(&rw->rw_condwriters);
-    }
-  } else if (rw->rw_nwaitreaders > 0) {
-    ink_cond_broadcast(&rw->rw_condreaders);
-  }
-
-  ink_mutex_release(&rw->rw_mutex);
-
-  return 0;
 }


[trafficserver] 02/03: Use default rwlock attributes on initialize

Posted by zw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit dd430436e10a6361df36e11b0782fc0e720518e3
Author: Masaori Koshiba <ma...@apache.org>
AuthorDate: Wed Apr 8 10:24:47 2020 +0900

    Use default rwlock attributes on initialize
    
    (cherry picked from commit d0bbc078d1e0cf9864090821f00b30db1d2ccb53)
---
 src/tscore/ink_rwlock.cc | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/tscore/ink_rwlock.cc b/src/tscore/ink_rwlock.cc
index c181858..19f4c8e 100644
--- a/src/tscore/ink_rwlock.cc
+++ b/src/tscore/ink_rwlock.cc
@@ -24,8 +24,6 @@
 #include "tscore/ink_config.h"
 #include "tscore/ink_rwlock.h"
 
-static pthread_rwlockattr_t attr;
-
 //-------------------------------------------------------------------------
 // ink_rwlock_init
 //
@@ -34,7 +32,7 @@ static pthread_rwlockattr_t attr;
 void
 ink_rwlock_init(ink_rwlock *rw)
 {
-  int error = pthread_rwlock_init(rw, &attr);
+  int error = pthread_rwlock_init(rw, nullptr);
   if (unlikely(error != 0)) {
     ink_abort("pthread_rwlock_init(%p) failed: %s (%d)", rw, strerror(error), error);
   }