2019-11-28 15:36:21

by Amol Grover

[permalink] [raw]
Subject: [PATCH v2] kernel: audit.c: Add __rcu notation to RCU pointer

add __rcu notation to RCU protected global pointer auditd_conn

Fixes multiple instances of sparse error:
error: incompatible types in comparison expression
(different address spaces)

Signed-off-by: Amol Grover <[email protected]>
---
v2:
- fix erroneous RCU pointer initialization

kernel/audit.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/audit.c b/kernel/audit.c
index da8dc0db5bd3..ff7cfc61f53d 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -102,12 +102,13 @@ struct audit_net {
* This struct is RCU protected; you must either hold the RCU lock for reading
* or the associated spinlock for writing.
*/
-static struct auditd_connection {
+struct auditd_connection {
struct pid *pid;
u32 portid;
struct net *net;
struct rcu_head rcu;
-} *auditd_conn = NULL;
+};
+static struct auditd_connection __rcu *auditd_conn;
static DEFINE_SPINLOCK(auditd_conn_lock);

/* If audit_rate_limit is non-zero, limit the rate of sending audit records
--
2.24.0


2019-11-30 02:09:21

by Joel Fernandes

[permalink] [raw]
Subject: Re: [PATCH v2] kernel: audit.c: Add __rcu notation to RCU pointer

On Thu, Nov 28, 2019 at 09:02:03PM +0530, Amol Grover wrote:
> add __rcu notation to RCU protected global pointer auditd_conn

Again, please use proper punctuation and captilization. This is unacceptable.
Please put more effort into changelog.

Otherwise the patch diff itself looks good to me, with the above nit
corrected, you could add my tag to the next revision:

Reviewed-by: Joel Fernandes (Google) <[email protected]>

thanks,

- Joel

>
> Fixes multiple instances of sparse error:
> error: incompatible types in comparison expression
> (different address spaces)
>
> Signed-off-by: Amol Grover <[email protected]>
> ---
> v2:
> - fix erroneous RCU pointer initialization
>
> kernel/audit.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/audit.c b/kernel/audit.c
> index da8dc0db5bd3..ff7cfc61f53d 100644
> --- a/kernel/audit.c
> +++ b/kernel/audit.c
> @@ -102,12 +102,13 @@ struct audit_net {
> * This struct is RCU protected; you must either hold the RCU lock for reading
> * or the associated spinlock for writing.
> */
> -static struct auditd_connection {
> +struct auditd_connection {
> struct pid *pid;
> u32 portid;
> struct net *net;
> struct rcu_head rcu;
> -} *auditd_conn = NULL;
> +};
> +static struct auditd_connection __rcu *auditd_conn;
> static DEFINE_SPINLOCK(auditd_conn_lock);
>
> /* If audit_rate_limit is non-zero, limit the rate of sending audit records
> --
> 2.24.0
>

2020-04-16 00:17:21

by Richard Guy Briggs

[permalink] [raw]
Subject: Re: [PATCH v2] kernel: audit.c: Add __rcu notation to RCU pointer

On 2019-11-29 21:07, Joel Fernandes wrote:
> On Thu, Nov 28, 2019 at 09:02:03PM +0530, Amol Grover wrote:
> > add __rcu notation to RCU protected global pointer auditd_conn
>
> Again, please use proper punctuation and captilization. This is unacceptable.
> Please put more effort into changelog.
>
> Otherwise the patch diff itself looks good to me, with the above nit
> corrected, you could add my tag to the next revision:
>
> Reviewed-by: Joel Fernandes (Google) <[email protected]>
>
> thanks,
>
> - Joel
>
> >
> > Fixes multiple instances of sparse error:
> > error: incompatible types in comparison expression
> > (different address spaces)

Amol or Joel: Is there a reproducer recipe for this?

> > Signed-off-by: Amol Grover <[email protected]>
> > ---
> > v2:
> > - fix erroneous RCU pointer initialization
> >
> > kernel/audit.c | 5 +++--
> > 1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/kernel/audit.c b/kernel/audit.c
> > index da8dc0db5bd3..ff7cfc61f53d 100644
> > --- a/kernel/audit.c
> > +++ b/kernel/audit.c
> > @@ -102,12 +102,13 @@ struct audit_net {
> > * This struct is RCU protected; you must either hold the RCU lock for reading
> > * or the associated spinlock for writing.
> > */
> > -static struct auditd_connection {
> > +struct auditd_connection {
> > struct pid *pid;
> > u32 portid;
> > struct net *net;
> > struct rcu_head rcu;
> > -} *auditd_conn = NULL;
> > +};
> > +static struct auditd_connection __rcu *auditd_conn;
> > static DEFINE_SPINLOCK(auditd_conn_lock);
> >
> > /* If audit_rate_limit is non-zero, limit the rate of sending audit records
> > --
> > 2.24.0

- RGB

--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems
Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635

2020-04-16 00:19:12

by Richard Guy Briggs

[permalink] [raw]
Subject: Re: [PATCH v2] kernel: audit.c: Add __rcu notation to RCU pointer

On 2020-04-15 12:06, Paul Moore wrote:
> On Wed, Apr 15, 2020 at 11:34 AM Richard Guy Briggs <[email protected]> wrote:
> > On 2019-11-29 21:07, Joel Fernandes wrote:
> > > On Thu, Nov 28, 2019 at 09:02:03PM +0530, Amol Grover wrote:
> > > > add __rcu notation to RCU protected global pointer auditd_conn
> > >
> > > Again, please use proper punctuation and captilization. This is unacceptable.
> > > Please put more effort into changelog.
> > >
> > > Otherwise the patch diff itself looks good to me, with the above nit
> > > corrected, you could add my tag to the next revision:
> > >
> > > Reviewed-by: Joel Fernandes (Google) <[email protected]>
> > >
> > > thanks,
> > >
> > > - Joel
> > >
> > > >
> > > > Fixes multiple instances of sparse error:
> > > > error: incompatible types in comparison expression
> > > > (different address spaces)
> >
> > Amol or Joel: Is there a reproducer recipe for this?
>
> The commit which was merged has a slightly better description which may help.

I've already seen this. Perhaps I should have replied to this message
instead to make that evident. What really needed was Amol's original
message sent to this list, but it was Joel who included this list in his
reply (all 3 versions).

I'm looking for the specific setup and commands that produced this error.

> commit cb5172d96d16df72db8b55146b0ec00bfd97f079
> Author: Amol Grover <[email protected]>
> Date: Mon Dec 2 00:03:48 2019 +0530
>
> audit: Add __rcu annotation to RCU pointer
>
> Add __rcu annotation to RCU-protected global pointer auditd_conn.
>
> auditd_conn is an RCU-protected global pointer,i.e., accessed
> via RCU methods rcu_dereference() and rcu_assign_pointer(),
> hence it must be annotated with __rcu for sparse to report
> warnings/errors correctly.
>
> Fix multiple instances of the sparse error:
> error: incompatible types in comparison expression
> (different address spaces)
>
> Reviewed-by: Joel Fernandes (Google) <[email protected]>
> Signed-off-by: Amol Grover <[email protected]>
> [PM: tweak subject line]
> Signed-off-by: Paul Moore <[email protected]>
>
> --
> paul moore
> http://www.paul-moore.com
>

- RGB

--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems
Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635

2020-04-16 00:19:54

by Paul Moore

[permalink] [raw]
Subject: Re: [PATCH v2] kernel: audit.c: Add __rcu notation to RCU pointer

On Wed, Apr 15, 2020 at 11:34 AM Richard Guy Briggs <[email protected]> wrote:
> On 2019-11-29 21:07, Joel Fernandes wrote:
> > On Thu, Nov 28, 2019 at 09:02:03PM +0530, Amol Grover wrote:
> > > add __rcu notation to RCU protected global pointer auditd_conn
> >
> > Again, please use proper punctuation and captilization. This is unacceptable.
> > Please put more effort into changelog.
> >
> > Otherwise the patch diff itself looks good to me, with the above nit
> > corrected, you could add my tag to the next revision:
> >
> > Reviewed-by: Joel Fernandes (Google) <[email protected]>
> >
> > thanks,
> >
> > - Joel
> >
> > >
> > > Fixes multiple instances of sparse error:
> > > error: incompatible types in comparison expression
> > > (different address spaces)
>
> Amol or Joel: Is there a reproducer recipe for this?

The commit which was merged has a slightly better description which may help.

commit cb5172d96d16df72db8b55146b0ec00bfd97f079
Author: Amol Grover <[email protected]>
Date: Mon Dec 2 00:03:48 2019 +0530

audit: Add __rcu annotation to RCU pointer

Add __rcu annotation to RCU-protected global pointer auditd_conn.

auditd_conn is an RCU-protected global pointer,i.e., accessed
via RCU methods rcu_dereference() and rcu_assign_pointer(),
hence it must be annotated with __rcu for sparse to report
warnings/errors correctly.

Fix multiple instances of the sparse error:
error: incompatible types in comparison expression
(different address spaces)

Reviewed-by: Joel Fernandes (Google) <[email protected]>
Signed-off-by: Amol Grover <[email protected]>
[PM: tweak subject line]
Signed-off-by: Paul Moore <[email protected]>

--
paul moore
http://www.paul-moore.com

2020-04-16 01:01:04

by Richard Guy Briggs

[permalink] [raw]
Subject: Re: [PATCH v2] kernel: audit.c: Add __rcu notation to RCU pointer

On 2020-04-15 18:53, Ondrej Mosnacek wrote:
> On Wed, Apr 15, 2020 at 6:15 PM Richard Guy Briggs <[email protected]> wrote:
> > On 2020-04-15 12:06, Paul Moore wrote:
> > > On Wed, Apr 15, 2020 at 11:34 AM Richard Guy Briggs <[email protected]> wrote:
> > > > On 2019-11-29 21:07, Joel Fernandes wrote:
> > > > > On Thu, Nov 28, 2019 at 09:02:03PM +0530, Amol Grover wrote:
> > > > > > add __rcu notation to RCU protected global pointer auditd_conn
> > > > >
> > > > > Again, please use proper punctuation and captilization. This is unacceptable.
> > > > > Please put more effort into changelog.
> > > > >
> > > > > Otherwise the patch diff itself looks good to me, with the above nit
> > > > > corrected, you could add my tag to the next revision:
> > > > >
> > > > > Reviewed-by: Joel Fernandes (Google) <[email protected]>
> > > > >
> > > > > thanks,
> > > > >
> > > > > - Joel
> > > > >
> > > > > >
> > > > > > Fixes multiple instances of sparse error:
> > > > > > error: incompatible types in comparison expression
> > > > > > (different address spaces)
> > > >
> > > > Amol or Joel: Is there a reproducer recipe for this?
> > >
> > > The commit which was merged has a slightly better description which may help.
> >
> > I've already seen this. Perhaps I should have replied to this message
> > instead to make that evident. What really needed was Amol's original
> > message sent to this list, but it was Joel who included this list in his
> > reply (all 3 versions).
> >
> > I'm looking for the specific setup and commands that produced this error.
>
> You can run make with "C=1", which will run sparse on all files that
> are rebuilt during that make run. For example, if I fully build the
> kernel and then revert commit
> cb5172d96d16df72db8b55146b0ec00bfd97f079, I get:
>
> $ make [...] C=1
> [...]
> CHECK [...]/kernel/audit.c
> [...]/kernel/audit.c:218:14: error: incompatible types in comparison
> expression (different address spaces):
> [...]/kernel/audit.c:218:14: struct auditd_connection [noderef] <asn:4> *
> [...]/kernel/audit.c:218:14: struct auditd_connection *
> (...and a lot more errors like this + 2 different warnings)
>
> And when I un-revert it again, I get only the 2 warnings.

Perfect, thanks Ondrej.

> Ondrej Mosnacek <omosnace at redhat dot com>

- RGB

--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems
Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635

2020-04-16 01:51:14

by Ondrej Mosnacek

[permalink] [raw]
Subject: Re: [PATCH v2] kernel: audit.c: Add __rcu notation to RCU pointer

On Wed, Apr 15, 2020 at 6:15 PM Richard Guy Briggs <[email protected]> wrote:
> On 2020-04-15 12:06, Paul Moore wrote:
> > On Wed, Apr 15, 2020 at 11:34 AM Richard Guy Briggs <[email protected]> wrote:
> > > On 2019-11-29 21:07, Joel Fernandes wrote:
> > > > On Thu, Nov 28, 2019 at 09:02:03PM +0530, Amol Grover wrote:
> > > > > add __rcu notation to RCU protected global pointer auditd_conn
> > > >
> > > > Again, please use proper punctuation and captilization. This is unacceptable.
> > > > Please put more effort into changelog.
> > > >
> > > > Otherwise the patch diff itself looks good to me, with the above nit
> > > > corrected, you could add my tag to the next revision:
> > > >
> > > > Reviewed-by: Joel Fernandes (Google) <[email protected]>
> > > >
> > > > thanks,
> > > >
> > > > - Joel
> > > >
> > > > >
> > > > > Fixes multiple instances of sparse error:
> > > > > error: incompatible types in comparison expression
> > > > > (different address spaces)
> > >
> > > Amol or Joel: Is there a reproducer recipe for this?
> >
> > The commit which was merged has a slightly better description which may help.
>
> I've already seen this. Perhaps I should have replied to this message
> instead to make that evident. What really needed was Amol's original
> message sent to this list, but it was Joel who included this list in his
> reply (all 3 versions).
>
> I'm looking for the specific setup and commands that produced this error.

You can run make with "C=1", which will run sparse on all files that
are rebuilt during that make run. For example, if I fully build the
kernel and then revert commit
cb5172d96d16df72db8b55146b0ec00bfd97f079, I get:

$ make [...] C=1
[...]
CHECK [...]/kernel/audit.c
[...]/kernel/audit.c:218:14: error: incompatible types in comparison
expression (different address spaces):
[...]/kernel/audit.c:218:14: struct auditd_connection [noderef] <asn:4> *
[...]/kernel/audit.c:218:14: struct auditd_connection *
(...and a lot more errors like this + 2 different warnings)

And when I un-revert it again, I get only the 2 warnings.

--
Ondrej Mosnacek <omosnace at redhat dot com>
Software Engineer, Security Technologies
Red Hat, Inc.