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] [day] [month] [year] [list]
Date:   Wed, 4 May 2022 16:16:03 -0500
From:   Daniel Latypov <dlatypov@...gle.com>
To:     Brendan Higgins <brendanhiggins@...gle.com>
Cc:     David Gow <davidgow@...gle.com>, Kees Cook <keescook@...omium.org>,
        Shuah Khan <skhan@...uxfoundation.org>,
        Steven Rostedt <rostedt@...dmis.org>,
        kunit-dev@...glegroups.com, linux-kselftest@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: Re: [RFC PATCH 1/2] kunit: Expose 'static stub' API to redirect functions

On Wed, May 4, 2022 at 3:42 PM 'Brendan Higgins' via KUnit Development
<kunit-dev@...glegroups.com> wrote:
>
> On Wed, May 4, 2022 at 4:35 PM Daniel Latypov <dlatypov@...gle.com> wrote:
> >
> > On Thu, Mar 17, 2022 at 9:13 PM David Gow <davidgow@...gle.com> wrote:
> > > +#define kunit_activate_static_stub(test, real_fn_addr, replacement_addr) do {  \
> > > +       typecheck(typeof(real_fn_addr), replacement_addr);                      \
> >
> > We can't call this macro in the same scope for functions w/ different
> > signatures.
> >
> > E.g. if we add this func to the example test
> >   static void other_func(void) {}
> > then trying to call kunit_activate_static_stub() on it in the same
> > test case, we get
> >
> > ./include/linux/typecheck.h:10:14: error: conflicting types for
> > ‘__dummy’; have ‘void(void)’
> >    10 | ({      type __dummy; \
> >       |              ^~~~~~~
> > ./include/kunit/static_stub.h:99:9: note: in expansion of macro ‘typecheck’
> >    99 |         typecheck(typeof(real_fn_addr), replacement_addr);
> >                  \
> >       |         ^~~~~~~~~
> > lib/kunit/example-test.c:64:9: note: in expansion of macro
> > ‘kunit_activate_static_stub’
> >    64 |         kunit_activate_static_stub(test, other_func, other_func);
> >       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~
> > ./include/linux/typecheck.h:10:14: note: previous declaration of
> > ‘__dummy’ with type ‘int(int)’
> >    10 | ({      type __dummy; \
> >       |              ^~~~~~~
> > ./include/kunit/static_stub.h:99:9: note: in expansion of macro ‘typecheck’
> >    99 |         typecheck(typeof(real_fn_addr), replacement_addr);
> >                  \
> >       |         ^~~~~~~~~
> > lib/kunit/example-test.c:62:9: note: in expansion of macro
> > ‘kunit_activate_static_stub’
> >    62 |         kunit_activate_static_stub(test, add_one, subtract_one);
> >       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~
> >
> > Afaict, the problem is that GCC thinks we're declaring a *function*
> > called __dummy, not a variable.
> > So it bleeds across the scope boundary of do-while unlike normal variables.
>
> Yeah, I ran into that problem too. I posted a fix to gerrit. I have
> been meaning to share it here.

For others, gerrit == https://kunit-review.googlesource.com/c/linux/+/5129

>
> > There's the typecheck_fn macro, but it doesn't work either.
>
> That's weird. It worked for me.

I'm running on top of 5.5.
I tried reproducing w/ a stripped down version on 5.18 and saw the same issues.

Huh, I'm trying with
 #define kunit_activate_static_stub(test, real_fn_addr,
replacement_addr) do {  \
-       typecheck(typeof(real_fn_addr), replacement_addr);
         \
+       typecheck_fn(typeof(real_fn_addr), replacement_addr); \
        __kunit_activate_static_stub(test, real_fn_addr,
replacement_addr);     \

This gives me
lib/kunit/example-test.c:62:9: error: function ‘__tmp’ is initialized
like a variable
   62 |         kunit_activate_static_stub(test, add_one, subtract_one);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kunit/example-test.c:64:9: error: function ‘__tmp’ is initialized
like a variable
   64 |         kunit_activate_static_stub(test, other_func, other_func);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~

Perhaps I'm missing something silly.

Can you post your fix and I can try it out?

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ