Merge "Require vendor users and groups to start with vendor_" into pi-dev
diff --git a/libc/Android.bp b/libc/Android.bp
index 008c01a..6ba7cce 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -773,6 +773,16 @@
                     "arch-arm/cortex-a15/bionic/__strcpy_chk.S",
                 ],
             },
+            cortex_a55: {
+                srcs: [
+                    "arch-arm/denver/bionic/__strcat_chk.S",
+                    "arch-arm/denver/bionic/__strcpy_chk.S",
+                ],
+                exclude_srcs: [
+                    "arch-arm/cortex-a15/bionic/__strcat_chk.S",
+                    "arch-arm/cortex-a15/bionic/__strcpy_chk.S",
+                ],
+            },
             cortex_a73: {
                 srcs: [
                     "arch-arm/denver/bionic/__strcat_chk.S",
@@ -783,6 +793,16 @@
                     "arch-arm/cortex-a15/bionic/__strcpy_chk.S",
                 ],
             },
+            cortex_a75: {
+                srcs: [
+                    "arch-arm/denver/bionic/__strcat_chk.S",
+                    "arch-arm/denver/bionic/__strcpy_chk.S",
+                ],
+                exclude_srcs: [
+                    "arch-arm/cortex-a15/bionic/__strcat_chk.S",
+                    "arch-arm/cortex-a15/bionic/__strcpy_chk.S",
+                ],
+            },
             denver: {
                 srcs: [
                     "arch-arm/denver/bionic/__strcat_chk.S",
@@ -916,6 +936,19 @@
                     "arch-arm/cortex-a15/bionic/memcpy.S",
                 ],
             },
+            cortex_a55: {
+                srcs: [
+                    "arch-arm/cortex-a7/bionic/memset.S",
+                    "arch-arm/denver/bionic/memcpy.S",
+
+                    "arch-arm/krait/bionic/strcmp.S",
+                ],
+                exclude_srcs: [
+                    "arch-arm/cortex-a15/bionic/memset.S",
+                    "arch-arm/cortex-a15/bionic/memcpy.S",
+                    "arch-arm/cortex-a15/bionic/strcmp.S",
+                ],
+            },
             cortex_a73: {
                 srcs: [
                     "arch-arm/cortex-a7/bionic/memset.S",
@@ -929,6 +962,19 @@
                     "arch-arm/cortex-a15/bionic/strcmp.S",
                 ],
             },
+            cortex_a75: {
+                srcs: [
+                    "arch-arm/cortex-a7/bionic/memset.S",
+                    "arch-arm/denver/bionic/memcpy.S",
+
+                    "arch-arm/krait/bionic/strcmp.S",
+                ],
+                exclude_srcs: [
+                    "arch-arm/cortex-a15/bionic/memset.S",
+                    "arch-arm/cortex-a15/bionic/memcpy.S",
+                    "arch-arm/cortex-a15/bionic/strcmp.S",
+                ],
+            },
             denver: {
                 srcs: [
                     "arch-arm/denver/bionic/memcpy.S",
@@ -1021,6 +1067,14 @@
                     "arch-arm64/generic/bionic/memmove.S",
                 ],
             },
+            cortex_a55: {
+                srcs: [
+                    "arch-arm64/cortex-a53/bionic/memmove.S",
+                ],
+                exclude_srcs: [
+                    "arch-arm64/generic/bionic/memmove.S",
+                ],
+            },
             cortex_a73: {
                 srcs: [
                     "arch-arm64/cortex-a53/bionic/memmove.S",
@@ -1029,6 +1083,14 @@
                     "arch-arm64/generic/bionic/memmove.S",
                 ],
             },
+            cortex_a75: {
+                srcs: [
+                    "arch-arm64/cortex-a53/bionic/memmove.S",
+                ],
+                exclude_srcs: [
+                    "arch-arm64/generic/bionic/memmove.S",
+                ],
+            },
         },
 
         mips: {
diff --git a/libc/dns/resolv/res_send.c b/libc/dns/resolv/res_send.c
index 3b94fcf..18bb752 100644
--- a/libc/dns/resolv/res_send.c
+++ b/libc/dns/resolv/res_send.c
@@ -100,6 +100,7 @@
 #ifdef ANDROID_CHANGES
 #include "resolv_netid.h"
 #include "resolv_private.h"
+#include "private/android_filesystem_config.h"
 #else
 #include <resolv.h>
 #endif
@@ -820,6 +821,7 @@
 				return (-1);
 			}
 		}
+		fchown(statp->_vcsock, AID_DNS, -1);
 		if (statp->_mark != MARK_UNSET) {
 			if (setsockopt(statp->_vcsock, SOL_SOCKET,
 				    SO_MARK, &statp->_mark, sizeof(statp->_mark)) < 0) {
@@ -1122,6 +1124,7 @@
 			}
 		}
 
+		fchown(EXT(statp).nssocks[ns], AID_DNS, -1);
 		if (statp->_mark != MARK_UNSET) {
 			if (setsockopt(EXT(statp).nssocks[ns], SOL_SOCKET,
 					SO_MARK, &(statp->_mark), sizeof(statp->_mark)) < 0) {
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 32df911..c78b9ab 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -44,6 +44,7 @@
 #include <unordered_map>
 #include <vector>
 
+#include <android-base/properties.h>
 #include <android-base/scopeguard.h>
 
 #include <async_safe/log.h>
@@ -89,6 +90,7 @@
 static const char* const kLdConfigArchFilePath = "/system/etc/ld.config." ABI_STRING ".txt";
 
 static const char* const kLdConfigFilePath = "/system/etc/ld.config.txt";
+static const char* const kLdConfigVndkLiteFilePath = "/system/etc/ld.config.vndk_lite.txt";
 
 #if defined(__LP64__)
 static const char* const kSystemLibDir     = "/system/lib64";
@@ -3721,6 +3723,42 @@
   return namespaces;
 }
 
+static std::string get_ld_config_file_vndk_path() {
+  if (android::base::GetBoolProperty("ro.vndk.lite", false)) {
+    return kLdConfigVndkLiteFilePath;
+  }
+
+  std::string ld_config_file_vndk = kLdConfigFilePath;
+  size_t insert_pos = ld_config_file_vndk.find_last_of('.');
+  if (insert_pos == std::string::npos) {
+    insert_pos = ld_config_file_vndk.length();
+  }
+  ld_config_file_vndk.insert(insert_pos, Config::get_vndk_version_string('.'));
+  return ld_config_file_vndk;
+}
+
+static std::string get_ld_config_file_path() {
+#ifdef USE_LD_CONFIG_FILE
+  // This is a debugging/testing only feature. Must not be available on
+  // production builds.
+  const char* ld_config_file_env = getenv("LD_CONFIG_FILE");
+  if (ld_config_file_env != nullptr && file_exists(ld_config_file_env)) {
+    return ld_config_file_env;
+  }
+#endif
+
+  if (file_exists(kLdConfigArchFilePath)) {
+    return kLdConfigArchFilePath;
+  }
+
+  std::string ld_config_file_vndk = get_ld_config_file_vndk_path();
+  if (file_exists(ld_config_file_vndk.c_str())) {
+    return ld_config_file_vndk;
+  }
+
+  return kLdConfigFilePath;
+}
+
 std::vector<android_namespace_t*> init_default_namespaces(const char* executable_path) {
   g_default_namespace.set_name("(default)");
 
@@ -3738,31 +3776,16 @@
 
   std::string error_msg;
 
-  std::string ld_config_vndk = kLdConfigFilePath;
-  size_t insert_pos = ld_config_vndk.find_last_of('.');
-  if (insert_pos == std::string::npos) {
-    insert_pos = ld_config_vndk.length();
-  }
-  ld_config_vndk.insert(insert_pos, Config::get_vndk_version_string('.'));
-  const char* ld_config_txt = file_exists(ld_config_vndk.c_str()) ? ld_config_vndk.c_str() : kLdConfigFilePath;
-  const char* config_file = file_exists(kLdConfigArchFilePath) ? kLdConfigArchFilePath : ld_config_txt;
-#ifdef USE_LD_CONFIG_FILE
-  // This is a debugging/testing only feature. Must not be available on
-  // production builds.
-  const char* ld_config_file = getenv("LD_CONFIG_FILE");
-  if (ld_config_file != nullptr && file_exists(ld_config_file)) {
-    config_file = ld_config_file;
-  }
-#endif
+  std::string ld_config_file_path = get_ld_config_file_path();
 
-  if (!Config::read_binary_config(config_file,
+  if (!Config::read_binary_config(ld_config_file_path.c_str(),
                                   executable_path,
                                   g_is_asan,
                                   &config,
                                   &error_msg)) {
     if (!error_msg.empty()) {
       DL_WARN("Warning: couldn't read \"%s\" for \"%s\" (using default configuration instead): %s",
-              config_file,
+              ld_config_file_path.c_str(),
               executable_path,
               error_msg.c_str());
     }
@@ -3826,8 +3849,14 @@
   // we can no longer rely on the fact that libdl.so is part of default namespace
   // this is why we want to add ld-android.so to all namespaces from ld.config.txt
   soinfo* ld_android_so = solist_get_head();
+
+  // we also need vdso to be available for all namespaces (if present)
+  soinfo* vdso = solist_get_vdso();
   for (auto it : namespaces) {
     it.second->add_soinfo(ld_android_so);
+    if (vdso != nullptr) {
+      it.second->add_soinfo(vdso);
+    }
     // somain and ld_preloads are added to these namespaces after LD_PRELOAD libs are linked
   }
 
diff --git a/linker/linker_main.cpp b/linker/linker_main.cpp
index dc1fa75..00c72d0 100644
--- a/linker/linker_main.cpp
+++ b/linker/linker_main.cpp
@@ -64,6 +64,7 @@
 static soinfo* solist;
 static soinfo* sonext;
 static soinfo* somain; // main process, always the one after libdl_info
+static soinfo* vdso; // vdso if present
 
 void solist_add_soinfo(soinfo* si) {
   sonext->next = si;
@@ -104,6 +105,10 @@
   return somain;
 }
 
+soinfo* solist_get_vdso() {
+  return vdso;
+}
+
 int g_ld_debug_verbosity;
 abort_msg_t* g_abort_message = nullptr; // For debuggerd.
 
@@ -158,6 +163,8 @@
   si->set_dt_flags_1(si->get_dt_flags_1() | DF_1_NODELETE);
   si->set_linked();
   si->call_constructors();
+
+  vdso = si;
 }
 
 /* gdb expects the linker to be in the debug shared object list.
@@ -280,6 +287,8 @@
     }
   }
 
+  add_vdso(args);
+
   struct stat file_stat;
   // Stat "/proc/self/exe" instead of executable_path because
   // the executable could be unlinked by this point and it should
@@ -366,8 +375,6 @@
     }
   }
 
-  add_vdso(args);
-
   // Load ld_preloads and dependencies.
   std::vector<const char*> needed_library_name_list;
   size_t ld_preloads_count = 0;
diff --git a/linker/linker_main.h b/linker/linker_main.h
index 8d486e8..b37b947 100644
--- a/linker/linker_main.h
+++ b/linker/linker_main.h
@@ -70,3 +70,4 @@
 bool solist_remove_soinfo(soinfo* si);
 soinfo* solist_get_head();
 soinfo* solist_get_somain();
+soinfo* solist_get_vdso();
diff --git a/tests/dl_test.cpp b/tests/dl_test.cpp
index 38d7783..25341f4 100644
--- a/tests/dl_test.cpp
+++ b/tests/dl_test.cpp
@@ -168,7 +168,11 @@
 }
 
 #if defined(__BIONIC__)
+extern "C" void android_get_LD_LIBRARY_PATH(char*, size_t);
 static void create_ld_config_file(const char* config_file) {
+  char default_search_paths[PATH_MAX];
+  android_get_LD_LIBRARY_PATH(default_search_paths, sizeof(default_search_paths));
+
   std::ofstream fout(config_file, std::ios::out);
   fout << "dir.test = " << get_testlib_root() << "/ld_config_test_helper/" << std::endl
        << "[test]" << std::endl
@@ -176,7 +180,7 @@
        << "namespace.default.search.paths = " << get_testlib_root() << std::endl
        << "namespace.default.links = ns2" << std::endl
        << "namespace.default.link.ns2.shared_libs = libc.so:libm.so:libdl.so:ld_config_test_helper_lib1.so" << std::endl
-       << "namespace.ns2.search.paths = /system/${LIB}:" << get_testlib_root() << "/ns2" << std::endl;
+       << "namespace.ns2.search.paths = " << default_search_paths << ":" << get_testlib_root() << "/ns2" << std::endl;
   fout.close();
 }
 #endif
diff --git a/tests/libs/ld_config_test_helper.cpp b/tests/libs/ld_config_test_helper.cpp
index 592e8c0..87e512e 100644
--- a/tests/libs/ld_config_test_helper.cpp
+++ b/tests/libs/ld_config_test_helper.cpp
@@ -14,13 +14,37 @@
  * limitations under the License.
  */
 
+#include <dlfcn.h>
 #include <errno.h>
 #include <stdio.h>
+#if __has_include(<sys/auxv.h>)
+#include <sys/auxv.h>
+#endif
 #include <unistd.h>
 
 extern int get_value_from_lib();
 
 int main() {
+  bool skip_vdso_check = false;
+#if __has_include(<sys/auxv.h>)
+  if (getauxval(AT_SYSINFO_EHDR) == 0) {
+    skip_vdso_check = true;
+  }
+#endif
+
+  if (!skip_vdso_check) {
+    const char* vdso_name = "linux-vdso.so.1";
+#if defined(__i386__)
+    vdso_name = "linux-gate.so.1";
+#endif
+    void* handle = dlopen(vdso_name, RTLD_NOW);
+    if (handle == nullptr) {
+      printf("%s", dlerror());
+      return 1;
+    }
+    dlclose(handle);
+  }
+
   printf("%d", get_value_from_lib());
   return 0;
 }