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: <1c4a5a6e-1f11-b04f-ebd0-17919ba93bca@suse.cz>
Date:   Tue, 8 Sep 2020 16:40:00 +0200
From:   Vlastimil Babka <vbabka@...e.cz>
To:     Alexander Potapenko <glider@...gle.com>
Cc:     Marco Elver <elver@...gle.com>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Catalin Marinas <catalin.marinas@....com>,
        Christoph Lameter <cl@...ux.com>,
        David Rientjes <rientjes@...gle.com>,
        Joonsoo Kim <iamjoonsoo.kim@....com>,
        Mark Rutland <mark.rutland@....com>,
        Pekka Enberg <penberg@...nel.org>,
        "H. Peter Anvin" <hpa@...or.com>, paulmck@...nel.org,
        Andrey Konovalov <andreyknvl@...gle.com>,
        Andrey Ryabinin <aryabinin@...tuozzo.com>,
        Andy Lutomirski <luto@...nel.org>,
        Borislav Petkov <bp@...en8.de>, dave.hansen@...ux.intel.com,
        Dmitriy Vyukov <dvyukov@...gle.com>,
        Eric Dumazet <edumazet@...gle.com>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Ingo Molnar <mingo@...hat.com>, Jann Horn <jannh@...gle.com>,
        Jonathan Corbet <corbet@....net>,
        Kees Cook <keescook@...omium.org>,
        Peter Zijlstra <peterz@...radead.org>, Qian Cai <cai@....pw>,
        Thomas Gleixner <tglx@...utronix.de>,
        Will Deacon <will@...nel.org>,
        the arch/x86 maintainers <x86@...nel.org>,
        linux-doc@...r.kernel.org, LKML <linux-kernel@...r.kernel.org>,
        kasan-dev <kasan-dev@...glegroups.com>,
        linux-arm-kernel@...ts.infradead.org,
        Linux Memory Management List <linux-mm@...ck.org>
Subject: Re: [PATCH RFC 00/10] KFENCE: A low-overhead sampling-based memory
 safety error detector

On 9/8/20 2:16 PM, Alexander Potapenko wrote:
>> Toggling a static branch is AFAIK quite disruptive (PeterZ will probably tell
>> you better), and with the default 100ms sample interval, I'd think it's not good
>> to toggle it so often? Did you measure what performance would you get, if the
>> static key was only for long-term toggling the whole feature on and off (boot
>> time or even runtime), but the decisions "am I in a sample interval right now?"
>> would be normal tests behind this static key? Thanks.
> 
> 100ms is the default that we use for testing, but for production it
> should be fine to pick a longer interval (e.g. 1 second or more).
> We haven't noticed any performance impact with neither 100ms nor bigger values.

Hmm, I see.

> Regarding using normal branches, they are quite expensive.
> E.g. at some point we used to have a branch in slab_free() to check
> whether the freed object belonged to KFENCE pool.
> When the pool address was taken from memory, this resulted in some
> non-zero performance penalty.

Well yeah, if the checks involve extra cache misses, that adds up. But AFAICS
you can't avoid that kind of checks with static key anyway (am I looking right
at is_kfence_address()?) because some kfence-allocated objects will exist even
after the sampling period ended, right?
So AFAICS kfence_alloc() is the only user of the static key and I wonder if it
really makes such difference there.

> As for enabling the whole feature at runtime, our intention is to let
> the users have it enabled by default, otherwise someone will need to
> tell every machine in the fleet when the feature is to be enabled.

Sure, but I guess there are tools that make it no difference in effort between 1
machine and fleet.

I'll try to explain my general purpose distro-kernel POV. What I like e.g. about
debug_pagealloc and page_owner (and contributed to that state of these features)
is that a distro kernel can be shipped with them compiled in, but they are
static-key disabled thus have no overhead, until a user enables them on boot,
without a need to replace the kernel with a debug one first. Users can enable
them for their own debugging, or when asked by somebody from the distro
assisting with the debugging.

I think KFENCE has similar potential and could work the same way - compiled in
always, but a static key would eliminate everything, even the
is_kfence_address() checks, until it became enabled (but then it would probably
be a one-way street for the rest of the kernel's uptime). Some distro users
would decide to enable it always, some not, but could be advised to when needed.
So the existing static key could be repurposed for this, or if it's really worth
having the current one to control just the sampling period, then there would be two?

Thanks.

>> > We have verified by running synthetic benchmarks (sysbench I/O,
>> > hackbench) that a kernel with KFENCE is performance-neutral compared to
>> > a non-KFENCE baseline kernel.
>> >
>> > KFENCE is inspired by GWP-ASan [1], a userspace tool with similar
>> > properties. The name "KFENCE" is a homage to the Electric Fence Malloc
>> > Debugger [2].
>> >
>> > For more details, see Documentation/dev-tools/kfence.rst added in the
>> > series -- also viewable here:
>> >
>> >       https://raw.githubusercontent.com/google/kasan/kfence/Documentation/dev-tools/kfence.rst
>> >
>> > [1] http://llvm.org/docs/GwpAsan.html
>> > [2] https://linux.die.net/man/3/efence
>> >
>> > Alexander Potapenko (6):
>> >   mm: add Kernel Electric-Fence infrastructure
>> >   x86, kfence: enable KFENCE for x86
>> >   mm, kfence: insert KFENCE hooks for SLAB
>> >   mm, kfence: insert KFENCE hooks for SLUB
>> >   kfence, kasan: make KFENCE compatible with KASAN
>> >   kfence, kmemleak: make KFENCE compatible with KMEMLEAK
>> >
>> > Marco Elver (4):
>> >   arm64, kfence: enable KFENCE for ARM64
>> >   kfence, lockdep: make KFENCE compatible with lockdep
>> >   kfence, Documentation: add KFENCE documentation
>> >   kfence: add test suite
>> >
>> >  Documentation/dev-tools/index.rst  |   1 +
>> >  Documentation/dev-tools/kfence.rst | 285 +++++++++++
>> >  MAINTAINERS                        |  11 +
>> >  arch/arm64/Kconfig                 |   1 +
>> >  arch/arm64/include/asm/kfence.h    |  39 ++
>> >  arch/arm64/mm/fault.c              |   4 +
>> >  arch/x86/Kconfig                   |   2 +
>> >  arch/x86/include/asm/kfence.h      |  60 +++
>> >  arch/x86/mm/fault.c                |   4 +
>> >  include/linux/kfence.h             | 174 +++++++
>> >  init/main.c                        |   2 +
>> >  kernel/locking/lockdep.c           |   8 +
>> >  lib/Kconfig.debug                  |   1 +
>> >  lib/Kconfig.kfence                 |  70 +++
>> >  mm/Makefile                        |   1 +
>> >  mm/kasan/common.c                  |   7 +
>> >  mm/kfence/Makefile                 |   6 +
>> >  mm/kfence/core.c                   | 730 +++++++++++++++++++++++++++
>> >  mm/kfence/kfence-test.c            | 777 +++++++++++++++++++++++++++++
>> >  mm/kfence/kfence.h                 | 104 ++++
>> >  mm/kfence/report.c                 | 201 ++++++++
>> >  mm/kmemleak.c                      |  11 +
>> >  mm/slab.c                          |  46 +-
>> >  mm/slab_common.c                   |   6 +-
>> >  mm/slub.c                          |  72 ++-
>> >  25 files changed, 2591 insertions(+), 32 deletions(-)
>> >  create mode 100644 Documentation/dev-tools/kfence.rst
>> >  create mode 100644 arch/arm64/include/asm/kfence.h
>> >  create mode 100644 arch/x86/include/asm/kfence.h
>> >  create mode 100644 include/linux/kfence.h
>> >  create mode 100644 lib/Kconfig.kfence
>> >  create mode 100644 mm/kfence/Makefile
>> >  create mode 100644 mm/kfence/core.c
>> >  create mode 100644 mm/kfence/kfence-test.c
>> >  create mode 100644 mm/kfence/kfence.h
>> >  create mode 100644 mm/kfence/report.c
>> >
>>
> 
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ