Commit ba66b14b authored by Pavel Emelyanov's avatar Pavel Emelyanov

packet: Get packet_sock_mmap test work in userns

The test uses map_files dir to check for mapping being restored,
while this proc directory is only available for CAP_SYS_ADMIN.

Fix this by checking less strict /proc/pid/maps.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 36497915
......@@ -251,7 +251,6 @@ generate_test_list()
ns/static/mlock_setuid
ns/static/sched_prio00
ns/static/sched_policy00
ns/static/packet_sock_mmap
ns/static/fanotify00
ns/static/fifo-ghost
ns/static/unlink_fifo
......
......@@ -34,24 +34,24 @@ struct tpacket_req3 {
static void check_map_is_there(unsigned long addr, int sk)
{
char name[128];
struct stat sk_s, link_s;
sprintf(name, "/proc/self/map_files/%lx-%lx",
addr, addr + 2 * 4096);
if (stat(name, &link_s) < 0) {
fail("No socket mapping\n");
FILE *f;
char line[64];
struct stat ss;
fstat(sk, &ss);
f = fopen("/proc/self/maps", "r");
while (fgets(line, sizeof(line), f) != NULL) {
unsigned long start;
int maj, min, ino;
sscanf(line, "%lx-%*x %*s %*s %x:%x %d %*s", &start, &maj, &min, &ino);
if ((start == addr) && ss.st_dev == makedev(maj, min) && ss.st_ino == ino) {
pass();
return;
}
fstat(sk, &sk_s);
if ((sk_s.st_dev != link_s.st_dev) || (sk_s.st_ino != link_s.st_ino)) {
fail("Non-socket mapping restored\n");
return;
}
pass();
fail("No socket mapping found");
}
int main(int argc, char **argv)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment