From e5349196b21d9ecc45ac59171584c4b136238bbd Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Mon, 24 Apr 2023 23:54:59 +0000 Subject: [PATCH] init: V devices need to specify user This also specifies user on an adbd service declaration which was missing before. It seems that certain services are declared mulitple times. Fixes: 276813155 Test: boot (on CF, the only V device in the tree) Test: remove 'user' specification and see error Change-Id: I138f3ace72d46f221551ad61e75ba4c01632da59 --- init/init_test.cpp | 28 ++++++++++++++++++++++++++++ init/service_parser.cpp | 10 ++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/init/init_test.cpp b/init/init_test.cpp index 0fc3ffcf2..7e8513bfc 100644 --- a/init/init_test.cpp +++ b/init/init_test.cpp @@ -180,9 +180,11 @@ TEST(init, OverrideService) { std::string init_script = R"init( service A something class first + user nobody service A something class second + user nobody override )init"; @@ -610,6 +612,31 @@ TEST(init, LazilyLoadedActionsCanBeTriggeredByTheNextTrigger) { EXPECT_EQ(2, num_executed); } +TEST(init, RejectsNoUserStartingInV) { + std::string init_script = + R"init( +service A something + class first +)init"; + + TemporaryFile tf; + ASSERT_TRUE(tf.fd != -1); + ASSERT_TRUE(android::base::WriteStringToFd(init_script, tf.fd)); + + ServiceList service_list; + Parser parser; + parser.AddSectionParser("service", + std::make_unique(&service_list, nullptr, std::nullopt)); + + ASSERT_TRUE(parser.ParseConfig(tf.path)); + + if (GetIntProperty("ro.vendor.api_level", 0) > __ANDROID_API_U__) { + ASSERT_EQ(1u, parser.parse_error_count()); + } else { + ASSERT_EQ(0u, parser.parse_error_count()); + } +} + TEST(init, RejectsCriticalAndOneshotService) { if (GetIntProperty("ro.product.first_api_level", 10000) < 30) { GTEST_SKIP() << "Test only valid for devices launching with R or later"; @@ -619,6 +646,7 @@ TEST(init, RejectsCriticalAndOneshotService) { R"init( service A something class first + user root critical oneshot )init"; diff --git a/init/service_parser.cpp b/init/service_parser.cpp index d89664c5b..d46e1f754 100644 --- a/init/service_parser.cpp +++ b/init/service_parser.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -678,8 +679,13 @@ Result ServiceParser::EndSection() { } if (service_->proc_attr_.parsed_uid == std::nullopt) { - LOG(WARNING) << "No user specified for service '" << service_->name() - << "'. Defaults to root."; + if (android::base::GetIntProperty("ro.vendor.api_level", 0) > __ANDROID_API_U__) { + return Error() << "No user specified for service '" << service_->name() + << "'. Defaults to root."; + } else { + LOG(WARNING) << "No user specified for service '" << service_->name() + << "'. Defaults to root."; + } } if (interface_inheritance_hierarchy_) {