Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tor
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
jarl
tor
Commits
1df11433
Commit
1df11433
authored
8 years ago
by
Nick Mathewson
Browse files
Options
Downloads
Plain Diff
Merge branch 'buf_sentinel_026_v2' into maint-0.2.8
parents
ab98c438
3cea86eb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
changes/buf-sentinel
+11
-0
11 additions, 0 deletions
changes/buf-sentinel
src/or/buffers.c
+32
-8
32 additions, 8 deletions
src/or/buffers.c
with
43 additions
and
8 deletions
changes/buf-sentinel
0 → 100644
+
11
−
0
View file @
1df11433
o Major features (security fixes):
- Prevent a class of security bugs caused by treating the contents
of a buffer chunk as if they were a NUL-terminated string. At
least one such bug seems to be present in all currently used
versions of Tor, and would allow an attacker to remotely crash
most Tor instances, especially those compiled with extra compiler
hardening. With this defense in place, such bugs can't crash Tor,
though we should still fix them as they occur. Closes ticket 20384
(TROVE-2016-10-001).
This diff is collapsed.
Click to expand it.
src/or/buffers.c
+
32
−
8
View file @
1df11433
...
...
@@ -70,12 +70,33 @@ static int parse_socks_client(const uint8_t *data, size_t datalen,
#define CHUNK_HEADER_LEN STRUCT_OFFSET(chunk_t, mem[0])
/* We leave this many NUL bytes at the end of the buffer. */
#define SENTINEL_LEN 4
/* Header size plus NUL bytes at the end */
#define CHUNK_OVERHEAD (CHUNK_HEADER_LEN + SENTINEL_LEN)
/** Return the number of bytes needed to allocate a chunk to hold
* <b>memlen</b> bytes. */
#define CHUNK_ALLOC_SIZE(memlen) (CHUNK_HEAD
ER_LEN
+ (memlen))
#define CHUNK_ALLOC_SIZE(memlen) (CHUNK_
OVER
HEAD + (memlen))
/** Return the number of usable bytes in a chunk allocated with
* malloc(<b>memlen</b>). */
#define CHUNK_SIZE_WITH_ALLOC(memlen) ((memlen) - CHUNK_HEADER_LEN)
#define CHUNK_SIZE_WITH_ALLOC(memlen) ((memlen) - CHUNK_OVERHEAD)
#define DEBUG_SENTINEL
#ifdef DEBUG_SENTINEL
#define DBG_S(s) s
#else
#define DBG_S(s) (void)0
#endif
#define CHUNK_SET_SENTINEL(chunk, alloclen) do { \
uint8_t *a = (uint8_t*) &(chunk)->mem[(chunk)->memlen]; \
DBG_S(uint8_t *b = &((uint8_t*)(chunk))[(alloclen)-SENTINEL_LEN]); \
DBG_S(tor_assert(a == b)); \
memset(a,0,SENTINEL_LEN); \
} while (0)
/** Return the next character in <b>chunk</b> onto which data can be appended.
* If the chunk is full, this might be off the end of chunk->mem. */
...
...
@@ -132,6 +153,7 @@ chunk_new_with_alloc_size(size_t alloc)
ch
->
memlen
=
CHUNK_SIZE_WITH_ALLOC
(
alloc
);
total_bytes_allocated_in_chunks
+=
alloc
;
ch
->
data
=
&
ch
->
mem
[
0
];
CHUNK_SET_SENTINEL
(
ch
,
alloc
);
return
ch
;
}
...
...
@@ -141,18 +163,20 @@ static inline chunk_t *
chunk_grow
(
chunk_t
*
chunk
,
size_t
sz
)
{
off_t
offset
;
size_t
memlen_orig
=
chunk
->
memlen
;
const
size_t
memlen_orig
=
chunk
->
memlen
;
const
size_t
orig_alloc
=
CHUNK_ALLOC_SIZE
(
memlen_orig
);
const
size_t
new_alloc
=
CHUNK_ALLOC_SIZE
(
sz
);
tor_assert
(
sz
>
chunk
->
memlen
);
offset
=
chunk
->
data
-
chunk
->
mem
;
chunk
=
tor_realloc
(
chunk
,
CHUNK_ALLOC_SIZE
(
sz
)
);
chunk
=
tor_realloc
(
chunk
,
new_alloc
);
chunk
->
memlen
=
sz
;
chunk
->
data
=
chunk
->
mem
+
offset
;
#ifdef DEBUG_CHUNK_ALLOC
tor_assert
(
chunk
->
DBG_alloc
==
CHUNK_ALLOC_SIZE
(
memlen_orig
)
);
chunk
->
DBG_alloc
=
CHUNK_ALLOC_SIZE
(
sz
)
;
tor_assert
(
chunk
->
DBG_alloc
==
orig_alloc
);
chunk
->
DBG_alloc
=
new_alloc
;
#endif
total_bytes_allocated_in_chunks
+=
CHUNK_
ALLOC_SIZE
(
sz
)
-
CHUNK_ALLOC_SIZE
(
memlen_orig
);
total_bytes_allocated_in_chunks
+=
new_alloc
-
orig_alloc
;
CHUNK_
SET_SENTINEL
(
chunk
,
new_alloc
);
return
chunk
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment