mbox series

[v7,0/5] KUnit-KASAN Integration

Message ID 20200424061342.212535-1-davidgow@google.com (mailing list archive)
Headers show
Series KUnit-KASAN Integration | expand

Message

David Gow April 24, 2020, 6:13 a.m. UTC
This patchset contains everything needed to integrate KASAN and KUnit.

KUnit will be able to:
(1) Fail tests when an unexpected KASAN error occurs
(2) Pass tests when an expected KASAN error occurs

Convert KASAN tests to KUnit with the exception of copy_user_test
because KUnit is unable to test those.

Add documentation on how to run the KASAN tests with KUnit and what to
expect when running these tests.

This patchset depends on:
- "[PATCH v3 kunit-next 0/2] kunit: extend kunit resources API" [1]
- "[PATCH v3 0/3] Fix some incompatibilites between KASAN and
  FORTIFY_SOURCE" [2]

Changes from v6:
 - Rebased on top of kselftest/kunit
 - Rebased on top of Daniel Axtens' fix for FORTIFY_SOURCE
   incompatibilites [2]
 - Removed a redundant report_enabled() check.
 - Fixed some places with out of date Kconfig names in the
   documentation.

Changes from v5:
 - Split out the panic_on_warn changes to a separate patch.
 - Fix documentation to fewer to the new Kconfig names.
 - Fix some changes which were in the wrong patch.
 - Rebase on top of kselftest/kunit (currently identical to 5.7-rc1)

Changes from v4:
 - KASAN no longer will panic on errors if both panic_on_warn and
   kasan_multishot are enabled.
 - As a result, the KASAN tests will no-longer disable panic_on_warn.
 - This also means panic_on_warn no-longer needs to be exported.
 - The use of temporary "kasan_data" variables has been cleaned up
   somewhat.
 - A potential refcount/resource leak should multiple KASAN errors
   appear during an assertion was fixed.
 - Some wording changes to the KASAN test Kconfig entries.

Changes from v3:
 - KUNIT_SET_KASAN_DATA and KUNIT_DO_EXPECT_KASAN_FAIL have been
 combined and included in KUNIT_DO_EXPECT_KASAN_FAIL() instead.
 - Reordered logic in kasan_update_kunit_status() in report.c to be
 easier to read.
 - Added comment to not use the name "kasan_data" for any kunit tests
 outside of KUNIT_EXPECT_KASAN_FAIL().

Changes since v2:
 - Due to Alan's changes in [1], KUnit can be built as a module.
 - The name of the tests that could not be run with KUnit has been
 changed to be more generic: test_kasan_module.
 - Documentation on how to run the new KASAN tests and what to expect
 when running them has been added.
 - Some variables and functions are now static.
 - Now save/restore panic_on_warn in a similar way to kasan_multi_shot
 and renamed the init/exit functions to be more generic to accommodate.
 - Due to [3] in kasan_strings, kasan_memchr, and
 kasan_memcmp will fail if CONFIG_AMD_MEM_ENCRYPT is enabled so return
 early and print message explaining this circumstance.
 - Changed preprocessor checks to C checks where applicable.

Changes since v1:
 - Make use of Alan Maguire's suggestion to use his patch that allows
   static resources for integration instead of adding a new attribute to
   the kunit struct
 - All KUNIT_EXPECT_KASAN_FAIL statements are local to each test
 - The definition of KUNIT_EXPECT_KASAN_FAIL is local to the
   test_kasan.c file since it seems this is the only place this will
   be used.
 - Integration relies on KUnit being builtin
 - copy_user_test has been separated into its own file since KUnit
   is unable to test these. This can be run as a module just as before,
   using CONFIG_TEST_KASAN_USER
 - The addition to the current task has been separated into its own
   patch as this is a significant enough change to be on its own.


[1] https://lore.kernel.org/linux-kselftest/1585313122-26441-1-git-send-email-alan.maguire@oracle.com/T/#t
[2] https://lkml.org/lkml/2020/4/23/708
[3] https://bugzilla.kernel.org/show_bug.cgi?id=206337



David Gow (1):
  mm: kasan: Do not panic if both panic_on_warn and kasan_multishot set

Patricia Alfonso (4):
  Add KUnit Struct to Current Task
  KUnit: KASAN Integration
  KASAN: Port KASAN Tests to KUnit
  KASAN: Testing Documentation

 Documentation/dev-tools/kasan.rst |  70 +++
 include/kunit/test.h              |   5 +
 include/linux/kasan.h             |   6 +
 include/linux/sched.h             |   4 +
 lib/Kconfig.kasan                 |  18 +-
 lib/Makefile                      |   3 +-
 lib/kunit/test.c                  |  13 +-
 lib/test_kasan.c                  | 688 +++++++++++++-----------------
 lib/test_kasan_module.c           |  76 ++++
 mm/kasan/report.c                 |  34 +-
 10 files changed, 514 insertions(+), 403 deletions(-)
 create mode 100644 lib/test_kasan_module.c

Comments

Alan Maguire May 3, 2020, 10:09 a.m. UTC | #1
On Thu, 23 Apr 2020, David Gow wrote:

> This patchset contains everything needed to integrate KASAN and KUnit.
> 
> KUnit will be able to:
> (1) Fail tests when an unexpected KASAN error occurs
> (2) Pass tests when an expected KASAN error occurs
> 
> Convert KASAN tests to KUnit with the exception of copy_user_test
> because KUnit is unable to test those.
> 
> Add documentation on how to run the KASAN tests with KUnit and what to
> expect when running these tests.
> 
> This patchset depends on:
> - "[PATCH v3 kunit-next 0/2] kunit: extend kunit resources API" [1]
> - "[PATCH v3 0/3] Fix some incompatibilites between KASAN and
>   FORTIFY_SOURCE" [2]
> 
> Changes from v6:
>  - Rebased on top of kselftest/kunit
>  - Rebased on top of Daniel Axtens' fix for FORTIFY_SOURCE
>    incompatibilites [2]
>  - Removed a redundant report_enabled() check.
>  - Fixed some places with out of date Kconfig names in the
>    documentation.
>

Sorry for the delay in getting to this; I retested the
series with the above patchsets pre-applied; all looks
good now, thanks!  Looks like Daniel's patchset has a v4
so I'm not sure if that will have implications for applying
your changes on top of it (haven't tested it yet myself).

For the series feel free to add

Tested-by: Alan Maguire <alan.maguire@oracle.com>

I'll try and take some time to review v7 shortly, but I wanted
to confirm the issues I saw went away first in case you're
blocked.  The only remaining issue I see is that we'd need the
named resource patchset to land first; it would be good
to ensure the API it provides is solid so you won't need to
respin.

Thanks!

Alan
 
> Changes from v5:
>  - Split out the panic_on_warn changes to a separate patch.
>  - Fix documentation to fewer to the new Kconfig names.
>  - Fix some changes which were in the wrong patch.
>  - Rebase on top of kselftest/kunit (currently identical to 5.7-rc1)
> 
> Changes from v4:
>  - KASAN no longer will panic on errors if both panic_on_warn and
>    kasan_multishot are enabled.
>  - As a result, the KASAN tests will no-longer disable panic_on_warn.
>  - This also means panic_on_warn no-longer needs to be exported.
>  - The use of temporary "kasan_data" variables has been cleaned up
>    somewhat.
>  - A potential refcount/resource leak should multiple KASAN errors
>    appear during an assertion was fixed.
>  - Some wording changes to the KASAN test Kconfig entries.
> 
> Changes from v3:
>  - KUNIT_SET_KASAN_DATA and KUNIT_DO_EXPECT_KASAN_FAIL have been
>  combined and included in KUNIT_DO_EXPECT_KASAN_FAIL() instead.
>  - Reordered logic in kasan_update_kunit_status() in report.c to be
>  easier to read.
>  - Added comment to not use the name "kasan_data" for any kunit tests
>  outside of KUNIT_EXPECT_KASAN_FAIL().
> 
> Changes since v2:
>  - Due to Alan's changes in [1], KUnit can be built as a module.
>  - The name of the tests that could not be run with KUnit has been
>  changed to be more generic: test_kasan_module.
>  - Documentation on how to run the new KASAN tests and what to expect
>  when running them has been added.
>  - Some variables and functions are now static.
>  - Now save/restore panic_on_warn in a similar way to kasan_multi_shot
>  and renamed the init/exit functions to be more generic to accommodate.
>  - Due to [3] in kasan_strings, kasan_memchr, and
>  kasan_memcmp will fail if CONFIG_AMD_MEM_ENCRYPT is enabled so return
>  early and print message explaining this circumstance.
>  - Changed preprocessor checks to C checks where applicable.
> 
> Changes since v1:
>  - Make use of Alan Maguire's suggestion to use his patch that allows
>    static resources for integration instead of adding a new attribute to
>    the kunit struct
>  - All KUNIT_EXPECT_KASAN_FAIL statements are local to each test
>  - The definition of KUNIT_EXPECT_KASAN_FAIL is local to the
>    test_kasan.c file since it seems this is the only place this will
>    be used.
>  - Integration relies on KUnit being builtin
>  - copy_user_test has been separated into its own file since KUnit
>    is unable to test these. This can be run as a module just as before,
>    using CONFIG_TEST_KASAN_USER
>  - The addition to the current task has been separated into its own
>    patch as this is a significant enough change to be on its own.
> 
> 
> [1] https://lore.kernel.org/linux-kselftest/1585313122-26441-1-git-send-email-alan.maguire@oracle.com/T/#t
> [2] https://lkml.org/lkml/2020/4/23/708
> [3] https://bugzilla.kernel.org/show_bug.cgi?id=206337
> 
> 
> 
> David Gow (1):
>   mm: kasan: Do not panic if both panic_on_warn and kasan_multishot set
> 
> Patricia Alfonso (4):
>   Add KUnit Struct to Current Task
>   KUnit: KASAN Integration
>   KASAN: Port KASAN Tests to KUnit
>   KASAN: Testing Documentation
> 
>  Documentation/dev-tools/kasan.rst |  70 +++
>  include/kunit/test.h              |   5 +
>  include/linux/kasan.h             |   6 +
>  include/linux/sched.h             |   4 +
>  lib/Kconfig.kasan                 |  18 +-
>  lib/Makefile                      |   3 +-
>  lib/kunit/test.c                  |  13 +-
>  lib/test_kasan.c                  | 688 +++++++++++++-----------------
>  lib/test_kasan_module.c           |  76 ++++
>  mm/kasan/report.c                 |  34 +-
>  10 files changed, 514 insertions(+), 403 deletions(-)
>  create mode 100644 lib/test_kasan_module.c
> 
> -- 
> 2.26.2.303.gf8c07b1a785-goog
> 
>
Shuah May 22, 2020, 10:30 p.m. UTC | #2
On 5/3/20 4:09 AM, Alan Maguire wrote:
> On Thu, 23 Apr 2020, David Gow wrote:
> 
>> This patchset contains everything needed to integrate KASAN and KUnit.
>>
>> KUnit will be able to:
>> (1) Fail tests when an unexpected KASAN error occurs
>> (2) Pass tests when an expected KASAN error occurs
>>
>> Convert KASAN tests to KUnit with the exception of copy_user_test
>> because KUnit is unable to test those.
>>
>> Add documentation on how to run the KASAN tests with KUnit and what to
>> expect when running these tests.
>>
>> This patchset depends on:
>> - "[PATCH v3 kunit-next 0/2] kunit: extend kunit resources API" [1]
>> - "[PATCH v3 0/3] Fix some incompatibilites between KASAN and
>>    FORTIFY_SOURCE" [2]
>>
>> Changes from v6:
>>   - Rebased on top of kselftest/kunit
>>   - Rebased on top of Daniel Axtens' fix for FORTIFY_SOURCE
>>     incompatibilites [2]
>>   - Removed a redundant report_enabled() check.
>>   - Fixed some places with out of date Kconfig names in the
>>     documentation.
>>
> 
> Sorry for the delay in getting to this; I retested the
> series with the above patchsets pre-applied; all looks
> good now, thanks!  Looks like Daniel's patchset has a v4
> so I'm not sure if that will have implications for applying
> your changes on top of it (haven't tested it yet myself).
> 
> For the series feel free to add
> 
> Tested-by: Alan Maguire <alan.maguire@oracle.com>
> 
> I'll try and take some time to review v7 shortly, but I wanted
> to confirm the issues I saw went away first in case you're
> blocked.  The only remaining issue I see is that we'd need the
> named resource patchset to land first; it would be good
> to ensure the API it provides is solid so you won't need to
> respin.
> 
> Thanks!
> 
> Alan
>   
>> Changes from v5:
>>   - Split out the panic_on_warn changes to a separate patch.
>>   - Fix documentation to fewer to the new Kconfig names.
>>   - Fix some changes which were in the wrong patch.
>>   - Rebase on top of kselftest/kunit (currently identical to 5.7-rc1)
>>
>

Hi Brendan,

Is this series ready to go inot Linux 5.8-rc1? Let me know.
Probably needs rebase on top of kselftest/kunit. I applied
patches from David and Vitor

thanks,
-- Shuah
David Gow May 27, 2020, 2:50 a.m. UTC | #3
On Sat, May 23, 2020 at 6:30 AM shuah <shuah@kernel.org> wrote:
>
> On 5/3/20 4:09 AM, Alan Maguire wrote:
> > On Thu, 23 Apr 2020, David Gow wrote:
> >
> >> This patchset contains everything needed to integrate KASAN and KUnit.
> >>
> >> KUnit will be able to:
> >> (1) Fail tests when an unexpected KASAN error occurs
> >> (2) Pass tests when an expected KASAN error occurs
> >>
> >> Convert KASAN tests to KUnit with the exception of copy_user_test
> >> because KUnit is unable to test those.
> >>
> >> Add documentation on how to run the KASAN tests with KUnit and what to
> >> expect when running these tests.
> >>
> >> This patchset depends on:
> >> - "[PATCH v3 kunit-next 0/2] kunit: extend kunit resources API" [1]
> >> - "[PATCH v3 0/3] Fix some incompatibilites between KASAN and
> >>    FORTIFY_SOURCE" [2]
> >>
> >> Changes from v6:
> >>   - Rebased on top of kselftest/kunit
> >>   - Rebased on top of Daniel Axtens' fix for FORTIFY_SOURCE
> >>     incompatibilites [2]
> >>   - Removed a redundant report_enabled() check.
> >>   - Fixed some places with out of date Kconfig names in the
> >>     documentation.
> >>
> >
> > Sorry for the delay in getting to this; I retested the
> > series with the above patchsets pre-applied; all looks
> > good now, thanks!  Looks like Daniel's patchset has a v4
> > so I'm not sure if that will have implications for applying
> > your changes on top of it (haven't tested it yet myself).
> >
> > For the series feel free to add
> >
> > Tested-by: Alan Maguire <alan.maguire@oracle.com>
> >
> > I'll try and take some time to review v7 shortly, but I wanted
> > to confirm the issues I saw went away first in case you're
> > blocked.  The only remaining issue I see is that we'd need the
> > named resource patchset to land first; it would be good
> > to ensure the API it provides is solid so you won't need to
> > respin.
> >
> > Thanks!
> >
> > Alan
> >
> >> Changes from v5:
> >>   - Split out the panic_on_warn changes to a separate patch.
> >>   - Fix documentation to fewer to the new Kconfig names.
> >>   - Fix some changes which were in the wrong patch.
> >>   - Rebase on top of kselftest/kunit (currently identical to 5.7-rc1)
> >>
> >
>
> Hi Brendan,
>
> Is this series ready to go inot Linux 5.8-rc1? Let me know.
> Probably needs rebase on top of kselftest/kunit. I applied
> patches from David and Vitor
>
> thanks,
> -- Shuah
>

Hi Shuah,

I think the only things holding this up are the missing dependencies:
the "extend kunit resources API" patches[1] for KUnit (which look
ready to me), and the "Fix some incompatibilities between KASAN and
FORTIFY_SOURCE" changes[2] on the KASAN side (which also seem ready).

This patchset may need a (likely rather trivial) rebase on top of
whatever versions of those end up merged: I'm happy to do that if
necessary.

Cheers,
-- David

[1]: https://lore.kernel.org/linux-kselftest/1585313122-26441-1-git-send-email-alan.maguire@oracle.com/T/#t
[2]: http://lkml.iu.edu/hypermail/linux/kernel/2004.3/00735.html
Brendan Higgins May 28, 2020, 7:52 p.m. UTC | #4
On Tue, May 26, 2020 at 7:51 PM David Gow <davidgow@google.com> wrote:
>
> On Sat, May 23, 2020 at 6:30 AM shuah <shuah@kernel.org> wrote:
> >
> > On 5/3/20 4:09 AM, Alan Maguire wrote:
> > > On Thu, 23 Apr 2020, David Gow wrote:
> > >
> > >> This patchset contains everything needed to integrate KASAN and KUnit.
> > >>
> > >> KUnit will be able to:
> > >> (1) Fail tests when an unexpected KASAN error occurs
> > >> (2) Pass tests when an expected KASAN error occurs
> > >>
> > >> Convert KASAN tests to KUnit with the exception of copy_user_test
> > >> because KUnit is unable to test those.
> > >>
> > >> Add documentation on how to run the KASAN tests with KUnit and what to
> > >> expect when running these tests.
> > >>
> > >> This patchset depends on:
> > >> - "[PATCH v3 kunit-next 0/2] kunit: extend kunit resources API" [1]
> > >> - "[PATCH v3 0/3] Fix some incompatibilites between KASAN and
> > >>    FORTIFY_SOURCE" [2]
> > >>
> > >> Changes from v6:
> > >>   - Rebased on top of kselftest/kunit
> > >>   - Rebased on top of Daniel Axtens' fix for FORTIFY_SOURCE
> > >>     incompatibilites [2]
> > >>   - Removed a redundant report_enabled() check.
> > >>   - Fixed some places with out of date Kconfig names in the
> > >>     documentation.
> > >>
> > >
> > > Sorry for the delay in getting to this; I retested the
> > > series with the above patchsets pre-applied; all looks
> > > good now, thanks!  Looks like Daniel's patchset has a v4
> > > so I'm not sure if that will have implications for applying
> > > your changes on top of it (haven't tested it yet myself).
> > >
> > > For the series feel free to add
> > >
> > > Tested-by: Alan Maguire <alan.maguire@oracle.com>
> > >
> > > I'll try and take some time to review v7 shortly, but I wanted
> > > to confirm the issues I saw went away first in case you're
> > > blocked.  The only remaining issue I see is that we'd need the
> > > named resource patchset to land first; it would be good
> > > to ensure the API it provides is solid so you won't need to
> > > respin.
> > >
> > > Thanks!
> > >
> > > Alan
> > >
> > >> Changes from v5:
> > >>   - Split out the panic_on_warn changes to a separate patch.
> > >>   - Fix documentation to fewer to the new Kconfig names.
> > >>   - Fix some changes which were in the wrong patch.
> > >>   - Rebase on top of kselftest/kunit (currently identical to 5.7-rc1)
> > >>
> > >
> >
> > Hi Brendan,
> >
> > Is this series ready to go inot Linux 5.8-rc1? Let me know.
> > Probably needs rebase on top of kselftest/kunit. I applied
> > patches from David and Vitor
> >
> > thanks,
> > -- Shuah
> >
>
> Hi Shuah,
>
> I think the only things holding this up are the missing dependencies:
> the "extend kunit resources API" patches[1] for KUnit (which look
> ready to me), and the "Fix some incompatibilities between KASAN and
> FORTIFY_SOURCE" changes[2] on the KASAN side (which also seem ready).
>
> This patchset may need a (likely rather trivial) rebase on top of
> whatever versions of those end up merged: I'm happy to do that if
> necessary.
>
> Cheers,
> -- David
>
> [1]: https://lore.kernel.org/linux-kselftest/1585313122-26441-1-git-send-email-alan.maguire@oracle.com/T/#t
> [2]: http://lkml.iu.edu/hypermail/linux/kernel/2004.3/00735.html

As David pointed out, this series is waiting on its dependencies.
Sorry, I thought the "extend KUnit resources API" patchset was ready
to go, but I realized I only gave a reviewed-by to one of the patches.
Both have been reviewed now, but one patch needs a minor fix.

As for other patches, the patches from David, Vitor, and Anders should
cover everything. Thanks!
Shuah Khan May 28, 2020, 8:16 p.m. UTC | #5
On 5/28/20 1:52 PM, Brendan Higgins wrote:
> On Tue, May 26, 2020 at 7:51 PM David Gow <davidgow@google.com> wrote:
>>
>> On Sat, May 23, 2020 at 6:30 AM shuah <shuah@kernel.org> wrote:
>>>
>>> On 5/3/20 4:09 AM, Alan Maguire wrote:
>>>> On Thu, 23 Apr 2020, David Gow wrote:
>>>>
>>>>> This patchset contains everything needed to integrate KASAN and KUnit.
>>>>>
>>>>> KUnit will be able to:
>>>>> (1) Fail tests when an unexpected KASAN error occurs
>>>>> (2) Pass tests when an expected KASAN error occurs
>>>>>
>>>>> Convert KASAN tests to KUnit with the exception of copy_user_test
>>>>> because KUnit is unable to test those.
>>>>>
>>>>> Add documentation on how to run the KASAN tests with KUnit and what to
>>>>> expect when running these tests.
>>>>>
>>>>> This patchset depends on:
>>>>> - "[PATCH v3 kunit-next 0/2] kunit: extend kunit resources API" [1]
>>>>> - "[PATCH v3 0/3] Fix some incompatibilites between KASAN and
>>>>>     FORTIFY_SOURCE" [2]
>>>>>
>>>>> Changes from v6:
>>>>>    - Rebased on top of kselftest/kunit
>>>>>    - Rebased on top of Daniel Axtens' fix for FORTIFY_SOURCE
>>>>>      incompatibilites [2]
>>>>>    - Removed a redundant report_enabled() check.
>>>>>    - Fixed some places with out of date Kconfig names in the
>>>>>      documentation.
>>>>>
>>>>
>>>> Sorry for the delay in getting to this; I retested the
>>>> series with the above patchsets pre-applied; all looks
>>>> good now, thanks!  Looks like Daniel's patchset has a v4
>>>> so I'm not sure if that will have implications for applying
>>>> your changes on top of it (haven't tested it yet myself).
>>>>
>>>> For the series feel free to add
>>>>
>>>> Tested-by: Alan Maguire <alan.maguire@oracle.com>
>>>>
>>>> I'll try and take some time to review v7 shortly, but I wanted
>>>> to confirm the issues I saw went away first in case you're
>>>> blocked.  The only remaining issue I see is that we'd need the
>>>> named resource patchset to land first; it would be good
>>>> to ensure the API it provides is solid so you won't need to
>>>> respin.
>>>>
>>>> Thanks!
>>>>
>>>> Alan
>>>>
>>>>> Changes from v5:
>>>>>    - Split out the panic_on_warn changes to a separate patch.
>>>>>    - Fix documentation to fewer to the new Kconfig names.
>>>>>    - Fix some changes which were in the wrong patch.
>>>>>    - Rebase on top of kselftest/kunit (currently identical to 5.7-rc1)
>>>>>
>>>>
>>>
>>> Hi Brendan,
>>>
>>> Is this series ready to go inot Linux 5.8-rc1? Let me know.
>>> Probably needs rebase on top of kselftest/kunit. I applied
>>> patches from David and Vitor
>>>
>>> thanks,
>>> -- Shuah
>>>
>>
>> Hi Shuah,
>>
>> I think the only things holding this up are the missing dependencies:
>> the "extend kunit resources API" patches[1] for KUnit (which look
>> ready to me), and the "Fix some incompatibilities between KASAN and
>> FORTIFY_SOURCE" changes[2] on the KASAN side (which also seem ready).
>>
>> This patchset may need a (likely rather trivial) rebase on top of
>> whatever versions of those end up merged: I'm happy to do that if
>> necessary.
>>
>> Cheers,
>> -- David
>>
>> [1]: https://lore.kernel.org/linux-kselftest/1585313122-26441-1-git-send-email-alan.maguire@oracle.com/T/#t
>> [2]: http://lkml.iu.edu/hypermail/linux/kernel/2004.3/00735.html
> 
> As David pointed out, this series is waiting on its dependencies.
> Sorry, I thought the "extend KUnit resources API" patchset was ready
> to go, but I realized I only gave a reviewed-by to one of the patches.
> Both have been reviewed now, but one patch needs a minor fix.
> 

Yes. Thanks David.

> As for other patches, the patches from David, Vitor, and Anders should
> cover everything. Thanks!
>
I pulled David's and Vitor's patches. I am waiting for patch from
Vitor to fix a problem that was introduced when I was resolving merge
conflicts between Vitor's and David's patches.

I will pull Anders patches.

thanks,
-- Shuah