Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
3a9018bb
Unverified
Commit
3a9018bb
authored
Jun 26, 2020
by
Stéphane Graber
Committed by
GitHub
Jun 26, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3463 from brauner/2020-06-26/fixes
confile: handle overflow in lxc.time.offset.{boot,monotonic}
parents
11e5f16a
f1c43439
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
24 deletions
+60
-24
confile.c
src/lxc/confile.c
+32
-24
start.c
src/lxc/start.c
+14
-0
utils.c
src/lxc/utils.c
+12
-0
utils.h
src/lxc/utils.h
+2
-0
No files found.
src/lxc/confile.c
View file @
3a9018bb
...
...
@@ -2831,22 +2831,26 @@ static int set_config_time_offset_boot(const char *key, const char *value,
if
(
ret
)
return
ret
;
/* TODO: Handle overflow. */
unit
=
lxc_trim_whitespace_in_place
(
buf
);
if
(
strcmp
(
unit
,
"h"
)
==
0
)
lxc_conf
->
timens
.
s_boot
=
offset
*
3600
;
else
if
(
strcmp
(
unit
,
"m"
)
==
0
)
lxc_conf
->
timens
.
s_boot
=
offset
*
60
;
else
if
(
strcmp
(
unit
,
"s"
)
==
0
)
if
(
strcmp
(
unit
,
"h"
)
==
0
)
{
if
(
!
multiply_overflow
(
offset
,
3600
,
&
lxc_conf
->
timens
.
s_boot
))
return
-
EOVERFLOW
;
}
else
if
(
strcmp
(
unit
,
"m"
)
==
0
)
{
if
(
!
multiply_overflow
(
offset
,
60
,
&
lxc_conf
->
timens
.
s_boot
))
return
-
EOVERFLOW
;
}
else
if
(
strcmp
(
unit
,
"s"
)
==
0
)
{
lxc_conf
->
timens
.
s_boot
=
offset
;
else
if
(
strcmp
(
unit
,
"ms"
)
==
0
)
lxc_conf
->
timens
.
ns_boot
=
offset
*
1000000
;
else
if
(
strcmp
(
unit
,
"us"
)
==
0
)
lxc_conf
->
timens
.
ns_boot
=
offset
*
1000
;
else
if
(
strcmp
(
unit
,
"ns"
)
==
0
)
}
else
if
(
strcmp
(
unit
,
"ms"
)
==
0
)
{
if
(
!
multiply_overflow
(
offset
,
1000000
,
&
lxc_conf
->
timens
.
ns_boot
))
return
-
EOVERFLOW
;
}
else
if
(
strcmp
(
unit
,
"us"
)
==
0
)
{
if
(
!
multiply_overflow
(
offset
,
1000
,
&
lxc_conf
->
timens
.
ns_boot
))
return
-
EOVERFLOW
;
}
else
if
(
strcmp
(
unit
,
"ns"
)
==
0
)
{
lxc_conf
->
timens
.
ns_boot
=
offset
;
else
}
else
{
return
ret_errno
(
EINVAL
);
}
return
0
;
}
...
...
@@ -2866,22 +2870,26 @@ static int set_config_time_offset_monotonic(const char *key, const char *value,
if
(
ret
)
return
ret
;
// TODO: Handle overflow.
unit
=
lxc_trim_whitespace_in_place
(
buf
);
if
(
strcmp
(
unit
,
"h"
)
==
0
)
lxc_conf
->
timens
.
s_monotonic
=
offset
*
3600
;
else
if
(
strcmp
(
unit
,
"m"
)
==
0
)
lxc_conf
->
timens
.
s_monotonic
=
offset
*
60
;
else
if
(
strcmp
(
unit
,
"s"
)
==
0
)
if
(
strcmp
(
unit
,
"h"
)
==
0
)
{
if
(
!
multiply_overflow
(
offset
,
3600
,
&
lxc_conf
->
timens
.
s_monotonic
))
return
-
EOVERFLOW
;
}
else
if
(
strcmp
(
unit
,
"m"
)
==
0
)
{
if
(
!
multiply_overflow
(
offset
,
60
,
&
lxc_conf
->
timens
.
s_monotonic
))
return
-
EOVERFLOW
;
}
else
if
(
strcmp
(
unit
,
"s"
)
==
0
)
{
lxc_conf
->
timens
.
s_monotonic
=
offset
;
else
if
(
strcmp
(
unit
,
"ms"
)
==
0
)
lxc_conf
->
timens
.
ns_monotonic
=
offset
*
1000000
;
else
if
(
strcmp
(
unit
,
"us"
)
==
0
)
lxc_conf
->
timens
.
ns_monotonic
=
offset
*
1000
;
else
if
(
strcmp
(
unit
,
"ns"
)
==
0
)
}
else
if
(
strcmp
(
unit
,
"ms"
)
==
0
)
{
if
(
!
multiply_overflow
(
offset
,
1000000
,
&
lxc_conf
->
timens
.
ns_monotonic
))
return
-
EOVERFLOW
;
}
else
if
(
strcmp
(
unit
,
"us"
)
==
0
)
{
if
(
!
multiply_overflow
(
offset
,
1000
,
&
lxc_conf
->
timens
.
ns_monotonic
))
return
-
EOVERFLOW
;
}
else
if
(
strcmp
(
unit
,
"ns"
)
==
0
)
{
lxc_conf
->
timens
.
ns_monotonic
=
offset
;
else
}
else
{
return
ret_errno
(
EINVAL
);
}
return
0
;
}
...
...
src/lxc/start.c
View file @
3a9018bb
...
...
@@ -1870,6 +1870,20 @@ static int lxc_spawn(struct lxc_handler *handler)
cgroup_ops
->
payload_finalize
(
cgroup_ops
);
TRACE
(
"Finished setting up cgroups"
);
if
(
handler
->
ns_clone_flags
&
CLONE_NEWTIME
)
{
/* Now we're ready to preserve the cgroup namespace */
ret
=
lxc_try_preserve_ns
(
handler
->
pid
,
"time"
);
if
(
ret
<
0
)
{
if
(
ret
!=
-
EOPNOTSUPP
)
{
SYSERROR
(
"Failed to preserve time namespace"
);
goto
out_delete_net
;
}
}
else
{
handler
->
nsfd
[
LXC_NS_TIME
]
=
ret
;
DEBUG
(
"Preserved time namespace via fd %d"
,
ret
);
}
}
/* Run any host-side start hooks */
ret
=
run_lxc_hooks
(
name
,
"start-host"
,
conf
,
NULL
);
if
(
ret
<
0
)
{
...
...
src/lxc/utils.c
View file @
3a9018bb
...
...
@@ -1904,3 +1904,15 @@ int fix_stdio_permissions(uid_t uid)
return
fret
;
}
bool
multiply_overflow
(
int64_t
base
,
uint64_t
mult
,
int64_t
*
res
)
{
if
(
base
>
0
&&
base
>
(
INT64_MAX
/
mult
))
return
false
;
if
(
base
<
0
&&
base
<
(
INT64_MIN
/
mult
))
return
false
;
*
res
=
base
*
mult
;
return
true
;
}
src/lxc/utils.h
View file @
3a9018bb
...
...
@@ -251,4 +251,6 @@ static inline bool gid_valid(gid_t gid)
return
gid
!=
LXC_INVALID_GID
;
}
extern
bool
multiply_overflow
(
int64_t
base
,
uint64_t
mult
,
int64_t
*
res
);
#endif
/* __LXC_UTILS_H */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment