Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
The Tor Project
Core
Tor
Commits
95d4bff7
Commit
95d4bff7
authored
4 years ago
by
Nick Mathewson
Browse files
Options
Downloads
Plain Diff
Merge remote-tracking branch 'tor-gitlab/mr/67' into maint-0.4.4
parents
09601c3c
d75e7daa
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
changes/bug27315
+6
-0
6 additions, 0 deletions
changes/bug27315
src/lib/sandbox/sandbox.c
+32
-10
32 additions, 10 deletions
src/lib/sandbox/sandbox.c
with
38 additions
and
10 deletions
changes/bug27315
0 → 100644
+
6
−
0
View file @
95d4bff7
o Minor bugfixes (linux seccomp2 sandbox):
- Fix a regression on sandboxing rules for the openat() syscall.
The fix for bug 25440 fixed the problem on systems with glibc >=
2.27 but broke tor on previous versions of glibc. We now apply
the correct seccomp rule according to the running glibc version.
Patch from Daniel Pinto. Fixes bug 27315; bugfix on 0.3.5.11.
This diff is collapsed.
Click to expand it.
src/lib/sandbox/sandbox.c
+
32
−
10
View file @
95d4bff7
...
...
@@ -137,6 +137,10 @@ static sandbox_cfg_t *filter_dynamic = NULL;
* the high bits of the value might get masked out improperly. */
#define SCMP_CMP_MASKED(a,b,c) \
SCMP_CMP4((a), SCMP_CMP_MASKED_EQ, ~(scmp_datum_t)(b), (c))
/* For negative constants, the rule to add depends on the glibc version. */
#define SCMP_CMP_NEG(a,op,b) (libc_negative_constant_needs_cast() ? \
(SCMP_CMP((a), (op), (unsigned int)(b))) : \
(SCMP_CMP_STR((a), (op), (b))))
/** Variable used for storing all syscall numbers that will be allowed with the
* stage 1 general Tor sandbox.
...
...
@@ -438,31 +442,49 @@ sb_mmap2(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
#endif
#endif
/* Return true
if we think we're running with a libc that always uses
*
openat on linux
. */
/* Return true
the libc version is greater or equal than
*
<b>major</b>.<b>minor</b>. Returns false otherwise
. */
static
int
libc_
uses_openat_for_everything
(
void
)
is_
libc_
at_least
(
int
major
,
int
minor
)
{
#ifdef CHECK_LIBC_VERSION
const
char
*
version
=
gnu_get_libc_version
();
if
(
version
==
NULL
)
return
0
;
int
major
=
-
1
;
int
minor
=
-
1
;
int
libc_
major
=
-
1
;
int
libc_
minor
=
-
1
;
tor_sscanf
(
version
,
"%d.%d"
,
&
major
,
&
minor
);
if
(
major
>
=
3
)
tor_sscanf
(
version
,
"%d.%d"
,
&
libc_
major
,
&
libc_
minor
);
if
(
libc_
major
>
major
)
return
1
;
else
if
(
major
==
2
&&
minor
>=
26
)
else
if
(
libc_
major
==
major
&&
libc_
minor
>=
minor
)
return
1
;
else
return
0
;
#else
/* !defined(CHECK_LIBC_VERSION) */
(
void
)
major
;
(
void
)
minor
;
return
0
;
#endif
/* defined(CHECK_LIBC_VERSION) */
}
/* Return true if we think we're running with a libc that always uses
* openat on linux. */
static
int
libc_uses_openat_for_everything
(
void
)
{
return
is_libc_at_least
(
2
,
26
);
}
/* Return true if we think we're running with a libc that needs to cast
* negative arguments like AT_FDCWD for seccomp rules. */
static
int
libc_negative_constant_needs_cast
(
void
)
{
return
is_libc_at_least
(
2
,
27
);
}
/** Allow a single file to be opened. If <b>use_openat</b> is true,
* we're using a libc that remaps all the opens into openats. */
static
int
...
...
@@ -470,7 +492,7 @@ allow_file_open(scmp_filter_ctx ctx, int use_openat, const char *file)
{
if
(
use_openat
)
{
return
seccomp_rule_add_2
(
ctx
,
SCMP_ACT_ALLOW
,
SCMP_SYS
(
openat
),
SCMP_CMP
(
0
,
SCMP_CMP_EQ
,
(
unsigned
int
)
AT_FDCWD
),
SCMP_CMP
_NEG
(
0
,
SCMP_CMP_EQ
,
AT_FDCWD
),
SCMP_CMP_STR
(
1
,
SCMP_CMP_EQ
,
file
));
}
else
{
return
seccomp_rule_add_1
(
ctx
,
SCMP_ACT_ALLOW
,
SCMP_SYS
(
open
),
...
...
@@ -606,7 +628,7 @@ sb_openat(scmp_filter_ctx ctx, sandbox_cfg_t *filter)
if
(
param
!=
NULL
&&
param
->
prot
==
1
&&
param
->
syscall
==
SCMP_SYS
(
openat
))
{
rc
=
seccomp_rule_add_3
(
ctx
,
SCMP_ACT_ALLOW
,
SCMP_SYS
(
openat
),
SCMP_CMP
(
0
,
SCMP_CMP_EQ
,
AT_FDCWD
),
SCMP_CMP
_NEG
(
0
,
SCMP_CMP_EQ
,
AT_FDCWD
),
SCMP_CMP_STR
(
1
,
SCMP_CMP_EQ
,
param
->
value
),
SCMP_CMP
(
2
,
SCMP_CMP_EQ
,
O_RDONLY
|
O_NONBLOCK
|
O_LARGEFILE
|
O_DIRECTORY
|
O_CLOEXEC
));
...
...
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