pac...@kosh.dhis.org hat am Mon 27. Jun, 23:02 (-0500) geschrieben: > =?iso-8859-1?Q?J=F6rg?= Sommer writes: > > I don't know, why dd thinks something went wrong. llseek() and fstat64() > > didn't return an error. Accessing the file with Ruby yields the expected > > result. > > I don't speak ruby, but that sounds unlikely. Would it do a ptrace > behind your back? Or did you maybe think it succeeded when actually it > just didn't report the errors it encountered? You should strace that too.
% cat /tmp/mem-cat.c #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <unistd.h> #define ASSERT(cmp, msg) if (!(cmp)) { perror(msg); return EXIT_FAILURE; } int main(void) { int fd_in = open("/proc/self/mem", O_RDONLY); ASSERT(fd_in != -1, "open(/p/s/m)"); int fd_out = open("/tmp/mem-cat.out", O_WRONLY | O_CREAT, 0600); ASSERT(fd_out != -1, "open(/t/m)"); off_t ret = lseek(fd_in, 0x100000, SEEK_SET); printf("seek: %ld\n", ret); ASSERT(ret != (off_t)-1, "lseek"); size_t buf_len = 0x103000 - 0x100000; char* buf = malloc(buf_len); ASSERT(buf != NULL, "malloc"); ssize_t read_len = read(fd_in, buf, buf_len); printf("read: %d\n", read_len); ASSERT(read_len == (ssize_t)buf_len, "read"); ssize_t write_len = write(fd_out, buf, buf_len); printf("write: %d\n", write_len); ASSERT(write_len == (ssize_t)buf_len, "write"); return EXIT_SUCCESS; } % make /tmp/mem-cat cc -O2 -fPIC -fPIE -Wall -Wformat=2 -Wunused -Wlogical-op -Wundef -Wextra -Wswitch-enum -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -D_FORTIFY_SOURCE=2 -fstack-protector -Wbad-function-cast -Wnested-externs -Wl,-zrelro,-pie /tmp/mem-cat.c -o /tmp/mem-cat % /tmp/mem-cat seek: 1048576 read: 12288 write: 12288 % file /tmp/mem-cat.out /tmp/mem-cat.out: ELF 32-bit MSB shared object, PowerPC or cisco 4500, version 1 (SYSV), dynamically linked, stripped Bye, Jörg. -- Die Erde ist das einzigste Irrenhaus, das von seinen eigenen Insassen verwaltet wird. (U. Schmidt)
signature.asc
Description: Digital signature http://en.wikipedia.org/wiki/OpenPGP