@@ -764,6 +764,172 @@ TEST(activation_transaction_rejects_symlink_candidate_target_and_parent) {
764764 PASS ();
765765}
766766
767+ #if (defined(__APPLE__ ) || defined(__linux__ )) && defined(CBM_ENABLE_TEST_SEAMS )
768+ /* These tests reach the actual shared alias helper independently of the home
769+ * root check. Only the link UID is substituted: resolving and inspecting the
770+ * target still use the filesystem, without requiring privileged chown calls. */
771+ TEST (activation_transaction_alias_rejects_untrusted_link_owner ) {
772+ char root [ACTIVATION_TEST_PATH_CAP ];
773+ char target [ACTIVATION_TEST_PATH_CAP ];
774+ char link [ACTIVATION_TEST_PATH_CAP ];
775+ char resolved [4096 ];
776+ char expected [4096 ];
777+ ASSERT_TRUE (activation_test_fixture (root ));
778+ ASSERT_TRUE (activation_test_path (target , root , "target" ));
779+ ASSERT_TRUE (activation_test_path (link , root , "alias" ));
780+ ASSERT_TRUE (cbm_mkdir_p (target , 0700 ));
781+ ASSERT_EQ (symlink (target , link ), 0 );
782+ ASSERT_NOT_NULL (realpath (target , resolved ));
783+ ASSERT_TRUE (activation_test_path (expected , resolved , "bin/cbm" ));
784+ unsigned long self = (unsigned long )geteuid ();
785+ unsigned long other = self == 0 ? 1U : 0U ;
786+
787+ char * trusted =
788+ cbm_activation_transaction_map_alias_for_testing (link , self , self , false, "/bin/cbm" );
789+ char * untrusted =
790+ cbm_activation_transaction_map_alias_for_testing (link , other , self , false, "/bin/cbm" );
791+ bool trusted_maps_target = trusted && strcmp (trusted , expected ) == 0 ;
792+ bool untrusted_refused = untrusted == NULL ;
793+ free (trusted );
794+ free (untrusted );
795+ int unlink_status = unlink (link );
796+ int cleanup_status = th_rmtree (root );
797+
798+ ASSERT_TRUE (trusted_maps_target );
799+ ASSERT_TRUE (untrusted_refused );
800+ ASSERT_EQ (unlink_status , 0 );
801+ ASSERT_EQ (cleanup_status , 0 );
802+ PASS ();
803+ }
804+
805+ TEST (activation_transaction_alias_allows_own_target_only_when_enabled ) {
806+ char root [ACTIVATION_TEST_PATH_CAP ];
807+ char target [ACTIVATION_TEST_PATH_CAP ];
808+ char link [ACTIVATION_TEST_PATH_CAP ];
809+ char resolved [4096 ];
810+ char expected [4096 ];
811+ ASSERT_TRUE (activation_test_fixture (root ));
812+ ASSERT_TRUE (activation_test_path (target , root , "target" ));
813+ ASSERT_TRUE (activation_test_path (link , root , "alias" ));
814+ ASSERT_TRUE (cbm_mkdir_p (target , 0700 ));
815+ ASSERT_EQ (symlink (target , link ), 0 );
816+ ASSERT_NOT_NULL (realpath (target , resolved ));
817+ ASSERT_TRUE (activation_test_path (expected , resolved , "bin/cbm" ));
818+ unsigned long self = (unsigned long )geteuid ();
819+ unsigned long trusted_owner = self == 0 ? 1U : 0U ;
820+ struct stat target_status ;
821+ ASSERT_EQ (lstat (resolved , & target_status ), 0 );
822+ ASSERT_EQ ((unsigned long )target_status .st_uid , self );
823+ ASSERT_TRUE ((unsigned long )target_status .st_uid != trusted_owner );
824+
825+ char * strict = cbm_activation_transaction_map_alias_for_testing (
826+ link , trusted_owner , trusted_owner , false, "/bin/cbm" );
827+ char * own = cbm_activation_transaction_map_alias_for_testing (link , trusted_owner , trusted_owner ,
828+ true, "/bin/cbm" );
829+ bool strict_refused = strict == NULL ;
830+ bool own_maps_target = own && strcmp (own , expected ) == 0 ;
831+ free (strict );
832+ free (own );
833+ int unlink_status = unlink (link );
834+ int cleanup_status = th_rmtree (root );
835+
836+ ASSERT_TRUE (strict_refused );
837+ ASSERT_TRUE (own_maps_target );
838+ ASSERT_EQ (unlink_status , 0 );
839+ ASSERT_EQ (cleanup_status , 0 );
840+ PASS ();
841+ }
842+ #endif
843+
844+ /* #2306: managed Linux hosts keep /home a real directory and point the
845+ * per-user entry elsewhere (/home/alice -> /local/home/alice). Root owns that
846+ * entry, so it is trusted like the #2175 /home alias; the seam stands a
847+ * fixture tree in for /home and the test account in for root. Every status is
848+ * captured before the seam is reset so a failure cannot leak into the
849+ * following tests. */
850+ TEST (activation_transaction_follows_trusted_per_user_home_entry ) {
851+ #if defined(__linux__ ) && defined(CBM_ENABLE_TEST_SEAMS )
852+ char root [ACTIVATION_TEST_PATH_CAP ];
853+ char home [ACTIVATION_TEST_PATH_CAP ];
854+ char entry [ACTIVATION_TEST_PATH_CAP ];
855+ char relocated [ACTIVATION_TEST_PATH_CAP ];
856+ char relocated_bin [ACTIVATION_TEST_PATH_CAP ];
857+ char relocated_target [ACTIVATION_TEST_PATH_CAP ];
858+ char target [ACTIVATION_TEST_PATH_CAP ];
859+ ASSERT_TRUE (activation_test_fixture (root ));
860+ ASSERT_TRUE (activation_test_path (home , root , "home" ));
861+ ASSERT_TRUE (activation_test_path (entry , home , "alice" ));
862+ ASSERT_TRUE (activation_test_path (relocated , root , "local-alice" ));
863+ ASSERT_TRUE (activation_test_path (relocated_bin , relocated , "bin" ));
864+ ASSERT_TRUE (activation_test_path (relocated_target , relocated_bin , "cbm" ));
865+ ASSERT_TRUE (activation_test_path (target , entry , "bin/cbm" ));
866+ ASSERT_TRUE (cbm_mkdir_p (home , 0755 ));
867+ ASSERT_EQ (chmod (home , 0755 ), 0 );
868+ ASSERT_TRUE (cbm_mkdir_p (relocated_bin , 0700 ));
869+ ASSERT_EQ (symlink (relocated , entry ), 0 );
870+ unsigned long self = (unsigned long )geteuid ();
871+
872+ /* Without the seam the entry is an ordinary user symlink: refused. */
873+ cbm_activation_transaction_t * transaction = NULL ;
874+ cbm_activation_transaction_status_t untrusted_status = cbm_activation_transaction_stage_bytes (
875+ target , "candidate" , strlen ("candidate" ), & transaction );
876+ bool untrusted_created = transaction != NULL ;
877+ (void )cbm_activation_transaction_close (& transaction );
878+
879+ /* A home root belonging to another owner is refused before entry checks. */
880+ cbm_activation_transaction_set_home_root_for_testing (home , self + 1U );
881+ cbm_activation_transaction_status_t foreign_owner_status =
882+ cbm_activation_transaction_stage_bytes (target , "candidate" , strlen ("candidate" ),
883+ & transaction );
884+ bool foreign_owner_created = transaction != NULL ;
885+ (void )cbm_activation_transaction_close (& transaction );
886+
887+ /* A home root others can write could have its entry swapped: refused. */
888+ cbm_activation_transaction_set_home_root_for_testing (home , self );
889+ (void )chmod (home , 0775 );
890+ cbm_activation_transaction_status_t writable_home_status =
891+ cbm_activation_transaction_stage_bytes (target , "candidate" , strlen ("candidate" ),
892+ & transaction );
893+ bool writable_home_created = transaction != NULL ;
894+ (void )cbm_activation_transaction_close (& transaction );
895+ (void )chmod (home , 0755 );
896+
897+ /* Trusted root, trusted entry: staged and committed into the target. */
898+ cbm_activation_transaction_status_t trusted_status = cbm_activation_transaction_stage_bytes (
899+ target , "candidate" , strlen ("candidate" ), & transaction );
900+ cbm_activation_transaction_status_t commit_status =
901+ transaction ? cbm_activation_transaction_commit (transaction , NULL , NULL )
902+ : CBM_ACTIVATION_TRANSACTION_INVALID_STATE ;
903+ cbm_activation_transaction_status_t finalize_status =
904+ transaction ? cbm_activation_transaction_finalize (transaction )
905+ : CBM_ACTIVATION_TRANSACTION_INVALID_STATE ;
906+ cbm_activation_transaction_status_t close_status =
907+ cbm_activation_transaction_close (& transaction );
908+ cbm_activation_transaction_set_home_root_for_testing (NULL , 0 );
909+
910+ char contents [ACTIVATION_TEST_CONTENT_CAP ] = "" ;
911+ bool published = activation_test_read (relocated_target , contents );
912+ int unlink_status = unlink (entry );
913+ int cleanup_status = th_rmtree (root );
914+
915+ ASSERT_EQ (untrusted_status , CBM_ACTIVATION_TRANSACTION_IO );
916+ ASSERT_FALSE (untrusted_created );
917+ ASSERT_EQ (foreign_owner_status , CBM_ACTIVATION_TRANSACTION_IO );
918+ ASSERT_FALSE (foreign_owner_created );
919+ ASSERT_EQ (writable_home_status , CBM_ACTIVATION_TRANSACTION_IO );
920+ ASSERT_FALSE (writable_home_created );
921+ ASSERT_EQ (trusted_status , CBM_ACTIVATION_TRANSACTION_OK );
922+ ASSERT_EQ (commit_status , CBM_ACTIVATION_TRANSACTION_OK );
923+ ASSERT_EQ (finalize_status , CBM_ACTIVATION_TRANSACTION_OK );
924+ ASSERT_EQ (close_status , CBM_ACTIVATION_TRANSACTION_OK );
925+ ASSERT_TRUE (published );
926+ ASSERT_STR_EQ (contents , "candidate" );
927+ ASSERT_EQ (unlink_status , 0 );
928+ ASSERT_EQ (cleanup_status , 0 );
929+ #endif
930+ PASS ();
931+ }
932+
767933TEST (activation_transaction_fails_closed_if_target_directory_is_replaced ) {
768934 char root [ACTIVATION_TEST_PATH_CAP ];
769935 char active [ACTIVATION_TEST_PATH_CAP ];
@@ -1089,6 +1255,11 @@ SUITE(activation_transaction) {
10891255 RUN_TEST (activation_transaction_admits_group_writable_ancestor );
10901256 RUN_TEST (activation_transaction_rejects_windows_callback_allow_directory_ace );
10911257 RUN_TEST (activation_transaction_rejects_symlink_candidate_target_and_parent );
1258+ #if (defined(__APPLE__ ) || defined(__linux__ )) && defined(CBM_ENABLE_TEST_SEAMS )
1259+ RUN_TEST (activation_transaction_alias_rejects_untrusted_link_owner );
1260+ RUN_TEST (activation_transaction_alias_allows_own_target_only_when_enabled );
1261+ #endif
1262+ RUN_TEST (activation_transaction_follows_trusted_per_user_home_entry );
10921263 RUN_TEST (activation_transaction_fails_closed_if_target_directory_is_replaced );
10931264 RUN_TEST (activation_transaction_does_not_replace_target_created_at_publish_boundary );
10941265 RUN_TEST (activation_transaction_rejects_macos_mutating_extended_acl );
0 commit comments