|
|
Log in / Subscribe / Register

overflow: Implement size_t saturating arithmetic helpers

From:  Kees Cook <keescook-AT-chromium.org>
To:  Rasmus Villemoes <linux-AT-rasmusvillemoes.dk>
Subject:  [PATCH v2 0/2] overflow: Implement size_t saturating arithmetic helpers
Date:  Mon, 24 Jan 2022 15:23:40 -0800
Message-ID:  <20220124232342.3113350-1-keescook@chromium.org>
Cc:  Kees Cook <keescook-AT-chromium.org>, Nick Desaulniers <ndesaulniers-AT-google.com>, "Gustavo A. R. Silva" <gustavoars-AT-kernel.org>, Nathan Chancellor <nathan-AT-kernel.org>, Jason Gunthorpe <jgg-AT-ziepe.ca>, Leon Romanovsky <leon-AT-kernel.org>, Keith Busch <kbusch-AT-kernel.org>, Len Baker <len.baker-AT-gmx.com>, Jonathan Corbet <corbet-AT-lwn.net>, linux-kernel-AT-vger.kernel.org, linux-doc-AT-vger.kernel.org, linux-hardening-AT-vger.kernel.org
Archive-link:  Article

Hi,

While doing more array_size() scans on the kernel, and reviewing recent[1]
struct_size() work[2], it became clear we needed helpers to perform
composed saturating adds and multiplies. This creates those helpers and
updates the self tests to check them.

v1: https://lore.kernel.org/lkml/20210920180853.1825195-1-kee...
v2:
 - use static inlines instead of macros (Rasmus)
 - undef local helpers defs in selftest (Rasmus)
 - Make sure to keep saturation for size_sub() arguments
 - update selftests for size_sub() behavior
 - Add reviews

Thanks,

-Kees

[1] https://lore.kernel.org/linux-hardening/202201241213.82E7...
[2] https://lore.kernel.org/lkml/?q=%22open-coded+arithmetic%22

Kees Cook (2):
  test_overflow: Regularize test reporting output
  overflow: Implement size_t saturating arithmetic helpers

 Documentation/process/deprecated.rst |  20 +++-
 include/linux/overflow.h             | 110 +++++++++++--------
 lib/test_overflow.c                  | 152 ++++++++++++++++++++++-----
 3 files changed, 214 insertions(+), 68 deletions(-)

-- 
2.30.2



Copyright © 2022, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds