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  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]
Date:   Wed, 13 Jun 2018 16:10:49 +0300
From:   Dan Carpenter <dan.carpenter@...cle.com>
To:     Josh Poimboeuf <jpoimboe@...hat.com>
Cc:     linux-kernel@...r.kernel.org,
        Peter Zijlstra <peterz@...radead.org>,
        "Gustavo A. R. Silva" <gustavo@...eddedor.com>
Subject: Re: Smatch check for Spectre stuff

On Fri, Jun 08, 2018 at 11:12:19AM -0500, Josh Poimboeuf wrote:
> I have a few questions/comments.
> 
> 1) I've noticed a common pattern for many of the false positives.
>    Smatch doesn't seem to detect when the code masks off the array index
>    to ensure that it's safe.
> 
>    For example:
> 
>    > ./include/linux/mmzone.h:1161 __nr_to_section() warn: potential spectre issue 'mem_section[(nr / (((1) << 12) / 32))]'
> 
>    1153 static inline struct mem_section *__nr_to_section(unsigned long nr)
>    1154 {
>    1155 #ifdef CONFIG_SPARSEMEM_EXTREME
>    1156         if (!mem_section)
>    1157                 return NULL;
>    1158 #endif
>    1159         if (!mem_section[SECTION_NR_TO_ROOT(nr)])
>    1160                 return NULL;
>    1161         return &mem_section[SECTION_NR_TO_ROOT(nr)][nr & SECTION_ROOT_MASK];
>    1162 }
> 
>    In the 2-D array access, it seems to be complaining about the '[nr &
>    SECTION_ROOT_MASK]' reference.  But that appears to be safe because
>    all the unsafe bits are masked off.
>  
>    It would be great if Smatch could detect that situation if possible.

I can try.  The thing is that it would have to be masked within the same
function because that information isn't passed across the function
calls.

Also it turns out that mem_section[] is declared in mm/sparse.c and
Smatch is supposed to be able to figure out the size of it but
apparently there is a bug...  :(  I'll take a look at that.

> 
> 2) Looking at the above example, it seems that the value of 'nr' is
>    untrusted.  If so, then I wonder why didn't it warn about the other
>    array accesses in the function: line 1559 and the first dimension
>    access in 1161?

Good point.  I'll change that as well.

> 
> 3) One thing that I think would help with analyzing the results would be
>    if there was a way to see the call chain for each warning, so that
>    it's clear which value isn't trusted and why.

The information is mostly there in the cross function DB, but the user
interface is bad...  Use the smdb.py script to see how functions are
called:

	 ~/smatch/smatch_data/db/smdb.py __nr_to_section

> 
> 4) Is there a way to put some results in a whitelist to mark them as
>    false positives so they won't show up in future scans?  Something
>    like that would help with automatic detection and reporting of new
>    issues by the 0-day kbuild test robot, for example.

There is a script called smatch_scripts/new_bugs.sh but I use a
different new_bugs.sh script which I am embarrassed to publish.  I guess
I'll attach it though.

regards,
dan carpenter



Download attachment "new_bugs.sh" of type "application/x-sh" (1794 bytes)

Powered by blists - more mailing lists