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

Valgrind reports that statx arguments point to unaddressable bytes #68979

Closed
shepmaster opened this issue Feb 9, 2020 · 8 comments
Closed

Valgrind reports that statx arguments point to unaddressable bytes #68979

shepmaster opened this issue Feb 9, 2020 · 8 comments
Labels
C-bug Category: This is a bug. O-linux Operating system: Linux T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@shepmaster
Copy link
Member

I tried this code:

fn main() {
    std::fs::metadata("/").unwrap();
}

I compiled it and ran it under Valgrind:

$ rustc example.rs
$ valgrind ./example

I expected to see that Valgrind reported no errors.

Instead, it reports errors:

==1164== Memcheck, a memory error detector
==1164== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==1164== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==1164== Command: ./example
==1164==
==1164== Syscall param statx(file_name) points to unaddressable byte(s)
==1164==    at 0x49B094D: syscall (syscall.S:38)
==1164==    by 0x1149AB: statx (weak.rs:90)
==1164==    by 0x1149AB: std::sys::unix::fs::try_statx (fs.rs:132)
==1164==    by 0x11430E: std::sys::unix::fs::stat (fs.rs:995)
==1164==    by 0x10C43B: std::fs::metadata (in /home/ubuntu/example)
==1164==    by 0x10CBB2: example::main (in /home/ubuntu/example)
==1164==    by 0x10C382: std::rt::lang_start::{{closure}} (in /home/ubuntu/example)
==1164==    by 0x113082: {{closure}} (rt.rs:52)
==1164==    by 0x113082: std::panicking::try::do_call (panicking.rs:292)
==1164==    by 0x114E39: __rust_maybe_catch_panic (lib.rs:78)
==1164==    by 0x113A7F: try<i32,closure-0> (panicking.rs:270)
==1164==    by 0x113A7F: catch_unwind<closure-0,i32> (panic.rs:394)
==1164==    by 0x113A7F: std::rt::lang_start_internal (rt.rs:51)
==1164==    by 0x10C367: std::rt::lang_start (in /home/ubuntu/example)
==1164==    by 0x10CBEA: main (in /home/ubuntu/example)
==1164==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==1164==
==1164== Syscall param statx(buf) points to unaddressable byte(s)
==1164==    at 0x49B094D: syscall (syscall.S:38)
==1164==    by 0x1149AB: statx (weak.rs:90)
==1164==    by 0x1149AB: std::sys::unix::fs::try_statx (fs.rs:132)
==1164==    by 0x11430E: std::sys::unix::fs::stat (fs.rs:995)
==1164==    by 0x10C43B: std::fs::metadata (in /home/ubuntu/example)
==1164==    by 0x10CBB2: example::main (in /home/ubuntu/example)
==1164==    by 0x10C382: std::rt::lang_start::{{closure}} (in /home/ubuntu/example)
==1164==    by 0x113082: {{closure}} (rt.rs:52)
==1164==    by 0x113082: std::panicking::try::do_call (panicking.rs:292)
==1164==    by 0x114E39: __rust_maybe_catch_panic (lib.rs:78)
==1164==    by 0x113A7F: try<i32,closure-0> (panicking.rs:270)
==1164==    by 0x113A7F: catch_unwind<closure-0,i32> (panic.rs:394)
==1164==    by 0x113A7F: std::rt::lang_start_internal (rt.rs:51)
==1164==    by 0x10C367: std::rt::lang_start (in /home/ubuntu/example)
==1164==    by 0x10CBEA: main (in /home/ubuntu/example)
==1164==  Address 0x0 is not stack'd, malloc'd or (recently) free'd

Meta

rustc --version --verbose:

$ rustc --version --verbose
rustc 1.41.0 (5e1a79984 2020-01-27)
binary: rustc
commit-hash: 5e1a799842ba6ed4a57e91f7ab9435947482f7d8
commit-date: 2020-01-27
host: x86_64-unknown-linux-gnu
release: 1.41.0
LLVM version: 9.0

rustc +nightly --version --verbose:

rustc 1.43.0-nightly (a29424a22 2020-02-07)
binary: rustc
commit-hash: a29424a2265411dda7d7446516ac5fd7499e2b55
commit-date: 2020-02-07
host: x86_64-unknown-linux-gnu
release: 1.43.0-nightly
LLVM version: 9.0
@shepmaster shepmaster added C-bug Category: This is a bug. O-linux Operating system: Linux T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Feb 9, 2020
@shepmaster
Copy link
Member Author

/cc @oxalica (from what appears to be the original commit)

@nagisa
Copy link
Member

nagisa commented Feb 9, 2020

Looks genuine, we do indeed pass in 0s to the syscall:

statx(0, NULL, AT_STATX_SYNC_AS_STAT, STATX_ALL, NULL) = -1 EFAULT (Bad address)
statx(AT_FDCWD, "/", AT_STATX_SYNC_AS_STAT, STATX_ALL, {stx_mask=STATX_TYPE|STATX_MODE|STATX_NLINK|STATX_UID|STATX_GID|STATX_MTIME|STATX_CTIME|STATX_INO|STATX_SIZE|STATX_BLOCKS, stx_attributes=0, stx_mode=S_IFDIR|0755, stx_size=19, ...}) = 0

@glandium
Copy link
Contributor

glandium commented Feb 9, 2020

Try valgrind master. It was fixed there.

@nagisa
Copy link
Member

nagisa commented Feb 9, 2020

@glandium what was? We do in fact get EFAULTed by the kernel, with or without valgrind.

@tmiasko
Copy link
Contributor

tmiasko commented Feb 9, 2020

@glandium
Copy link
Contributor

glandium commented Feb 9, 2020

As to why the "dubious" call: #65685

@nagisa
Copy link
Member

nagisa commented Feb 9, 2020

Cool. Closing as inactionable.

@johan-bjareholt
Copy link

If anyone is wondering, the fix in valgrind is available on version 3.16.0 and up to be exact (released 2020-05-27).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. O-linux Operating system: Linux T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants