From 93ad3e9fed2373147fe6997c2dc9991404bce7a0 Mon Sep 17 00:00:00 2001 From: Nick Kralevich Date: Tue, 5 May 2015 17:19:14 -0700 Subject: rootdir: make sure the /oem mountpoint is always available The /oem mount point is used to mount semi-trusted data, and many Android One devices depend on it. Make sure it's guaranteed to always be available. (cherrypicked from commit f3b554fc614fffaa5fc62ef1b4147131a8fa373c) Bug: 20816563 Change-Id: Ib5272f025d14d4da6125d753879054b3faeae696 --- rootdir/Android.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rootdir/Android.mk b/rootdir/Android.mk index 3ecb1db..7ab76b8 100644 --- a/rootdir/Android.mk +++ b/rootdir/Android.mk @@ -26,7 +26,7 @@ LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT) # # create some directories (some are mount points) LOCAL_POST_INSTALL_CMD := mkdir -p $(addprefix $(TARGET_ROOT_OUT)/, \ - sbin dev proc sys system data) + sbin dev proc sys system data oem) include $(BUILD_SYSTEM)/base_rules.mk -- cgit v1.1 From 266316e0b8c8296e07a7bb54e907a91e8b95970a Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Tue, 19 May 2015 09:12:30 -0700 Subject: logd: switch to unordered_map from BasicHashtable (charry pick from commit 511338dd575572d567c04d69eaea60627b6c3452) BasicHashtable is relatively untested, move over to a C++ template library that has more bake time. Bug: 20419786 Bug: 21590652 Bug: 20500228 Change-Id: I926aaecdc8345eca75c08fdd561b0473504c5d95 --- logd/LogBuffer.cpp | 46 ++++++++++++++---------------------- logd/LogStatistics.cpp | 9 ++++--- logd/LogStatistics.h | 64 +++++++++++++++++++++++++++----------------------- 3 files changed, 56 insertions(+), 63 deletions(-) diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp index 1da52d8..80fc9f5 100644 --- a/logd/LogBuffer.cpp +++ b/logd/LogBuffer.cpp @@ -22,6 +22,8 @@ #include #include +#include + #include #include @@ -246,31 +248,21 @@ public: uint64_t getKey() { return value; } }; -class LogBufferElementEntry { - const uint64_t key; - LogBufferElement *last; - -public: - LogBufferElementEntry(const uint64_t &k, LogBufferElement *e):key(k),last(e) { } +class LogBufferElementLast { - const uint64_t&getKey() const { return key; } - - LogBufferElement *getLast() { return last; } -}; - -class LogBufferElementLast : public android::BasicHashtable { + typedef std::unordered_map LogBufferElementMap; + LogBufferElementMap map; public: + bool merge(LogBufferElement *e, unsigned short dropped) { LogBufferElementKey key(e->getUid(), e->getPid(), e->getTid()); - android::hash_t hash = android::hash_type(key.getKey()); - ssize_t index = find(-1, hash, key.getKey()); - if (index != -1) { - LogBufferElementEntry &entry = editEntryAt(index); - LogBufferElement *l = entry.getLast(); + LogBufferElementMap::iterator it = map.find(key.getKey()); + if (it != map.end()) { + LogBufferElement *l = it->second; unsigned short d = l->getDropped(); if ((dropped + d) > USHRT_MAX) { - removeAt(index); + map.erase(it); } else { l->setDropped(dropped + d); return true; @@ -279,26 +271,24 @@ public: return false; } - size_t add(LogBufferElement *e) { + void add(LogBufferElement *e) { LogBufferElementKey key(e->getUid(), e->getPid(), e->getTid()); - android::hash_t hash = android::hash_type(key.getKey()); - return android::BasicHashtable:: - add(hash, LogBufferElementEntry(key.getKey(), e)); + map[key.getKey()] = e; } inline void clear() { - android::BasicHashtable::clear(); + map.clear(); } void clear(LogBufferElement *e) { uint64_t current = e->getRealTime().nsec() - NS_PER_SEC; - ssize_t index = -1; - while((index = next(index)) >= 0) { - LogBufferElement *l = editEntryAt(index).getLast(); + for(LogBufferElementMap::iterator it = map.begin(); it != map.end();) { + LogBufferElement *l = it->second; if ((l->getDropped() >= EXPIRE_THRESHOLD) && (current > l->getRealTime().nsec())) { - removeAt(index); - index = -1; + it = map.erase(it); + } else { + ++it; } } } diff --git a/logd/LogStatistics.cpp b/logd/LogStatistics.cpp index 90c49c0..48c2fe6 100644 --- a/logd/LogStatistics.cpp +++ b/logd/LogStatistics.cpp @@ -161,9 +161,8 @@ char *LogStatistics::uidToName(uid_t uid) { } // report uid -> pid(s) -> pidToName if unique - ssize_t index = -1; - while ((index = pidTable.next(index)) != -1) { - const PidEntry &entry = pidTable.entryAt(index); + for(pidTable_t::iterator it = pidTable.begin(); it != pidTable.end(); ++it) { + const PidEntry &entry = it->second; if (entry.getUid() == uid) { const char *n = entry.getName(); @@ -520,12 +519,12 @@ uid_t pidToUid(pid_t pid) { } uid_t LogStatistics::pidToUid(pid_t pid) { - return pidTable.entryAt(pidTable.add(pid)).getUid(); + return pidTable.add(pid)->second.getUid(); } // caller must free character string char *LogStatistics::pidToName(pid_t pid) { - const char *name = pidTable.entryAt(pidTable.add(pid)).getName(); + const char *name = pidTable.add(pid)->second.getName(); if (!name) { return NULL; } diff --git a/logd/LogStatistics.h b/logd/LogStatistics.h index f60f3ed..b9e9650 100644 --- a/logd/LogStatistics.h +++ b/logd/LogStatistics.h @@ -21,8 +21,9 @@ #include #include +#include + #include -#include #include "LogBufferElement.h" @@ -30,8 +31,14 @@ for (log_id_t i = LOG_ID_MIN; i < LOG_ID_MAX; i = (log_id_t) (i + 1)) template -class LogHashtable : public android::BasicHashtable { +class LogHashtable { + + std::unordered_map map; + public: + + typedef typename std::unordered_map::iterator iterator; + std::unique_ptr sort(size_t n) { if (!n) { std::unique_ptr sorted(NULL); @@ -41,9 +48,8 @@ public: const TEntry **retval = new const TEntry* [n]; memset(retval, 0, sizeof(*retval) * n); - ssize_t index = -1; - while ((index = android::BasicHashtable::next(index)) >= 0) { - const TEntry &entry = android::BasicHashtable::entryAt(index); + for(iterator it = map.begin(); it != map.end(); ++it) { + const TEntry &entry = it->second; size_t s = entry.getSizes(); ssize_t i = n - 1; while ((!retval[i] || (s > retval[i]->getSizes())) && (--i >= 0)) @@ -70,45 +76,43 @@ public: return index; } - ssize_t next(ssize_t index) { - return android::BasicHashtable::next(index); - } - - size_t add(TKey key, LogBufferElement *e) { - android::hash_t hash = android::hash_type(key); - ssize_t index = android::BasicHashtable::find(-1, hash, key); - if (index == -1) { - return android::BasicHashtable::add(hash, TEntry(e)); + inline iterator add(TKey key, LogBufferElement *e) { + iterator it = map.find(key); + if (it == map.end()) { + it = map.insert(std::make_pair(key, TEntry(e))).first; + } else { + it->second.add(e); } - android::BasicHashtable::editEntryAt(index).add(e); - return index; + return it; } - inline size_t add(TKey key) { - android::hash_t hash = android::hash_type(key); - ssize_t index = android::BasicHashtable::find(-1, hash, key); - if (index == -1) { - return android::BasicHashtable::add(hash, TEntry(key)); + inline iterator add(TKey key) { + iterator it = map.find(key); + if (it == map.end()) { + it = map.insert(std::make_pair(key, TEntry(key))).first; + } else { + it->second.add(key); } - android::BasicHashtable::editEntryAt(index).add(key); - return index; + return it; } void subtract(TKey key, LogBufferElement *e) { - ssize_t index = android::BasicHashtable::find(-1, android::hash_type(key), key); - if ((index != -1) - && android::BasicHashtable::editEntryAt(index).subtract(e)) { - android::BasicHashtable::removeAt(index); + iterator it = map.find(key); + if ((it != map.end()) && it->second.subtract(e)) { + map.erase(it); } } inline void drop(TKey key, LogBufferElement *e) { - ssize_t index = android::BasicHashtable::find(-1, android::hash_type(key), key); - if (index != -1) { - android::BasicHashtable::editEntryAt(index).drop(e); + iterator it = map.find(key); + if (it != map.end()) { + it->second.drop(e); } } + inline iterator begin() { return map.begin(); } + inline iterator end() { return map.end(); } + }; struct EntryBase { -- cgit v1.1 From 8c49e5e998ce766f803adbfe133dab31250ccb61 Mon Sep 17 00:00:00 2001 From: Andres Morales Date: Tue, 23 Jun 2015 11:27:09 -0700 Subject: [gatekeeperd] invalidate stale password cache password may change offline, invalidate the cache if it is stale Bug: 22019187 Change-Id: I2aaae978c8bd4629a0f93df3778d8679ae9b53d5 --- gatekeeperd/SoftGateKeeper.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gatekeeperd/SoftGateKeeper.h b/gatekeeperd/SoftGateKeeper.h index 4c16c52..75fe11d 100644 --- a/gatekeeperd/SoftGateKeeper.h +++ b/gatekeeperd/SoftGateKeeper.h @@ -151,8 +151,8 @@ public: bool DoVerify(const password_handle_t *expected_handle, const SizedBuffer &password) { FastHashMap::const_iterator it = fast_hash_map_.find(expected_handle->user_id); - if (it != fast_hash_map_.end()) { - return VerifyFast(it->second, password); + if (it != fast_hash_map_.end() && VerifyFast(it->second, password)) { + return true; } else { if (GateKeeper::DoVerify(expected_handle, password)) { uint64_t salt; -- cgit v1.1 From 0b261101f6702f1d40305b90ed5c1afcf00c3786 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Tue, 30 Jun 2015 16:02:40 -0700 Subject: Gracefully handle ENODEV in sdcard daemon. When someone force-unmounts our target endpoint, gracefully handle by terminating, instead of looping on the same errno forever. Bug: 22197797 Change-Id: I7e71632f69d47152ea78a94431c23ae69aba9b93 --- sdcard/sdcard.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sdcard/sdcard.c b/sdcard/sdcard.c index a136232..3cd5bc4 100644 --- a/sdcard/sdcard.c +++ b/sdcard/sdcard.c @@ -1510,6 +1510,10 @@ static void handle_fuse_requests(struct fuse_handler* handler) if (errno != EINTR) { ERROR("[%d] handle_fuse_requests: errno=%d\n", handler->token, errno); } + if (errno == ENODEV) { + ERROR("[%d] someone stole our marbles!\n", handler->token); + exit(2); + } continue; } -- cgit v1.1