File tree Expand file tree Collapse file tree 2 files changed +20
-6
lines changed Expand file tree Collapse file tree 2 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -622,6 +622,10 @@ kpatch_process_mem_open(kpatch_process_t *proc, int mode)
622622{
623623 char path [sizeof ("/proc/0123456789/mem" )];
624624
625+ if (proc -> memfd >= 0 ) {
626+ close (proc -> memfd );
627+ }
628+
625629 snprintf (path , sizeof (path ), "/proc/%d/mem" , proc -> pid );
626630 proc -> memfd = open (path , mode == MEM_WRITE ? O_RDWR : O_RDONLY );
627631 if (proc -> memfd < 0 ) {
@@ -883,6 +887,12 @@ kpatch_process_load_libraries(kpatch_process_t *proc)
883887 if (!proc -> is_just_started )
884888 return 0 ;
885889
890+ ret = kpatch_process_attach (proc );
891+ if (ret < 0 ) {
892+ kperr ("unable to attach to just started process\n" );
893+ return -1 ;
894+ }
895+
886896 if (proc -> send_fd != -1 ) {
887897 ret = kpatch_process_kickstart_execve_wrapper (proc );
888898 if (ret < 0 ) {
Original file line number Diff line number Diff line change @@ -1010,7 +1010,7 @@ static int process_patch(int pid, void *_data)
10101010
10111011 kpatch_process_print_short (proc );
10121012
1013- ret = kpatch_process_attach (proc );
1013+ ret = kpatch_process_mem_open (proc , MEM_READ );
10141014 if (ret < 0 )
10151015 goto out_free ;
10161016
@@ -1030,11 +1030,10 @@ static int process_patch(int pid, void *_data)
10301030 goto out_free ;
10311031
10321032 /*
1033- * For each object file that we want to patch (either binary
1034- * itself or shared library) we need its ELF structure
1035- * to perform relocations. Because we know uniq BuildID of
1036- * the object the section addresses stored in the patch
1037- * are valid for the original object.
1033+ * For each object file that we want to patch (either binary itself or
1034+ * shared library) we need its ELF structure to perform relocations.
1035+ * Because we know uniq BuildID of the object the section addresses
1036+ * stored in the patch are valid for the original object.
10381037 */
10391038 ret = kpatch_process_map_object_files (proc );
10401039 if (ret < 0 )
@@ -1047,6 +1046,11 @@ static int process_patch(int pid, void *_data)
10471046 if (ret <= 0 )
10481047 goto out_free ;
10491048
1049+ /* Finally, attach to process */
1050+ ret = kpatch_process_attach (proc );
1051+ if (ret < 0 )
1052+ goto out_free ;
1053+
10501054 ret = kpatch_coroutines_find (proc );
10511055 if (ret < 0 )
10521056 goto out_free ;
You can’t perform that action at this time.
0 commit comments