1 Star 0 Fork 58

gnaygnil/docker

forked from src-openEuler/docker 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0051-docker-fix-panic-when-load-maliciously-image.patch 3.14 KB
一键复制 编辑 原始数据 按行查看 历史
gnaygnil 提交于 2020-02-13 15:36 . docker: Fixed build error and URL
From 1fe0a4bfad5d7fa418f4e726211f4f037e59cfee Mon Sep 17 00:00:00 2001
From: zhangyu235 <zhangyu235@huawei.com>
Date: Tue, 8 Jan 2019 19:47:28 +0800
Subject: [PATCH 051/111] docker: fix panic when load maliciously
image
reason:fix oom panic when load maliciously modified image with
huge size manifest files
cherry-pick from docker 1.11.2:
- bbe29c3 fix panic when load maliciously image
Change-Id: I2525e492fac31c33d3ba7275c95b570322a05025
Signed-off-by: leizhongkai <leizhongkai@huawei.com>
Signed-off-by: zhangyu235 <zhangyu235@huawei.com>
---
components/engine/image/tarexport/load.go | 28 +++++++++++++++++++
.../engine/image/tarexport/tarexport.go | 1 +
2 files changed, 29 insertions(+)
diff --git a/components/engine/image/tarexport/load.go b/components/engine/image/tarexport/load.go
index 786214383e..b9f8f7e3ac 100644
--- a/components/engine/image/tarexport/load.go
+++ b/components/engine/image/tarexport/load.go
@@ -49,6 +49,11 @@ func (l *tarexporter) Load(inTar io.ReadCloser, outStream io.Writer, quiet bool)
if err != nil {
return err
}
+
+ if err = checkJsonFileSize(manifestPath); err != nil {
+ return err
+ }
+
manifestFile, err := os.Open(manifestPath)
if err != nil {
if os.IsNotExist(err) {
@@ -72,6 +77,9 @@ func (l *tarexporter) Load(inTar io.ReadCloser, outStream io.Writer, quiet bool)
if err != nil {
return err
}
+ if err = checkJsonFileSize(configPath); err != nil {
+ return err
+ }
config, err := ioutil.ReadFile(configPath)
if err != nil {
return err
@@ -246,6 +254,11 @@ func (l *tarexporter) legacyLoad(tmpDir string, outStream io.Writer, progressOut
if err != nil {
return err
}
+
+ if err = checkJsonFileSize(repositoriesPath); err != nil {
+ return err
+ }
+
repositoriesFile, err := os.Open(repositoriesPath)
if err != nil {
return err
@@ -286,6 +299,9 @@ func (l *tarexporter) legacyLoadImage(oldID, sourceDir string, loadedMap map[str
if err != nil {
return err
}
+ if err = checkJsonFileSize(configPath); err != nil {
+ return err
+ }
imageJSON, err := ioutil.ReadFile(configPath)
if err != nil {
logrus.Debugf("Error reading json: %v", err)
@@ -413,6 +429,18 @@ func checkValidParent(img, parent *image.Image) bool {
return true
}
+func checkJsonFileSize(path string) error {
+ fileInfo, err := os.Stat(path)
+ if err != nil {
+ return err
+ }
+ fileSize := fileInfo.Size()
+ if fileSize > maxJsonFileSize {
+ return fmt.Errorf("%s is too large", filepath.Base(path))
+ }
+ return nil
+}
+
func checkCompatibleOS(imageOS string) error {
// always compatible if the images OS matches the host OS; also match an empty image OS
if imageOS == runtime.GOOS || imageOS == "" {
diff --git a/components/engine/image/tarexport/tarexport.go b/components/engine/image/tarexport/tarexport.go
index beff668cd8..f23fe6f8bb 100644
--- a/components/engine/image/tarexport/tarexport.go
+++ b/components/engine/image/tarexport/tarexport.go
@@ -13,6 +13,7 @@ const (
legacyConfigFileName = "json"
legacyVersionFileName = "VERSION"
legacyRepositoriesFileName = "repositories"
+ maxJsonFileSize = (10 * 1024 * 1024)
)
type manifestItem struct {
--
2.17.1
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gnaygnil/docker.git
git@gitee.com:gnaygnil/docker.git
gnaygnil
docker
docker
master

搜索帮助