[LTP] [PATCH v3 0/2] mount03: Convert to new API

xuyang2018.jy@fujitsu.com xuyang2018.jy@fujitsu.com
Tue Aug 16 09:28:41 CEST 2022


Hi Petr

> Hi Xu,
> 
>>>> Why here is nobody_gid?
> 
>>>>> +		SAFE_SETGID(nobody_gid);
>>>>> +		SAFE_SETREUID(-1, nobody_uid);
> 
>>>> What problem do you meet?
> 
>>> Using original code SAFE_SETREUID(nobody_uid, nobody_gid);
>>> causes mount03_setuid_test to fail (exit 1).
>>> The same code is in creat08.c, creat09.c, open10.c.
>>> Did I answer your question?
> 
>> I look mount03_setuid_test code today, nosuid mount option should
>> expect setuid failed when using a non-privileged user even this program
>> has set-user-id bit.
> 
>> Old api also think PASS when mount03_setuid_test exit 1
> 
> Ah, thanks for catching my error!
> 
>> So I think you should use  SAFE_SETREUID(nobody_uid, nobody_uid);
>> and then use code as below:
> 
>> 	if (WIFEXITED(status)) {
>> 		switch (WEXITSTATUS(status)) {
>> 		case EXIT_FAILURE:
>> 			tst_res(TPASS, "%s passed", TESTBIN);
>> 			return;
>> 		case EXIT_SUCCESS:
>> 			tst_res(TFAIL, "%s failed", TESTBIN);
>> 			return;
>> 		default:
>> 		case TBROK:
>> 			break;
>> 		}
> I guess we can drop the default and TBROK part, right?
> It's caught later by tst_brk(TBROK, ...)
>> 	}

Yes, I am fine with drop this.

Best Regards
Yang Xu
> 
> https://github.com/pevik/ltp/blob/22652d668a5ccbf3c7aa835c2dab6d0eb6058ba2/testcases/kernel/syscalls/mount/mount03.c#L74-L105
> 
> static void test_nosuid(void)
> {
> 	pid_t pid;
> 	int status;
> 	struct stat st;
> 
> 	SAFE_CP(TESTBIN, BIN_PATH);
> 	SAFE_STAT(BIN_PATH, &st);
> 	if (st.st_mode != SUID_MODE)
> 		SAFE_CHMOD(BIN_PATH, SUID_MODE);
> 
> 	pid = SAFE_FORK();
> 	if (!pid) {
> 		SAFE_SETREUID(nobody_uid, nobody_uid);
> 		SAFE_EXECL(BIN_PATH, TESTBIN, NULL);
> 	}
> 
> 	SAFE_WAITPID(pid, &status, 0);
> 
> 	if (WIFEXITED(status)) {
> 		switch (WEXITSTATUS(status)) {
> 		case EXIT_FAILURE:
> 			tst_res(TPASS, "%s passed", TESTBIN);
> 			return;
> 		case EXIT_SUCCESS:
> 			tst_res(TFAIL, "%s failed", TESTBIN);
> 			return;
> 		}
> 	}
> 
> 	tst_brk(TBROK, "Child %s", tst_strstatus(status));
> }
> 
> Kind regards,
> Petr
> 
>> Best Regards
>> Yang Xu


More information about the ltp mailing list