Clement Calmels
1804dc6e14
/proc/self/maps doesn't display the real file offset
...
This addresses
http://bugzilla.kernel.org/show_bug.cgi?id=11318
In function show_map (file: fs/proc/task_mmu.c), if vma->vm_pgoff > 2^20
than (vma->vm_pgoff << PAGE_SIZE) is greater than 2^32 (with PAGE_SIZE
equal to 4096 (i.e. 2^12). The next seq_printf use an unsigned long for
the conversion of (vma->vm_pgoff << PAGE_SIZE), as a result the offset
value displayed in /proc/self/maps is truncated if the page offset is
greater than 2^20.
A test that shows this issue:
#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#define PAGE_SIZE (getpagesize())
#if __i386__
# define U64_STR "%llx"
#elif __x86_64
# define U64_STR "%lx"
#else
# error "Architecture Unsupported"
#endif
int main(int argc, char *argv[])
{
int fd;
char *addr;
off64_t offset = 0x10000000;
char *filename = "/dev/zero";
fd = open(filename, O_RDONLY);
if (fd < 0) {
perror("open");
return 1;
}
offset *= 0x10;
printf("offset = " U64_STR "\n", offset);
addr = (char*)mmap64(NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE, fd,
offset);
if ((void*)addr == MAP_FAILED) {
perror("mmap64");
return 1;
}
{
FILE *fmaps;
char *line = NULL;
size_t len = 0;
ssize_t read;
size_t filename_len = strlen(filename);
fmaps = fopen("/proc/self/maps", "r");
if (!fmaps) {
perror("fopen");
return 1;
}
while ((read = getline(&line, &len, fmaps)) != -1) {
if ((read > filename_len + 1)
&& (strncmp(&line[read - filename_len - 1], filename, filename_len) == 0))
printf("%s", line);
}
if (line)
free(line);
fclose(fmaps);
}
close(fd);
return 0;
}
[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: Clement Calmels <cboulte@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-08-20 15:40:30 -07:00
..
2008-07-03 09:59:03 -05:00
2008-07-26 12:00:07 -07:00
2008-07-26 20:53:40 -04:00
2008-08-04 21:31:34 -07:00
2008-07-24 10:47:33 -07:00
2008-07-26 12:00:07 -07:00
2008-07-26 12:00:07 -07:00
2008-08-14 03:55:14 +00:00
2008-07-26 20:53:34 -04:00
2008-07-31 16:21:13 -07:00
2008-04-18 22:16:44 -04:00
2008-07-21 21:54:59 -07:00
2008-08-01 11:25:29 -04:00
2008-08-13 12:47:36 -05:00
2008-07-28 16:30:21 -07:00
2008-07-26 12:00:07 -07:00
2008-04-30 08:29:54 -07:00
2008-07-28 16:30:21 -07:00
2008-08-01 11:25:25 -04:00
2008-08-03 10:50:44 -07:00
2008-08-20 08:31:19 -07:00
2008-04-29 08:06:00 -07:00
2008-07-26 20:53:21 -04:00
2008-07-26 20:53:36 -04:00
2008-07-26 20:53:40 -04:00
2008-07-26 20:53:40 -04:00
2008-07-26 20:53:14 -04:00
2008-07-26 20:53:13 -04:00
2008-07-26 20:53:07 -04:00
2008-07-26 12:00:07 -07:00
2008-07-26 12:00:07 -07:00
2008-08-12 00:11:49 +02:00
2008-08-12 00:11:49 +02:00
2008-08-01 10:07:51 +01:00
2008-07-26 20:53:14 -04:00
2008-08-12 16:39:22 -07:00
2008-07-26 12:00:07 -07:00
2008-07-25 10:53:34 -07:00
2008-07-26 20:53:37 -04:00
2008-08-04 16:50:38 -07:00
2008-08-12 16:39:22 -07:00
2008-08-04 21:56:09 -07:00
2008-07-31 16:21:14 -07:00
2008-08-15 08:35:44 -07:00
2008-07-26 12:00:07 -07:00
2008-07-25 10:53:44 -07:00
2008-08-20 15:40:30 -07:00
2008-07-26 12:00:07 -07:00
2008-07-04 09:52:14 +02:00
2008-08-12 16:07:30 -07:00
2008-07-30 14:30:34 -07:00
2008-07-26 20:53:14 -04:00
2008-07-26 12:00:07 -07:00
2008-07-26 12:00:07 -07:00
2008-08-14 12:46:20 +03:00
2008-07-26 12:00:07 -07:00
2008-08-04 16:50:38 -07:00
2008-07-25 10:53:34 -07:00
2008-08-14 09:35:23 +10:00
2008-07-26 20:53:40 -04:00
2008-07-24 10:47:28 -07:00
2008-07-26 20:53:28 -04:00
2008-07-26 20:53:14 -04:00
2008-07-26 12:00:08 -07:00
2008-07-28 18:10:28 +09:00
2008-07-26 12:00:08 -07:00
2008-04-29 08:06:04 -07:00
2008-08-11 20:17:55 +09:00
2008-07-24 10:47:27 -07:00
2008-04-29 08:06:04 -07:00
2008-07-26 12:00:08 -07:00
2008-07-28 16:30:21 -07:00
2008-08-06 12:30:04 +02:00
2008-08-01 11:25:31 -04:00
2008-08-04 21:56:09 -07:00
2008-06-20 14:05:53 -06:00
2008-07-25 10:53:34 -07:00
2008-07-26 20:53:34 -04:00
2008-07-28 16:58:39 +10:00
2008-02-14 21:17:09 -08:00
2008-07-26 12:00:06 -07:00
2008-05-01 13:08:16 -04:00
2008-08-01 11:25:25 -04:00
2008-04-29 08:06:05 -07:00
2008-07-24 10:47:29 -07:00
2008-08-12 16:07:30 -07:00
2008-07-28 16:30:20 -07:00
2008-08-01 11:25:24 -04:00
2008-07-26 20:53:06 -04:00
2008-07-26 20:53:40 -04:00
2008-08-01 11:25:23 -04:00
2008-07-14 19:10:52 +03:00
2008-08-15 08:35:44 -07:00
2008-07-26 20:53:34 -04:00
2008-04-21 23:11:01 -04:00
2008-04-29 08:06:00 -07:00
2008-07-26 12:00:05 -07:00
2008-07-28 18:10:28 +09:00
2008-07-30 09:41:44 -07:00
2008-07-26 12:00:07 -07:00
2008-07-26 12:00:05 -07:00
2008-04-15 19:35:41 -07:00
2008-07-11 19:27:31 -04:00
2008-08-01 11:25:30 -04:00
2008-08-01 11:25:32 -04:00
2008-02-14 21:13:33 -08:00
2008-08-01 11:25:23 -04:00
2008-07-26 20:53:06 -04:00
2008-04-23 00:05:09 -04:00
2008-04-23 00:05:09 -04:00
2008-07-25 10:53:35 -07:00
2008-07-25 10:53:35 -07:00
2008-07-25 10:53:35 -07:00
2008-07-02 15:06:27 -06:00
2008-06-22 12:23:15 -07:00
2008-08-12 16:07:30 -07:00
2008-07-24 10:47:29 -07:00
2008-08-04 21:31:34 -07:00
2008-07-26 20:53:34 -04:00
2008-07-24 10:47:15 -07:00
2008-07-24 10:47:17 -07:00
2008-07-24 10:47:29 -07:00
2008-07-26 20:53:34 -04:00
2008-07-26 20:53:34 -04:00