[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240214090640.GB14017@redhat.com>
Date: Wed, 14 Feb 2024 10:06:41 +0100
From: Oleg Nesterov <oleg@...hat.com>
To: Tycho Andersen <tycho@...ho.pizza>
Cc: coverity-bot <keescook@...omium.org>,
Christian Brauner <brauner@...nel.org>,
Nicholas Piggin <npiggin@...il.com>,
Sebastian Andrzej Siewior <bigeasy@...utronix.de>,
Peng Zhang <zhangpeng.00@...edance.com>,
Ard Biesheuvel <ardb@...nel.org>,
Luis Chamberlain <mcgrof@...nel.org>,
Heiko Carstens <hca@...ux.ibm.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Suren Baghdasaryan <surenb@...gle.com>,
Thomas Gleixner <tglx@...utronix.de>,
Mateusz Guzik <mjguzik@...il.com>,
Dmitry Vyukov <dvyukov@...gle.com>,
Tycho Andersen <tandersen@...flix.com>,
Mike Christie <michael.christie@...cle.com>,
"Paul E. McKenney" <paulmck@...nel.org>,
linux-kernel@...r.kernel.org,
"Gustavo A. R. Silva" <gustavo@...eddedor.com>,
linux-next@...r.kernel.org, linux-hardening@...r.kernel.org
Subject: Re: Coverity: __do_sys_pidfd_send_signal(): UNINIT
On 02/14, Oleg Nesterov wrote:
>
> On 02/13, Tycho Andersen wrote:
> >
> > I think this is a false positive, we have:
>
> Agreed,
>
> > That said, a default case wouldn't hurt, and we should fix the first
> > comment anyways, since now we have extensions.
> >
> > I'm happy to send a patch or maybe it's better for Christian to fix it
> > in-tree.
>
> I leave this to you and Christian, whatever you prefer. But perhaps we
> can simplify these checks? Something like below.
forgot about -EINVAL ...
Oleg.
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -3876,10 +3876,6 @@ static struct pid *pidfd_to_pid(const struct file *file)
return tgid_pidfd_to_pid(file);
}
-#define PIDFD_SEND_SIGNAL_FLAGS \
- (PIDFD_SIGNAL_THREAD | PIDFD_SIGNAL_THREAD_GROUP | \
- PIDFD_SIGNAL_PROCESS_GROUP)
-
/**
* sys_pidfd_send_signal - Signal a process through a pidfd
* @pidfd: file descriptor of the process
@@ -3903,13 +3899,23 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig,
kernel_siginfo_t kinfo;
enum pid_type type;
- /* Enforce flags be set to 0 until we add an extension. */
- if (flags & ~PIDFD_SEND_SIGNAL_FLAGS)
- return -EINVAL;
-
- /* Ensure that only a single signal scope determining flag is set. */
- if (hweight32(flags & PIDFD_SEND_SIGNAL_FLAGS) > 1)
+ switch (flags) {
+ case 0:
+ /* but see the PIDFD_THREAD check below */
+ type = PIDTYPE_TGID;
+ break;
+ case PIDFD_SIGNAL_THREAD:
+ type = PIDTYPE_PID;
+ break;
+ case PIDFD_SIGNAL_THREAD_GROUP:
+ type = PIDTYPE_TGID;
+ break;
+ case PIDFD_SIGNAL_PROCESS_GROUP:
+ type = PIDTYPE_PGID;
+ break;
+ default:
return -EINVAL;
+ }
f = fdget(pidfd);
if (!f.file)
@@ -3926,24 +3932,8 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig,
if (!access_pidfd_pidns(pid))
goto err;
- switch (flags) {
- case 0:
- /* Infer scope from the type of pidfd. */
- if (f.file->f_flags & PIDFD_THREAD)
- type = PIDTYPE_PID;
- else
- type = PIDTYPE_TGID;
- break;
- case PIDFD_SIGNAL_THREAD:
+ if (!flags && (f.file->f_flags & PIDFD_THREAD))
type = PIDTYPE_PID;
- break;
- case PIDFD_SIGNAL_THREAD_GROUP:
- type = PIDTYPE_TGID;
- break;
- case PIDFD_SIGNAL_PROCESS_GROUP:
- type = PIDTYPE_PGID;
- break;
- }
if (info) {
ret = copy_siginfo_from_user_any(&kinfo, info);
Powered by blists - more mailing lists