1414** limitations under the License.
1515*/
1616
17+ #include <linux/capability.h>
1718#include "installd.h"
1819#include <diskusage/dirsize.h>
1920
@@ -665,16 +666,16 @@ int dexopt(const char *apk_path, uid_t uid, int is_public)
665666 ALOGE ("dexopt cannot open '%s' for output\n" , dex_path );
666667 goto fail ;
667668 }
668- if (fchown (odex_fd , AID_SYSTEM , uid ) < 0 ) {
669- ALOGE ("dexopt cannot chown '%s'\n" , dex_path );
670- goto fail ;
671- }
672669 if (fchmod (odex_fd ,
673670 S_IRUSR |S_IWUSR |S_IRGRP |
674671 (is_public ? S_IROTH : 0 )) < 0 ) {
675672 ALOGE ("dexopt cannot chmod '%s'\n" , dex_path );
676673 goto fail ;
677674 }
675+ if (fchown (odex_fd , AID_SYSTEM , uid ) < 0 ) {
676+ ALOGE ("dexopt cannot chown '%s'\n" , dex_path );
677+ goto fail ;
678+ }
678679
679680 ALOGV ("DexInv: --- BEGIN '%s' ---\n" , apk_path );
680681
@@ -690,13 +691,23 @@ int dexopt(const char *apk_path, uid_t uid, int is_public)
690691 ALOGE ("setuid(%d) during dexopt\n" , uid );
691692 exit (65 );
692693 }
694+ // drop capabilities
695+ struct __user_cap_header_struct capheader ;
696+ struct __user_cap_data_struct capdata [2 ];
697+ memset (& capheader , 0 , sizeof (capheader ));
698+ memset (& capdata , 0 , sizeof (capdata ));
699+ capheader .version = _LINUX_CAPABILITY_VERSION_3 ;
700+ if (capset (& capheader , & capdata [0 ]) < 0 ) {
701+ ALOGE ("capset failed: %s\n" , strerror (errno ));
702+ exit (66 );
703+ }
693704 if (flock (odex_fd , LOCK_EX | LOCK_NB ) != 0 ) {
694705 ALOGE ("flock(%s) failed: %s\n" , dex_path , strerror (errno ));
695- exit (66 );
706+ exit (67 );
696707 }
697708
698709 run_dexopt (zip_fd , odex_fd , apk_path , dexopt_flags );
699- exit (67 ); /* only get here on exec failure */
710+ exit (68 ); /* only get here on exec failure */
700711 } else {
701712 res = wait_dexopt (pid , apk_path );
702713 if (res != 0 ) {
0 commit comments