Skip to content

Commit feb4d26

Browse files
author
james
committed
docs: address first round of review comments on other slides and add intro to ql decks
1 parent 4c71498 commit feb4d26

22 files changed

+275
-250
lines changed

docs/language/ql-training-rst/_static-training/slides-semmle-2/static/theme/css/default.css

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ ul {
480480
ul li {
481481
margin-bottom: 0.5em;
482482
color: #2c2a8a;
483+
line-height: 1.3em;
483484
}
484485
/* line 303, ../scss/default.scss */
485486
ul li ul {
@@ -494,9 +495,10 @@ ul li ul li:before {
494495
/* line 314, ../scss/default.scss */
495496
ul > li:before {
496497
content: '\00B7';
497-
margin-left: -1em;
498+
margin-left: -0.5em;
498499
position: absolute;
499500
font-weight: 600;
501+
font-size: 2em;
500502
}
501503
/* line 321, ../scss/default.scss */
502504
ul ul {
@@ -1415,16 +1417,8 @@ slide {
14151417
background-size: cover;
14161418
}
14171419

1418-
.agenda-slide h1 {
1419-
padding:0;
1420-
}
14211420

1422-
.background2 h1, .background2 p {
1423-
color: white;
1424-
}
1425-
1426-
1427-
/* Title slide styles */
1421+
/* Custom slide styles */
14281422

14291423
.semmle-logo sup {
14301424
vertical-align: super;
@@ -1442,6 +1436,23 @@ slide {
14421436
color: white;
14431437
font-size: 1.2em;
14441438
}
1439+
1440+
.agenda-slide h1 {
1441+
padding:0;
1442+
}
1443+
1444+
.background2 h1, .background2 p {
1445+
color: white;
1446+
}
1447+
1448+
hgroup .pre {
1449+
color: #5c31ff;
1450+
}
1451+
1452+
.title-slide hgroup .pre {
1453+
color: white;
1454+
}
1455+
14451456
/* James column experiments */
14461457

14471458
.column-left {

docs/language/ql-training-rst/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,7 @@ def setup(sphinx):
120120
'nosidebar':True,
121121
}
122122

123+
# Exclude the slide snippets from the build
124+
exclude_patterns = ['slide-snippets']
123125

124126
##############################################################################

docs/language/ql-training-rst/cpp/bad-overflow-guard.rst

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,22 @@ Example: Bad overflow guard
55

66
Semmle :sup:`TM`
77

8+
.. Include information slides here
89
9-
Getting started and setting up
10-
==============================
10+
.. include:: ../slide-snippets/info.rst
1111

12-
To try the examples in this presentation you should download:
12+
QL snapshot
13+
===========
1314

14-
- `QL for Eclipse <https://help.semmle.com/ql-for-eclipse/Content/WebHelp/install-plugin-free.html>`__
15-
- Snapshot: `ChakraCore <https://downloads.lgtm.com/snapshots/cpp/microsoft/chakracore/ChakraCore-revision-2017-April-12--18-13-26.zip>`__
15+
For the examples in this presentation, we will be analyzing `ChakraCore <https://github.com/microsoft/ChakraCore>`__.
1616

17-
More resources:
17+
We recommend you download `this historic snapshot <https://downloads.lgtm.com/snapshots/cpp/microsoft/chakracore/ChakraCore-revision-2017-April-12--18-13-26.zip>`__ to analyze in QL for Eclipse.
1818

19-
- To learn more about the main features of QL, try looking at the `QL language handbook <https://help.semmle.com/QL/ql-handbook/>`__.
20-
- For further information about writing queries in QL, see `Writing QL queries <https://help.semmle.com/QL/learn-ql/ql/writing-queries/writing-queries.html>`__.
19+
Alternatively, you can query the project in `the query console <https://lgtm.com/query/project:2034240708/lang:cpp/>`__ on LGTM.com.
2120

2221
.. note::
2322

24-
To run the queries featured in this training presentation, we recommend you download the free-to-use `QL for Eclipse plugin <https://help.semmle.com/ql-for-eclipse/Content/WebHelp/getting-started.html>`__.
25-
26-
This plugin allows you to locally access the latest features of QL, including the standard QL libraries and queries. It also provides standard IDE features such as syntax highlighting, jump-to-definition, and tab completion.
27-
28-
A good project to start analyzing is `ChakraCore <https://github.com/microsoft/ChakraCore>`__–a suitable snapshot to query is available by visiting the link on the slide.
29-
30-
Alternatively, you can query any project (including ChakraCore) in the `query console on LGTM.com <https://lgtm.com/query/project:2034240708/lang:cpp/>`__.
31-
32-
Note that results generated in the query console are likely to differ to those generated in the QL plugin. LGTM.com analyzes the most recent revisions of each project that has been added–the snapshot available to download above is for an historical version of the code base.
33-
23+
Note that results generated in the query console are likely to differ to those generated in the QL plugin as LGTM.com analyzes the most recent revisions of each project that has been added–the snapshot available to download above is based on an historical version of the code base.
3424

3525
Checking for overflow in C
3626
==========================

docs/language/ql-training-rst/cpp/control-flow-cpp.rst

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,23 @@ Analyzing control flow for C/C++
44
.. container:: semmle-logo
55

66
Semmle :sup:`TM`
7-
8-
Getting started and setting up
9-
==============================
10-
11-
To try the examples in this presentation you should download:
12-
13-
- `QL for Eclipse <https://help.semmle.com/ql-for-eclipse/Content/WebHelp/install-plugin-free.html>`__
14-
- Snapshot: `ChakraCore <https://downloads.lgtm.com/snapshots/cpp/microsoft/chakracore/ChakraCore-revision-2017-April-12--18-13-26.zip>`__
157

16-
More resources:
8+
.. Include information slides here
179
18-
- To learn more about the main features of QL, try looking at the `QL language handbook <https://help.semmle.com/QL/ql-handbook/>`__.
19-
- For further information about writing queries in QL, see `Writing QL queries <https://help.semmle.com/QL/learn-ql/ql/writing-queries/writing-queries.html>`__.
10+
.. include:: ../slide-snippets/info.rst
2011

21-
.. note::
12+
QL snapshot
13+
===========
2214

23-
To run the queries featured in this training presentation, we recommend you download the free-to-use `QL for Eclipse plugin <https://help.semmle.com/ql-for-eclipse/Content/WebHelp/getting-started.html>`__.
15+
For the examples in this presentation, we will be analyzing `ChakraCore <https://github.com/microsoft/ChakraCore>`__.
2416

25-
This plugin allows you to locally access the latest features of QL, including the standard QL libraries and queries. It also provides standard IDE features such as syntax highlighting, jump-to-definition, and tab completion.
17+
We recommend you download `this historic snapshot <https://downloads.lgtm.com/snapshots/cpp/microsoft/chakracore/ChakraCore-revision-2017-April-12--18-13-26.zip>`__ to analyze in QL for Eclipse.
2618

27-
A good project to start analyzing is `ChakraCore <https://github.com/microsoft/ChakraCore>`__–a suitable snapshot to query is available by visiting the link on the slide.
19+
Alternatively, you can query the project in `the query console <https://lgtm.com/query/project:2034240708/lang:cpp/>`__ on LGTM.com.
2820

29-
Alternatively, you can query any project (including ChakraCore) in the `query console on LGTM.com <https://lgtm.com/query/project:2034240708/lang:cpp/>`__.
21+
.. note::
3022

31-
Note that results generated in the query console are likely to differ to those generated in the QL plugin. LGTM.com analyzes the most recent revisions of each project that has been added–the snapshot available to download above is based on an historical version of the code base.
23+
Note that results generated in the query console are likely to differ to those generated in the QL plugin as LGTM.com analyzes the most recent revisions of each project that has been added–the snapshot available to download above is based on an historical version of the code base.
3224

3325
Agenda
3426
======
@@ -116,7 +108,7 @@ Find calls to free that are reachable from an allocation on the same variable:
116108

117109
.. note::
118110

119-
Predicates allocationCall and freeCall are defined in the standard library and model a number of standard alloc/free-like functions.
111+
Predicates ``allocationCall`` and ``freeCall`` are defined in the standard library and model a number of standard alloc/free-like functions.
120112

121113
Exercise: use after free
122114
========================
@@ -125,12 +117,12 @@ Based on this query, write a query that finds accesses to the variable that occu
125117

126118
.. rst-class:: build
127119

128-
- What do you find? What problems occur with this approach to detecting use-after-free vulnerabilities?
120+
- What do you find? What problems occur with this approach to detecting use-after-free vulnerabilities?
129121

130122
.. rst-class:: build
131123

132124
.. literalinclude:: ../query-examples/cpp/control-flow-cpp-2.ql
133-
:language: ql
125+
:language: ql
134126

135127
Utilizing recursion
136128
===================
@@ -300,7 +292,7 @@ Write a query that finds all calls to a field called ``error_exit``.
300292

301293
.. code-block:: ql
302294
303-
class CallThroughVariable extends ExprCall { }
295+
class CallThroughVariable extends ExprCall { ... }
304296
305297
class ErrorExitCall extends CallThroughVariable {
306298
override Field v;
@@ -322,7 +314,7 @@ Override ``ControlFlowNode`` to mark calls to ``error_exit`` as non-returning.
322314

323315
.. code-block:: ql
324316
325-
class CallThroughVariable extends ExprCall { }
317+
class CallThroughVariable extends ExprCall { ... }
326318
327319
class ErrorExitCall extends CallThroughVariable {
328320
override Field v;

docs/language/ql-training-rst/cpp/data-flow-cpp.rst

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,22 @@ Introduction to data flow
77

88
Finding string formatting vulnerabilities in C/C++
99

10-
Getting started and setting up
11-
==============================
10+
.. Include information slides here
1211
13-
To try the examples in this presentation you should download:
12+
.. include:: ../slide-snippets/info.rst
1413

15-
- `QL for Eclipse <https://help.semmle.com/ql-for-eclipse/Content/WebHelp/install-plugin-free.html>`__
16-
- Snapshot: `dotnet/coreclr <http://downloads.lgtm.com/snapshots/cpp/dotnet/coreclr/dotnet_coreclr_fbe0c77.zip>`__
14+
QL snapshot
15+
===========
1716

18-
More resources:
17+
For the examples in this presentation, we will be analyzing `dotnet/coreclr <https://github.com/dotnet/coreclr>`__.
1918

20-
- To learn more about the main features of QL, try looking at the `QL language handbook <https://help.semmle.com/QL/ql-handbook/>`__.
21-
- For further information about writing queries in QL, see `Writing QL queries <https://help.semmle.com/QL/learn-ql/ql/writing-queries/writing-queries.html>`__.
19+
We recommend you download `this historic snapshot <http://downloads.lgtm.com/snapshots/cpp/dotnet/coreclr/dotnet_coreclr_fbe0c77.zip>`__ to analyze in QL for Eclipse.
2220

23-
.. note::
24-
25-
To run the queries featured in this training presentation, we recommend you download the free-to-use `QL for Eclipse plugin <https://help.semmle.com/ql-for-eclipse/Content/WebHelp/getting-started.html>`__.
26-
27-
This plugin allows you to locally access the latest features of QL, including the standard QL libraries and queries. It also provides standard IDE features such as syntax highlighting, jump-to-definition, and tab completion.
21+
Alternatively, you can query the project in `the query console <https://lgtm.com/query/projects:1505958977333/lang:cpp/>`__ on LGTM.com.
2822

29-
A good project to start analyzing is `ChakraCore <https://github.com/dotnet/coreclr>`__–a suitable snapshot to query is available by visiting the link on the slide.
30-
31-
Alternatively, you can query any project (including ChakraCore) in the `query console on LGTM.com <https://lgtm.com/query/projects:1505958977333/lang:cpp/>`__.
23+
.. note::
3224

33-
Note that results generated in the query console are likely to differ to those generated in the QL plugin as LGTM.com analyzes the most recent revisions of each project that has been added–the snapshot available to download above is based on an historical version of the code base.
25+
Note that results generated in the query console are likely to differ to those generated in the QL plugin as LGTM.com analyzes the most recent revisions of each project that has been added–the snapshot available to download above is based on an historical version of the code base.
3426

3527
Agenda
3628
======
@@ -68,7 +60,7 @@ Let’s write a query to identify instances of `CWE-134 <https://cwe.mitre.org/d
6860
6961
In this case, we have one more format specifier than we have arguments. In a managed language such as Java or C#, this simply leads to a runtime exception. However, in C/C++, the formatting functions are typically implemented by reading values from the stack without any validation of the number of arguments. This means a mismatch in the number of format specifiers and format arguments can lead to information disclosure.
7062

71-
Of course, in practice this happens rarely with *constant* formatting strings. Instead, it’s most problematic when the formatting string can be specified by the user, allowing an attacker to provide a formatting string with the wrong number of format specifiers. Furthermore, if an attacker can control the format string, they may be able to provide the %n format specifier, which causes ``printf`` to write the number characters in the generated output string to a specified location.
63+
Of course, in practice this happens rarely with *constant* formatting strings. Instead, it’s most problematic when the formatting string can be specified by the user, allowing an attacker to provide a formatting string with the wrong number of format specifiers. Furthermore, if an attacker can control the format string, they may be able to provide the ``%n`` format specifier, which causes ``printf`` to write the number characters in the generated output string to a specified location.
7264

7365
See https://en.wikipedia.org/wiki/Uncontrolled_format_string for more background.
7466

@@ -107,26 +99,29 @@ We need something better.
10799

108100
.. code-block:: cpp
109101
110-
const char *format = align == AlignLeft ? "%-*.*s" : "%*.*s";
111-
112-
if (IsDMLEnabled())
113-
DMLOut(format, width, precision, mValue);
114-
else
115-
ExtOut(format, width, precision, mValue);
102+
const char *format = align == AlignLeft ? "%-*.*s" : "%*.*s";
103+
104+
if (IsDMLEnabled())
105+
DMLOut(format, width, precision, mValue);
106+
else
107+
ExtOut(format, width, precision, mValue);
116108
117109
Here, ``DMLOut`` and ``ExtOut`` are macros that expand to formatting calls. The format specifier is not constant, in the sense that the format argument is not a string literal. However, it is clearly one of two possible constants, both with the same number of format specifiers.
118110

119-
What we need is a way to determine whether the format argument is ever set to something that is not constant.
111+
What we need is a way to determine whether the format argument is ever set to something that is, not constant.
120112

121113
Data flow analysis
122114
==================
123115

124116
- Models flow of data through the program.
125117
- Implemented in the module ``semmle.code.cpp.dataflow.DataFlow``.
126118
- Class ``DataFlow::Node`` represents program elements that have a value, such as expressions and function parameters.
119+
127120
- Nodes of the data flow graph.
121+
128122
- Various predicated represent flow between these nodes.
129-
Edges of the data flow graph.
123+
124+
- Edges of the data flow graph.
130125

131126
.. note::
132127

@@ -183,8 +178,7 @@ Local vs global data flow
183178
- Local (“intra-procedural”) data flow models flow within one function; feasible to compute for all functions in a snapshot
184179
- Global (“inter-procedural”) data flow models flow across function calls; not feasible to compute for all functions in a snapshot
185180
- Different APIs, so discussed separately
186-
187-
This slide deck focuses on the former.
181+
- This slide deck focuses on the former.
188182

189183
.. note::
190184

@@ -212,14 +206,14 @@ To use the data flow library, add the following import:
212206
.. code-block:: ql
213207
214208
module DataFlow {
215-
class Node extends { }
209+
class Node extends ... { ... }
216210
predicate localFlow(Node source, Node sink) {
217211
localFlowStep*(source, sink)
218212
}
219-
213+
...
220214
}
221215
222-
So all references will need to be qualified (that is ``DataFlow::Node``)
216+
So all references will need to be qualified (that is, ``DataFlow::Node``)
223217

224218
.. note::
225219

@@ -248,7 +242,7 @@ Data flow graph
248242

249243
The ``DataFlow::Node`` class is shared between both the local and global data flow graphs–the primary difference is the edges, which in the “global” case can link different functions.
250244

251-
``localFlowStep`` is the “single step” flow relation–that is it describes single edges in the local data flow graph. ``localFlow`` represents the `transitive <https://help.semmle.com/QL/ql-handbook/recursion.html#transitive-closures>`__ closure of this relation–in other words, it contains every pair of nodes where the second node is reachable from the first in the data flow graph.
245+
``localFlowStep`` is the “single step” flow relation–that is, it describes single edges in the local data flow graph. ``localFlow`` represents the `transitive <https://help.semmle.com/QL/ql-handbook/recursion.html#transitive-closures>`__ closure of this relation–in other words, it contains every pair of nodes where the second node is reachable from the first in the data flow graph.
252246

253247
The data flow graph is separate from the `AST <https://en.wikipedia.org/wiki/Abstract_syntax_tree>`__, to allow for flexibility in how data flow is modeled. There are a small number of data flow node types–expression nodes, parameter nodes, uninitialized variable nodes, and definition by reference nodes. Each node provides mapping functions to and from the relevant AST (for example ``Expr``, ``Parameter`` etc.) or symbol table (for example ``Variable``) classes.
254248

@@ -306,7 +300,7 @@ Define a subclass of ``DataFlow::Node`` representing “source” nodes, that is
306300
Revisiting non-constant format strings
307301
======================================
308302

309-
Refine the query to find calls to ``printf``-like functions where the format argument derives from a local source that is not a constant string.
303+
Refine the query to find calls to ``printf``-like functions where the format argument derives from a local source that is, not a constant string.
310304

311305
.. rst-class:: build
312306

@@ -320,6 +314,7 @@ Audit the results and apply any refinements you deem necessary.
320314
Suggestions:
321315

322316
- Replace ``DataFlow::localFlowStep`` with a custom predicate that includes steps through global variable definitions.
317+
323318
**Hint**: Use class ``GlobalVariable`` and its member predicates ``getAnAssignedValue()`` and ``getAnAccess()``.
324319

325320
- Exclude calls in wrapper functions that just forward their format argument to another ``printf``-like function; instead, flag calls to those functions.
@@ -330,4 +325,4 @@ Beyond local data flow
330325
- Results are still underwhelming.
331326
- Dealing with parameter passing becomes cumbersome.
332327
- Instead, let’s turn the problem around and find user-controlled data that flows into a ``printf`` format argument, potentially through calls.
333-
- This needs **global data flow**.
328+
- This needs **global data flow**.

0 commit comments

Comments
 (0)