Preparing for the next release: call for testing

Dmitry V. Levin ldv at altlinux.org
Sun Mar 1 23:37:44 UTC 2015


On Sun, Mar 01, 2015 at 02:56:41AM -0500, Mike Frysinger wrote:
> but uid is not as easy because __NR_getuid might operate on 32bits in which case 
> you'd corrupt vars on the stack.  you could work around it by doing:
> --- a/tests/uid.c
> +++ b/tests/uid.c
> @@ -16,15 +16,19 @@ main(void)
>   && defined(__NR_setresuid) \
>   && defined(__NR_chown) \
>   && defined(__NR_getgroups)
> -	int r, e, s;
> +	/* The kernel API might be 16bit or 32bit */
> +	union {
> +		int u32;
> +		short u16;
> +	} r, e, s;
>  	int size;
>  	int *list = 0;
>  
> -	e = syscall(__NR_getuid);
> -	assert(syscall(__NR_setuid, e) == 0);
> -	assert(syscall(__NR_getresuid, &r, &e, &s) == 0);
> +	e.u16 = syscall(__NR_getuid);
> +	assert(syscall(__NR_setuid, e.u16) == 0);
> +	assert(syscall(__NR_getresuid, &r.u16, &e.u16, &s.u16) == 0);
>  	assert(syscall(__NR_setreuid, -1, -1L) == 0);
> -	assert(syscall(__NR_setresuid, -1, e, -1L) == 0);
> +	assert(syscall(__NR_setresuid, -1, e.u16, -1L) == 0);
>  	assert(syscall(__NR_chown, ".", -1, -1L) == 0);
>  	assert((size = syscall(__NR_getgroups, 0, list)) >= 0);
>  	assert(list = calloc(size + 1, sizeof(*list)));
> 
> this will fail if your uid is actually larger than 16bits and you're on an arch 
> that only has 32bit syscalls.  but maybe that case is unusual enough to not care 
> about ?  or at least, that is testable:
> 	int uid = syscall(__NR_getuid);
> 	if (uid >= (short)-1)
> 		return 77;

Can we fix all these issues by ignoring
getresuid results in subsequent calls?

--- a/tests/uid.c
+++ b/tests/uid.c
@@ -16,15 +16,16 @@ main(void)
  && defined(__NR_setresuid) \
  && defined(__NR_chown) \
  && defined(__NR_getgroups)
+	int uid;
 	int r, e, s;
 	int size;
 	int *list = 0;
 
-	e = syscall(__NR_getuid);
-	assert(syscall(__NR_setuid, e) == 0);
+	uid = syscall(__NR_getuid);
+	assert(syscall(__NR_setuid, uid) == 0);
 	assert(syscall(__NR_getresuid, &r, &e, &s) == 0);
 	assert(syscall(__NR_setreuid, -1, -1L) == 0);
-	assert(syscall(__NR_setresuid, -1, e, -1L) == 0);
+	assert(syscall(__NR_setresuid, -1, uid, -1L) == 0);
 	assert(syscall(__NR_chown, ".", -1, -1L) == 0);
 	assert((size = syscall(__NR_getgroups, 0, list)) >= 0);
 	assert(list = calloc(size + 1, sizeof(*list)));


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20150302/d5b45219/attachment.bin>


More information about the Strace-devel mailing list