lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f3dadda8af7eef6613d7a4105170058f2759507d.camel@perches.com>
Date:   Thu, 01 Oct 2020 06:42:32 -0700
From:   Joe Perches <joe@...ches.com>
To:     Dwaipayan Ray <dwaipayanray1@...il.com>
Cc:     linux-kernel@...r.kernel.org,
        linux-kernel-mentees@...ts.linuxfoundation.org,
        Lukas Bulwahn <lukas.bulwahn@...il.com>
Subject: Re: [PATCH RFC] checkpatch: fix multi-statement macro checks

On Thu, 2020-10-01 at 18:57 +0530, Dwaipayan Ray wrote:
> On Thu, Oct 1, 2020 at 6:47 PM Joe Perches <joe@...ches.com> wrote:
> > On Thu, 2020-10-01 at 16:03 +0530, Dwaipayan Ray wrote:
> > > Checkpatch.pl doesn't have a check for excluding while (...) {...}
> > > blocks from MULTISTATEMENT_MACRO_USE_DO_WHILE error.
> > > 
> > > For example, running checkpatch.pl on the file mm/access.c in the
> > > kernel generates the following error:
> > > 
> > > ERROR: Macros with complex values should be enclosed in parentheses
> > > +#define copy_from_kernel_nofault_loop(dst, src, len, type, err_label)        \
> > > +     while (len >= sizeof(type)) {                                   \
> > > +             __get_kernel_nofault(dst, src, type, err_label);        \
> > > +             dst += sizeof(type);                                    \
> > > +             src += sizeof(type);                                    \
> > > +             len -= sizeof(type);                                    \
> > > +     }
> > > 
> > > The error is misleading for this case. Enclosing it in parantheses
> > > doesn't make any sense.
> > 
> > OK
> > 
> > > Checkpatch already has an exception list for such common macro types.
> > > Added a new exception for while (...) {...} style blocks to the same.
> > > This effectively fixed the wrong error message.
> > []
> > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> > []
> > > @@ -5342,6 +5342,7 @@ sub process {
> > >                           $dstat !~ /^\.$Ident\s*=/ &&                                # .foo =
> > >                           $dstat !~ /^(?:\#\s*$Ident|\#\s*$Constant)\s*$/ &&          # stringification #foo
> > >                           $dstat !~ /^do\s*$Constant\s*while\s*$Constant;?$/ &&       # do {...} while (...); // do {...} while (...)
> > > +                         $dstat !~ /^while\s*$Constant\s*$Constant\s*$/ &&           # while (...) {...}

Note the \s*
                                                              ^

> > Did you try to output $dstat for some matching cases?
> > What was the $dstat value for the cases you tried?
> > 
> > 
> Hi,
> I did check $dstat values.
> 
> For example on file mm/maccess.c, there were two such macros:
> 
> Case 1:
> 
> $ctx:
> +#define copy_from_kernel_nofault_loop(dst, src, len, type, err_label) \
> + while (len >= sizeof(type)) { \
> + __get_kernel_nofault(dst, src, type, err_label); \
> + dst += sizeof(type); \
> + src += sizeof(type); \
> + len -= sizeof(type); \
> + }
> 
> $dstat:
> while 1 1

And perhaps this test should use \s+ instead.
What is $dstat with a #define like:

#define foo(bar,baz)while(bar){bar--;baz++;}

(no spaces anywhere bot the required one after define
	
> Case 2:
> 
> $ctx:
> +#define copy_to_kernel_nofault_loop(dst, src, len, type, err_label) \
> + while (len >= sizeof(type)) { \
> + __put_kernel_nofault(dst, src, type, err_label); \
> + dst += sizeof(type); \
> + src += sizeof(type); \
> + len -= sizeof(type); \
> + }
> 
> $dstat:
> while 1 1
> 
> 
> Thanks,
> Dwaipayan.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ