public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug analyzer/106373] New: False positives from -Wanalyzer-tainted-array-index with casts @ 2022-07-20 18:09 dmalcolm at gcc dot gnu.org 2022-07-20 19:06 ` [Bug analyzer/106373] False positives from -Wanalyzer-tainted-array-index on comparison with non-const dmalcolm at gcc dot gnu.org ` (2 more replies) 0 siblings, 3 replies; 4+ messages in thread From: dmalcolm at gcc dot gnu.org @ 2022-07-20 18:09 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106373 Bug ID: 106373 Summary: False positives from -Wanalyzer-tainted-array-index with casts Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: analyzer Assignee: dmalcolm at gcc dot gnu.org Reporter: dmalcolm at gcc dot gnu.org Blocks: 106358 Target Milestone: --- See: https://godbolt.org/z/P5nGMohxd Am seeing false positive with -O1 -fanalyzer -fanalyzer-checker=taint on this code: struct raw_ep { /* ...snip... */ int state; /* ...snip... */ }; struct raw_dev { /* ...snip... */ struct raw_ep eps[30]; int eps_num; /* ...snip... */ }; int __attribute__((tainted_args)) simplified_raw_ioctl_ep_disable(struct raw_dev *dev, unsigned long value) { int ret = 0, i = value; if (i < 0 || i >= dev->eps_num) { ret = -16; goto out_unlock; } if (dev->eps[i].state == 0) { ret = -22; goto out_unlock; } out_unlock: return ret; } ../../src/raw_gadget.c: In function ‘simplified_raw_ioctl_ep_disable’: ../../src/raw_gadget.c:23:18: warning: use of attacker-controlled value ‘value’ in array lookup without upper-bounds checking [CWE-129] [-Wanalyzer-tainted-array-index] 23 | if (dev->eps[i].state == 0) { | ~~~~~~~~~~~^~~~~~ ‘simplified_raw_ioctl_ep_disable’: event 1 | | 15 | simplified_raw_ioctl_ep_disable(struct raw_dev *dev, unsigned long value) | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (1) function ‘simplified_raw_ioctl_ep_disable’ marked with ‘__attribute__((tainted_args))’ | +--> ‘simplified_raw_ioctl_ep_disable’: events 2-5 | | 15 | simplified_raw_ioctl_ep_disable(struct raw_dev *dev, unsigned long value) | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (2) entry to ‘simplified_raw_ioctl_ep_disable’ |...... | 19 | if (i < 0 || i >= dev->eps_num) { | | ~ | | | | | (3) following ‘false’ branch... |...... | 23 | if (dev->eps[i].state == 0) { | | ~~~~~~~~~~~~~~~~~ | | | | | (4) ...to here | | (5) use of attacker-controlled value ‘value’ in array lookup without upper-bounds checking | Seems to need at least -O1. Reduced from false positives seen in various ioctl handlers in Linux kernel in drivers/usb/gadget/legacy/raw_gadget.c (with "allyesconfig"). Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106358 [Bug 106358] [meta-bug] tracker bug for building the Linux kernel with -fanalyzer ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug analyzer/106373] False positives from -Wanalyzer-tainted-array-index on comparison with non-const 2022-07-20 18:09 [Bug analyzer/106373] New: False positives from -Wanalyzer-tainted-array-index with casts dmalcolm at gcc dot gnu.org @ 2022-07-20 19:06 ` dmalcolm at gcc dot gnu.org 2022-07-20 21:28 ` cvs-commit at gcc dot gnu.org 2022-07-20 21:32 ` dmalcolm at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: dmalcolm at gcc dot gnu.org @ 2022-07-20 19:06 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106373 David Malcolm <dmalcolm at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Last reconfirmed| |2022-07-20 Status|UNCONFIRMED |ASSIGNED Summary|False positives from |False positives from |-Wanalyzer-tainted-array-in |-Wanalyzer-tainted-array-in |dex with casts |dex on comparison with | |non-const --- Comment #1 from David Malcolm <dmalcolm at gcc dot gnu.org> --- The issue isn't the casts; it's the comparison against non-const, which looks like: _1 = dev_6(D)->eps_num; if (_1 <= i_4(D)) at the gimple level, and where i_4(D) is on the RHS, and sm-taint.cc is only looking at comparisons of the LHS. I'm testing a fix. ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug analyzer/106373] False positives from -Wanalyzer-tainted-array-index on comparison with non-const 2022-07-20 18:09 [Bug analyzer/106373] New: False positives from -Wanalyzer-tainted-array-index with casts dmalcolm at gcc dot gnu.org 2022-07-20 19:06 ` [Bug analyzer/106373] False positives from -Wanalyzer-tainted-array-index on comparison with non-const dmalcolm at gcc dot gnu.org @ 2022-07-20 21:28 ` cvs-commit at gcc dot gnu.org 2022-07-20 21:32 ` dmalcolm at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: cvs-commit at gcc dot gnu.org @ 2022-07-20 21:28 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106373 --- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by David Malcolm <dmalcolm@gcc.gnu.org>: https://gcc.gnu.org/g:5e830693dd335621940368b6d39b23afc2c98545 commit r13-1768-g5e830693dd335621940368b6d39b23afc2c98545 Author: David Malcolm <dmalcolm@redhat.com> Date: Wed Jul 20 17:25:35 2022 -0400 analyzer: update "tainted" state of RHS in comparisons [PR106373] Doing so fixes various false positives from -Wanalyzer-tainted-array-index at -O1 and above (e.g. seen on the Linux kernel) gcc/analyzer/ChangeLog: PR analyzer/106373 * sm-taint.cc (taint_state_machine::on_condition): Potentially update the state of the RHS as well as the LHS. gcc/testsuite/ChangeLog: PR analyzer/106373 * gcc.dg/analyzer/torture/taint-read-index-3.c: New test. Signed-off-by: David Malcolm <dmalcolm@redhat.com> ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug analyzer/106373] False positives from -Wanalyzer-tainted-array-index on comparison with non-const 2022-07-20 18:09 [Bug analyzer/106373] New: False positives from -Wanalyzer-tainted-array-index with casts dmalcolm at gcc dot gnu.org 2022-07-20 19:06 ` [Bug analyzer/106373] False positives from -Wanalyzer-tainted-array-index on comparison with non-const dmalcolm at gcc dot gnu.org 2022-07-20 21:28 ` cvs-commit at gcc dot gnu.org @ 2022-07-20 21:32 ` dmalcolm at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: dmalcolm at gcc dot gnu.org @ 2022-07-20 21:32 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106373 David Malcolm <dmalcolm at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|ASSIGNED |RESOLVED Resolution|--- |FIXED --- Comment #3 from David Malcolm <dmalcolm at gcc dot gnu.org> --- Should be fixed on trunk by the above patch. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-07-20 21:32 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-07-20 18:09 [Bug analyzer/106373] New: False positives from -Wanalyzer-tainted-array-index with casts dmalcolm at gcc dot gnu.org 2022-07-20 19:06 ` [Bug analyzer/106373] False positives from -Wanalyzer-tainted-array-index on comparison with non-const dmalcolm at gcc dot gnu.org 2022-07-20 21:28 ` cvs-commit at gcc dot gnu.org 2022-07-20 21:32 ` dmalcolm at gcc dot gnu.org
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).