diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2017-09-14 07:26:48 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2017-09-14 07:26:48 +0000 |
commit | e108ff9153b31af4eaf8b423232faee22920ab08 (patch) | |
tree | 98c438c240a49a5a53e2ecf4f2b26f8fb3a8ca46 | |
parent | 4578c1e41513695378a61894abc279098c02b883 (diff) | |
parent | 3f3fe12c0527f8701653caadbc4ce4b84e4ea260 (diff) | |
download | native-e108ff9153b31af4eaf8b423232faee22920ab08.tar.gz |
release-request-f0fc1aa1-730c-4deb-b1ff-e8ebeeccc4b5-for-git_oc-mr1-release-4335659 snap-temp-L85900000102427279
Change-Id: I275b9aaa79e004779ec52a2fa597bd50b520ce7f
-rw-r--r-- | cmds/installd/dexopt.cpp | 8 | ||||
-rw-r--r-- | cmds/installd/utils.cpp | 23 | ||||
-rw-r--r-- | cmds/installd/utils.h | 2 | ||||
-rw-r--r-- | cmds/lshal/Android.bp | 4 | ||||
-rw-r--r-- | libs/vr/libpdx_uds/client_channel.cpp | 10 | ||||
-rw-r--r-- | libs/vr/libpdx_uds/ipc_helper.cpp | 59 | ||||
-rw-r--r-- | libs/vr/libpdx_uds/private/uds/ipc_helper.h | 15 |
7 files changed, 75 insertions, 46 deletions
diff --git a/cmds/installd/dexopt.cpp b/cmds/installd/dexopt.cpp index 3c4a933ad6..f29da17457 100644 --- a/cmds/installd/dexopt.cpp +++ b/cmds/installd/dexopt.cpp @@ -1796,8 +1796,14 @@ bool reconcile_secondary_dex_file(const std::string& dex_path, } const char* volume_uuid_cstr = volume_uuid == nullptr ? nullptr : volume_uuid->c_str(); + + // Note that we cannot validate the package path here because the file might not exist + // and we cannot call realpath to resolve system symlinks. Since /data/user/0 symlinks to + // /data/data/ a lot of validations will fail if we attempt to check the package path. + // It is still ok to be more relaxed because any file removal is done after forking and + // dropping capabilities. if (!validate_secondary_dex_path(pkgname.c_str(), dex_path.c_str(), volume_uuid_cstr, - uid, storage_flag)) { + uid, storage_flag, /*validate_package_path*/ false)) { LOG(ERROR) << "Could not validate secondary dex path " << dex_path; return false; } diff --git a/cmds/installd/utils.cpp b/cmds/installd/utils.cpp index d277bd3ad8..dd32ac6425 100644 --- a/cmds/installd/utils.cpp +++ b/cmds/installd/utils.cpp @@ -801,7 +801,7 @@ int validate_system_app_path(const char* path) { } bool validate_secondary_dex_path(const std::string& pkgname, const std::string& dex_path, - const char* volume_uuid, int uid, int storage_flag) { + const char* volume_uuid, int uid, int storage_flag, bool validate_package_path) { CHECK(storage_flag == FLAG_STORAGE_CE || storage_flag == FLAG_STORAGE_DE); // Empty paths are not allowed. @@ -815,15 +815,18 @@ bool validate_secondary_dex_path(const std::string& pkgname, const std::string& // The path should be at most PKG_PATH_MAX long. if (dex_path.size() > PKG_PATH_MAX) { return false; } - // The dex_path should be under the app data directory. - std::string app_private_dir = storage_flag == FLAG_STORAGE_CE - ? create_data_user_ce_package_path( - volume_uuid, multiuser_get_user_id(uid), pkgname.c_str()) - : create_data_user_de_package_path( - volume_uuid, multiuser_get_user_id(uid), pkgname.c_str()); - - if (strncmp(dex_path.c_str(), app_private_dir.c_str(), app_private_dir.size()) != 0) { - return false; + if (validate_package_path) { + // If we are asked to validate the package path check that + // the dex_path is under the app data directory. + std::string app_private_dir = storage_flag == FLAG_STORAGE_CE + ? create_data_user_ce_package_path( + volume_uuid, multiuser_get_user_id(uid), pkgname.c_str()) + : create_data_user_de_package_path( + volume_uuid, multiuser_get_user_id(uid), pkgname.c_str()); + + if (strncmp(dex_path.c_str(), app_private_dir.c_str(), app_private_dir.size()) != 0) { + return false; + } } // If we got here we have a valid path. diff --git a/cmds/installd/utils.h b/cmds/installd/utils.h index da3a2933ec..e938042a3b 100644 --- a/cmds/installd/utils.h +++ b/cmds/installd/utils.h @@ -125,7 +125,7 @@ std::string read_path_inode(const std::string& parent, const char* name, const c int validate_system_app_path(const char* path); bool validate_secondary_dex_path(const std::string& pkgname, const std::string& dex_path, - const char* volume_uuid, int uid, int storage_flag); + const char* volume_uuid, int uid, int storage_flag, bool validate_package_path = true); int get_path_from_env(dir_rec_t* rec, const char* var); diff --git a/cmds/lshal/Android.bp b/cmds/lshal/Android.bp index 67b5b46829..8a64717ea4 100644 --- a/cmds/lshal/Android.bp +++ b/cmds/lshal/Android.bp @@ -61,6 +61,10 @@ cc_test { shared_libs: [ "android.hardware.tests.baz@1.0" ], + ldflags: [ + "-Wl,--rpath,${ORIGIN}/..", + "-Wl,--enable-new-dtags", + ], srcs: [ "test.cpp" ] diff --git a/libs/vr/libpdx_uds/client_channel.cpp b/libs/vr/libpdx_uds/client_channel.cpp index 9d9161784a..3f785fa62e 100644 --- a/libs/vr/libpdx_uds/client_channel.cpp +++ b/libs/vr/libpdx_uds/client_channel.cpp @@ -90,10 +90,12 @@ Status<void> SendRequest(const BorrowedHandle& socket_fd, size_t send_len = CountVectorSize(send_vector, send_count); InitRequest(&transaction_state->request, opcode, send_len, max_recv_len, false); - auto status = SendData(socket_fd, transaction_state->request); - if (status && send_len > 0) - status = SendDataVector(socket_fd, send_vector, send_count); - return status; + if (send_len == 0) { + send_vector = nullptr; + send_count = 0; + } + return SendData(socket_fd, transaction_state->request, send_vector, + send_count); } Status<void> ReceiveResponse(const BorrowedHandle& socket_fd, diff --git a/libs/vr/libpdx_uds/ipc_helper.cpp b/libs/vr/libpdx_uds/ipc_helper.cpp index d75ce86e4b..f85b3bb666 100644 --- a/libs/vr/libpdx_uds/ipc_helper.cpp +++ b/libs/vr/libpdx_uds/ipc_helper.cpp @@ -20,6 +20,9 @@ namespace uds { namespace { +constexpr size_t kMaxFdCount = + 256; // Total of 1KiB of data to transfer these FDs. + // Default implementations of Send/Receive interfaces to use standard socket // send/sendmsg/recv/recvmsg functions. class SocketSender : public SendInterface { @@ -175,20 +178,31 @@ Status<void> SendPayload::Send(const BorrowedHandle& socket_fd) { } Status<void> SendPayload::Send(const BorrowedHandle& socket_fd, - const ucred* cred) { + const ucred* cred, const iovec* data_vec, + size_t vec_count) { + if (file_handles_.size() > kMaxFdCount) { + ALOGE( + "SendPayload::Send: Trying to send too many file descriptors (%zu), " + "max allowed = %zu", + file_handles_.size(), kMaxFdCount); + return ErrorStatus{EINVAL}; + } + SendInterface* sender = sender_ ? sender_ : &g_socket_sender; MessagePreamble preamble; preamble.magic = kMagicPreamble; preamble.data_size = buffer_.size(); preamble.fd_count = file_handles_.size(); - Status<void> ret = SendAll(sender, socket_fd, &preamble, sizeof(preamble)); - if (!ret) - return ret; msghdr msg = {}; - iovec recv_vect = {buffer_.data(), buffer_.size()}; - msg.msg_iov = &recv_vect; - msg.msg_iovlen = 1; + msg.msg_iovlen = 2 + vec_count; + msg.msg_iov = static_cast<iovec*>(alloca(sizeof(iovec) * msg.msg_iovlen)); + msg.msg_iov[0].iov_base = &preamble; + msg.msg_iov[0].iov_len = sizeof(preamble); + msg.msg_iov[1].iov_base = buffer_.data(); + msg.msg_iov[1].iov_len = buffer_.size(); + for (size_t i = 0; i < vec_count; i++) + msg.msg_iov[i + 2] = data_vec[i]; if (cred || !file_handles_.empty()) { const size_t fd_bytes = file_handles_.size() * sizeof(int); @@ -270,7 +284,15 @@ Status<void> ReceivePayload::Receive(const BorrowedHandle& socket_fd, ucred* cred) { RecvInterface* receiver = receiver_ ? receiver_ : &g_socket_receiver; MessagePreamble preamble; - Status<void> ret = RecvAll(receiver, socket_fd, &preamble, sizeof(preamble)); + msghdr msg = {}; + iovec recv_vect = {&preamble, sizeof(preamble)}; + msg.msg_iov = &recv_vect; + msg.msg_iovlen = 1; + const size_t receive_fd_bytes = kMaxFdCount * sizeof(int); + msg.msg_controllen = CMSG_SPACE(sizeof(ucred)) + CMSG_SPACE(receive_fd_bytes); + msg.msg_control = alloca(msg.msg_controllen); + + Status<void> ret = RecvMsgAll(receiver, socket_fd, &msg); if (!ret) return ret; @@ -284,23 +306,6 @@ Status<void> ReceivePayload::Receive(const BorrowedHandle& socket_fd, file_handles_.clear(); read_pos_ = 0; - msghdr msg = {}; - iovec recv_vect = {buffer_.data(), buffer_.size()}; - msg.msg_iov = &recv_vect; - msg.msg_iovlen = 1; - - if (cred || preamble.fd_count) { - const size_t receive_fd_bytes = preamble.fd_count * sizeof(int); - msg.msg_controllen = - (cred ? CMSG_SPACE(sizeof(ucred)) : 0) + - (receive_fd_bytes == 0 ? 0 : CMSG_SPACE(receive_fd_bytes)); - msg.msg_control = alloca(msg.msg_controllen); - } - - ret = RecvMsgAll(receiver, socket_fd, &msg); - if (!ret) - return ret; - bool cred_available = false; file_handles_.reserve(preamble.fd_count); cmsghdr* cmsg = CMSG_FIRSTHDR(&msg); @@ -320,6 +325,10 @@ Status<void> ReceivePayload::Receive(const BorrowedHandle& socket_fd, cmsg = CMSG_NXTHDR(&msg, cmsg); } + ret = RecvAll(receiver, socket_fd, buffer_.data(), buffer_.size()); + if (!ret) + return ret; + if (cred && !cred_available) { ALOGE("ReceivePayload::Receive: Failed to obtain message credentials"); ret.SetError(EIO); diff --git a/libs/vr/libpdx_uds/private/uds/ipc_helper.h b/libs/vr/libpdx_uds/private/uds/ipc_helper.h index bde16d3d31..664a0d1a1b 100644 --- a/libs/vr/libpdx_uds/private/uds/ipc_helper.h +++ b/libs/vr/libpdx_uds/private/uds/ipc_helper.h @@ -59,7 +59,8 @@ class SendPayload : public MessageWriter, public OutputResourceMapper { public: SendPayload(SendInterface* sender = nullptr) : sender_{sender} {} Status<void> Send(const BorrowedHandle& socket_fd); - Status<void> Send(const BorrowedHandle& socket_fd, const ucred* cred); + Status<void> Send(const BorrowedHandle& socket_fd, const ucred* cred, + const iovec* data_vec = nullptr, size_t vec_count = 0); // MessageWriter void* GetNextWriteBufferSection(size_t size) override; @@ -156,18 +157,22 @@ class ResponseHeader { }; template <typename T> -inline Status<void> SendData(const BorrowedHandle& socket_fd, const T& data) { +inline Status<void> SendData(const BorrowedHandle& socket_fd, const T& data, + const iovec* data_vec = nullptr, + size_t vec_count = 0) { SendPayload payload; rpc::Serialize(data, &payload); - return payload.Send(socket_fd); + return payload.Send(socket_fd, nullptr, data_vec, vec_count); } template <typename FileHandleType> inline Status<void> SendData(const BorrowedHandle& socket_fd, - const RequestHeader<FileHandleType>& request) { + const RequestHeader<FileHandleType>& request, + const iovec* data_vec = nullptr, + size_t vec_count = 0) { SendPayload payload; rpc::Serialize(request, &payload); - return payload.Send(socket_fd, &request.cred); + return payload.Send(socket_fd, &request.cred, data_vec, vec_count); } Status<void> SendData(const BorrowedHandle& socket_fd, const void* data, |