makewrappers: Fix EFAULT implementation
PATCH 1/1 makewrappers: Fix EFAULT implementation
From: "mark.hatle" <[email protected]>
A bug was discovered in the makewrappers change in commit 9ce8c09980af23ebd4ebf072010469882d0459a6.
If EFAULT was returned, it would exist with signals blocked and the function lock still held. This would eventually deaadlock in certain use-cases.
The change introduces a quick path exit to the makewrappers and does a 'goto' to this quick exit in the case of the EFAULT.
A seperate issue was identified where the EFAULT code could try to set a return code in a void function. Fix this by using rc_decl.
Signed-off-by mark.hatle <[email protected]>
--- makewrappers | 6 +++--- templates/wrapfuncs.c | 2 ++ test/test-statx.c | 19 ++++++++++++++++++- 3 files changed, 23 insertions(+), 4 deletions(-)
makewrappers +3 -3
@@ -399,9 +399,9 @@ class Function: # Emulate EFAULT when path is null "if (%s == NULL) {\n" "\t\t\terrno = EFAULT;\n" - "\t\t\trc = -1;\n" - "\t\t\t%s\n" - "\t\t}\n" % (path, self.rc_return())) + "\t\t\t%s -1;\n" + "\t\t\tgoto quick_exit;\n" + "\t\t}\n" % (path, self.rc_assign())) fix_paths.append( "%s = pseudo_root_path(__func__, __LINE__, %s%s, %s, %s);" % (path, prefix, self.dirfd, path, self.flags))
templates/wrapfuncs.c +2 -0
@@ -71,6 +71,8 @@ ${maybe_async_skip} } } ${variadic_end} +quick_exit: + __attribute__((unused)); save_errno = errno;pseudo_droplock ();sigprocmask (SIG_SETMASK , &saved,NULL );
test/test-statx.c +18 -1
@@ -8,13 +8,30 @@#include <sys/stat.h> #include <unistd.h> #include <fcntl.h> +#include <errno.h> // Passing a null pointer is the test scenario #pragma GCC diagnostic ignored "-Wnonnull" -int main (void ) { +int statx_test () {if (statx (0 ,NULL ,0 ,0 ,NULL ) !=-1 ) {return 1 ; } +if (errno !=EFAULT ) { +return 2 ; + } +return 0 ; +} + +/* We run this multiple times to ensure that pseudo does not deadlock */ +int main (void ) { +int rc =0 ; + +for (int i =0 ; i <5 ; i++) { + rc =statx_test (); +if (rc !=0 ) +return rc; + } +return 0 ; }
Signature · 1 line
1.8.3.1