Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mountinfo: add "empty source" test case #5

Merged
merged 1 commit into from
Mar 19, 2020

Conversation

kolyshkin
Copy link
Collaborator

@kolyshkin kolyshkin commented Mar 16, 2020

TIL older kernels (presumably < 5.1) has a bug of not showing
the "source" field in /proc/self/mountinfo in case an empty
string was passed as the source argument to mount() syscall.

My best guess is it was fixed by the kernel commit 8f2918898eb5f
("new helpers: vfs_create_mount(), fc_mount()", Nov 4 2018) which
is v5.1-rc1~12^2~37, i.e. kernel 5.1 should be the one with the fix.

I was able to reproduce it on a machine with an old kernel:

[kir@micros ~]$ cat a.c
 #include <sys/mount.h>
 #include <stdio.h>

int main(void) {
	int r;

	r = mount("", "/tmp/bb", "tmpfs", MS_MGC_VAL, (void*)0);
	if (r != 0) {
		perror("mount");
		return 1;
	}

	return 0;
}
[kir@micros ~]$ gcc -Wall -o a a.c
[kir@micros ~]$ mkdir /tmp/bb
[kir@micros ~]$ ./a; echo $?
mount: Operation not permitted
1
[kir@micros ~]$ sudo ./a; echo $?
0
[kir@micros ~]$ grep -F /tmp/bb /proc/self/mountinfo
279 23 0:108 / /tmp/bb rw,relatime - tmpfs  rw
[kir@micros ~]$ # notice the two spaces ^^^^^ here

[kir@micros ~]$ uname -a
Linux micros 2.6.32-042stab133.2 #1 SMP Mon Aug 27 21:07:08 MSK 2018 x86_64 x86_64 x86_64 GNU/Linux

The most interesting thing is this package is not affected by the bug,
working as expected, since strings.Split by a space gives an empty
element in case of two spaces.

Nevertheless, it makes sense to add a test case for it.

Signed-off-by: Kir Kolyshkin [email protected]

TIL older kernels (presumably < 5.1) has a bug of not showing
the "source" field in /proc/self/mountinfo in case an empty
string was passed as the source argument to mount() syscall.

My best guess is it was fixed by the kernel commit 8f2918898eb5f
("new helpers: vfs_create_mount(), fc_mount()", Nov 4 2018) which
is v5.1-rc1~12^2~37, i.e. kernel 5.1 should be the one with the fix.

I was able to reproduce it on a machine with an old kernel:

```console
[kir@micros ~]$ cat a.c
 #include <sys/mount.h>
 #include <stdio.h>

int main(void) {
	int r;

	r = mount("", "/tmp/bb", "tmpfs", MS_MGC_VAL, (void*)0);
	if (r != 0) {
		perror("mount");
		return 1;
	}

	return 0;
}
[kir@micros ~]$ gcc -Wall -o a a.c
[kir@micros ~]$ mkdir /tmp/bb
[kir@micros ~]$ ./a; echo $?
mount: Operation not permitted
1
[kir@micros ~]$ sudo ./a; echo $?
0
[kir@micros ~]$ grep -F /tmp/bb /proc/self/mountinfo
279 23 0:108 / /tmp/bb rw,relatime - tmpfs  rw
[kir@micros ~]$ # notice the two spaces ^^^^^ here

[kir@micros ~]$ uname -a
Linux micros 2.6.32-042stab133.2 #1 SMP Mon Aug 27 21:07:08 MSK 2018 x86_64 x86_64 x86_64 GNU/Linux
```

The most interesting thing is this package is not affected by the bug,
working as expected, since strings.Split by a space gives an empty
element in case of two spaces.

Nevertheless, it makes sense to add a test case for it.

Signed-off-by: Kir Kolyshkin <[email protected]>
@kolyshkin
Copy link
Collaborator Author

rebased to kick CI

@kolyshkin
Copy link
Collaborator Author

Windows CI failures are expected (and are fixed in #8)

Copy link
Member

@tianon tianon left a comment

Choose a reason for hiding this comment

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

Nice find!

Copy link
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

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

LGTM

@cpuguy83 cpuguy83 merged commit 5a58efb into moby:master Mar 19, 2020
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.

3 participants