lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ac23d886-8b9b-463c-91e4-aa541351976e@t-8ch.de>
Date: Wed, 21 May 2025 13:10:26 +0200
From: Thomas Weißschuh <linux@...ssschuh.net>
To: Dmitry Vyukov <dvyukov@...gle.com>
Cc: Thomas Gleixner <tglx@...utronix.de>, krisman@...labora.com, 
	luto@...nel.org, peterz@...radead.org, keescook@...omium.org, 
	gregory.price@...verge.com, Marco Elver <elver@...gle.com>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 2/3] selftests: Fix errno checking in
 syscall_user_dispatch test

On 2025-05-21 12:07:13+0200, Dmitry Vyukov wrote:
> On Sat, 8 Mar 2025 at 13:34, Thomas Gleixner <tglx@...utronix.de> wrote:
> >
> > On Mon, Feb 24 2025 at 09:45, Dmitry Vyukov wrote:
> > >
> > > Also use EXPECT/ASSERT consistently. Currently there is an inconsistent mix
> > > without obvious reasons for usage of one or another.
> > >
> > > Signed-off-by: Dmitry Vyukov <dvyukov@...gle.com>
> >
> > As Gregory said, this should be the first patch in the series with a
> > proper Fixes tag.
> >
> > >       /* Invalid op */
> > >       op = -1;
> > > -     prctl(PR_SET_SYSCALL_USER_DISPATCH, op, 0, 0, &sel);
> > > -     ASSERT_EQ(EINVAL, errno);
> 
> > > +     EXPECT_EQ(-1, prctl(PR_SET_SYSCALL_USER_DISPATCH, op, 0, 0, &sel));
> > > +     EXPECT_EQ(EINVAL, errno);
> >
> > Seriously?
> >
> > Something like:
> >
> > static void prctl_invalid(unsigned long op, unsigned long offs, unsigned long len,
> >                           void *sel, int err)
> > {
> >         EXPECT_EQ(-1, prctl(PR_SET_SYSCALL_USER_DISPATCH, op, offs, len, 0, (unsigned long)sel));
> >         EXPECT_EQ(err, errno);
> > }
> >
> > static void prctl_valid(unsigned long op, unsigned long offs, unsigned long len,
> >                         void *sel)
> > {
> >         EXPECT_EQ(0, prctl(PR_SET_SYSCALL_USER_DISPATCH, op, offs, len, 0, (unsigned long)sel));
> > }
> >
> > ....
> >         /* Invalid op */
> >         prctl_invalid(-1, 0, 0, &sel, -EINVAL);
> >         /* offset != 0 */
> >         prctl_invalid(PR_SYS_DISPATCH_OFF, 1, 0, NULL, -EINVAL);
> >         ....
> >         /* The odd valid test in bad_prctl_param() */
> >         prctl_valid(PR_SYS_DISPATCH_OFF, 0, 0, NULL);
> >
> > But that's not enough macro uglyness sprinkled all over the place and
> > too readable, right?
> 
> The EXPECT* macros unfortunately can't be used in helper functions,
> they require some hidden _metadata variable that is present only in
> TEST/TEST_F functions:
> 
> sud_test.c: In function ‘prctl_valid’:
> ../kselftest_harness.h:107:45: error: ‘_metadata’ undeclared (first
> use in this function)
>   107 |                         __FILE__, __LINE__, _metadata->name,
> ##__VA_ARGS__)

You can pass the _metadata parameter to your helper functions.
While it's a bit iffy, many selftests do this.
Also the upcoming harness selftests will make sure that this pattern
keeps working.


Thomas

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ