Date: Thu, 23 Jul 2020 19:05:50 +0000 From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 248223] Linuxulator: pread behavior differences Message-ID: <bug-248223-227@https.bugs.freebsd.org/bugzilla/>
next in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D248223 Bug ID: 248223 Summary: Linuxulator: pread behavior differences Product: Base System Version: 12.1-RELEASE Hardware: amd64 OS: Any Status: New Severity: Affects Only Me Priority: --- Component: kern Assignee: bugs@FreeBSD.org Reporter: iwtcex@gmail.com % cat pread.c #define _GNU_SOURCE #include <assert.h> #include <errno.h> #include <fcntl.h> #include <stdio.h> #include <string.h> #include <unistd.h> #include <sys/mman.h> void pread_v(int fd, void* buf, size_t nbytes, off64_t offset) { printf("pread(_, _, 0x%lx, _) -> ", nbytes); int ret =3D pread(fd, buf, nbytes, offset); if (ret !=3D -1) { printf("0x%x\n", ret); } else { printf("%s\n", strerror(errno)); } } int main() { int mem =3D open("/proc/self/mem", O_RDONLY); assert(mem !=3D -1); char buf[0x4000]; pread_v(mem, buf, 0x1000, 0); // should be EIO printf("---\n"); void* p1 =3D mmap(NULL, 0x2000, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); void* p2 =3D mmap(p1 + 0x1000, 0x1000, PROT_NONE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); assert(p1 !=3D MAP_FAILED); assert(p2 =3D=3D p1 + 0x1000); assert(munmap(p2, 0x1000) =3D=3D 0); for (int n =3D sizeof(buf); n >=3D 0x1000; n /=3D 2) { pread_v(mem, buf, n, (off64_t)p1); // should return 0x1000 } return 0; } % /compat/linux/bin/gcc -std=3Dc99 -Wall pread.c -o pread % ./pread pread(_, _, 0x1000, _) -> Bad address --- pread(_, _, 0x4000, _) -> Bad address pread(_, _, 0x2000, _) -> Bad address pread(_, _, 0x1000, _) -> 0x1000 On the other hand, Linux (Xubuntu 18.04.3) prints Input/Output errors and 0x1000, 0x1000, 0x1000 there. --=20 You are receiving this mail because: You are the assignee for the bug.=
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-248223-227>