Skip to content

Commit ffcaa70

Browse files
Expand the answers allowed by oob1 (#476)
* Expand the answers allowed by oob1 There are many variations of possible answers for oob1. Be more generous by allowing more of them. This uses the new "definitions" capability (and is a demonstration of their use). Signed-off-by: David A. Wheeler <[email protected]> * Improve text description Signed-off-by: David A. Wheeler <[email protected]> --------- Signed-off-by: David A. Wheeler <[email protected]>
1 parent c4b3728 commit ffcaa70

File tree

1 file changed

+48
-29
lines changed

1 file changed

+48
-29
lines changed

docs/labs/oob1.html

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,16 @@
2626
<!-- Full pattern of correct answer -->
2727
<script id="correct0" type="plain/text">
2828
\s*
29-
if \s+ \(
30-
(1 \+ 2 \+ 16|19) > s -> s3 -> rrec \. length \)
31-
\s+ RETURN0
29+
if \( (NINETEEN > FULL_LENGTH|FULL_LENGTH < NINETEEN) \)
30+
RETURN0
3231
\s*
3332
</script>
3433
<script id="correct1" type="plain/text">
3534
\s*
36-
if \s+ \( (1 \+ 2|3) \+ payload \+ 16 > s -> s3 -> rrec \. length \)
37-
\s+ RETURN0
35+
if \( (PAYLOAD_LENGTH > FULL_LENGTH|FULL_LENGTH < PAYLOAD_LENGTH) \)
36+
RETURN0
3837
\s*
3938
</script>
40-
<!--
41-
\s* app \. use \( helmet \( \{
42-
contentSecurityPolicy: \{
43-
directives: \{
44-
"script-src": \[ "'self'" ,
45-
(["'`])https://example\.com\1 \] ,
46-
"style-src": \[ "'self'" \]
47-
\} ,
48-
\}
49-
\} \) \) ;
50-
-->
5139

5240
<script id="info" type="application/yaml">
5341
---
@@ -60,12 +48,30 @@
6048
- absent: |
6149
>
6250
text: Need comparison "if ( ... > ....)"
51+
- absent: s -> s3 -> rrec \. length
52+
text: Need to compare a value with s->s3->rrec.length
6353
- absent: return
6454
text: Need "return 0;" to skip attempts to send a too-long response.
6555
definitions:
56+
- term: NINETEEN
57+
value: |
58+
(1 \+ 2 \+ 16|19)
59+
- term: NINETEEN
60+
value: |
61+
(NINETEEN|\( NINETEEN \))
62+
- term: PAYLOAD_LENGTH
63+
value: (1 \+ 2|3) \+ payload \+ 16
64+
- term: PAYLOAD_LENGTH
65+
value: (PAYLOAD_LENGTH|payload \+ NINETEEN|NINETEEN \+ payload)
66+
- term: PAYLOAD_LENGTH
67+
value: |
68+
(PAYLOAD_LENGTH|\( PAYLOAD_LENGTH \))
6669
- term: RETURN0
6770
value: |
6871
return \s+ 0 ;
72+
- term: FULL_LENGTH
73+
value: |
74+
s -> s3 -> rrec \. length
6975
- term: RETURN0
7076
value: |
7177
(RETURN0|\{ RETURN0 \})
@@ -161,23 +167,32 @@ <h2>Task</h2>
161167
<p>
162168
<h2>Background</h2>
163169
<p>
164-
In almost all programming languages, the default response a program
165-
attempts to read or write outside
166-
of a buffer is either an attempt to resize the buffer or
167-
an error of some kind (e.g., raising an exception).
170+
In almost all programming languages, if program
171+
attempts to read or write outside of a buffer,
172+
the default is always either an attempt to resize the buffer or
173+
an error of some kind (e.g., by raising an exception).
168174
That's because it's extremely easy to accidentally attempt to read
169175
or write outside of a buffer.
170176
<p>
171-
However, C and the built-in arrays of C++ are different.
172-
In C and C++, attempting to read or write outside a buffer is
173-
<i>undefined behavior</i> and <i>anything</i> is allowed to happen
177+
However, C and C++ are different.
178+
C++ has evolved to become somewhat safer (e.g., through smart pointers),
179+
In C and C++, attempting to do actions like read or write outside a buffer is
180+
in many cases
181+
<i>undefined behavior</i>, and when undefined behavior occurs,
182+
<i>anything</i> is allowed to happen
174183
without any kind of protection.
175184
In practice, what often happens is a read or write (respectively) of
176185
other data.
186+
There are
187+
<a href="https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2771r0.html"
188+
>proposals to improve C++ memory safety</a>,
189+
but currently many C++ built-in constructs (like arrays) are not memory safe,
190+
so we will treat the two languages together here.
177191
<p>
178192
The 2014 revelation of the Heartbleed vulnerability
179193
(CVE-2014-0160) is an example of a buffer overread vulnerability.
180194
Heartbleed was a vulnerability in OpenSSL, a widely-used toolkit
195+
written in C
181196
that implements the cryptographic protocol Secure Sockets Layer
182197
(SSL) and its successor the Transport Layer Security (TLS).
183198
Heartbleed affected a huge number of popular websites, including
@@ -196,31 +211,35 @@ <h2>Task Information</h2>
196211
At this point in the code, the construct
197212
<tt>s->s3->rrec.length</tt>
198213
indicates how many bytes are available.
199-
Modify the code below in two places.
214+
If we don't check for the maximum sizes, we could easily cause
215+
reading beyond a buffer.
216+
Modify the code below in two places to fix this.
200217
<p>
201218
First, modify the code so that
202219
if the minimum length of a response <tt>(1 + 2 + 16)</tt> is more than
203220
the length claimed by
204221
<tt>s->s3->rrec.length</tt>,
205-
return return 0 without sending a heartbeat,
222+
and return 0 without sending a heartbeat,
206223
This will prevent trying to create a heartbeat when there's not enough
207-
room to create one.
224+
room to create a heartbeat at all.
208225
<p>
209226
Second, modify the code so that
210227
if the minimum length of a response with a payload
211228
<tt>(1 + 2 + payload + 16</tt>
212229
is more than the total length for a response given in
213230
<tt>s->s3->rrec.length</tt> then again
214-
return return 0 without sending a heartbeat,
231+
return 0 without sending a heartbeat,
215232
<p>
216233
This will prevent trying to create a heartbeat when there's not enough
217-
room to create one.
234+
room to create one and there was a payload to return as a heartbeat.
218235
<p>
219236
Note that this is not terribly difficult to fix.
237+
The code we add is short.
220238
The problem is that reading and writing buffers is extremely common,
221239
but by default such accesses are unsafe in C and C++.
222240
In practice it is difficult to <i>always</i> check all ranges
223-
in all possible cases.
241+
in all possible cases, which is why memory safety vulnerabilities
242+
are so common in programs written in C or C++.
224243
<!--
225244
if (1 + 2 + 16 > s->s3->rrec.length)
226245
return 0; /* silently discard */

0 commit comments

Comments
 (0)