Skip to content

Commit c9b649d

Browse files
authored
Merge pull request #1357 from cyphar/noterminal-io-tests
tests: add various !terminal tests
2 parents 74a1729 + ffe5cdc commit c9b649d

File tree

3 files changed

+64
-8
lines changed

3 files changed

+64
-8
lines changed

libcontainer/init_linux.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -348,21 +348,22 @@ func fixStdioPermissions(config *initConfig, u *user.ExecUser) error {
348348
continue
349349
}
350350

351-
// Skip chown if s.Gid is actually an unmapped gid in the host. While
352-
// this is a bit dodgy if it just so happens that the console _is_
353-
// owned by overflow_gid, there's no way for us to disambiguate this as
354-
// a userspace program.
355-
if _, err := config.Config.HostGID(int(s.Gid)); err != nil {
356-
continue
357-
}
358-
359351
// We only change the uid owner (as it is possible for the mount to
360352
// prefer a different gid, and there's no reason for us to change it).
361353
// The reason why we don't just leave the default uid=X mount setup is
362354
// that users expect to be able to actually use their console. Without
363355
// this code, you couldn't effectively run as a non-root user inside a
364356
// container and also have a console set up.
365357
if err := unix.Fchown(int(fd), u.Uid, int(s.Gid)); err != nil {
358+
// If we've hit an EINVAL then s.Gid isn't mapped in the user
359+
// namespace. If we've hit an EPERM then the inode's current owner
360+
// is not mapped in our user namespace (in particular,
361+
// privileged_wrt_inode_uidgid() has failed). In either case, we
362+
// are in a configuration where it's better for us to just not
363+
// touch the stdio rather than bail at this point.
364+
if err == unix.EINVAL || err == unix.EPERM {
365+
continue
366+
}
366367
return err
367368
}
368369
}

tests/integration/config.json

Whitespace-only changes.

tests/integration/tty.bats

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,58 @@ EOF
173173
# test tty width and height against original process.json
174174
[[ ${lines[0]} =~ "rows 10; columns 110" ]]
175175
}
176+
177+
@test "runc create [terminal=false]" {
178+
# Disable terminal creation.
179+
sed -i 's|"terminal": true,|"terminal": false,|g' config.json
180+
# Replace sh script with sleep.
181+
sed -i 's|"sh"|"sleep", "1000s"|' config.json
182+
183+
# Make sure that the handling of detached IO is done properly. See #1354.
184+
__runc create test_busybox
185+
186+
# Start the command.
187+
runc start test_busybox
188+
[ "$status" -eq 0 ]
189+
190+
testcontainer test_busybox running
191+
192+
# Kill the container.
193+
runc kill test_busybox KILL
194+
[ "$status" -eq 0 ]
195+
}
196+
197+
@test "runc run [terminal=false]" {
198+
# Disable terminal creation.
199+
sed -i 's|"terminal": true,|"terminal": false,|g' config.json
200+
# Replace sh script with sleep.
201+
sed -i 's|"sh"|"sleep", "1000s"|' config.json
202+
203+
# Make sure that the handling of non-detached IO is done properly. See #1354.
204+
(
205+
__runc run test_busybox
206+
) &
207+
208+
wait_for_container 15 1 test_busybox
209+
testcontainer test_busybox running
210+
211+
# Kill the container.
212+
runc kill test_busybox KILL
213+
[ "$status" -eq 0 ]
214+
}
215+
216+
@test "runc run -d [terminal=false]" {
217+
# Disable terminal creation.
218+
sed -i 's|"terminal": true,|"terminal": false,|g' config.json
219+
# Replace sh script with sleep.
220+
sed -i 's|"sh"|"sleep", "1000s"|' config.json
221+
222+
# Make sure that the handling of detached IO is done properly. See #1354.
223+
__runc run -d test_busybox
224+
225+
testcontainer test_busybox running
226+
227+
# Kill the container.
228+
runc kill test_busybox KILL
229+
[ "$status" -eq 0 ]
230+
}

0 commit comments

Comments
 (0)