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

Li Wang liwang@redhat.com
Thu Dec 8 07:54:41 CET 2022


On Thu, Dec 8, 2022 at 2:35 PM Avinesh Kumar <akumar@suse.de> wrote:
>
> 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);

Agree, and with ".needs_root = 1" setting at the beginning
of the test, they are definitely 0 so I didn't correct them
because the test is already done when going there.

But yes, if you'd pursuing perfection I'd help ack your new patch :).

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

+1

>
>
> > 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
>
>
>
>


-- 
Regards,
Li Wang



More information about the ltp mailing list