mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	coredump: make coredump_parse() return bool
There's no point in returning negative error values. They will never be seen by anyone. Link: https://lore.kernel.org/20250612-work-coredump-massage-v1-2-315c0c34ba94@kernel.org Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
		
							parent
							
								
									fb4366ba8f
								
							
						
					
					
						commit
						a5715af549
					
				
					 1 changed files with 16 additions and 17 deletions
				
			
		| 
						 | 
					@ -230,7 +230,7 @@ static int cn_print_exe_file(struct core_name *cn, bool name_only)
 | 
				
			||||||
 * into corename, which must have space for at least CORENAME_MAX_SIZE
 | 
					 * into corename, which must have space for at least CORENAME_MAX_SIZE
 | 
				
			||||||
 * bytes plus one byte for the zero terminator.
 | 
					 * bytes plus one byte for the zero terminator.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
static int coredump_parse(struct core_name *cn, struct coredump_params *cprm,
 | 
					static bool coredump_parse(struct core_name *cn, struct coredump_params *cprm,
 | 
				
			||||||
			   size_t **argv, int *argc)
 | 
								   size_t **argv, int *argc)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	const struct cred *cred = current_cred();
 | 
						const struct cred *cred = current_cred();
 | 
				
			||||||
| 
						 | 
					@ -251,7 +251,7 @@ static int coredump_parse(struct core_name *cn, struct coredump_params *cprm,
 | 
				
			||||||
	else
 | 
						else
 | 
				
			||||||
		cn->core_type = COREDUMP_FILE;
 | 
							cn->core_type = COREDUMP_FILE;
 | 
				
			||||||
	if (expand_corename(cn, core_name_size))
 | 
						if (expand_corename(cn, core_name_size))
 | 
				
			||||||
		return -ENOMEM;
 | 
							return false;
 | 
				
			||||||
	cn->corename[0] = '\0';
 | 
						cn->corename[0] = '\0';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	switch (cn->core_type) {
 | 
						switch (cn->core_type) {
 | 
				
			||||||
| 
						 | 
					@ -259,33 +259,33 @@ static int coredump_parse(struct core_name *cn, struct coredump_params *cprm,
 | 
				
			||||||
		int argvs = sizeof(core_pattern) / 2;
 | 
							int argvs = sizeof(core_pattern) / 2;
 | 
				
			||||||
		(*argv) = kmalloc_array(argvs, sizeof(**argv), GFP_KERNEL);
 | 
							(*argv) = kmalloc_array(argvs, sizeof(**argv), GFP_KERNEL);
 | 
				
			||||||
		if (!(*argv))
 | 
							if (!(*argv))
 | 
				
			||||||
			return -ENOMEM;
 | 
								return false;
 | 
				
			||||||
		(*argv)[(*argc)++] = 0;
 | 
							(*argv)[(*argc)++] = 0;
 | 
				
			||||||
		++pat_ptr;
 | 
							++pat_ptr;
 | 
				
			||||||
		if (!(*pat_ptr))
 | 
							if (!(*pat_ptr))
 | 
				
			||||||
			return -ENOMEM;
 | 
								return false;
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	case COREDUMP_SOCK: {
 | 
						case COREDUMP_SOCK: {
 | 
				
			||||||
		/* skip the @ */
 | 
							/* skip the @ */
 | 
				
			||||||
		pat_ptr++;
 | 
							pat_ptr++;
 | 
				
			||||||
		if (!(*pat_ptr))
 | 
							if (!(*pat_ptr))
 | 
				
			||||||
			return -ENOMEM;
 | 
								return false;
 | 
				
			||||||
		if (*pat_ptr == '@') {
 | 
							if (*pat_ptr == '@') {
 | 
				
			||||||
			pat_ptr++;
 | 
								pat_ptr++;
 | 
				
			||||||
			if (!(*pat_ptr))
 | 
								if (!(*pat_ptr))
 | 
				
			||||||
				return -ENOMEM;
 | 
									return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			cn->core_type = COREDUMP_SOCK_REQ;
 | 
								cn->core_type = COREDUMP_SOCK_REQ;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		err = cn_printf(cn, "%s", pat_ptr);
 | 
							err = cn_printf(cn, "%s", pat_ptr);
 | 
				
			||||||
		if (err)
 | 
							if (err)
 | 
				
			||||||
			return err;
 | 
								return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* Require absolute paths. */
 | 
							/* Require absolute paths. */
 | 
				
			||||||
		if (cn->corename[0] != '/')
 | 
							if (cn->corename[0] != '/')
 | 
				
			||||||
			return -EINVAL;
 | 
								return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/*
 | 
							/*
 | 
				
			||||||
		 * Ensure we can uses spaces to indicate additional
 | 
							 * Ensure we can uses spaces to indicate additional
 | 
				
			||||||
| 
						 | 
					@ -293,7 +293,7 @@ static int coredump_parse(struct core_name *cn, struct coredump_params *cprm,
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		if (strchr(cn->corename, ' ')) {
 | 
							if (strchr(cn->corename, ' ')) {
 | 
				
			||||||
			coredump_report_failure("Coredump socket may not %s contain spaces", cn->corename);
 | 
								coredump_report_failure("Coredump socket may not %s contain spaces", cn->corename);
 | 
				
			||||||
			return -EINVAL;
 | 
								return false;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/*
 | 
							/*
 | 
				
			||||||
| 
						 | 
					@ -303,13 +303,13 @@ static int coredump_parse(struct core_name *cn, struct coredump_params *cprm,
 | 
				
			||||||
		 * via /proc/<pid>, using the SO_PEERPIDFD to guard
 | 
							 * via /proc/<pid>, using the SO_PEERPIDFD to guard
 | 
				
			||||||
		 * against pid recycling when opening /proc/<pid>.
 | 
							 * against pid recycling when opening /proc/<pid>.
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		return 0;
 | 
							return true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	case COREDUMP_FILE:
 | 
						case COREDUMP_FILE:
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		WARN_ON_ONCE(true);
 | 
							WARN_ON_ONCE(true);
 | 
				
			||||||
		return -EINVAL;
 | 
							return false;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Repeat as long as we have more pattern to process and more output
 | 
						/* Repeat as long as we have more pattern to process and more output
 | 
				
			||||||
| 
						 | 
					@ -447,7 +447,7 @@ static int coredump_parse(struct core_name *cn, struct coredump_params *cprm,
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (err)
 | 
							if (err)
 | 
				
			||||||
			return err;
 | 
								return false;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
out:
 | 
					out:
 | 
				
			||||||
| 
						 | 
					@ -457,9 +457,9 @@ static int coredump_parse(struct core_name *cn, struct coredump_params *cprm,
 | 
				
			||||||
	 * and core_uses_pid is set, then .%pid will be appended to
 | 
						 * and core_uses_pid is set, then .%pid will be appended to
 | 
				
			||||||
	 * the filename. Do not do this for piped commands. */
 | 
						 * the filename. Do not do this for piped commands. */
 | 
				
			||||||
	if (cn->core_type == COREDUMP_FILE && !pid_in_pattern && core_uses_pid)
 | 
						if (cn->core_type == COREDUMP_FILE && !pid_in_pattern && core_uses_pid)
 | 
				
			||||||
		return cn_printf(cn, ".%d", task_tgid_vnr(current));
 | 
							return cn_printf(cn, ".%d", task_tgid_vnr(current)) == 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int zap_process(struct signal_struct *signal, int exit_code)
 | 
					static int zap_process(struct signal_struct *signal, int exit_code)
 | 
				
			||||||
| 
						 | 
					@ -911,8 +911,7 @@ void do_coredump(const kernel_siginfo_t *siginfo)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	old_cred = override_creds(cred);
 | 
						old_cred = override_creds(cred);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	retval = coredump_parse(&cn, &cprm, &argv, &argc);
 | 
						if (!coredump_parse(&cn, &cprm, &argv, &argc)) {
 | 
				
			||||||
	if (retval < 0) {
 | 
					 | 
				
			||||||
		coredump_report_failure("format_corename failed, aborting core");
 | 
							coredump_report_failure("format_corename failed, aborting core");
 | 
				
			||||||
		goto fail_unlock;
 | 
							goto fail_unlock;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue