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] [day] [month] [year] [list]
Message-ID: <1473001581.5018.37.camel@perches.com>
Date:   Sun, 04 Sep 2016 08:06:21 -0700
From:   Joe Perches <joe@...ches.com>
To:     Julia Lawall <julia.lawall@...6.fr>
Cc:     Dan Carpenter <error27@...il.com>,
        LKML <linux-kernel@...r.kernel.org>
Subject: Re: Possible code defects: macros and precedence

On Sun, 2016-09-04 at 18:10 +0800, Julia Lawall wrote:
> On Sat, 3 Sep 2016, Joe Perches wrote:
> > There are many nominally incorrect macro definitions
> > in linux-kernel source where parentheses are not used
> > for various macros arguments with calculations.
> >
> > Does coccinelle or smatch have the ability to detect
> > potential macro misuse where arguments passed to the
> > macro are not correctly parenthesized by the macro?
> >
> > Something like:
> >
> >       #define A 1
> >       #define B 2
> >       #define shift(val) (val << 1)
> >
> > where a use is:
> >
> >       int c = shift(A | B)
> >
> > where the actual result is 5 but the expected result is 6?
> >
> > Can either tool suggest changing the macro to
> >
> >       #define shift(val) ((val) << 1)
> 
> Coccinelle could do this.  It is possible to match macro parameters, and
> it is possible to match binary operators generically.  I can look into it.

Thanks Julia.

It is not just binary operators though, it is all
operations including dereference where precedence
and associativity operations on the macro argument
might cause an unexpected result.

The possible regex checkpatch rule I sent for this
https://lkml.org/lkml/2016/9/3/271
is _way_ too noisy and stupid.

The $Operator test there includes a comma which
makes the possible macro argument precedence test
output silly.  More work is necessary to make the
checkpatch test more reasonable.


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ