diff --git a/kernel/fork.c b/kernel/fork.c index 784f35e61efe..e53b0470dedc 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2706,6 +2706,13 @@ __latent_entropy struct task_struct *copy_process( spin_lock_irq(¤t->sighand->siglock); hlist_del_init(&delayed.node); spin_unlock_irq(¤t->sighand->siglock); + /* + * The error path returns ERR_PTR(retval), which requires retval to be a + * negative errno in the range [-MAX_ERRNO, -1]. Normalize unexpected + * values to avoid returning non-error pointers to callers. + */ + if (unlikely(retval >= 0 || retval < -MAX_ERRNO)) + retval = -EINVAL; return ERR_PTR(retval); }