diff --git a/kernel/fork.c b/kernel/fork.c index a420db040f6b..450a5d7586bb 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2512,6 +2512,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); }