2020-02-05 16:24:51

by Madhuparna Bhowmik

[permalink] [raw]
Subject: [PATCH] signal.c: Fix sparse warnings

From: Madhuparna Bhowmik <[email protected]>

This patch fixes the following two sparse warnings caused due to
accessing RCU protected pointer tsk->parent without rcu primitives.

kernel/signal.c:1948:65: warning: incorrect type in argument 1 (different address spaces)
kernel/signal.c:1948:65: expected struct task_struct *tsk
kernel/signal.c:1948:65: got struct task_struct [noderef] <asn:4> *parent
kernel/signal.c:1949:40: warning: incorrect type in argument 1 (different address spaces)
kernel/signal.c:1949:40: expected void const volatile *p
kernel/signal.c:1949:40: got struct cred const [noderef] <asn:4> *[noderef] <asn:4> *
kernel/signal.c:1949:40: warning: incorrect type in argument 1 (different address spaces)
kernel/signal.c:1949:40: expected void const volatile *p
kernel/signal.c:1949:40: got struct cred const [noderef] <asn:4> *[noderef] <asn:4> *

Signed-off-by: Madhuparna Bhowmik <[email protected]>
---
kernel/signal.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/signal.c b/kernel/signal.c
index 9ad8dea93dbb..3d59e5652d94 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -1945,8 +1945,8 @@ bool do_notify_parent(struct task_struct *tsk, int sig)
* correct to rely on this
*/
rcu_read_lock();
- info.si_pid = task_pid_nr_ns(tsk, task_active_pid_ns(tsk->parent));
- info.si_uid = from_kuid_munged(task_cred_xxx(tsk->parent, user_ns),
+ info.si_pid = task_pid_nr_ns(tsk, task_active_pid_ns(rcu_access_pointer(tsk->parent)));
+ info.si_uid = from_kuid_munged(task_cred_xxx(rcu_access_pointer(tsk->parent), user_ns),
task_uid(tsk));
rcu_read_unlock();

--
2.17.1


2020-02-05 16:53:05

by Amol Grover

[permalink] [raw]
Subject: Re: [PATCH] signal.c: Fix sparse warnings

On Wed, Feb 05, 2020 at 09:53:19PM +0530, [email protected] wrote:
> From: Madhuparna Bhowmik <[email protected]>
>
> This patch fixes the following two sparse warnings caused due to
> accessing RCU protected pointer tsk->parent without rcu primitives.
>
> kernel/signal.c:1948:65: warning: incorrect type in argument 1 (different address spaces)
> kernel/signal.c:1948:65: expected struct task_struct *tsk
> kernel/signal.c:1948:65: got struct task_struct [noderef] <asn:4> *parent
> kernel/signal.c:1949:40: warning: incorrect type in argument 1 (different address spaces)
> kernel/signal.c:1949:40: expected void const volatile *p
> kernel/signal.c:1949:40: got struct cred const [noderef] <asn:4> *[noderef] <asn:4> *
> kernel/signal.c:1949:40: warning: incorrect type in argument 1 (different address spaces)
> kernel/signal.c:1949:40: expected void const volatile *p
> kernel/signal.c:1949:40: got struct cred const [noderef] <asn:4> *[noderef] <asn:4> *
>
> Signed-off-by: Madhuparna Bhowmik <[email protected]>
> ---
> kernel/signal.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/signal.c b/kernel/signal.c
> index 9ad8dea93dbb..3d59e5652d94 100644
> --- a/kernel/signal.c
> +++ b/kernel/signal.c
> @@ -1945,8 +1945,8 @@ bool do_notify_parent(struct task_struct *tsk, int sig)
> * correct to rely on this
> */
> rcu_read_lock();
> - info.si_pid = task_pid_nr_ns(tsk, task_active_pid_ns(tsk->parent));
> - info.si_uid = from_kuid_munged(task_cred_xxx(tsk->parent, user_ns),
> + info.si_pid = task_pid_nr_ns(tsk, task_active_pid_ns(rcu_access_pointer(tsk->parent)));
> + info.si_uid = from_kuid_munged(task_cred_xxx(rcu_access_pointer(tsk->parent), user_ns),

Shouldn't rcu_dereference() OR rcu_dereference_check() be better suited
here? Since, rcu_access_pointer() omits all lockdep checks.

Thanks
Amol

> task_uid(tsk));
> rcu_read_unlock();
>
> --
> 2.17.1
>

2020-02-05 17:12:11

by Madhuparna Bhowmik

[permalink] [raw]
Subject: Re: [PATCH] signal.c: Fix sparse warnings

On Wed, Feb 05, 2020 at 10:21:38PM +0530, Amol Grover wrote:
> On Wed, Feb 05, 2020 at 09:53:19PM +0530, [email protected] wrote:
> > From: Madhuparna Bhowmik <[email protected]>
> >
> > This patch fixes the following two sparse warnings caused due to
> > accessing RCU protected pointer tsk->parent without rcu primitives.
> >
> > kernel/signal.c:1948:65: warning: incorrect type in argument 1 (different address spaces)
> > kernel/signal.c:1948:65: expected struct task_struct *tsk
> > kernel/signal.c:1948:65: got struct task_struct [noderef] <asn:4> *parent
> > kernel/signal.c:1949:40: warning: incorrect type in argument 1 (different address spaces)
> > kernel/signal.c:1949:40: expected void const volatile *p
> > kernel/signal.c:1949:40: got struct cred const [noderef] <asn:4> *[noderef] <asn:4> *
> > kernel/signal.c:1949:40: warning: incorrect type in argument 1 (different address spaces)
> > kernel/signal.c:1949:40: expected void const volatile *p
> > kernel/signal.c:1949:40: got struct cred const [noderef] <asn:4> *[noderef] <asn:4> *
> >
> > Signed-off-by: Madhuparna Bhowmik <[email protected]>
> > ---
> > kernel/signal.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/kernel/signal.c b/kernel/signal.c
> > index 9ad8dea93dbb..3d59e5652d94 100644
> > --- a/kernel/signal.c
> > +++ b/kernel/signal.c
> > @@ -1945,8 +1945,8 @@ bool do_notify_parent(struct task_struct *tsk, int sig)
> > * correct to rely on this
> > */
> > rcu_read_lock();
> > - info.si_pid = task_pid_nr_ns(tsk, task_active_pid_ns(tsk->parent));
> > - info.si_uid = from_kuid_munged(task_cred_xxx(tsk->parent, user_ns),
> > + info.si_pid = task_pid_nr_ns(tsk, task_active_pid_ns(rcu_access_pointer(tsk->parent)));
> > + info.si_uid = from_kuid_munged(task_cred_xxx(rcu_access_pointer(tsk->parent), user_ns),
>
> Shouldn't rcu_dereference() OR rcu_dereference_check() be better suited
> here? Since, rcu_access_pointer() omits all lockdep checks.
>
I used rcu_access_pointer() because I thought the pointer is not
dereferenced. But it is dereferenced in task_pid() and task_cred_xxx().

Thank you for pointing out, I will send the updated patch.

Thanks,
Madhuparna

> Thanks
> Amol
>
> > task_uid(tsk));
> > rcu_read_unlock();
> >
> > --
> > 2.17.1
> >