public inbox for smatch@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Joel Savitz <jsavitz@redhat.com>
Cc: smatch@vger.kernel.org, error27@gmail.com
Subject: Re: I would like to contribute to smatch
Date: Fri, 3 May 2019 22:32:25 +0300	[thread overview]
Message-ID: <20190503193225.GO2239@kadam> (raw)
In-Reply-To: <CAL1p7m49h+gM7iXvYmbyk7NvxAtUxirXY2OU1kJpxTd=7xbqPA@mail.gmail.com>

Hi Joel,

Smatch has two checks for Spectre v1 issues:

ipc/sem.c:445 sem_unlock() warn: potential spectre issue 'sma->sems' [r]

	copy_from_user(var, src, size);
	if (var >= ARRAY_SIZE())
		return -EINVAL;
	foo = array[bar];

These warning are for when we read from an array without using
array_index_nospec() or a different method of turning off speculation.
One of the issues with this warning is that most are not exploitable.

The second warning is for Spectre second halves:

block/genhd.c:117 __disk_get_part() warn: possible spectre second half.  '__u.__val'

	/* First half */
	copy_from_user(var, src, size);
	if (var >= ARRAY_SIZE())
		return -EINVAL;
	foo = array[bar];

	/* The second half is when we use "foo" */
	if (foo) {

I'm looking through the warnings now and they seem pretty low
quality...  :(  Part of it is that the CPU can only speculate maybe 200
instructions ahead so if the bounds checking is a long way from the
first or second half then it's not exploitable.  I think what's
is that it's restarting the clock at the start of the function?

I could just check to see if we have compared the index with something
in the function.  That's stored in smatch_comparison.c.  Or I could pass
the counter and store that in the DB.  I would be counting C statements
and not machine instructions, but they are obviously correlated.

What would really help me is if someone looked through the results and
pointed out what's false positives.

Btw, the smatch_data/db/smdb.py script is really essential to
understanding any of the spectre warnings.  It's looking at USER_DATA
which comes from copy_from_user() etc.

Also it's essential to build the DB.  The Smatch program to do that is:
~/smatch/smatch_scripts/build_kernel_data.sh
It's straightforward, but it takes 5 hours to complete.

regards,
dan carpenter

      reply	other threads:[~2019-05-03 19:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-03 18:36 I would like to contribute to smatch Joel Savitz
2019-05-03 19:32 ` Dan Carpenter [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190503193225.GO2239@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=error27@gmail.com \
    --cc=jsavitz@redhat.com \
    --cc=smatch@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox