[LTP] [PATCH] setresuid04.c: Rewrite the test using new LTP API

Avinesh Kumar akumar@suse.de
Thu Dec 8 07:35:28 CET 2022


Hi Li,

On Thursday, December 8, 2022 9:07:08 AM IST Li Wang wrote:
> Hi Avinesh,
> 
> Avinesh Kumar <akumar@suse.de> wrote:
> 
> > -               /* Test 2: Check a son process cannot open the file
> > -                *         with RDWR permissions.
> > -                */
> > -               pid = FORK_OR_VFORK();
> > -               if (pid < 0)
> > -                       tst_brkm(TBROK, NULL, "Fork failed");
> > -
> > -               if (pid == 0) {
> > -                       int tst_fd2;
> > +       SAFE_SETRESUID(0, ltpuser->pw_uid, 0);
> 
> There is no reason to modify 'real UID' and 'saved set-user-ID'
> at this time, we do only care about 'effective UID' made changes
> successfully or not.
> 
Yes, Thank you, I realized this while working on setresuid05.c test.
I think we should leave the 'real UID' and 'saved set-user-ID'
untouched even when resetting 'effective UID' to root:
       SAFE_SETRESUID(0, 0, 0); should be
       SAFE_SETRESUID(-1, 0, -1);

I will send another patch as we also need to add .needs_tmpdir=1
because we are creating a temp file.


> So I tweaked the patch a tiny and merged it:
> 
> --- a/testcases/kernel/syscalls/setresuid/setresuid04.c
> +++ b/testcases/kernel/syscalls/setresuid/setresuid04.c
> @@ -40,7 +40,7 @@ static void run(void)
>         pid_t pid;
>         int status;
> 
> -       SAFE_SETRESUID(0, ltpuser->pw_uid, 0);
> +       SAFE_SETRESUID(-1, ltpuser->pw_uid, -1);
>         TST_EXP_FAIL2(open(TEMP_FILE, O_RDWR), EACCES);
> 
>         pid = SAFE_FORK();
> 
> 
> 

Best regards,
Avinesh






More information about the ltp mailing list