Re: [PATCH v2] signal: factor out the kernel reserved si_code check
From: Oleg Nesterov
Date: Thu Aug 06 2026 - 13:34:39 EST
On 08/06, Bradley Morgan wrote:
>
> The check that prevents userspace from sending siginfo with si_code
> values reserved to the kernel is duplicated across do_rt_sigqueueinfo(),
> do_rt_tgsigqueueinfo() and do_pidfd_send_signal(). Move the check
> into a helper so the rule lives in one place.
> +/*
> + * Not even root can pretend to send SI_FROMKERNEL() signals.
> + * Nor can they impersonate kill()/tgkill(), which have si_pid/uid
> + */
> +static bool si_code_reserved_to_kernel(int si_code)
> +{
> + return si_code >= 0 || si_code == SI_TKILL;
> +}
OK, Acked-by: Oleg Nesterov <oleg@xxxxxxxxxx>
But can't resist... We already have SI_FROMUSER() and SI_FROMKERNEL()
both take the pointer to siginfo as an argument.
Now we also have si_code_reserved_to_kernel() which falls into the same
category, but it aceepts .si_code and the names don't match...
OK, nevermind. I can't suggest a better name. Even if we change the
new helper to take "kernel_siginfo_t *info" to match SI_FROMXXX macros.
Oleg.