diff options
Diffstat (limited to 'cmds')
-rw-r--r-- | cmds/app_process/app_main.cpp | 28 | ||||
-rw-r--r-- | cmds/content/src/com/android/commands/content/Content.java | 8 | ||||
-rw-r--r--[-rwxr-xr-x] | cmds/input/src/com/android/commands/input/Input.java | 0 | ||||
-rw-r--r-- | cmds/installd/Android.mk | 9 | ||||
-rw-r--r-- | cmds/installd/commands.c | 27 | ||||
-rw-r--r-- | cmds/installd/installd.c | 11 | ||||
-rw-r--r-- | cmds/installd/installd.h | 4 | ||||
-rw-r--r-- | cmds/installd/tests/Android.mk | 11 | ||||
-rw-r--r-- | cmds/interrupter/Android.mk | 21 | ||||
-rw-r--r-- | cmds/interrupter/interrupter.c | 53 | ||||
-rw-r--r-- | cmds/interrupter/interrupter.h | 79 | ||||
-rw-r--r-- | cmds/servicemanager/service_manager.c | 1 |
12 files changed, 207 insertions, 45 deletions
diff --git a/cmds/app_process/app_main.cpp b/cmds/app_process/app_main.cpp index 6fe358c..0668be6 100644 --- a/cmds/app_process/app_main.cpp +++ b/cmds/app_process/app_main.cpp @@ -13,7 +13,9 @@ #include <cutils/process_name.h> #include <cutils/memory.h> #include <android_runtime/AndroidRuntime.h> +#include <sys/personality.h> +#include <stdlib.h> #include <stdio.h> #include <unistd.h> @@ -128,8 +130,32 @@ static void setArgv0(const char *argv0, const char *newArgv0) strlcpy(const_cast<char *>(argv0), newArgv0, strlen(argv0)); } -int main(int argc, const char* const argv[]) +int main(int argc, char* const argv[]) { +#ifdef __arm__ + /* + * b/7188322 - Temporarily revert to the compat memory layout + * to avoid breaking third party apps. + * + * THIS WILL GO AWAY IN A FUTURE ANDROID RELEASE. + * + * http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=7dbaa466 + * changes the kernel mapping from bottom up to top-down. + * This breaks some programs which improperly embed + * an out of date copy of Android's linker. + */ + if (getenv("NO_ADDR_COMPAT_LAYOUT_FIXUP") == NULL) { + int current = personality(0xFFFFFFFF); + if ((current & ADDR_COMPAT_LAYOUT) == 0) { + personality(current | ADDR_COMPAT_LAYOUT); + setenv("NO_ADDR_COMPAT_LAYOUT_FIXUP", "1", 1); + execv("/system/bin/app_process", argv); + return -1; + } + } + unsetenv("NO_ADDR_COMPAT_LAYOUT_FIXUP"); +#endif + // These are global variables in ProcessState.cpp mArgC = argc; mArgV = argv; diff --git a/cmds/content/src/com/android/commands/content/Content.java b/cmds/content/src/com/android/commands/content/Content.java index 070e105..ae39d24 100644 --- a/cmds/content/src/com/android/commands/content/Content.java +++ b/cmds/content/src/com/android/commands/content/Content.java @@ -83,25 +83,25 @@ public class Content { + " Example:\n" + " # Change \"new_setting\" secure setting to \"newer_value\".\n" + " adb shell content update --uri content://settings/secure --bind" - + " value:s:newer_value --where \"name=\\'new_setting\\'\"\n" + + " value:s:newer_value --where \"name=\'new_setting\'\"\n" + "\n" + "usage: adb shell content delete --uri <URI> [--user <USER_ID>] --bind <BINDING>" + " [--bind <BINDING>...] [--where <WHERE>]\n" + " Example:\n" + " # Remove \"new_setting\" secure setting.\n" + " adb shell content delete --uri content://settings/secure " - + "--where \"name=\\'new_setting\\'\"\n" + + "--where \"name=\'new_setting\'\"\n" + "\n" + "usage: adb shell content query --uri <URI> [--user <USER_ID>]" + " [--projection <PROJECTION>] [--where <WHERE>] [--sort <SORT_ORDER>]\n" + " <PROJECTION> is a list of colon separated column names and is formatted:\n" + " <COLUMN_NAME>[:<COLUMN_NAME>...]\n" - + " <SORT_OREDER> is the order in which rows in the result should be sorted.\n" + + " <SORT_ORDER> is the order in which rows in the result should be sorted.\n" + " Example:\n" + " # Select \"name\" and \"value\" columns from secure settings where \"name\" is " + "equal to \"new_setting\" and sort the result by name in ascending order.\n" + " adb shell content query --uri content://settings/secure --projection name:value" - + " --where \"name=\\'new_setting\\'\" --sort \"name ASC\"\n" + + " --where \"name=\'new_setting\'\" --sort \"name ASC\"\n" + "\n"; private static class Parser { diff --git a/cmds/input/src/com/android/commands/input/Input.java b/cmds/input/src/com/android/commands/input/Input.java index a21df0d..a21df0d 100755..100644 --- a/cmds/input/src/com/android/commands/input/Input.java +++ b/cmds/input/src/com/android/commands/input/Input.java diff --git a/cmds/installd/Android.mk b/cmds/installd/Android.mk index 3e722ea..1dd4ee5 100644 --- a/cmds/installd/Android.mk +++ b/cmds/installd/Android.mk @@ -29,17 +29,12 @@ LOCAL_SRC_FILES := \ $(common_src_files) LOCAL_SHARED_LIBRARIES := \ - libcutils + libcutils \ + libselinux LOCAL_STATIC_LIBRARIES := \ libdiskusage -ifeq ($(HAVE_SELINUX),true) -LOCAL_C_INCLUDES += external/libselinux/include -LOCAL_SHARED_LIBRARIES += libselinux -LOCAL_CFLAGS := -DHAVE_SELINUX -endif # HAVE_SELINUX - LOCAL_MODULE := installd LOCAL_MODULE_TAGS := optional diff --git a/cmds/installd/commands.c b/cmds/installd/commands.c index 387f33d..09d6f89 100644 --- a/cmds/installd/commands.c +++ b/cmds/installd/commands.c @@ -14,13 +14,10 @@ ** limitations under the License. */ -#include <linux/capability.h> +#include <sys/capability.h> #include "installd.h" #include <diskusage/dirsize.h> - -#ifdef HAVE_SELINUX #include <selinux/android.h> -#endif /* Directory records that are used in execution of commands. */ dir_rec_t android_data_dir; @@ -31,7 +28,7 @@ dir_rec_t android_app_lib_dir; dir_rec_t android_media_dir; dir_rec_array_t android_system_dirs; -int install(const char *pkgname, uid_t uid, gid_t gid) +int install(const char *pkgname, uid_t uid, gid_t gid, const char *seinfo) { char pkgdir[PKG_PATH_MAX]; char libsymlink[PKG_PATH_MAX]; @@ -94,14 +91,12 @@ int install(const char *pkgname, uid_t uid, gid_t gid) return -1; } -#ifdef HAVE_SELINUX - if (selinux_android_setfilecon(pkgdir, pkgname, uid) < 0) { + if (selinux_android_setfilecon2(pkgdir, pkgname, seinfo, uid) < 0) { ALOGE("cannot setfilecon dir '%s': %s\n", pkgdir, strerror(errno)); unlink(libsymlink); unlink(pkgdir); - return -1; + return -errno; } -#endif if (chown(pkgdir, uid, gid) < 0) { ALOGE("cannot chown dir '%s': %s\n", pkgdir, strerror(errno)); @@ -189,7 +184,7 @@ int delete_user_data(const char *pkgname, uid_t persona) return delete_dir_contents(pkgdir, 0, "lib"); } -int make_user_data(const char *pkgname, uid_t uid, uid_t persona) +int make_user_data(const char *pkgname, uid_t uid, uid_t persona, const char* seinfo) { char pkgdir[PKG_PATH_MAX]; char applibdir[PKG_PATH_MAX]; @@ -250,21 +245,19 @@ int make_user_data(const char *pkgname, uid_t uid, uid_t persona) return -1; } - if (chown(pkgdir, uid, uid) < 0) { - ALOGE("cannot chown dir '%s': %s\n", pkgdir, strerror(errno)); + if (selinux_android_setfilecon2(pkgdir, pkgname, seinfo, uid) < 0) { + ALOGE("cannot setfilecon dir '%s': %s\n", pkgdir, strerror(errno)); unlink(libsymlink); unlink(pkgdir); return -errno; } -#ifdef HAVE_SELINUX - if (selinux_android_setfilecon(pkgdir, pkgname, uid) < 0) { - ALOGE("cannot setfilecon dir '%s': %s\n", pkgdir, strerror(errno)); + if (chown(pkgdir, uid, uid) < 0) { + ALOGE("cannot chown dir '%s': %s\n", pkgdir, strerror(errno)); unlink(libsymlink); unlink(pkgdir); return -errno; } -#endif return 0; } @@ -324,7 +317,7 @@ int clone_persona_data(uid_t src_persona, uid_t target_persona, int copy) uid = (uid_t) s.st_uid % PER_USER_RANGE; /* Create the directory for the target */ make_user_data(name, uid + target_persona * PER_USER_RANGE, - target_persona); + target_persona, NULL); } } closedir(d); diff --git a/cmds/installd/installd.c b/cmds/installd/installd.c index 21d674a..281aaab 100644 --- a/cmds/installd/installd.c +++ b/cmds/installd/installd.c @@ -14,7 +14,7 @@ ** limitations under the License. */ -#include <linux/capability.h> +#include <sys/capability.h> #include <linux/prctl.h> #include "installd.h" @@ -31,7 +31,7 @@ static int do_ping(char **arg, char reply[REPLY_MAX]) static int do_install(char **arg, char reply[REPLY_MAX]) { - return install(arg[0], atoi(arg[1]), atoi(arg[2])); /* pkgname, uid, gid */ + return install(arg[0], atoi(arg[1]), atoi(arg[2]), arg[3]); /* pkgname, uid, gid, seinfo */ } static int do_dexopt(char **arg, char reply[REPLY_MAX]) @@ -103,7 +103,8 @@ static int do_rm_user_data(char **arg, char reply[REPLY_MAX]) static int do_mk_user_data(char **arg, char reply[REPLY_MAX]) { - return make_user_data(arg[0], atoi(arg[1]), atoi(arg[2])); /* pkgname, uid, userid */ + return make_user_data(arg[0], atoi(arg[1]), atoi(arg[2]), arg[3]); + /* pkgname, uid, userid, seinfo */ } static int do_rm_user(char **arg, char reply[REPLY_MAX]) @@ -134,7 +135,7 @@ struct cmdinfo { struct cmdinfo cmds[] = { { "ping", 0, do_ping }, - { "install", 3, do_install }, + { "install", 4, do_install }, { "dexopt", 3, do_dexopt }, { "movedex", 2, do_move_dex }, { "rmdex", 1, do_rm_dex }, @@ -147,7 +148,7 @@ struct cmdinfo cmds[] = { { "rmuserdata", 2, do_rm_user_data }, { "movefiles", 0, do_movefiles }, { "linklib", 3, do_linklib }, - { "mkuserdata", 3, do_mk_user_data }, + { "mkuserdata", 4, do_mk_user_data }, { "rmuser", 1, do_rm_user }, { "cloneuserdata", 3, do_clone_user_data }, }; diff --git a/cmds/installd/installd.h b/cmds/installd/installd.h index 0500c23..04498ef 100644 --- a/cmds/installd/installd.h +++ b/cmds/installd/installd.h @@ -192,12 +192,12 @@ int ensure_media_user_dirs(userid_t userid); /* commands.c */ -int install(const char *pkgname, uid_t uid, gid_t gid); +int install(const char *pkgname, uid_t uid, gid_t gid, const char *seinfo); int uninstall(const char *pkgname, uid_t persona); int renamepkg(const char *oldpkgname, const char *newpkgname); int fix_uid(const char *pkgname, uid_t uid, gid_t gid); int delete_user_data(const char *pkgname, uid_t persona); -int make_user_data(const char *pkgname, uid_t uid, uid_t persona); +int make_user_data(const char *pkgname, uid_t uid, uid_t persona, const char* seinfo); int delete_persona(uid_t persona); int clone_persona_data(uid_t src_persona, uid_t target_persona, int copy); int delete_cache(const char *pkgname, uid_t persona); diff --git a/cmds/installd/tests/Android.mk b/cmds/installd/tests/Android.mk index 315acdb..c0192f4 100644 --- a/cmds/installd/tests/Android.mk +++ b/cmds/installd/tests/Android.mk @@ -18,13 +18,7 @@ static_libraries := \ libgtest_main c_includes := \ - frameworks/base/cmds/installd \ - bionic \ - bionic/libstdc++/include \ - external/gtest/include \ - external/stlport/stlport - -module_tags := eng tests + frameworks/base/cmds/installd $(foreach file,$(test_src_files), \ $(eval include $(CLEAR_VARS)) \ @@ -33,6 +27,5 @@ $(foreach file,$(test_src_files), \ $(eval LOCAL_SRC_FILES := $(file)) \ $(eval LOCAL_C_INCLUDES := $(c_includes)) \ $(eval LOCAL_MODULE := $(notdir $(file:%.cpp=%))) \ - $(eval LOCAL_MODULE_TAGS := $(module_tags)) \ - $(eval include $(BUILD_EXECUTABLE)) \ + $(eval include $(BUILD_NATIVE_TEST)) \ ) diff --git a/cmds/interrupter/Android.mk b/cmds/interrupter/Android.mk new file mode 100644 index 0000000..e324627 --- /dev/null +++ b/cmds/interrupter/Android.mk @@ -0,0 +1,21 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := \ + interrupter.c +LOCAL_MODULE := interrupter +LOCAL_MODULE_TAGS := eng tests +LOCAL_LDFLAGS := -ldl + +include $(BUILD_SHARED_LIBRARY) + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := \ + interrupter.c +LOCAL_MODULE := interrupter +LOCAL_MODULE_TAGS := eng tests +LOCAL_LDFLAGS := -ldl + +include $(BUILD_HOST_SHARED_LIBRARY)
\ No newline at end of file diff --git a/cmds/interrupter/interrupter.c b/cmds/interrupter/interrupter.c new file mode 100644 index 0000000..ae55515 --- /dev/null +++ b/cmds/interrupter/interrupter.c @@ -0,0 +1,53 @@ +/* + * Copyright 2012, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +/** + * The probability of a syscall failing from 0.0 to 1.0 + */ +#define PROBABILITY 0.9 + + + +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> + +/* for various intercepted calls */ +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/stat.h> +#include <fcntl.h> + +/* For builds on glibc */ +#define __USE_GNU +#include <dlfcn.h> + +#include "interrupter.h" + +static int probability = PROBABILITY * RAND_MAX; + +static int maybe_interrupt() { + if (rand() < probability) { + return 1; + } + return 0; +} + +DEFINE_INTERCEPT(read, ssize_t, int, void*, size_t); +DEFINE_INTERCEPT(write, ssize_t, int, const void*, size_t); +DEFINE_INTERCEPT(accept, int, int, struct sockaddr*, socklen_t*); +DEFINE_INTERCEPT(creat, int, const char*, mode_t); diff --git a/cmds/interrupter/interrupter.h b/cmds/interrupter/interrupter.h new file mode 100644 index 0000000..9ad0277 --- /dev/null +++ b/cmds/interrupter/interrupter.h @@ -0,0 +1,79 @@ +/* + * Copyright 2012, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define CONCATENATE(arg1, arg2) CONCATENATE1(arg1, arg2) +#define CONCATENATE1(arg1, arg2) CONCATENATE2(arg1, arg2) +#define CONCATENATE2(arg1, arg2) arg1##arg2 + +#define INTERRUPTER(sym) \ + if (real_##sym == NULL) \ + __init_##sym(); \ + if (maybe_interrupt()) { \ + errno = EINTR; \ + return -1; \ + } + +#define CALL_FUNCTION_1(sym, ret, type1) \ +ret (*real_##sym)(type1) = NULL; \ +ret sym(type1 arg1) { \ + INTERRUPTER(sym) \ + return real_##sym(arg1); \ +} + +#define CALL_FUNCTION_2(sym, ret, type1, type2) \ +ret (*real_##sym)(type1, type2) = NULL; \ +ret sym(type1 arg1, type2 arg2) { \ + INTERRUPTER(sym) \ + return real_##sym(arg1, arg2); \ +} + +#define CALL_FUNCTION_3(sym, ret, type1, type2, type3) \ +ret (*real_##sym)(type1, type2, type3) = NULL; \ +ret sym(type1 arg1, type2 arg2, type3 arg3) { \ + INTERRUPTER(sym) \ + return real_##sym(arg1, arg2, arg3); \ +} + +#define CALL_FUNCTION_4(sym, ret, type1, type2, type3, type4) \ +ret (*real_##sym)(type1, type2, type3, type4) = NULL; \ +ret sym(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \ + INTERRUPTER(sym) \ + return real_##sym(arg1, arg2, arg3, arg4); \ +} + +#define CALL_FUNCTION_5(sym, ret, type1, type2, type3, type4, type5) \ +ret (*real_##sym)(type1, type2, type3, type4, type5) = NULL; \ +ret sym(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) { \ + INTERRUPTER(sym) \ + return real_##sym(arg1, arg2, arg3, arg4, arg5); \ +} + +#define DEFINE_INTERCEPT_N(N, sym, ret, ...) \ +static void __init_##sym(void); \ +CONCATENATE(CALL_FUNCTION_, N)(sym, ret, __VA_ARGS__) \ +static void __init_##sym(void) { \ + real_##sym = dlsym(RTLD_NEXT, #sym); \ + if (real_##sym == NULL) { \ + fprintf(stderr, "Error hooking " #sym ": %s\n", dlerror()); \ + } \ +} + +#define INTERCEPT_NARG(...) INTERCEPT_NARG_N(__VA_ARGS__, INTERCEPT_RSEQ_N()) +#define INTERCEPT_NARG_N(...) INTERCEPT_ARG_N(__VA_ARGS__) +#define INTERCEPT_ARG_N(_1, _2, _3, _4, _5, _6, _7, _8, N, ...) N +#define INTERCEPT_RSEQ_N() 8, 7, 6, 5, 4, 3, 2, 1, 0 + +#define DEFINE_INTERCEPT(sym, ret, ...) DEFINE_INTERCEPT_N(INTERCEPT_NARG(__VA_ARGS__), sym, ret, __VA_ARGS__) diff --git a/cmds/servicemanager/service_manager.c b/cmds/servicemanager/service_manager.c index 71e840e..c563a82 100644 --- a/cmds/servicemanager/service_manager.c +++ b/cmds/servicemanager/service_manager.c @@ -47,6 +47,7 @@ static struct { { AID_RADIO, "simphonebook" }, { AID_MEDIA, "common_time.clock" }, { AID_MEDIA, "common_time.config" }, + { AID_KEYSTORE, "android.security.keystore" }, }; void *svcmgr_handle; |