You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`Variant analysis <https://semmle.com/variant-analysis>`__ is the process of using a known vulnerability as a seed to find similar problems in your code. Security engineers typically perform variant analysis to identify possible vulnerabilities and to ensure that these threats are properly fixed across multiple code bases.
8
8
9
-
`QL<https://semmle.com/ql>`__ is Semmle's variant analysis engine, and it is also the technology that underpins LGTM, Semmle's community driven security analysis platform. Together, QL and LGTM provide continuous monitoring and scalable variant analysis for your projects, even if you don’t have your own team of dedicated security engineers. You can read more about using QL and LGTM in variant analysis in the `Semmle blog <https://blog.semmle.com/tags/variant-analysis>`__.
9
+
`CodeQL<https://semmle.com/ql>`__ is the code analysis enginethat underpins LGTM, Semmle's community driven security analysis platform. Together, CodeQL and LGTM provide continuous monitoring and scalable variant analysis for your projects, even if you don’t have your own team of dedicated security engineers. You can read more about using CodeQL and LGTM in variant analysis in the `Semmle blog <https://blog.semmle.com/tags/variant-analysis>`__.
10
10
11
-
The QL language is easy to learn, and exploring code using QL is the most efficient way to perform variant analysis.
11
+
CodeQL is easy to learn, and exploring code using CodeQL is the most efficient way to perform variant analysis.
12
12
13
-
Learning QL for variant analysis
14
-
================================
13
+
Learning CodeQL for variant analysis
14
+
------------------------------------
15
15
16
-
Start learning how to use QL in variant analysis for a specific language by looking at the topics below. Each topic links to a short presentation on the QL language, QL libraries, or an example variant discovered using QL.
16
+
Start learning how to use CodeQL in variant analysis for a specific language by looking at the topics below. Each topic links to a short presentation on CodeQL, its libraries, or an example variant discovered using CodeQL.
17
17
18
18
.. |arrow-l| unicode:: U+2190
19
19
@@ -24,43 +24,43 @@ Start learning how to use QL in variant analysis for a specific language by look
24
24
When you have selected a presentation, use |arrow-r| and |arrow-l| to navigate between slides.
25
25
Press **p** to view the additional notes on slides that have an information icon |info| in the top right corner, and press **f** to enter full-screen mode.
26
26
27
-
The presentations contain a number of QL query examples.
27
+
The presentations contain a number of query examples.
28
28
We recommend that you download `QL for Eclipse <https://help.semmle.com/ql-for-eclipse/Content/WebHelp/home-page.html>`__ and import the example snapshot for each presentation so that you can find the bugs mentioned in the slides.
29
29
30
30
31
31
.. pull-quote::
32
32
33
33
Information
34
34
35
-
The presentations listed below are used in QL language and variant analysis training sessions run by Semmle engineers.
35
+
The presentations listed below are used in CodeQL and variant analysis training sessions run by Semmle engineers.
36
36
Therefore, be aware that the slides are designed to be presented by an instructor.
37
37
If you are using the slides without an instructor, please use the additional notes to help guide you through the examples.
38
38
39
-
QL and variant analysis for C/C++
40
-
---------------------------------
39
+
CodeQL and variant analysis for C/C++
40
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
41
41
42
-
- `Introduction to variant analysis: QL for C/C++ <../ql-training/cpp/intro-ql-cpp.html>`__–an introduction to variant analysis and QL for C/C++ programmers.
42
+
- `Introduction to variant analysis: CodeQL for C/C++ <../ql-training/cpp/intro-ql-cpp.html>`__–an introduction to variant analysis and CodeQL for C/C++ programmers.
43
43
- `Example: Bad overflow guard <../ql-training/cpp/bad-overflow-guard.html>`__–an example of iterative query development to find bad overflow guards in a C++ project.
44
-
- `Program representation: QL for C/C++ <../ql-training/cpp/program-representation-cpp.html>`__–information on how QL analysis represents C/C++ programs.
45
-
- `Introduction to local data flow <../ql-training/cpp/data-flow-cpp.html>`__–an introduction to analyzing local data flow in C/C++ using QL, including an example demonstrating how to develop a query to find a real CVE.
44
+
- `Program representation: CodeQL for C/C++ <../ql-training/cpp/program-representation-cpp.html>`__–information on how CodeQL analysis represents C/C++ programs.
45
+
- `Introduction to local data flow <../ql-training/cpp/data-flow-cpp.html>`__–an introduction to analyzing local data flow in C/C++ using CodeQL, including an example demonstrating how to develop a query to find a real CVE.
46
46
- `Exercise: snprintf overflow <../ql-training/cpp/snprintf.html>`__–an example demonstrating how to develop a data flow query.
47
-
- `Introduction to global data flow <../ql-training/cpp/global-data-flow-cpp.html>`__–an introduction to analyzing global data flow in C/C++ using QL.
48
-
- `Analyzing control flow: QL for C/C++ <../ql-training/cpp/control-flow-cpp.html>`__–an introduction to analyzing control flow in C/C++ using QL.
47
+
- `Introduction to global data flow <../ql-training/cpp/global-data-flow-cpp.html>`__–an introduction to analyzing global data flow in C/C++ using CodeQL.
48
+
- `Analyzing control flow: CodeQL for C/C++ <../ql-training/cpp/control-flow-cpp.html>`__–an introduction to analyzing control flow in C/C++ using CodeQL.
49
49
50
-
QL and variant analysis for Java
51
-
--------------------------------
50
+
CodeQL and variant analysis for Java
51
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
52
52
53
-
- `Introduction to variant analysis: QL for Java <../ql-training/java/intro-ql-java.html>`__–an introduction to variant analysis and QL for Java programmers.
53
+
- `Introduction to variant analysis: CodeQL for Java <../ql-training/java/intro-ql-java.html>`__–an introduction to variant analysis and CodeQL for Java programmers.
54
54
- `Example: Query injection <../ql-training/java/query-injection-java.html>`__–an example of iterative query development to find unsanitized SPARQL injections in a Java project.
55
-
- `Program representation: QL for Java <../ql-training/java/program-representation-java.html>`__–information on how QL analysis represents Java programs.
56
-
- `Introduction to local data flow <../ql-training/java/data-flow-java.html>`__–an introduction to analyzing local data flow in Java using QL, including an example demonstrating how to develop a query to find a real CVE.
55
+
- `Program representation: CodeQL for Java <../ql-training/java/program-representation-java.html>`__–information on how CodeQL analysis represents Java programs.
56
+
- `Introduction to local data flow <../ql-training/java/data-flow-java.html>`__–an introduction to analyzing local data flow in Java using CodeQL, including an example demonstrating how to develop a query to find a real CVE.
57
57
- `Exercise: Apache Struts <../ql-training/java/apache-struts-java.html>`__–an example demonstrating how to develop a data flow query.
58
-
- `Introduction to global data flow <../ql-training/java/global-data-flow-java.html>`__–an introduction to analyzing global data flow in Java using QL.
58
+
- `Introduction to global data flow <../ql-training/java/global-data-flow-java.html>`__–an introduction to analyzing global data flow in Java using CodeQL.
59
59
60
60
More resources
61
-
--------------
61
+
~~~~~~~~~~~~~~
62
62
63
-
- If you are completely new to QL, look at our introductory topics in :ref:`Getting started <getting-started>`.
64
-
- To find more detailed information about how to write QL queries for specific languages, visit the links in :ref:`Writing QL queries <writing-ql-queries>`.
65
-
- To read more about how QL queries have been used in Semmle's security research, and to read about new QL developments, visit the `Semmle blog <https://blog.semmle.com>`__.
63
+
- If you are completely new to CodeQL, look at our introductory topics in :doc:`Learning CodeQL <index>`.
64
+
- To find more detailed information about how to write queries for specific languages, visit the links in :ref:`Writing CodeQL queries <writing-ql-queries>`.
65
+
- To read more about how CodeQL queries have been used in Semmle's security research, and to read about new CodeQL developments, visit the `Semmle blog <https://blog.semmle.com>`__.
66
66
- Find more examples of queries written by Semmle's own security researchers in the `Semmle Demos repository <https://github.com/semmle/demos>`__ on GitHub.
For the examples in this presentation, we will be analyzing `ChakraCore <https://github.com/microsoft/ChakraCore>`__.
24
20
25
21
You can query the project in `the query console <https://lgtm.com/query/project:2034240708/lang:cpp/>`__ on LGTM.com.
26
22
27
-
.. insert snapshot-note.rst to explain differences between snapshot available to download and the version available in the query console.
23
+
.. insert database-note.rst to explain differences between database available to download and the version available in the query console.
28
24
29
-
.. include:: ../slide-snippets/snapshot-note.rst
25
+
.. include:: ../slide-snippets/database-note.rst
30
26
31
27
.. resume slides
32
28
@@ -127,13 +123,13 @@ This happens even though the overflow check passed!
127
123
128
124
.. rst-class:: background2
129
125
130
-
Developing a QL query
131
-
=====================
126
+
Developing a CodeQL query
127
+
=========================
132
128
133
129
Finding bad overflow guards
134
130
135
-
QL query: bad overflow guards
136
-
=============================
131
+
CodeQL query: bad overflow guards
132
+
==================================
137
133
138
134
Let’s look for overflow guards of the form ``v + b < v``, using the classes
139
135
``AddExpr``, ``Variable`` and ``RelationalOperation`` from the ``cpp`` library.
@@ -153,10 +149,10 @@ Let’s look for overflow guards of the form ``v + b < v``, using the classes
153
149
- a ``RelationalOperation``: the overflow comparison check.
154
150
- a ``Variable``: used as an argument to both the addition and comparison.
155
151
156
-
- The ``where`` part of the query ties these three QL variables together using `predicates <https://help.semmle.com/QL/ql-handbook/predicates.html>`__ defined in the `standard QL for C/C++ library <https://help.semmle.com/qldoc/cpp/>`__.
152
+
- The ``where`` part of the query ties these three variables together using `predicates <https://help.semmle.com/QL/ql-handbook/predicates.html>`__ defined in the `standard CodeQL for C/C++ library <https://help.semmle.com/qldoc/cpp/>`__.
157
153
158
-
QL query: bad overflow guards
159
-
=============================
154
+
CodeQL query: bad overflow guards
155
+
=================================
160
156
161
157
We want to ensure the operands being added have size less than 4 bytes.
162
158
@@ -180,8 +176,8 @@ We can get the size (in bytes) of a type using the ``getSize()`` method.
180
176
- We therefore write a helper predicate for small expressions.
181
177
- This predicate effectively represents the set of all expressions in the database where the size of the type of the expression is less than 4 bytes, that is, less than 32-bits.
182
178
183
-
QL query: bad overflow guards
184
-
=============================
179
+
CodeQL query: bad overflow guards
180
+
==================================
185
181
186
182
We can ensure the operands being added have size less than 4 bytes, using our new predicate.
187
183
@@ -216,8 +212,8 @@ Now our query becomes:
216
212
- The “range” part, ``op = a.getAnOperand()``, restricts ``op`` to being one of the two operands to the addition.
217
213
- The “condition” part, ``isSmall(op)``, says that the ``forall`` holds only if the condition (that the ``op`` is small) holds for everything in the range–that is, both the arguments to the addition.
218
214
219
-
QL query: bad overflow guards
220
-
=============================
215
+
CodeQL query: bad overflow guards
216
+
=================================
221
217
222
218
Sometimes the result of the addition is cast to a small type of size less than 4 bytes, preventing automatic widening. We don’t want our query to flag these instances.
This query finds a single result in our historic snapshot, which was `a genuine bug in ChakraCore <https://github.com/Microsoft/ChakraCore/commit/2500e1cdc12cb35af73d5c8c9b85656aba6bab4d>`__.
232
+
This query finds a single result in our historic database, which was `a genuine bug in ChakraCore <https://github.com/Microsoft/ChakraCore/commit/2500e1cdc12cb35af73d5c8c9b85656aba6bab4d>`__.
0 commit comments