Commit graph

13 commits

Author SHA1 Message Date
Josh Gao
97271920bf Add a tool to track down fd leaks.
Add a hook that's called upon file descriptor creation to libc, and a
library that uses it to capture backtraces for file descriptor creation,
to make it easier to hunt down file descriptor leaks.

Currently, this doesn't capture all of the ways of creating a file
descriptor, but completeness isn't required for this to be useful as
long as leaked file descriptors are created with a function that is
tracked. The primary unhandled case is binder, which receives file
descriptors as a payload in a not-trivially-parsable byte blob, but
there's a chance that the leak we're currently trying to track down
isn't of a file descriptor received over binder, so leave that for
later.

Bug: http://b/140703823
Test: manual
Change-Id: I308a14c2e234cdba4207157b634ab6b8bc539dd9
(cherry picked from commit b7eccd4b15)
2020-01-30 13:55:10 -08:00
George Burgess IV
23e6f0a900 libc: remove now-unused FORTIFY functions
As of I2037548cc2061e46c379931588194c21dfe234b4, these are no longer
used. Since they're new in R, we can remove them instead of keeping
backwards compat 'forever'. Take that opportunity now.

Bug: 141267932
Test: TreeHugger
Change-Id: I13f94cdcff6e75ad19b964be76445f113f79559b
2019-10-07 19:09:38 -07:00
George Burgess IV
2356c93d39 fortify: add bit checking for open(at)?64 functions
This also adds _2-variants for these functions, for extra glorious
checking

Bug: 131861088
Test: mma
Change-Id: I80475ff4bb220c0c47894e9532426f53412f176f
2019-06-13 23:26:02 -07:00
Elliott Hughes
b115aefbb3 With O_TMPFILE, open(2) takes a mode argument.
Strictly, the mode isn't really meaningful unless you supply O_EXCL,
but the kernel will take it and fstat will return it even if you
never give the file a name.

Also warn for O_TMPFILE without a mode at compile time where possible.

Bug: N/A
Test: ran tests
Change-Id: I729b6d6e6190676fd017a1190b6200bf9abdbfd8
2017-08-04 10:20:18 -07:00
Christopher Ferris
7a3681e5b6 Move libc_log code into libasync_safe.
This library is used by a number of different libraries in the system.
Make it easy for platform libraries to use this library and create
an actual exported include file.

Change the names of the functions to reflect the new name of the library.

Run clang_format on the async_safe_log.cpp file since the formatting is
all over the place.

Bug: 31919199

Test: Compiled for angler/bullhead, and booted.
Test: Ran bionic unit tests.
Test: Ran the malloc debug tests.
Change-Id: I8071bf690c17b0ea3bc8dc5749cdd5b6ad58478a
2017-05-03 08:50:43 -07:00
Josh Gao
b36efa4343 Fix instances of '#if __LP64__'.
Triggers -Wundef, which is on in -Weverything.

Bug: http://b/31496165
Change-Id: Ib06107073f7dd1d584c19c222d0430da9d35630b
2016-09-15 14:21:28 -07:00
Elliott Hughes
b83d6747fa Improve FORTIFY failure diagnostics.
Our FORTIFY _chk functions' implementations were very repetitive and verbose
but not very helpful. We'd also screwed up and put the SSIZE_MAX checks where
they would never fire unless you actually had a buffer as large as half your
address space, which probably doesn't happen very often.

Factor out the duplication and take the opportunity to actually show details
like how big the overrun buffer was, or by how much it was overrun.

Also remove the obsolete FORTIFY event logging.

Also remove the unused __libc_fatal_no_abort.

This change doesn't improve the diagnostics from the optimized assembler
implementations.

Change-Id: I176a90701395404d50975b547a00bd2c654e1252
2016-02-26 22:06:17 -08:00
Elliott Hughes
8b5df3920f Turn on -Wold-style-cast and fix the errors.
A couple of dodgy cases where we cast away const, but otherwise pretty boring.

Change-Id: Ibc39ebd525377792b5911464be842121c20f03b9
2015-01-21 17:09:58 -08:00
Elliott Hughes
db1ea34748 Implement some of the missing LFS64 support.
This gives us:

* <dirent.h>
  struct dirent64
  readdir64, readdir64_r, alphasort64, scandir64

* <fcntl.h>
  creat64, openat64, open64.

* <sys/stat.h>
  struct stat64
  fstat64, fstatat64, lstat64, stat64.

* <sys/statvfs.h>
  struct statvfs64
  statvfs64, fstatvfs64.

* <sys/vfs.h>
  struct statfs64
  statfs64, fstatfs64.

This also removes some of the incorrect #define hacks we've had in the
past (for stat64, for example, which we promised to clean up way back
in bug 8472078).

Bug: 11865851
Bug: 8472078
Change-Id: Ia46443521918519f2dfa64d4621027dfd13ac566
2014-02-18 15:39:24 -08:00
Elliott Hughes
17cabe15d5 Don't force O_LARGEFILE on LP64.
aarch64's strace is confused by this, and it isn't necessary anyway.

Change-Id: Ib07b649eb1c38ff0296003874f73af78c47bc276
2013-12-19 16:48:56 -08:00
Elliott Hughes
9a42eef8b1 Revert "Add C linkage for __open_2 and __openat_2."
This reverts commit c13d89b829.

Change-Id: I40a3c6b926e920b65dd054353a2db8d314d5b300
2013-12-19 20:02:16 +00:00
Ben Cheng
c13d89b829 Add C linkage for __open_2 and __openat_2.
Otherwise Clang mangle them with C++ names.

Change-Id: I844e28d834df8b0752b32d2aadd2013fc8804a43
2013-12-19 10:49:20 -08:00
Elliott Hughes
f8fcfbc85a Move away from the __ARCH_WANT_SYSCALL_NO_AT system calls.
Modern architectures only get the *at(2) system calls. For example,
aarch64 doesn't have open(2), and expects userspace to use openat(2)
instead.

Change-Id: I87b4ed79790cb8a80844f5544ac1a13fda26c7b5
2013-10-22 16:31:01 -07:00
Renamed from libc/bionic/openat.c (Browse further)