Skip to content

Commit 3a4db72

Browse files
committed
coredump: add coredump_write()
to encapsulate that logic simplifying vfs_coredump() even further. Link: https://lore.kernel.org/20250612-work-coredump-massage-v1-16-315c0c34ba94@kernel.org Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent d6527db commit 3a4db72

1 file changed

Lines changed: 34 additions & 22 deletions

File tree

fs/coredump.c

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ struct core_name {
9595
char *corename;
9696
int used, size;
9797
unsigned int core_pipe_limit;
98+
bool core_dumped;
9899
enum coredump_type_t core_type;
99100
u64 mask;
100101
};
@@ -247,6 +248,7 @@ static bool coredump_parse(struct core_name *cn, struct coredump_params *cprm,
247248
cn->used = 0;
248249
cn->corename = NULL;
249250
cn->core_pipe_limit = 0;
251+
cn->core_dumped = false;
250252
if (*pat_ptr == '|')
251253
cn->core_type = COREDUMP_PIPE;
252254
else if (*pat_ptr == '@')
@@ -1037,6 +1039,34 @@ static bool coredump_pipe(struct core_name *cn, struct coredump_params *cprm,
10371039
return true;
10381040
}
10391041

1042+
static bool coredump_write(struct core_name *cn,
1043+
struct coredump_params *cprm,
1044+
struct linux_binfmt *binfmt)
1045+
{
1046+
1047+
if (dump_interrupted())
1048+
return true;
1049+
1050+
if (!dump_vma_snapshot(cprm))
1051+
return false;
1052+
1053+
file_start_write(cprm->file);
1054+
cn->core_dumped = binfmt->core_dump(cprm);
1055+
/*
1056+
* Ensures that file size is big enough to contain the current
1057+
* file postion. This prevents gdb from complaining about
1058+
* a truncated file if the last "write" to the file was
1059+
* dump_skip.
1060+
*/
1061+
if (cprm->to_skip) {
1062+
cprm->to_skip--;
1063+
dump_emit(cprm, "", 1);
1064+
}
1065+
file_end_write(cprm->file);
1066+
free_vma_snapshot(cprm);
1067+
return true;
1068+
}
1069+
10401070
void vfs_coredump(const kernel_siginfo_t *siginfo)
10411071
{
10421072
struct core_state core_state;
@@ -1048,7 +1078,6 @@ void vfs_coredump(const kernel_siginfo_t *siginfo)
10481078
int retval = 0;
10491079
size_t *argv = NULL;
10501080
int argc = 0;
1051-
bool core_dumped = false;
10521081
struct coredump_params cprm = {
10531082
.siginfo = siginfo,
10541083
.limit = rlimit(RLIMIT_CORE),
@@ -1123,31 +1152,14 @@ void vfs_coredump(const kernel_siginfo_t *siginfo)
11231152
if (retval)
11241153
goto close_fail;
11251154

1126-
if ((cn.mask & COREDUMP_KERNEL) && !dump_interrupted()) {
1127-
if (!dump_vma_snapshot(&cprm))
1128-
goto close_fail;
1129-
1130-
file_start_write(cprm.file);
1131-
core_dumped = binfmt->core_dump(&cprm);
1132-
/*
1133-
* Ensures that file size is big enough to contain the current
1134-
* file postion. This prevents gdb from complaining about
1135-
* a truncated file if the last "write" to the file was
1136-
* dump_skip.
1137-
*/
1138-
if (cprm.to_skip) {
1139-
cprm.to_skip--;
1140-
dump_emit(&cprm, "", 1);
1141-
}
1142-
file_end_write(cprm.file);
1143-
free_vma_snapshot(&cprm);
1144-
}
1155+
if ((cn.mask & COREDUMP_KERNEL) && !coredump_write(&cn, &cprm, binfmt))
1156+
goto close_fail;
11451157

11461158
coredump_sock_shutdown(cprm.file);
11471159

11481160
/* Let the parent know that a coredump was generated. */
11491161
if (cn.mask & COREDUMP_USERSPACE)
1150-
core_dumped = true;
1162+
cn.core_dumped = true;
11511163

11521164
/*
11531165
* When core_pipe_limit is set we wait for the coredump server
@@ -1179,7 +1191,7 @@ void vfs_coredump(const kernel_siginfo_t *siginfo)
11791191
fail_unlock:
11801192
kfree(argv);
11811193
kfree(cn.corename);
1182-
coredump_finish(core_dumped);
1194+
coredump_finish(cn.core_dumped);
11831195
revert_creds(old_cred);
11841196
fail_creds:
11851197
put_cred(cred);

0 commit comments

Comments
 (0)