Skip to content

bugfix: allow hardlink to softlink file#2458

Merged
crosbymichael merged 1 commit intocontainerd:masterfrom
fuweid:bugfix_apply_hardlink_to_softlink
Jul 19, 2018
Merged

bugfix: allow hardlink to softlink file#2458
crosbymichael merged 1 commit intocontainerd:masterfrom
fuweid:bugfix_apply_hardlink_to_softlink

Conversation

@fuweid
Copy link
Copy Markdown
Member

@fuweid fuweid commented Jul 12, 2018

With fs.RootPath, the target file will be the file which the softlink points to, like:

  touch /tmp/zzz
  ln -s /tmp/zzz /tmp/xxx
  ln /tmp/xxx /tmp/yyy

The /tmp/yyy should be same with the /tmp/xxx, not /tmp/zzz.

Signed-off-by: Wei Fu [email protected]

@fuweid
Copy link
Copy Markdown
Member Author

fuweid commented Jul 12, 2018

There is the Dockerfile for the case:

FROM busybox:latest

RUN touch /tmp/zzz \
 && ln -s /tmp/zzz /tmp/xxx \
 && ln /tmp/xxx /tmp/yyy

And we will get message like that:

➜  image ctr image pull localhost:5000/test:1
localhost:5000/test:1:                                                            resolved       |++++++++++++++++++++++++++++++++++++++|
manifest-sha256:ef7956cb7dd23df318fb83a4d0e8f54ea165048eca66db1387f882d4b7880e93: done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:970eabf5aa7df00f9b6fffb5861facd625f2851f4acdcb09768648249591687f:    done           |++++++++++++++++++++++++++++++++++++++|
config-sha256:358a921423bc8db85f6f4b32cc6d6e3d33700eb58fe73084bda6dacb6ac92a49:   done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:07a152489297fc2bca20be96fab3527ceac5668328a30fd543a160cd689ee548:    done           |++++++++++++++++++++++++++++++++++++++|
elapsed: 0.1 s                                                                    total:   0.0 B (0.0 B/s)
unpacking sha256:ef7956cb7dd23df318fb83a4d0e8f54ea165048eca66db1387f882d4b7880e93...
INFO[0000] Apply failure, attempting cleanup             error="rpc error: code = NotFound desc = link /tmp/extract-661700870/tmp/zzz /tmp/extract-661700870/tmp/yyy: no such file or directory" key="extract-514942130-FIi0 sha256:ebac1d644fd76b7d13b5ab99bec73f63be2eb043567556a85625fa98f1fbec3b"
ctr: failed to extract layer sha256:d9acc7ab6c3578d3537f6bae0db2e667eaf38e8b4f612b661135f6ca261dd364: rpc error: code = NotFound desc = link /tmp/extract-661700870/tmp/zzz /tmp/extract-661700870/tmp/yyy: no such file or directory

@fuweid fuweid force-pushed the bugfix_apply_hardlink_to_softlink branch from 12d7ec1 to 3e689c9 Compare July 12, 2018 06:47
@AkihiroSuda
Copy link
Copy Markdown
Member

Could you add UT?

@fuweid
Copy link
Copy Markdown
Member Author

fuweid commented Jul 12, 2018

Could you add UT?

Sure. Will do @AkihiroSuda

@fuweid fuweid changed the title bugfix: allow hardlink to softlink file [WIP] bugfix: allow hardlink to softlink file Jul 13, 2018
@fuweid fuweid force-pushed the bugfix_apply_hardlink_to_softlink branch from 3e689c9 to 9c814e7 Compare July 16, 2018 14:19
@fuweid fuweid changed the title [WIP] bugfix: allow hardlink to softlink file bugfix: allow hardlink to softlink file Jul 16, 2018
@fuweid fuweid force-pushed the bugfix_apply_hardlink_to_softlink branch from 9c814e7 to 3bd32ea Compare July 16, 2018 14:38
@fuweid
Copy link
Copy Markdown
Member Author

fuweid commented Jul 16, 2018

Hi @AkihiroSuda and @dmcgowan

I update the code and the test case. Please take a look, thanks.

BTW, the CI fails cause of make check-protos check-api-descriptors;. Is it about the goproto tools?

@fuweid fuweid force-pushed the bugfix_apply_hardlink_to_softlink branch from 3bd32ea to 86d382a Compare July 16, 2018 15:03
Comment thread archive/tar.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need "/" here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need separator here. I have removed it. Thanks!

@fuweid fuweid force-pushed the bugfix_apply_hardlink_to_softlink branch 3 times, most recently from 1a58a48 to efae3d8 Compare July 17, 2018 02:50
@fuweid
Copy link
Copy Markdown
Member Author

fuweid commented Jul 17, 2018

ping @AkihiroSuda . Does the change make senses?

@fuweid fuweid force-pushed the bugfix_apply_hardlink_to_softlink branch from efae3d8 to dc12223 Compare July 17, 2018 15:06
@codecov-io
Copy link
Copy Markdown

codecov-io commented Jul 17, 2018

Codecov Report

Merging #2458 into master will increase coverage by <.01%.
The diff coverage is 50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2458      +/-   ##
==========================================
+ Coverage   44.73%   44.73%   +<.01%     
==========================================
  Files          93       93              
  Lines        9490     9501      +11     
==========================================
+ Hits         4245     4250       +5     
- Misses       4562     4566       +4     
- Partials      683      685       +2
Flag Coverage Δ
#linux 48.94% <60%> (ø) ⬆️
#windows 40.98% <0%> (-0.06%) ⬇️
Impacted Files Coverage Δ
archive/tar.go 43.11% <50%> (+0.05%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 94cfce6...3b1534c. Read the comment docs.

Comment thread archive/tar.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result of this should still be checked before returning since base could be ".." and this would return the parent directory. The link operation should fail but it should not get all the way to making a syscall with the parent directory as an arg.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make senses. Have updated. Please take a look. @dmcgowan

cc @AkihiroSuda

@fuweid fuweid force-pushed the bugfix_apply_hardlink_to_softlink branch from dc12223 to 52b74d1 Compare July 18, 2018 07:21
Comment thread archive/tar.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the Lstat is necessary here. When we do get a syscall error we want to error, but invalid input here should probably just end up returning a valid path, for example if you tried to join / and .. then instead of erroring, you would just return /.

Maybe try just doing this with another split

targetPath := filepath.Join(ppath, base)
if filepath.Base(targetPath) != ppath {
	targetPath = ppath
}
return targetPath, nil

In this case any further attempt to alter the directory location with the base name will just end up with ppath which we know is a safe path even though it might result in a Link error.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I made it complicated by the Lstat.

As you mentioned, don't allow the base to change the ppath so that we keep the scope. But it's quite strict. The base can be out of the ppath but in the root, which make the error information accuracy. In this case, we can check targetPath is out of root or not. If does, we just return the root.

How about this solution? 😄

With `fs.RootPath`, the target file will be the file which the softlink
points to, like:

  touch /tmp/zzz
  ln -s /tmp/zzz /tmp/xxx
  ln /tmp/xxx /tmp/yyy

The `/tmp/yyy` should be same with the `/tmp/xxx`, not `/tmp/zzz`. We
should allow hardlink to softlink file.

Signed-off-by: Wei Fu <[email protected]>
@fuweid fuweid force-pushed the bugfix_apply_hardlink_to_softlink branch from 52b74d1 to 3b1534c Compare July 19, 2018 07:14
@dmcgowan
Copy link
Copy Markdown
Member

LGTM

@crosbymichael crosbymichael merged commit 49fb363 into containerd:master Jul 19, 2018
@fuweid fuweid deleted the bugfix_apply_hardlink_to_softlink branch February 20, 2019 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants