diff options
author | Siddhesh Poyarekar <siddhesh@sourceware.org> | 2021-10-12 12:29:13 +0530 |
---|---|---|
committer | Siddhesh Poyarekar <siddhesh@sourceware.org> | 2021-10-20 08:33:31 +0530 |
commit | e938c02748402c50f60ba0eb983273e7b52937d1 (patch) | |
tree | 5784cd55dd66558fbdef877150dac886b1b09e5d /io | |
parent | 46baeb61e16511f26db1b255e19dc9163f590367 (diff) | |
download | glibc-e938c02748402c50f60ba0eb983273e7b52937d1.tar.gz glibc-e938c02748402c50f60ba0eb983273e7b52937d1.tar.xz glibc-e938c02748402c50f60ba0eb983273e7b52937d1.zip |
Don't add access size hints to fortifiable functions
In the context of a function definition, the size hints imply that the size of an object pointed to by one parameter is another parameter. This doesn't make sense for the fortified versions of the functions since that's the bit it's trying to validate. This is harmless with __builtin_object_size since it has fairly simple semantics when it comes to objects passed as function parameters. With __builtin_dynamic_object_size we could (as my patchset for gcc[1] already does) use the access attribute to determine the object size in the general case but it misleads the fortified functions. Basically the problem occurs when access attributes are present on regular functions that have inline fortified definitions to generate _chk variants; the attributes get inherited by these definitions, causing problems when analyzing them. For example with poll(fds, nfds, timeout), nfds is hinted using the __attr_access as being the size of fds. Now, when analyzing the inline function definition in bits/poll2.h, the compiler sees that nfds is the size of fds and tries to use that information in the function body. In _FORTIFY_SOURCE=3 case, where the object size could be a non-constant expression, this information results in the conclusion that nfds is the size of fds, which defeats the purpose of the implementation because we're trying to check here if nfds does indeed represent the size of fds. Hence for this case, it is best to not have the access attribute. With the attributes gone, the expression evaluation should get delayed until the function is actually inlined into its destinations. Disable the access attribute for fortified function inline functions when building at _FORTIFY_SOURCE=3 to make this work better. The access attributes remain for the _chk variants since they can be used by the compiler to warn when the caller is passing invalid arguments. [1] https://gcc.gnu.org/pipermail/gcc-patches/2021-October/581125.html Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Diffstat (limited to 'io')
-rw-r--r-- | io/bits/poll2.h | 4 | ||||
-rw-r--r-- | io/sys/poll.h | 6 |
2 files changed, 5 insertions, 5 deletions
diff --git a/io/bits/poll2.h b/io/bits/poll2.h index a623678c09..be74d020f2 100644 --- a/io/bits/poll2.h +++ b/io/bits/poll2.h @@ -33,7 +33,7 @@ extern int __REDIRECT (__poll_chk_warn, (struct pollfd *__fds, nfds_t __nfds, __poll_chk) __warnattr ("poll called with fds buffer too small file nfds entries"); -__fortify_function __attr_access ((__write_only__, 1, 2)) int +__fortify_function __fortified_attr_access (__write_only__, 1, 2) int poll (struct pollfd *__fds, nfds_t __nfds, int __timeout) { if (__glibc_objsize (__fds) != (__SIZE_TYPE__) -1) @@ -64,7 +64,7 @@ extern int __REDIRECT (__ppoll_chk_warn, (struct pollfd *__fds, nfds_t __nfds, __ppoll_chk) __warnattr ("ppoll called with fds buffer too small file nfds entries"); -__fortify_function __attr_access ((__write_only__, 1, 2)) int +__fortify_function __fortified_attr_access (__write_only__, 1, 2) int ppoll (struct pollfd *__fds, nfds_t __nfds, const struct timespec *__timeout, const __sigset_t *__ss) { diff --git a/io/sys/poll.h b/io/sys/poll.h index e640efb2bc..751c7f5f72 100644 --- a/io/sys/poll.h +++ b/io/sys/poll.h @@ -52,7 +52,7 @@ __BEGIN_DECLS This function is a cancellation point and therefore not marked with __THROW. */ extern int poll (struct pollfd *__fds, nfds_t __nfds, int __timeout) - __attr_access ((__write_only__, 1, 2)); + __fortified_attr_access (__write_only__, 1, 2); #ifdef __USE_GNU /* Like poll, but before waiting the threads signal mask is replaced @@ -64,7 +64,7 @@ extern int poll (struct pollfd *__fds, nfds_t __nfds, int __timeout) extern int ppoll (struct pollfd *__fds, nfds_t __nfds, const struct timespec *__timeout, const __sigset_t *__ss) - __attr_access ((__write_only__, 1, 2)); + __fortified_attr_access (__write_only__, 1, 2); # ifdef __USE_TIME_BITS64 # ifdef __REDIRECT @@ -72,7 +72,7 @@ extern int __REDIRECT (ppoll, (struct pollfd *__fds, nfds_t __nfds, const struct timespec *__timeout, const __sigset_t *__ss), __ppoll64) - __attr_access ((__write_only__, 1, 2)); + __fortified_attr_access (__write_only__, 1, 2); # else # define ppoll __ppoll64 # endif |