From d1076eb72871c7d5c8c921bcc6fa23b1349d50d1 Mon Sep 17 00:00:00 2001 From: Paul Lawrence Date: Tue, 11 Jul 2023 09:06:15 -0700 Subject: Revert "Fix deadlock caused by two-threaded property controls" This reverts commit aeddfc4aaffbeb2eded2728163bcd3ae5ee5deef. These fixes for b/262208935 introduced a race condition. We believe the race is fixed by ag/23879563, but at this point in the release feel that reverting the fixes and refixing in main is the better solution Test: Builds, boots Bug: 283202477 Bug: 288991737 Ignore-AOSP-First: Reverting CL only in internal Change-Id: If7e9e5f99728c2f3a18b08346b4cf3449132f920 --- libc/bionic/system_property_set.cpp | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/libc/bionic/system_property_set.cpp b/libc/bionic/system_property_set.cpp index 845ff27e6..bde0c1002 100644 --- a/libc/bionic/system_property_set.cpp +++ b/libc/bionic/system_property_set.cpp @@ -55,24 +55,16 @@ static const char* kServiceVersionPropertyName = "ro.property_service.version"; class PropertyServiceConnection { public: - PropertyServiceConnection(const char* name) : last_error_(0) { + PropertyServiceConnection() : last_error_(0) { socket_.reset(::socket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0)); if (socket_.get() == -1) { last_error_ = errno; return; } - // If we're trying to set "sys.powerctl" from a privileged process, use the special - // socket. Because this socket is only accessible to privileged processes, it can't - // be DoSed directly by malicious apps. (The shell user should be able to reboot, - // though, so we don't just always use the special socket for "sys.powerctl".) - // See b/262237198 for context - const char* socket = property_service_socket; - if (strcmp(name, "sys.powerctl") == 0 && - access(property_service_for_system_socket, W_OK) == 0) { - socket = property_service_for_system_socket; - } - + const char* socket = access(property_service_for_system_socket, W_OK) == 0 + ? property_service_for_system_socket + : property_service_socket; const size_t namelen = strlen(socket); sockaddr_un addr; memset(&addr, 0, sizeof(addr)); @@ -189,7 +181,7 @@ struct prop_msg { }; static int send_prop_msg(const prop_msg* msg) { - PropertyServiceConnection connection(msg->name); + PropertyServiceConnection connection; if (!connection.IsValid()) { return connection.GetLastError(); } @@ -282,7 +274,7 @@ int __system_property_set(const char* key, const char* value) { // New protocol only allows long values for ro. properties only. if (strlen(value) >= PROP_VALUE_MAX && strncmp(key, "ro.", 3) != 0) return -1; // Use proper protocol - PropertyServiceConnection connection(key); + PropertyServiceConnection connection; if (!connection.IsValid()) { errno = connection.GetLastError(); async_safe_format_log( -- cgit v1.2.3 From 78973da8efdb5b82f9833cf9a25ed89a752e1033 Mon Sep 17 00:00:00 2001 From: Paul Lawrence Date: Tue, 11 Jul 2023 09:06:26 -0700 Subject: Revert "Use proprety_socket_for_system if permissions allow" This reverts commit 24839a681e0f8d19ef5685cdf62631d8df2155f5. These fixes for b/262208935 introduced a race condition. We believe the race is fixed by ag/23879563, but at this point in the release feel that reverting the fixes and refixing in main is the better solution Test: Builds, boots Bug: 283202477 Bug: 288991737 Ignore-AOSP-First: Reverting CL only in internal Change-Id: If0736e504928641c85934eae4d298f14e711116c --- libc/bionic/system_property_set.cpp | 9 ++------- libc/include/sys/_system_properties.h | 1 - 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/libc/bionic/system_property_set.cpp b/libc/bionic/system_property_set.cpp index bde0c1002..212aafcc1 100644 --- a/libc/bionic/system_property_set.cpp +++ b/libc/bionic/system_property_set.cpp @@ -49,8 +49,6 @@ #include "private/ScopedFd.h" static const char property_service_socket[] = "/dev/socket/" PROP_SERVICE_NAME; -static const char property_service_for_system_socket[] = - "/dev/socket/" PROP_SERVICE_FOR_SYSTEM_NAME; static const char* kServiceVersionPropertyName = "ro.property_service.version"; class PropertyServiceConnection { @@ -62,13 +60,10 @@ class PropertyServiceConnection { return; } - const char* socket = access(property_service_for_system_socket, W_OK) == 0 - ? property_service_for_system_socket - : property_service_socket; - const size_t namelen = strlen(socket); + const size_t namelen = strlen(property_service_socket); sockaddr_un addr; memset(&addr, 0, sizeof(addr)); - strlcpy(addr.sun_path, socket, sizeof(addr.sun_path)); + strlcpy(addr.sun_path, property_service_socket, sizeof(addr.sun_path)); addr.sun_family = AF_LOCAL; socklen_t alen = namelen + offsetof(sockaddr_un, sun_path) + 1; diff --git a/libc/include/sys/_system_properties.h b/libc/include/sys/_system_properties.h index c7a30ebbd..744a45b71 100644 --- a/libc/include/sys/_system_properties.h +++ b/libc/include/sys/_system_properties.h @@ -41,7 +41,6 @@ __BEGIN_DECLS #define PROP_SERVICE_NAME "property_service" -#define PROP_SERVICE_FOR_SYSTEM_NAME "property_service_for_system" #define PROP_FILENAME "/dev/__properties__" #define PROP_MSG_SETPROP 1 -- cgit v1.2.3