Skip to content

install-xattr: avoid accessing empty storage#3

Closed
thesamesam wants to merge 6 commits intogentoo:masterfrom
thesamesam:install-xattr-ubsan
Closed

install-xattr: avoid accessing empty storage#3
thesamesam wants to merge 6 commits intogentoo:masterfrom
thesamesam:install-xattr-ubsan

Conversation

@thesamesam
Copy link
Member

UBSAN reports:

install-xattr.c:124:16: runtime error: load of address 0x55555556d440 with insufficient space for an object of type 'char'
0x55555556d440: note: pointer points here
 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  61 00 00 00
              ^
    #0 0x555555557a27 in copyxattr /home/sam/git/elfix/misc/install-xattr/install-xattr.c:124
    #1 0x555555556a4d in main /home/sam/git/elfix/misc/install-xattr/install-xattr.c:410
    #2 0x7ffff77c864f  (/usr/lib64/libc.so.6+0x2364f)
    #3 0x7ffff77c8708 in __libc_start_main (/usr/lib64/libc.so.6+0x23708)
    #4 0x555555557114 in _start (/home/sam/git/elfix/misc/install-xattr/install-xattr+0x3114)

Triggered with:

mkdir /tmp/a
touch /tmp/foo
./install-xattr -c /tmp/foo /tmp/foo2 /tmp/a

I don't see this with Clang or < GCC 12, but I do with GCC 13 (13.0.0_pre20230101 p5); I suspect it's because of object-size improvements.

Signed-off-by: Sam James sam@gentoo.org

@thesamesam
Copy link
Member Author

@blueness

Needed to correctly run tests with Clang, as Clang doesn't create
executable stacks by default.

Signed-off-by: Sam James <sam@gentoo.org>
It's hard to see why something failed otherwise, as we only have the
exit code.

Signed-off-by: Sam James <sam@gentoo.org>
UBSAN reports:
```
install-xattr.c:124:16: runtime error: load of address 0x55555556d440 with insufficient space for an object of type 'char'
0x55555556d440: note: pointer points here
 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  61 00 00 00
              ^
    #0 0x555555557a27 in copyxattr /home/sam/git/elfix/misc/install-xattr/install-xattr.c:124
    #1 0x555555556a4d in main /home/sam/git/elfix/misc/install-xattr/install-xattr.c:410
    #2 0x7ffff77c864f  (/usr/lib64/libc.so.6+0x2364f)
    #3 0x7ffff77c8708 in __libc_start_main (/usr/lib64/libc.so.6+0x23708)
    #4 0x555555557114 in _start (/home/sam/git/elfix/misc/install-xattr/install-xattr+0x3114)
```

Triggered with:
```
mkdir /tmp/a
touch /tmp/foo
./install-xattr -c /tmp/foo /tmp/foo2 /tmp/a
```

I don't see this with Clang or < GCC 12, but I do with GCC 13 (13.0.0_pre20230101 p5);
I suspect it's because of object-size improvements.

Signed-off-by: Sam James <sam@gentoo.org>
There's another with strdup/malloc but it gets a bit messier
to fix so let's leave that for now (this is mostly about correctness
anyway, as the runtime of install-xattr is very small):
```
Direct leak of 4097 byte(s) in 1 object(s) allocated from:
    #0 0x7f4a2c22e257 in __interceptor_malloc /usr/src/debug/sys-devel/gcc-13.0.0_pre20230101/gcc-13-20230101/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f4a2c1d2b40 in __interceptor_realpath /usr/src/debug/sys-devel/gcc-13.0.0_pre20230101/gcc-13-20230101/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:3904
    #2 0x55da3adf5629 in realpath /usr/include/bits/stdlib.h:42
    #3 0x55da3adf5629 in main /home/sam/git/elfix/misc/install-xattr/install-xattr.c:252
```

Signed-off-by: Sam James <sam@gentoo.org>
Obsolete.

Signed-off-by: Sam James <sam@gentoo.org>
Signed-off-by: Sam James <sam@gentoo.org>
gentoo-bot pushed a commit that referenced this pull request Jan 10, 2023
UBSAN reports:
```
install-xattr.c:124:16: runtime error: load of address 0x55555556d440 with insufficient space for an object of type 'char'
0x55555556d440: note: pointer points here
 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  61 00 00 00
              ^
    #0 0x555555557a27 in copyxattr /home/sam/git/elfix/misc/install-xattr/install-xattr.c:124
    #1 0x555555556a4d in main /home/sam/git/elfix/misc/install-xattr/install-xattr.c:410
    #2 0x7ffff77c864f  (/usr/lib64/libc.so.6+0x2364f)
    #3 0x7ffff77c8708 in __libc_start_main (/usr/lib64/libc.so.6+0x23708)
    #4 0x555555557114 in _start (/home/sam/git/elfix/misc/install-xattr/install-xattr+0x3114)
```

Triggered with:
```
mkdir /tmp/a
touch /tmp/foo
./install-xattr -c /tmp/foo /tmp/foo2 /tmp/a
```

I don't see this with Clang or < GCC 12, but I do with GCC 13 (13.0.0_pre20230101 p5);
I suspect it's because of object-size improvements.

Signed-off-by: Sam James <sam@gentoo.org>
gentoo-bot pushed a commit that referenced this pull request Jan 10, 2023
There's another with strdup/malloc but it gets a bit messier
to fix so let's leave that for now (this is mostly about correctness
anyway, as the runtime of install-xattr is very small):
```
Direct leak of 4097 byte(s) in 1 object(s) allocated from:
    #0 0x7f4a2c22e257 in __interceptor_malloc /usr/src/debug/sys-devel/gcc-13.0.0_pre20230101/gcc-13-20230101/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f4a2c1d2b40 in __interceptor_realpath /usr/src/debug/sys-devel/gcc-13.0.0_pre20230101/gcc-13-20230101/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:3904
    #2 0x55da3adf5629 in realpath /usr/include/bits/stdlib.h:42
    #3 0x55da3adf5629 in main /home/sam/git/elfix/misc/install-xattr/install-xattr.c:252
```

Signed-off-by: Sam James <sam@gentoo.org>
@thesamesam thesamesam deleted the install-xattr-ubsan branch January 10, 2023 05:21
gentoo-bot pushed a commit to gentoo/gentoo that referenced this pull request Jan 11, 2023
Bug: gentoo/elfix#3
Signed-off-by: Sam James <sam@gentoo.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants