Skip to content

Commit 63d6385

Browse files
committed
process_open_mem: add mode argument
Write access to the process memory is not always necessary. Add `mode` argument to `kpatch_process_open_mem` to reflect that. Signed-off-by: Pavel Boldin <[email protected]>
1 parent 0ef7eaf commit 63d6385

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/kpatch_process.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -618,12 +618,12 @@ process_has_thread_pid(kpatch_process_t *proc, int pid)
618618
}
619619

620620
int
621-
kpatch_process_mem_open(kpatch_process_t *proc)
621+
kpatch_process_mem_open(kpatch_process_t *proc, int mode)
622622
{
623623
char path[sizeof("/proc/0123456789/mem")];
624624

625625
snprintf(path, sizeof(path), "/proc/%d/mem", proc->pid);
626-
proc->memfd = open(path, O_RDWR);
626+
proc->memfd = open(path, mode == MEM_WRITE ? O_RDWR : O_RDONLY);
627627
if (proc->memfd < 0) {
628628
kplogerror("can't open /proc/%d/mem", proc->pid);
629629
return -1;
@@ -638,7 +638,7 @@ kpatch_process_attach(kpatch_process_t *proc)
638638
int *pids = NULL, ret;
639639
size_t i, npids = 0, alloc = 0, prevnpids = 0, nattempts;
640640

641-
if (kpatch_process_mem_open(proc) < 0)
641+
if (kpatch_process_mem_open(proc, MEM_WRITE) < 0)
642642
return -1;
643643

644644
for (nattempts = 0; nattempts < max_attach_attempts; nattempts++) {

src/kpatch_process.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,13 @@ int
174174
kpatch_process_map_object_files(kpatch_process_t *proc);
175175
int
176176
kpatch_process_attach(kpatch_process_t *proc);
177+
178+
enum {
179+
MEM_READ,
180+
MEM_WRITE,
181+
};
177182
int
178-
kpatch_process_mem_open(kpatch_process_t *proc);
183+
kpatch_process_mem_open(kpatch_process_t *proc, int mode);
179184
int
180185
kpatch_process_load_libraries(kpatch_process_t *proc);
181186
int

src/kpatch_user.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,7 @@ process_info(int pid, void *_data)
15571557
if (ret < 0)
15581558
return -1;
15591559

1560-
ret = kpatch_process_mem_open(proc);
1560+
ret = kpatch_process_mem_open(proc, MEM_READ);
15611561
if (ret < 0)
15621562
goto out;
15631563

0 commit comments

Comments
 (0)