This repository has been archived by the owner on Dec 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add restrictions to proc in libcontainer
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
- Loading branch information
1 parent
2ded58e
commit 4d2d635
Showing
3 changed files
with
86 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package restrict | ||
|
||
import ( | ||
"fmt" | ||
"github.com/dotcloud/docker/pkg/system" | ||
"path/filepath" | ||
"syscall" | ||
) | ||
|
||
const flags = syscall.MS_BIND | syscall.MS_REC | syscall.MS_RDONLY | ||
|
||
var restrictions = map[string]string{ | ||
// dirs | ||
"/proc/sys": "", | ||
"/proc/irq": "", | ||
"/proc/acpi": "", | ||
|
||
// files | ||
"/proc/sysrq-trigger": "/dev/null", | ||
"/proc/kcore": "/dev/null", | ||
} | ||
|
||
// Restrict locks down access to many areas of proc | ||
// by using the asumption that the user does not have mount caps to | ||
// revert the changes made here | ||
func Restrict(rootfs, empty string) error { | ||
for dest, source := range restrictions { | ||
dest = filepath.Join(rootfs, dest) | ||
|
||
// we don't have a "/dev/null" for dirs so have the requester pass a dir | ||
// for us to bind mount | ||
switch source { | ||
case "": | ||
source = empty | ||
default: | ||
source = filepath.Join(rootfs, source) | ||
} | ||
if err := system.Mount(source, dest, "bind", flags, ""); err != nil { | ||
return fmt.Errorf("unable to mount %s over %s %s", source, dest, err) | ||
} | ||
if err := system.Mount("", dest, "bind", flags|syscall.MS_REMOUNT, ""); err != nil { | ||
return fmt.Errorf("unable to mount %s over %s %s", source, dest, err) | ||
} | ||
} | ||
return nil | ||
} |