[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Proposal for deviations in static analyser findings


  • To: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • Date: Wed, 12 Oct 2022 16:00:41 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LSswIpNmi9PEvZthD1AbpwbfzH8zN6F0xboMfvxc098=; b=SRFwN0CklAhFo1qMRzz1/eVl+Hbq05g3BaP9eYUK3kQQaup9Buc6x6QzK9WC2rOE55OcOeC9gNhl4p6EXdIsUTrQ1QXBhvXlbMtLgMlnm32VioMq+8/VFld+SHkJDMLFyvaxTqUD/CgOEQeyHO4GYRIA7xqIF9MBWCvUHSNoCEQtJ5IddEw54HsQRrzXuFLN6iTT4IrFNkR/fUtS30LNN1dXe8ifZdFM8wR3UaAmryLWVj4Ym5SXcAmYPnxCDozEjGQluV8K0fgactNyLUDlPjLvefQSKEQv81KteEF6mxODaWivFwRISolR7XU5b0Z1/r5LVOcI7b2JLrNXxBqCxQ==
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LSswIpNmi9PEvZthD1AbpwbfzH8zN6F0xboMfvxc098=; b=lHW+Q7rnmimhHbQf1hZ4dtmkBdYIauhTzsleDXW5GNuVhr73bhQrcBvibUMVABDphjRYwZwbMvJIkYPSJyA2PH+7oDE+piH8m1cOUwWv6x7i1seAjnIYO88PyoZ2PuilEBvhcHPV/XWfKWSJBnT8aGDvoKY3fclVk6lTN+S0jSvjjzDdFLMABdoRL+/2or9hTVtHG6/sSH+RQfU8SOe4rK7p/OCAXo1rjxSNmiqGrbPkHlRpWKv9aoqOYLbSkjrHmN3B4mAO0/FL+cDa7YQtiXrV8ehO3cM9ra3y9gA6AU470yJVVL34PCO3n0Ds9E1YVm/dt4ypA3Yko5lEAE6WLQ==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=MdPvL+kpX2h/+ryoEJg9UnIqRWkf2Bz+kTuMSMYZwcwTnK75TIBYtFoKUAk2k5F3/JpQ77dv8+iCYQLToRLO3DTfBGB7fjnSOP5d7dqsOXUOQdnt1ltJrmsoDmaCLFFMEPij63gDa55c/ck7dKoK2hgBcI5sS2yjrmsn+CEI9e6GkWGVLfCcQpWVQwsDyyOIWBSa1sFDw18qpOFcFVBfTmrUrXFuYKdelxl06k7R2hq+dtFEy8Bsn4ANIXQp+htiudx8oJuxcDeGtQUAsqUbiO/OJIN3CsKDUN+oOwaH1l+orhwn1/zy8iTWJYFZZ45F4/6FUt+lP8fKlCeSTJtyVw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IWaffIKvsJ8zEdl1PzyukLSkAdGa3iEz1TmD9hPIXBdJ98BNM6bIhjPfr+JX3b85u1pgQZZZGYIKXZtg72M8wgdOCgiWqzuSx06zDeIP7b+iRMYI5H4l6L2fyfzNl5Q1VhTRAR6k0unXekkCkDLCOFQMY3xyYQR/BGeZUkup7gTI4RQo+8EL4bIHTOWe+LCw/Ph1tFCxAjy/qctB5JZ1Rwm0rpeaEP8ji40B/FyutCkGVgIUBXw+qHdpJx5Lbxnfknm1DGvqF8vZAHunDZ8CnCcuZweIWeXiLx0UpY5aWYgZaAzFmkBzeTWgAvxwmTSw13Z2Rc4Q6NA/k7D5Mn6BNg==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Wei Chen <Wei.Chen@xxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>
  • Delivery-date: Wed, 12 Oct 2022 16:01:03 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHY3lPHM2Tyba3hCkeKMW07GDOb2Q==
  • Thread-topic: Proposal for deviations in static analyser findings

Hi all,

Here is a proposal to create a deviation system for all the static analyser 
finding from
both generic static code checkers and MISRA compliance, as said before, there 
might
be some case where we won’t fix a part of the code because the way it is 
written is
safer than the proposed fix from the tool or coding guidance.

The proposed tags will be translated by a tool during the analysis, using the 
database (JSON file) reported below,
the analysis steps will be:
1) translate the “Xen codebase in-code comment tags” to the proprietary syntax 
of the chosen tool in the source code.
2) perform the analysis and produce a report
3) revert back the source code to the original.

The proposal includes also feedbacks from the design session about FuSa held at 
the Xen Summit 2022.


Documenting violations
======================

Static analysers are used on the Xen codebase for both static analysis and MISRA
compliance.
There might be the need to suppress some findings instead of fixing them and
many tools permit the usage of in-code comments that suppress findings so that
they are not shown in the final report.

Xen includes a tool capable of translating a specific comment used in its
codebase to the right proprietary in-code comment understandable by the selected
analyser that suppress its finding.

In the Xen codebase, these tags will be used to document and suppress findings:

- SAF-X-safe: This tag means that the next line of code contains a finding, but
  the non compliance to the checker is analysed and demonstrated to be safe.
- SAF-X-false-positive: This tag means that the next line of code contains a
  finding, but the finding is a bug of the tool.

SAF stands for Static Analyser Finding, the X is a placeholder for a positive
number that starts from zero, the number after SAF- shall be incremental and
unique.

Entries in the database should never be removed, even if they are not used
anymore in the code (if a patch is removing or modifying the faulty line).
This is to make sure that numbers are not reused which could lead to conflicts
with old branches or misleading justifications.

The files where to store all the justifications are in xen/docs/misra/ and are
named as safe.json and false-positive.json, they have JSON format.

Here is an example to add a new justification::

|{
|    "version": "1.0",
|    "content": [
|        {
|            "id":"SAF-0-safe",
|            "analyser": {
|                "cppcheck": "misra-c2012-20.7",
|                "coverity": "misra_c_2012_rule_20_7_violation",
|                "eclair": "MC3R1.R20.7"
|            },
|            "name": “R20.7 C macro parameters not used as expression",
|            "text": "The macro parameters used in this […]"
|        },
|        {
|            "id":”SAF-1-safe",
|            "analyser": {
|                "cppcheck": "unreadVariable",
|                "coverity": "UNUSED_VALUE"
|            },
|            "name": “Variable set but not used",
|            "text": “It is safe because […]"
|        },
|        {
|            "id":”SAF-2-safe",
|            "analyser": {},
|            "name": "Sentinel",
|            "text": ""
|        }
|    ]
|}

To document a finding, just add another block {[...]} before the sentinel block,
using the id contained in the sentinel block and increment by one the number
contained in the id of the sentinel block.

Here a brief explanation of the field inside an object of the "content" array:
- id: it is a unique string that is used to refer to the finding, many finding
  can be tagged with the same id, if the justification holds for any applied
  case.
  It tells the tool to substitute a Xen in-code comment having this structure:
  /* SAF-0-safe [...] \*/
- analyser: it is an object containing pair of key-value strings, the key is
  the analyser, so it can be cppcheck, coverity or eclair. The value is the
  proprietary id corresponding on the finding, for example when coverity is
  used as analyser, the tool will translate the Xen in-code coment in this way:
  /* SAF-0-safe [...] \*/ -> /* coverity[coverity-id] \*/
  if the object doesn't have a key-value, then the corresponding in-code
  comment won't be translated.
- name: a simple name for the finding
- text: a proper justification to turn off the finding.



Here an example of the usage of the in-code comment tags:

/* SAF-0-safe [eventual developer message that shall not exceeds line char max 
count, don’t break the line!] */
#define string_param(_name, _var) \
    __setup_str __setup_str_##_var[] = _name; \
    __kparam __setup_##_var = \
        { .name = __setup_str_##_var, \
          .type = OPT_STR, \
          .len = sizeof(_var), \
          .par.var = &_var }

In the example above, the tool finding for this macro is suppressed. When there 
are multiple findings for
the same line, multiple in-code comments needs to be inserted, every one on a 
different line.

Cheers,
Luca

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.