2020-12-11 12:36:41

by Zheng Yongjun

[permalink] [raw]
Subject: [PATCH -next] kernel/audit: convert comma to semicolon

Replace a comma between expression statements by a semicolon.

Signed-off-by: Zheng Yongjun <[email protected]>
---
kernel/audit.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/audit.c b/kernel/audit.c
index 68cee3bc8cfe..c8497115be35 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -2282,7 +2282,7 @@ static void audit_log_set_loginuid(kuid_t koldloginuid, kuid_t kloginuid,

uid = from_kuid(&init_user_ns, task_uid(current));
oldloginuid = from_kuid(&init_user_ns, koldloginuid);
- loginuid = from_kuid(&init_user_ns, kloginuid),
+ loginuid = from_kuid(&init_user_ns, kloginuid);
tty = audit_get_tty();

audit_log_format(ab, "pid=%d uid=%u", task_tgid_nr(current), uid);
--
2.22.0


2020-12-12 18:40:59

by Richard Guy Briggs

[permalink] [raw]
Subject: Re: [PATCH -next] kernel/audit: convert comma to semicolon

On 2020-12-11 16:42, Zheng Yongjun wrote:
> Replace a comma between expression statements by a semicolon.
>
> Signed-off-by: Zheng Yongjun <[email protected]>
> ---
> kernel/audit.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/audit.c b/kernel/audit.c
> index 68cee3bc8cfe..c8497115be35 100644
> --- a/kernel/audit.c
> +++ b/kernel/audit.c
> @@ -2282,7 +2282,7 @@ static void audit_log_set_loginuid(kuid_t koldloginuid, kuid_t kloginuid,
>
> uid = from_kuid(&init_user_ns, task_uid(current));
> oldloginuid = from_kuid(&init_user_ns, koldloginuid);
> - loginuid = from_kuid(&init_user_ns, kloginuid),
> + loginuid = from_kuid(&init_user_ns, kloginuid);

Nice catch. That went unnoticed through 3 patches, the last two mine...
Not quite sure why no compiler complained about it...

Reviewed-by: Richard Guy Briggs <[email protected]>

> tty = audit_get_tty();
>
> audit_log_format(ab, "pid=%d uid=%u", task_tgid_nr(current), uid);

- 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-12-15 02:52:50

by Paul Moore

[permalink] [raw]
Subject: Re: [PATCH -next] kernel/audit: convert comma to semicolon

On Fri, Dec 11, 2020 at 10:33 AM Richard Guy Briggs <[email protected]> wrote:
> On 2020-12-11 16:42, Zheng Yongjun wrote:
> > Replace a comma between expression statements by a semicolon.
> >
> > Signed-off-by: Zheng Yongjun <[email protected]>
> > ---
> > kernel/audit.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/kernel/audit.c b/kernel/audit.c
> > index 68cee3bc8cfe..c8497115be35 100644
> > --- a/kernel/audit.c
> > +++ b/kernel/audit.c
> > @@ -2282,7 +2282,7 @@ static void audit_log_set_loginuid(kuid_t koldloginuid, kuid_t kloginuid,
> >
> > uid = from_kuid(&init_user_ns, task_uid(current));
> > oldloginuid = from_kuid(&init_user_ns, koldloginuid);
> > - loginuid = from_kuid(&init_user_ns, kloginuid),
> > + loginuid = from_kuid(&init_user_ns, kloginuid);
>
> Nice catch. That went unnoticed through 3 patches, the last two mine...

Yes, thanks for catching this and submitting a patch. However, as it
came very late in the v5.10-rcX release cycle I'm going to wait until
after this merge window to merge it into audit/next.

> Not quite sure why no compiler complained about it...

Because it is legal; odd, but legal. :)

The comma operator allows multiple expressions to be executed with
only the last expression returned. Take the example below:

% cat test.c
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
int a, b, c;

a = (b = 1, c = 2);
printf("a = %d, b = %d, c = %d\n", a, b, c);

return 0;
}
% gcc -o test test.c
% ./test
a = 2, b = 1, c = 2

... we see both "b=1" and "c=2" are executed, and the last statement
in the comma separated list of expressions is used as the right-hand
value in the "a" assignment.

In the case of this patch, the existing code is actually okay: both
expressions are executed and we don't assign either expression's value
to a variable so it doesn't matter. However, it definitely looks odd
and is something we should fix.

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

2021-01-05 00:47:33

by Paul Moore

[permalink] [raw]
Subject: Re: [PATCH -next] kernel/audit: convert comma to semicolon

On Mon, Dec 14, 2020 at 9:34 PM Paul Moore <[email protected]> wrote:
> On Fri, Dec 11, 2020 at 10:33 AM Richard Guy Briggs <[email protected]> wrote:
> > On 2020-12-11 16:42, Zheng Yongjun wrote:
> > > Replace a comma between expression statements by a semicolon.
> > >
> > > Signed-off-by: Zheng Yongjun <[email protected]>
> > > ---
> > > kernel/audit.c | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/kernel/audit.c b/kernel/audit.c
> > > index 68cee3bc8cfe..c8497115be35 100644
> > > --- a/kernel/audit.c
> > > +++ b/kernel/audit.c
> > > @@ -2282,7 +2282,7 @@ static void audit_log_set_loginuid(kuid_t koldloginuid, kuid_t kloginuid,
> > >
> > > uid = from_kuid(&init_user_ns, task_uid(current));
> > > oldloginuid = from_kuid(&init_user_ns, koldloginuid);
> > > - loginuid = from_kuid(&init_user_ns, kloginuid),
> > > + loginuid = from_kuid(&init_user_ns, kloginuid);
> >
> > Nice catch. That went unnoticed through 3 patches, the last two mine...
>
> Yes, thanks for catching this and submitting a patch. However, as it
> came very late in the v5.10-rcX release cycle I'm going to wait until
> after this merge window to merge it into audit/next.

This should be in audit/next now, thanks!

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