Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1464300

Re: [PATCH v2 4/5] bug: Provide toggle for BUG on data corruption

From Kees Cook <keescook@chromium.org>
Newsgroups linux.kernel
Subject Re: [PATCH v2 4/5] bug: Provide toggle for BUG on data corruption
Date 2016-08-17 05:40 +0200
Message-ID <s6ZRT-3Oc-9@gated-at.bofh.it> (permalink)
References <s6WU2-1Ld-3@gated-at.bofh.it> <s6WU2-1Ld-25@gated-at.bofh.it> <s6WU2-1Ld-23@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Tue, Aug 16, 2016 at 5:26 PM, Joe Perches <joe@perches.com> wrote:
> On Tue, 2016-08-16 at 17:20 -0700, Kees Cook wrote:
>> The kernel checks for cases of data structure corruption under some
>> CONFIGs (e.g. CONFIG_DEBUG_LIST). When corruption is detected, some
>> systems may want to BUG() immediately instead of letting the system run
>> with known corruption.  Usually these kinds of manipulation primitives can
>> be used by security flaws to gain arbitrary memory write control. This
>> provides a new config CONFIG_BUG_ON_DATA_CORRUPTION and a corresponding
>> macro CHECK_DATA_CORRUPTION for handling these situations. Notably, even
>> if not BUGing, the kernel should not continue processing the corrupted
>> structure.
> []
>> diff --git a/include/linux/bug.h b/include/linux/bug.h
> []
>> @@ -118,4 +118,21 @@ static inline enum bug_trap_type report_bug(unsigned long bug_addr,
>>  }
>>
>>  #endif       /* CONFIG_GENERIC_BUG */
>> +
>> +/*
>> + * Since detected data corruption should stop operation on the affected
>> + * structures, this returns false if the corruption condition is found.
>> + */
>> +#define CHECK_DATA_CORRUPTION(condition, format...)                   \
>
> My preference would be to use (condition, fmt, ...)
>
>> +     do {                                                             \
>> +             if (unlikely(condition)) {                               \
>> +                     if (IS_ENABLED(CONFIG_BUG_ON_DATA_CORRUPTION)) { \
>> +                             printk(KERN_ERR format);                 \
>
> and
>                                 pr_err(fmt, ##__VA_ARGS__);
>
> so that any use would also get any local pr_fmt applied as well.
>
>> +                             BUG();                                   \
>> +                     } else                                           \
>> +                             WARN(1, format);                         \
>> +                     return false;                                    \
>> +             }                                                        \
>> +     } while (0)
>> +
>>  #endif       /* _LINUX_BUG_H */
>

Ah yes, excellent point. I'll convert this for my v3. Thanks!

-Kees

-- 
Kees Cook
Nexus Security

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v2 0/5] bug: Provide toggle for BUG on data corruption Kees Cook <keescook@chromium.org> - 2016-08-17 02:30 +0200
  [PATCH v2 1/5] list: Split list_add() debug checking into separate function Kees Cook <keescook@chromium.org> - 2016-08-17 02:30 +0200
    Re: [PATCH v2 1/5] list: Split list_add() debug checking into  separate function Steven Rostedt <rostedt@goodmis.org> - 2016-08-17 15:20 +0200
  [PATCH v2 2/5] rculist: Consolidate DEBUG_LIST for list_add_rcu() Kees Cook <keescook@chromium.org> - 2016-08-17 02:30 +0200
  Re: [PATCH v2 4/5] bug: Provide toggle for BUG on data corruption Joe Perches <joe@perches.com> - 2016-08-17 02:30 +0200
    Re: [PATCH v2 4/5] bug: Provide toggle for BUG on data corruption Kees Cook <keescook@chromium.org> - 2016-08-17 05:40 +0200
  [PATCH v2 5/5] lkdtm: Add tests for struct list corruption Kees Cook <keescook@chromium.org> - 2016-08-17 02:30 +0200
  [PATCH v2 4/5] bug: Provide toggle for BUG on data corruption Kees Cook <keescook@chromium.org> - 2016-08-17 02:50 +0200
    Re: [PATCH v2 4/5] bug: Provide toggle for BUG on data corruption Steven Rostedt <rostedt@goodmis.org> - 2016-08-17 15:30 +0200
  [PATCH v2 3/5] list: Split list_del() debug checking into separate function Kees Cook <keescook@chromium.org> - 2016-08-17 02:50 +0200
  Re: [PATCH v2 0/5] bug: Provide toggle for BUG on data corruption Henrique de Moraes Holschuh <hmh@hmh.eng.br> - 2016-08-17 03:00 +0200
    Re: [PATCH v2 0/5] bug: Provide toggle for BUG on data corruption Kees Cook <keescook@chromium.org> - 2016-08-17 05:40 +0200
  Re: [PATCH v2 0/5] bug: Provide toggle for BUG on data corruption Stephen Boyd <sboyd@codeaurora.org> - 2016-08-17 22:20 +0200
    Re: [PATCH v2 0/5] bug: Provide toggle for BUG on data corruption Kees Cook <keescook@chromium.org> - 2016-08-17 23:20 +0200

csiph-web