All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/17] Enable strict compile-time memcpy() fortify checks
@ 2021-12-13 22:33 Kees Cook
  2021-12-13 22:33 ` [PATCH 01/17] KVM: x86: Replace memset() "optimization" with normal per-field writes Kees Cook
                   ` (18 more replies)
  0 siblings, 19 replies; 47+ messages in thread
From: Kees Cook @ 2021-12-13 22:33 UTC (permalink / raw)
  To: linux-hardening; +Cc: Kees Cook, linux-kernel

Hi,

This is "phase 2" (of several phases) to hardening the kernel against
memcpy-based buffer overflows. With nearly all compile-time fixes
landed, the next step is to turn on the warning globally to keep future
compile-time issues from happening, and let us take the step towards
run-time checking (and towards a new API for flexible array structures).

This series is based on latest linux-next, and several patches here
have already been taken by subsystem maintainers but haven't appeared
in linux-next yet, and are noted below.

-Kees

refactoring patches expected to be going via subsystem trees:
    sata_fsl: Use struct_group() for memcpy() region
	https://lore.kernel.org/lkml/23527f89-d098-ab6b-f3c9-a8a395e32df5@opensource.wdc.com/
    ath11k: Use memset_startat() for clearing queue descriptors
	https://lore.kernel.org/lkml/163777372886.11557.5551795598856429949.kvalo@codeaurora.org/

refactoring patches going via my topic tree due to having no current response:
    net/mlx5e: Use struct_group() for memcpy() region
	https://lore.kernel.org/lkml/20211118183748.1283069-1-keescook@chromium.org/
    net/mlx5e: Avoid field-overflowing memcpy()
	https://lore.kernel.org/lkml/20211209053402.2202206-1-keescook@chromium.org/
    media: omap3isp: Use struct_group() for memcpy() region
	https://lore.kernel.org/lkml/20211118184352.1284792-1-keescook@chromium.org/
    drbd: Use struct_group() to zero algs
	https://lore.kernel.org/lkml/20211118203712.1288866-1-keescook@chromium.org/
    dm integrity: Use struct_group() to zero struct journal_sector
	https://lore.kernel.org/lkml/20211118203640.1288585-1-keescook@chromium.org/
    iw_cxgb4: Use memset_startat() for cpl_t5_pass_accept_rpl
	https://lore.kernel.org/lkml/20211118202335.1285836-1-keescook@chromium.org/

refactoring patches going via my topic tree due to Acks:
    KVM: x86: Replace memset() "optimization" with normal per-field writes
	https://lore.kernel.org/lkml/202108181605.44C504C@keescook/
    RDMA/mlx5: Use memset_after() to zero struct mlx5_ib_mr
	https://lore.kernel.org/lkml/YbByJSkBgLRp5S8V@unreal/
    intel_th: msu: Use memset_startat() for clearing hw header
	https://lore.kernel.org/lkml/87sfyzi97l.fsf@ashishki-desk.ger.corp.intel.com/
    IB/mthca: Use memset_startat() for clearing mpt_entry
	https://lore.kernel.org/lkml/20211118202126.1285376-1-keescook@chromium.org/
    scsi: lpfc: Use struct_group() to initialize struct lpfc_cgn_info
	https://lore.kernel.org/lkml/1164349c-93a5-ebb8-94aa-dbe03957c40f@gmail.com/

fortify changes going via my topic tree:
    fortify: Detect struct member overflows in memcpy() at compile-time
    fortify: Detect struct member overflows in memmove() at compile-time
    fortify: Detect struct member overflows in memset() at compile-time
    fortify: Work around Clang inlining bugs


 arch/x86/boot/compressed/misc.c               |   3 +-
 arch/x86/kvm/emulate.c                        |   9 +-
 arch/x86/kvm/kvm_emulate.h                    |   6 +-
 arch/x86/lib/memcpy_32.c                      |   1 +
 drivers/ata/sata_fsl.c                        |  10 +-
 drivers/block/drbd/drbd_main.c                |   3 +-
 drivers/block/drbd/drbd_protocol.h            |   6 +-
 drivers/block/drbd/drbd_receiver.c            |   3 +-
 drivers/hwtracing/intel_th/msu.c              |   4 +-
 drivers/infiniband/hw/cxgb4/cm.c              |   5 +-
 drivers/infiniband/hw/mlx5/mlx5_ib.h          |   4 +-
 drivers/infiniband/hw/mthca/mthca_mr.c        |   3 +-
 drivers/md/dm-integrity.c                     |   9 +-
 drivers/media/platform/omap3isp/ispstat.c     |   5 +-
 drivers/net/ethernet/chelsio/cxgb4/t4_msg.h   |   2 +-
 drivers/net/ethernet/mellanox/mlx5/core/en.h  |   6 +-
 .../net/ethernet/mellanox/mlx5/core/en/xdp.c  |   4 +-
 .../net/ethernet/mellanox/mlx5/core/en_tx.c   |   2 +-
 drivers/net/wireless/ath/ath11k/hal_rx.c      |  13 +-
 drivers/scsi/lpfc/lpfc.h                      |  90 ++++---
 drivers/scsi/lpfc/lpfc_init.c                 |   4 +-
 include/linux/fortify-string.h                | 245 +++++++++++++-----
 include/linux/if_vlan.h                       |   6 +-
 include/uapi/linux/omap3isp.h                 |  21 +-
 lib/Makefile                                  |   3 +-
 lib/string_helpers.c                          |   6 +
 .../read_overflow2_field-memcpy.c             |   5 +
 .../read_overflow2_field-memmove.c            |   5 +
 .../write_overflow_field-memcpy.c             |   5 +
 .../write_overflow_field-memmove.c            |   5 +
 .../write_overflow_field-memset.c             |   5 +
 scripts/test_fortify.sh                       |   8 +-
 security/Kconfig                              |   2 +-
 33 files changed, 344 insertions(+), 164 deletions(-)
 create mode 100644 lib/test_fortify/read_overflow2_field-memcpy.c
 create mode 100644 lib/test_fortify/read_overflow2_field-memmove.c
 create mode 100644 lib/test_fortify/write_overflow_field-memcpy.c
 create mode 100644 lib/test_fortify/write_overflow_field-memmove.c
 create mode 100644 lib/test_fortify/write_overflow_field-memset.c

-- 
2.30.2


^ permalink raw reply	[flat|nested] 47+ messages in thread
* Re: [PATCH 17/17] fortify: Work around Clang inlining bugs
@ 2021-12-15  3:25 kernel test robot
  0 siblings, 0 replies; 47+ messages in thread
From: kernel test robot @ 2021-12-15  3:25 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 15322 bytes --]

CC: llvm(a)lists.linux.dev
CC: kbuild-all(a)lists.01.org
In-Reply-To: <20211213223331.135412-18-keescook@chromium.org>
References: <20211213223331.135412-18-keescook@chromium.org>
TO: Kees Cook <keescook@chromium.org>

Hi Kees,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.16-rc5 next-20211213]
[cannot apply to rdma/for-next axboe-block/for-next kvm/queue tip/x86/core mkp-scsi/for-next jejb-scsi/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Kees-Cook/Enable-strict-compile-time-memcpy-fortify-checks/20211214-064002
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git aa50faff4416c869b52dff68a937c84d29e12f4b
:::::: branch date: 29 hours ago
:::::: commit date: 29 hours ago
config: x86_64-randconfig-c007-20211213 (https://download.01.org/0day-ci/archive/20211215/202112151126.bOLnKyZC-lkp(a)intel.com/config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project b6a2ddb6c8ac29412b1361810972e15221fa021c)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/e5d600e1abbdd2034dbc844654957a4ec1182dbf
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Kees-Cook/Enable-strict-compile-time-memcpy-fortify-checks/20211214-064002
        git checkout e5d600e1abbdd2034dbc844654957a4ec1182dbf
        # save the config file to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 clang-analyzer 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


clang-analyzer warnings: (new ones prefixed by >>)
   include/asm-generic/bug.h:131:2: note: expanded from macro 'WARN'
           if (unlikely(__ret_warn_on))                                    \
           ^
   lib/math/reciprocal_div.c:47:2: note: Loop condition is false.  Exiting loop
           WARN(l == 32,
           ^
   include/asm-generic/bug.h:132:3: note: expanded from macro 'WARN'
                   __WARN_printf(TAINT_WARN, format);                      \
                   ^
   include/asm-generic/bug.h:98:3: note: expanded from macro '__WARN_printf'
                   instrumentation_begin();                                \
                   ^
   include/linux/instrumentation.h:57:34: note: expanded from macro 'instrumentation_begin'
   # define instrumentation_begin()        do { } while(0)
                                           ^
   lib/math/reciprocal_div.c:47:2: note: Loop condition is false.  Exiting loop
           WARN(l == 32,
           ^
   include/asm-generic/bug.h:132:3: note: expanded from macro 'WARN'
                   __WARN_printf(TAINT_WARN, format);                      \
                   ^
   include/asm-generic/bug.h:100:3: note: expanded from macro '__WARN_printf'
                   __WARN_FLAGS(BUGFLAG_NO_CUT_HERE | BUGFLAG_TAINT(taint));\
                   ^
   arch/x86/include/asm/bug.h:78:2: note: expanded from macro '__WARN_FLAGS'
           instrumentation_begin();                                \
           ^
   include/linux/instrumentation.h:57:34: note: expanded from macro 'instrumentation_begin'
   # define instrumentation_begin()        do { } while(0)
                                           ^
   lib/math/reciprocal_div.c:47:2: note: Loop condition is false.  Exiting loop
           WARN(l == 32,
           ^
   include/asm-generic/bug.h:132:3: note: expanded from macro 'WARN'
                   __WARN_printf(TAINT_WARN, format);                      \
                   ^
   include/asm-generic/bug.h:100:3: note: expanded from macro '__WARN_printf'
                   __WARN_FLAGS(BUGFLAG_NO_CUT_HERE | BUGFLAG_TAINT(taint));\
                   ^
   arch/x86/include/asm/bug.h:79:2: note: expanded from macro '__WARN_FLAGS'
           _BUG_FLAGS(ASM_UD2, BUGFLAG_WARNING|(flags));           \
           ^
   arch/x86/include/asm/bug.h:25:37: note: expanded from macro '_BUG_FLAGS'
   #define _BUG_FLAGS(ins, flags)                                          \
                                                                           ^
   lib/math/reciprocal_div.c:47:2: note: Loop condition is false.  Exiting loop
           WARN(l == 32,
           ^
   include/asm-generic/bug.h:132:3: note: expanded from macro 'WARN'
                   __WARN_printf(TAINT_WARN, format);                      \
                   ^
   include/asm-generic/bug.h:100:3: note: expanded from macro '__WARN_printf'
                   __WARN_FLAGS(BUGFLAG_NO_CUT_HERE | BUGFLAG_TAINT(taint));\
                   ^
   arch/x86/include/asm/bug.h:81:2: note: expanded from macro '__WARN_FLAGS'
           instrumentation_end();                                  \
           ^
   include/linux/instrumentation.h:58:33: note: expanded from macro 'instrumentation_end'
   # define instrumentation_end()          do { } while(0)
                                           ^
   lib/math/reciprocal_div.c:47:2: note: Loop condition is false.  Exiting loop
           WARN(l == 32,
           ^
   include/asm-generic/bug.h:132:3: note: expanded from macro 'WARN'
                   __WARN_printf(TAINT_WARN, format);                      \
                   ^
   include/asm-generic/bug.h:100:3: note: expanded from macro '__WARN_printf'
                   __WARN_FLAGS(BUGFLAG_NO_CUT_HERE | BUGFLAG_TAINT(taint));\
                   ^
   arch/x86/include/asm/bug.h:76:33: note: expanded from macro '__WARN_FLAGS'
   #define __WARN_FLAGS(flags)                                     \
                                                                   ^
   lib/math/reciprocal_div.c:47:2: note: Loop condition is false.  Exiting loop
           WARN(l == 32,
           ^
   include/asm-generic/bug.h:132:3: note: expanded from macro 'WARN'
                   __WARN_printf(TAINT_WARN, format);                      \
                   ^
   include/asm-generic/bug.h:101:3: note: expanded from macro '__WARN_printf'
                   instrumentation_end();                                  \
                   ^
   include/linux/instrumentation.h:58:33: note: expanded from macro 'instrumentation_end'
   # define instrumentation_end()          do { } while(0)
                                           ^
   lib/math/reciprocal_div.c:47:2: note: Loop condition is false.  Exiting loop
           WARN(l == 32,
           ^
   include/asm-generic/bug.h:132:3: note: expanded from macro 'WARN'
                   __WARN_printf(TAINT_WARN, format);                      \
                   ^
   include/asm-generic/bug.h:97:38: note: expanded from macro '__WARN_printf'
   #define __WARN_printf(taint, arg...) do {                               \
                                        ^
   lib/math/reciprocal_div.c:51:14: note: The result of the left shift is undefined due to shifting by '64', which is greater or equal to the width of type 'unsigned long long'
           mlow = 1ULL << (32 + l);
                       ^  ~~~~~~~~
   6 warnings generated.
   Suppressed 6 warnings (6 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   12 warnings generated.
>> include/linux/fortify-string.h:393:9: warning: Null pointer passed as 2nd argument to memory comparison function [clang-analyzer-unix.cstring.NullArg]
           return __underlying_memcmp(p, q, size);
                  ^
   include/linux/fortify-string.h:42:29: note: expanded from macro '__underlying_memcmp'
   #define __underlying_memcmp     __builtin_memcmp
                                   ^
   security/keys/keyring.c:678:2: note: Taking false branch
           kenter("{%d},{%s,%s}",
           ^
   security/keys/internal.h:34:2: note: expanded from macro 'kenter'
           no_printk(KERN_DEBUG "==> %s("FMT")\n", __func__, ##__VA_ARGS__)
           ^
   include/linux/printk.h:131:2: note: expanded from macro 'no_printk'
           if (0)                                          \
           ^
   security/keys/keyring.c:684:9: note: Assuming the condition is false
           BUG_ON((ctx->flags & STATE_CHECKS) == 0 ||
                  ^
   include/asm-generic/bug.h:65:45: note: expanded from macro 'BUG_ON'
   #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
                                      ~~~~~~~~~^~~~~~~~~~
   include/linux/compiler.h:78:42: note: expanded from macro 'unlikely'
   # define unlikely(x)    __builtin_expect(!!(x), 0)
                                               ^
   security/keys/keyring.c:684:9: note: Left side of '||' is false
           BUG_ON((ctx->flags & STATE_CHECKS) == 0 ||
                  ^
   security/keys/keyring.c:685:9: note: Assuming the condition is false
                  (ctx->flags & STATE_CHECKS) == STATE_CHECKS);
                  ^
   include/asm-generic/bug.h:65:45: note: expanded from macro 'BUG_ON'
   #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
                                      ~~~~~~~~~^~~~~~~~~~
   include/linux/compiler.h:78:42: note: expanded from macro 'unlikely'
   # define unlikely(x)    __builtin_expect(!!(x), 0)
                                               ^
   security/keys/keyring.c:684:2: note: Taking false branch
           BUG_ON((ctx->flags & STATE_CHECKS) == 0 ||
           ^
   include/asm-generic/bug.h:65:32: note: expanded from macro 'BUG_ON'
   #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
                                  ^
   security/keys/keyring.c:684:2: note: Loop condition is false.  Exiting loop
           BUG_ON((ctx->flags & STATE_CHECKS) == 0 ||
           ^
   include/asm-generic/bug.h:65:27: note: expanded from macro 'BUG_ON'
   #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
                             ^
   security/keys/keyring.c:687:6: note: Assuming field 'description' is null
           if (ctx->index_key.description)
               ^~~~~~~~~~~~~~~~~~~~~~~~~~
   security/keys/keyring.c:687:2: note: Taking false branch
           if (ctx->index_key.description)
           ^
   security/keys/keyring.c:693:6: note: Assuming field 'lookup_type' is not equal to KEYRING_SEARCH_LOOKUP_ITERATE
           if (ctx->match_data.lookup_type == KEYRING_SEARCH_LOOKUP_ITERATE ||
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   security/keys/keyring.c:693:6: note: Left side of '||' is false
   security/keys/keyring.c:694:6: note: Calling 'keyring_compare_object'
               keyring_compare_object(keyring, &ctx->index_key)) {
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   security/keys/keyring.c:314:9: note: Assuming 'key->index_key.type' is equal to 'index_key->type'
           return key->index_key.type == index_key->type &&
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   security/keys/keyring.c:314:9: note: Left side of '&&' is true
   security/keys/keyring.c:315:3: note: Assuming 'key->index_key.domain_tag' is equal to 'index_key->domain_tag'
                   key->index_key.domain_tag == index_key->domain_tag &&
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   security/keys/keyring.c:314:9: note: Left side of '&&' is true
           return key->index_key.type == index_key->type &&
                  ^
   security/keys/keyring.c:316:3: note: Assuming 'key->index_key.desc_len' is equal to 'index_key->desc_len'
                   key->index_key.desc_len == index_key->desc_len &&
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   security/keys/keyring.c:314:9: note: Left side of '&&' is true
           return key->index_key.type == index_key->type &&
                  ^
   security/keys/keyring.c:317:38: note: Passing null pointer value via 2nd parameter 'q'
                   memcmp(key->index_key.description, index_key->description,
                                                      ^
   include/linux/fortify-string.h:379:45: note: expanded from macro 'memcmp'
   #define memcmp(p, q, s) __fortify_memcmp(p, q, s)
                                               ^
   security/keys/keyring.c:317:3: note: Calling '__fortify_memcmp'
                   memcmp(key->index_key.description, index_key->description,
                   ^
   include/linux/fortify-string.h:379:25: note: expanded from macro 'memcmp'
   #define memcmp(p, q, s) __fortify_memcmp(p, q, s)
                           ^~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/fortify-string.h:385:2: note: Taking false branch
           if (__builtin_constant_p(size)) {
           ^
   include/linux/fortify-string.h:391:6: note: Assuming 'p_size' is >= 'size'
           if (p_size < size || q_size < size)
               ^~~~~~~~~~~~~
   include/linux/fortify-string.h:391:6: note: Left side of '||' is false
   include/linux/fortify-string.h:391:23: note: Assuming 'q_size' is >= 'size'
           if (p_size < size || q_size < size)
                                ^~~~~~~~~~~~~
   include/linux/fortify-string.h:391:2: note: Taking false branch
           if (p_size < size || q_size < size)

vim +393 include/linux/fortify-string.h

a28a6e860c6cf2 Francis Laniel 2021-02-25  378  
e5d600e1abbdd2 Kees Cook      2021-12-13  379  #define memcmp(p, q, s) __fortify_memcmp(p, q, s)
e5d600e1abbdd2 Kees Cook      2021-12-13  380  __FORTIFY_INLINE int __fortify_memcmp(const void *p, const void *q, __kernel_size_t size)
a28a6e860c6cf2 Francis Laniel 2021-02-25  381  {
a28a6e860c6cf2 Francis Laniel 2021-02-25  382  	size_t p_size = __builtin_object_size(p, 0);
a28a6e860c6cf2 Francis Laniel 2021-02-25  383  	size_t q_size = __builtin_object_size(q, 0);
a28a6e860c6cf2 Francis Laniel 2021-02-25  384  
a28a6e860c6cf2 Francis Laniel 2021-02-25  385  	if (__builtin_constant_p(size)) {
a28a6e860c6cf2 Francis Laniel 2021-02-25  386  		if (p_size < size)
a28a6e860c6cf2 Francis Laniel 2021-02-25  387  			__read_overflow();
a28a6e860c6cf2 Francis Laniel 2021-02-25  388  		if (q_size < size)
a28a6e860c6cf2 Francis Laniel 2021-02-25  389  			__read_overflow2();
a28a6e860c6cf2 Francis Laniel 2021-02-25  390  	}
a28a6e860c6cf2 Francis Laniel 2021-02-25  391  	if (p_size < size || q_size < size)
a28a6e860c6cf2 Francis Laniel 2021-02-25  392  		fortify_panic(__func__);
a28a6e860c6cf2 Francis Laniel 2021-02-25 @393  	return __underlying_memcmp(p, q, size);
a28a6e860c6cf2 Francis Laniel 2021-02-25  394  }
a28a6e860c6cf2 Francis Laniel 2021-02-25  395  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

^ permalink raw reply	[flat|nested] 47+ messages in thread
* Re: [PATCH 17/17] fortify: Work around Clang inlining bugs
@ 2021-12-15  3:25 kernel test robot
  0 siblings, 0 replies; 47+ messages in thread
From: kernel test robot @ 2021-12-15  3:25 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 15642 bytes --]

CC: llvm(a)lists.linux.dev
CC: kbuild-all(a)lists.01.org
In-Reply-To: <20211213223331.135412-18-keescook@chromium.org>
References: <20211213223331.135412-18-keescook@chromium.org>
TO: Kees Cook <keescook@chromium.org>

Hi Kees,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.16-rc5 next-20211213]
[cannot apply to rdma/for-next axboe-block/for-next kvm/queue tip/x86/core mkp-scsi/for-next jejb-scsi/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Kees-Cook/Enable-strict-compile-time-memcpy-fortify-checks/20211214-064002
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git aa50faff4416c869b52dff68a937c84d29e12f4b
:::::: branch date: 29 hours ago
:::::: commit date: 29 hours ago
config: i386-randconfig-c001-20211213 (https://download.01.org/0day-ci/archive/20211215/202112151107.GkUtvCuq-lkp(a)intel.com/config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project b6a2ddb6c8ac29412b1361810972e15221fa021c)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/e5d600e1abbdd2034dbc844654957a4ec1182dbf
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Kees-Cook/Enable-strict-compile-time-memcpy-fortify-checks/20211214-064002
        git checkout e5d600e1abbdd2034dbc844654957a4ec1182dbf
        # save the config file to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=i386 clang-analyzer 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


clang-analyzer warnings: (new ones prefixed by >>)
   # define unlikely(x)    __builtin_expect(!!(x), 0)
                                               ^
   include/linux/hid.h:1010:15: note: Left side of '||' is false
           if (unlikely(c > limit || !bmap)) {
                        ^
   include/linux/hid.h:1010:28: note: Assuming 'bmap' is null
           if (unlikely(c > limit || !bmap)) {
                                     ^
   include/linux/compiler.h:78:42: note: expanded from macro 'unlikely'
   # define unlikely(x)    __builtin_expect(!!(x), 0)
                                               ^
   include/linux/hid.h:1010:2: note: Taking true branch
           if (unlikely(c > limit || !bmap)) {
           ^
   include/linux/hid.h:1011:3: note: Assuming the condition is true
                   pr_warn_ratelimited("%s: Invalid code %d type %d\n",
                   ^
   include/linux/printk.h:660:2: note: expanded from macro 'pr_warn_ratelimited'
           printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/printk.h:643:6: note: expanded from macro 'printk_ratelimited'
           if (__ratelimit(&_rs))                                          \
               ^~~~~~~~~~~~~~~~~
   include/linux/ratelimit_types.h:41:28: note: expanded from macro '__ratelimit'
   #define __ratelimit(state) ___ratelimit(state, __func__)
                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/hid.h:1011:3: note: Taking true branch
                   pr_warn_ratelimited("%s: Invalid code %d type %d\n",
                   ^
   include/linux/printk.h:660:2: note: expanded from macro 'pr_warn_ratelimited'
           printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
           ^
   include/linux/printk.h:643:2: note: expanded from macro 'printk_ratelimited'
           if (__ratelimit(&_rs))                                          \
           ^
   include/linux/hid.h:1011:3: note: Loop condition is false.  Exiting loop
                   pr_warn_ratelimited("%s: Invalid code %d type %d\n",
                   ^
   include/linux/printk.h:660:2: note: expanded from macro 'pr_warn_ratelimited'
           printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
           ^
   include/linux/printk.h:644:3: note: expanded from macro 'printk_ratelimited'
                   printk(fmt, ##__VA_ARGS__);                             \
                   ^
   include/linux/printk.h:450:26: note: expanded from macro 'printk'
   #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)
                            ^
   include/linux/printk.h:421:3: note: expanded from macro 'printk_index_wrap'
                   __printk_index_emit(_fmt, NULL, NULL);                  \
                   ^
   include/linux/printk.h:396:34: note: expanded from macro '__printk_index_emit'
   #define __printk_index_emit(...) do {} while (0)
                                    ^
   include/linux/hid.h:1012:9: note: Access to field 'name' results in a dereference of a null pointer (loaded from variable 'input')
                                       input->name, c, type);
                                       ^
   include/linux/printk.h:660:49: note: expanded from macro 'pr_warn_ratelimited'
           printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
                                                          ^~~~~~~~~~~
   include/linux/printk.h:644:17: note: expanded from macro 'printk_ratelimited'
                   printk(fmt, ##__VA_ARGS__);                             \
                                 ^~~~~~~~~~~
   include/linux/printk.h:450:60: note: expanded from macro 'printk'
   #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)
                                                              ^~~~~~~~~~~
   include/linux/printk.h:422:19: note: expanded from macro 'printk_index_wrap'
                   _p_func(_fmt, ##__VA_ARGS__);                           \
                                   ^~~~~~~~~~~
   Suppressed 3 warnings (3 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   4 warnings generated.
   drivers/gpu/drm/gma500/cdv_intel_display.c:752:2: warning: Value stored to 'dpll' is never read [clang-analyzer-deadcode.DeadStores]
           dpll |= DPLL_VCO_ENABLE;
           ^
   drivers/gpu/drm/gma500/cdv_intel_display.c:752:2: note: Value stored to 'dpll' is never read
   Suppressed 3 warnings (3 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   8 warnings generated.
   drivers/gpu/drm/gma500/cdv_intel_dp.c:965:2: warning: Value stored to 'm' is never read [clang-analyzer-deadcode.DeadStores]
           m = do_div(value, *den);
           ^
   drivers/gpu/drm/gma500/cdv_intel_dp.c:965:2: note: Value stored to 'm' is never read
   drivers/gpu/drm/gma500/cdv_intel_dp.c:1405:21: warning: Value stored to 'dev' during its initialization is never read [clang-analyzer-deadcode.DeadStores]
           struct drm_device *dev = encoder->base.dev;
                              ^~~   ~~~~~~~~~~~~~~~~~
   drivers/gpu/drm/gma500/cdv_intel_dp.c:1405:21: note: Value stored to 'dev' during its initialization is never read
           struct drm_device *dev = encoder->base.dev;
                              ^~~   ~~~~~~~~~~~~~~~~~
   drivers/gpu/drm/gma500/cdv_intel_dp.c:1411:3: warning: Value stored to 'ddi_reg' is never read [clang-analyzer-deadcode.DeadStores]
                   ddi_reg = &ddi_DP_train_table[0];
                   ^         ~~~~~~~~~~~~~~~~~~~~~~
   drivers/gpu/drm/gma500/cdv_intel_dp.c:1411:3: note: Value stored to 'ddi_reg' is never read
                   ddi_reg = &ddi_DP_train_table[0];
                   ^         ~~~~~~~~~~~~~~~~~~~~~~
   drivers/gpu/drm/gma500/cdv_intel_dp.c:1413:3: warning: Value stored to 'ddi_reg' is never read [clang-analyzer-deadcode.DeadStores]
                   ddi_reg = &ddi_DP_train_table[1];
                   ^         ~~~~~~~~~~~~~~~~~~~~~~
   drivers/gpu/drm/gma500/cdv_intel_dp.c:1413:3: note: Value stored to 'ddi_reg' is never read
                   ddi_reg = &ddi_DP_train_table[1];
                   ^         ~~~~~~~~~~~~~~~~~~~~~~
>> include/linux/fortify-string.h:61:9: warning: Null pointer passed as 2nd argument to string copy function [clang-analyzer-unix.cstring.NullArg]
           return __underlying_strncpy(p, q, size);
                  ^
   include/linux/fortify-string.h:50:30: note: expanded from macro '__underlying_strncpy'
   #define __underlying_strncpy    __builtin_strncpy
                                   ^
   drivers/gpu/drm/gma500/cdv_intel_dp.c:1958:2: note: 'name' initialized to a null pointer value
           const char *name = NULL;
           ^~~~~~~~~~~~~~~~
   drivers/gpu/drm/gma500/cdv_intel_dp.c:1961:16: note: Calling 'kzalloc'
           gma_encoder = kzalloc(sizeof(struct gma_encoder), GFP_KERNEL);
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/slab.h:724:9: note: Calling 'kmalloc'
           return kmalloc(size, flags | __GFP_ZERO);
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/slab.h:578:2: note: Taking false branch
           if (__builtin_constant_p(size)) {
           ^
   include/linux/slab.h:595:2: note: Returning pointer, which participates in a condition later
           return __kmalloc(size, flags);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/slab.h:724:9: note: Returning from 'kmalloc'
           return kmalloc(size, flags | __GFP_ZERO);
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/slab.h:724:2: note: Returning pointer, which participates in a condition later
           return kmalloc(size, flags | __GFP_ZERO);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/gpu/drm/gma500/cdv_intel_dp.c:1961:16: note: Returning from 'kzalloc'
           gma_encoder = kzalloc(sizeof(struct gma_encoder), GFP_KERNEL);
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/gpu/drm/gma500/cdv_intel_dp.c:1962:6: note: Assuming 'gma_encoder' is non-null
           if (!gma_encoder)
               ^~~~~~~~~~~~
   drivers/gpu/drm/gma500/cdv_intel_dp.c:1962:2: note: Taking false branch
           if (!gma_encoder)
           ^
   drivers/gpu/drm/gma500/cdv_intel_dp.c:1964:25: note: Calling 'kzalloc'
           gma_connector = kzalloc(sizeof(struct gma_connector), GFP_KERNEL);
                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/slab.h:724:9: note: Calling 'kmalloc'
           return kmalloc(size, flags | __GFP_ZERO);
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/slab.h:578:2: note: Taking false branch
           if (__builtin_constant_p(size)) {
           ^
   include/linux/slab.h:595:2: note: Returning pointer, which participates in a condition later
           return __kmalloc(size, flags);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/slab.h:724:9: note: Returning from 'kmalloc'
           return kmalloc(size, flags | __GFP_ZERO);
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/slab.h:724:2: note: Returning pointer, which participates in a condition later
           return kmalloc(size, flags | __GFP_ZERO);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/gpu/drm/gma500/cdv_intel_dp.c:1964:25: note: Returning from 'kzalloc'
           gma_connector = kzalloc(sizeof(struct gma_connector), GFP_KERNEL);
                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/gpu/drm/gma500/cdv_intel_dp.c:1965:13: note: Assuming 'gma_connector' is non-null
           if (!gma_connector)
               ^~~~~~~~~~~~~~
   drivers/gpu/drm/gma500/cdv_intel_dp.c:1965:9: note: Taking false branch
           if (!gma_connector)
           ^
   drivers/gpu/drm/gma500/cdv_intel_dp.c:1967:13: note: Calling 'kzalloc'
           intel_dp = kzalloc(sizeof(struct cdv_intel_dp), GFP_KERNEL);
                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/slab.h:724:9: note: Calling 'kmalloc'
           return kmalloc(size, flags | __GFP_ZERO);
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/slab.h:578:2: note: Taking false branch
           if (__builtin_constant_p(size)) {
           ^
   include/linux/slab.h:595:2: note: Returning pointer, which participates in a condition later
           return __kmalloc(size, flags);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/slab.h:724:9: note: Returning from 'kmalloc'
           return kmalloc(size, flags | __GFP_ZERO);
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/slab.h:724:2: note: Returning pointer, which participates in a condition later
           return kmalloc(size, flags | __GFP_ZERO);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/gpu/drm/gma500/cdv_intel_dp.c:1967:13: note: Returning from 'kzalloc'
           intel_dp = kzalloc(sizeof(struct cdv_intel_dp), GFP_KERNEL);
                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/gpu/drm/gma500/cdv_intel_dp.c:1968:6: note: Assuming 'intel_dp' is non-null
           if (!intel_dp)
               ^~~~~~~~~
   drivers/gpu/drm/gma500/cdv_intel_dp.c:1968:2: note: Taking false branch
           if (!intel_dp)
           ^
   drivers/gpu/drm/gma500/cdv_intel_dp.c:1971:7: note: Assuming 'output_reg' is not equal to DP_C
           if ((output_reg == DP_C) && cdv_intel_dpc_is_edp(dev))
                ^~~~~~~~~~~~~~~~~~
   drivers/gpu/drm/gma500/cdv_intel_dp.c:1971:27: note: Left side of '&&' is false
           if ((output_reg == DP_C) && cdv_intel_dpc_is_edp(dev))
                                    ^
   drivers/gpu/drm/gma500/cdv_intel_dp.c:1982:6: note: 'type' is equal to DRM_MODE_CONNECTOR_DisplayPort
           if (type == DRM_MODE_CONNECTOR_DisplayPort)
               ^~~~
   drivers/gpu/drm/gma500/cdv_intel_dp.c:1982:2: note: Taking true branch
           if (type == DRM_MODE_CONNECTOR_DisplayPort)

vim +61 include/linux/fortify-string.h

a28a6e860c6cf23 Francis Laniel 2021-02-25  52  
e5d600e1abbdd20 Kees Cook      2021-12-13  53  #define strncpy(p, q, s) __fortify_strncpy(p, q, s, __builtin_object_size(p, 1))
e5d600e1abbdd20 Kees Cook      2021-12-13  54  __FORTIFY_INLINE char *__fortify_strncpy(char *p, const char *q,
e5d600e1abbdd20 Kees Cook      2021-12-13  55  					 __kernel_size_t size, size_t p_size)
a28a6e860c6cf23 Francis Laniel 2021-02-25  56  {
a28a6e860c6cf23 Francis Laniel 2021-02-25  57  	if (__builtin_constant_p(size) && p_size < size)
a28a6e860c6cf23 Francis Laniel 2021-02-25  58  		__write_overflow();
a28a6e860c6cf23 Francis Laniel 2021-02-25  59  	if (p_size < size)
a28a6e860c6cf23 Francis Laniel 2021-02-25  60  		fortify_panic(__func__);
a28a6e860c6cf23 Francis Laniel 2021-02-25 @61  	return __underlying_strncpy(p, q, size);
a28a6e860c6cf23 Francis Laniel 2021-02-25  62  }
a28a6e860c6cf23 Francis Laniel 2021-02-25  63  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

^ permalink raw reply	[flat|nested] 47+ messages in thread
* Re: [PATCH 17/17] fortify: Work around Clang inlining bugs
@ 2021-12-16 15:37 kernel test robot
  0 siblings, 0 replies; 47+ messages in thread
From: kernel test robot @ 2021-12-16 15:37 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 18196 bytes --]

CC: llvm(a)lists.linux.dev
CC: kbuild-all(a)lists.01.org
In-Reply-To: <20211213223331.135412-18-keescook@chromium.org>
References: <20211213223331.135412-18-keescook@chromium.org>
TO: Kees Cook <keescook@chromium.org>

Hi Kees,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.16-rc5]
[cannot apply to rdma/for-next axboe-block/for-next kvm/queue tip/x86/core mkp-scsi/for-next jejb-scsi/for-next next-20211215]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Kees-Cook/Enable-strict-compile-time-memcpy-fortify-checks/20211214-064002
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git aa50faff4416c869b52dff68a937c84d29e12f4b
:::::: branch date: 3 days ago
:::::: commit date: 3 days ago
config: x86_64-randconfig-c007-20211215 (https://download.01.org/0day-ci/archive/20211216/202112162317.HYiDRObX-lkp(a)intel.com/config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project dd245bab9fbb364faa1581e4f92ba3119a872fba)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/e5d600e1abbdd2034dbc844654957a4ec1182dbf
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Kees-Cook/Enable-strict-compile-time-memcpy-fortify-checks/20211214-064002
        git checkout e5d600e1abbdd2034dbc844654957a4ec1182dbf
        # save the config file to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 clang-analyzer 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


clang-analyzer warnings: (new ones prefixed by >>)
               ^
   fs/jfs/jfs_logmgr.c:892:8: note: Assuming field 'gcrtc' is > 0
               ((log->gcrtc > 0) || (tblk->bp->l_wqnext != NULL) ||
                 ^~~~~~~~~~~~~~
   fs/jfs/jfs_logmgr.c:892:24: note: Left side of '||' is true
               ((log->gcrtc > 0) || (tblk->bp->l_wqnext != NULL) ||
                                 ^
   fs/jfs/jfs_logmgr.c:897:3: note: Calling 'lmGCwrite'
                   lmGCwrite(log, 1);
                   ^~~~~~~~~~~~~~~~~
   fs/jfs/jfs_logmgr.c:751:2: note: 'xtblk' initialized to a null pointer value
           struct tblock *xtblk = NULL;
           ^~~~~~~~~~~~~~~~~~~~
   fs/jfs/jfs_logmgr.c:762:2: note: Loop condition is false. Execution continues on line 771
           list_for_each_entry(tblk, &log->cqueue, cqueue) {
           ^
   include/linux/list.h:630:2: note: expanded from macro 'list_for_each_entry'
           for (pos = list_first_entry(head, typeof(*pos), member);        \
           ^
   fs/jfs/jfs_logmgr.c:771:2: note: Null pointer value stored to 'tblk'
           tblk = xtblk;           /* last tblk of the page */
           ^~~~~~~~~~~~
   fs/jfs/jfs_logmgr.c:776:23: note: Access to field 'bp' results in a dereference of a null pointer (loaded from variable 'tblk')
           bp = (struct lbuf *) tblk->bp;
                                ^~~~
   fs/jfs/jfs_logmgr.c:1346:3: warning: Value stored to 'lp' is never read [clang-analyzer-deadcode.DeadStores]
                   lp = (struct logpage *) bp->l_ldata;
                   ^    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   fs/jfs/jfs_logmgr.c:1346:3: note: Value stored to 'lp' is never read
                   lp = (struct logpage *) bp->l_ldata;
                   ^    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   Suppressed 5 warnings (5 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   4 warnings generated.
   Suppressed 4 warnings (4 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   5 warnings generated.
   Suppressed 5 warnings (5 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   5 warnings generated.
   Suppressed 5 warnings (5 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   5 warnings generated.
   Suppressed 5 warnings (5 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   5 warnings generated.
   Suppressed 5 warnings (5 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   4 warnings generated.
   Suppressed 4 warnings (4 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   3 warnings generated.
   Suppressed 3 warnings (3 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   4 warnings generated.
   Suppressed 4 warnings (4 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   4 warnings generated.
   Suppressed 4 warnings (4 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   4 warnings generated.
   Suppressed 4 warnings (4 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   4 warnings generated.
   Suppressed 4 warnings (4 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   4 warnings generated.
   Suppressed 4 warnings (4 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   4 warnings generated.
   Suppressed 4 warnings (4 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   4 warnings generated.
   Suppressed 4 warnings (4 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   4 warnings generated.
   Suppressed 4 warnings (4 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   4 warnings generated.
   Suppressed 4 warnings (4 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   5 warnings generated.
   Suppressed 5 warnings (5 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   4 warnings generated.
   Suppressed 4 warnings (4 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   4 warnings generated.
   Suppressed 4 warnings (4 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   4 warnings generated.
   Suppressed 4 warnings (4 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   11 warnings generated.
   fs/dlm/config.c:723:4: warning: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
                           strcat(buf, buf0);
                           ^~~~~~
   fs/dlm/config.c:723:4: note: Call to function 'strcat' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcat'. CWE-119
                           strcat(buf, buf0);
                           ^~~~~~
>> include/linux/fortify-string.h:137:3: warning: Null pointer passed as 1st argument to memory copy function [clang-analyzer-unix.cstring.NullArg]
                   __underlying_memcpy(p, q, len);
                   ^
   include/linux/fortify-string.h:43:29: note: expanded from macro '__underlying_memcpy'
   #define __underlying_memcpy     __builtin_memcpy
                                   ^
   fs/dlm/config.c:125:10: note: Passing null pointer value via 1st parameter 'p'
           strlcpy(cl->cl_cluster_name, buf, sizeof(cl->cl_cluster_name));
                   ^
   include/linux/fortify-string.h:114:44: note: expanded from macro 'strlcpy'
   #define strlcpy(p, q, s) __fortify_strlcpy(p, q, s,                     \
                                              ^
   fs/dlm/config.c:125:2: note: Calling '__fortify_strlcpy'
           strlcpy(cl->cl_cluster_name, buf, sizeof(cl->cl_cluster_name));
           ^
   include/linux/fortify-string.h:114:26: note: expanded from macro 'strlcpy'
   #define strlcpy(p, q, s) __fortify_strlcpy(p, q, s,                     \
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/fortify-string.h:125:27: note: Left side of '&&' is false
           if (p_size == (size_t)-1 && q_size == (size_t)-1)
                                    ^
   include/linux/fortify-string.h:128:9: note: 'q_len' is >= 'size'
           len = (q_len >= size) ? size - 1 : q_len;
                  ^~~~~
   include/linux/fortify-string.h:128:8: note: '?' condition is true
           len = (q_len >= size) ? size - 1 : q_len;
                 ^
   include/linux/fortify-string.h:129:33: note: Left side of '&&' is false
           if (__builtin_constant_p(size) && __builtin_constant_p(q_len) && size) {
                                          ^
   include/linux/fortify-string.h:134:6: note: 'size' is 64
           if (size) {
               ^~~~
   include/linux/fortify-string.h:134:2: note: Taking true branch
           if (size) {
           ^
   include/linux/fortify-string.h:135:7: note: 'len' is < 'p_size'
                   if (len >= p_size)
                       ^~~
   include/linux/fortify-string.h:135:3: note: Taking false branch
                   if (len >= p_size)
                   ^
   include/linux/fortify-string.h:137:3: note: Null pointer passed as 1st argument to memory copy function
                   __underlying_memcpy(p, q, len);
                   ^                   ~
   include/linux/fortify-string.h:43:29: note: expanded from macro '__underlying_memcpy'
   #define __underlying_memcpy     __builtin_memcpy
                                   ^
   Suppressed 9 warnings (9 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   5 warnings generated.
   Suppressed 5 warnings (5 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   5 warnings generated.
   Suppressed 5 warnings (4 in non-user code, 1 with check filters).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   6 warnings generated.
   Suppressed 6 warnings (6 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   6 warnings generated.
   Suppressed 6 warnings (6 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   6 warnings generated.
   Suppressed 6 warnings (6 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   6 warnings generated.
   Suppressed 6 warnings (6 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   7 warnings generated.
   Suppressed 7 warnings (6 in non-user code, 1 with check filters).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   6 warnings generated.
   Suppressed 6 warnings (6 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   6 warnings generated.
   Suppressed 6 warnings (6 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   6 warnings generated.
   Suppressed 6 warnings (6 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   5 warnings generated.
   Suppressed 5 warnings (5 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   4 warnings generated.
   Suppressed 4 warnings (4 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   4 warnings generated.
   Suppressed 4 warnings (4 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   5 warnings generated.
   Suppressed 5 warnings (5 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   6 warnings generated.
   fs/ntfs/inode.c:1840:3: warning: Value stored to 'err' is never read [clang-analyzer-deadcode.DeadStores]
                   err = -ENOMEM;
                   ^     ~~~~~~~
   fs/ntfs/inode.c:1840:3: note: Value stored to 'err' is never read
                   err = -ENOMEM;
                   ^     ~~~~~~~
   Suppressed 5 warnings (5 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.

vim +137 include/linux/fortify-string.h

a28a6e860c6cf2 Francis Laniel 2021-02-25  111  
a28a6e860c6cf2 Francis Laniel 2021-02-25  112  /* defined after fortified strlen to reuse it */
a28a6e860c6cf2 Francis Laniel 2021-02-25  113  extern size_t __real_strlcpy(char *, const char *, size_t) __RENAME(strlcpy);
e5d600e1abbdd2 Kees Cook      2021-12-13  114  #define strlcpy(p, q, s) __fortify_strlcpy(p, q, s,			\
e5d600e1abbdd2 Kees Cook      2021-12-13  115  					   __builtin_object_size(p, 1),	\
e5d600e1abbdd2 Kees Cook      2021-12-13  116  					   __builtin_object_size(q, 1))
e5d600e1abbdd2 Kees Cook      2021-12-13  117  __FORTIFY_INLINE size_t __fortify_strlcpy(char *p, const char *q,
e5d600e1abbdd2 Kees Cook      2021-12-13  118  					  size_t size,
e5d600e1abbdd2 Kees Cook      2021-12-13  119  					  const size_t p_size,
e5d600e1abbdd2 Kees Cook      2021-12-13  120  					  const size_t q_size)
a28a6e860c6cf2 Francis Laniel 2021-02-25  121  {
3009f891bb9f32 Kees Cook      2021-08-02  122  	size_t q_len;	/* Full count of source string length. */
3009f891bb9f32 Kees Cook      2021-08-02  123  	size_t len;	/* Count of characters going into destination. */
a28a6e860c6cf2 Francis Laniel 2021-02-25  124  
a28a6e860c6cf2 Francis Laniel 2021-02-25  125  	if (p_size == (size_t)-1 && q_size == (size_t)-1)
a28a6e860c6cf2 Francis Laniel 2021-02-25  126  		return __real_strlcpy(p, q, size);
3009f891bb9f32 Kees Cook      2021-08-02  127  	q_len = strlen(q);
3009f891bb9f32 Kees Cook      2021-08-02  128  	len = (q_len >= size) ? size - 1 : q_len;
3009f891bb9f32 Kees Cook      2021-08-02  129  	if (__builtin_constant_p(size) && __builtin_constant_p(q_len) && size) {
3009f891bb9f32 Kees Cook      2021-08-02  130  		/* Write size is always larger than destination. */
3009f891bb9f32 Kees Cook      2021-08-02  131  		if (len >= p_size)
a28a6e860c6cf2 Francis Laniel 2021-02-25  132  			__write_overflow();
3009f891bb9f32 Kees Cook      2021-08-02  133  	}
3009f891bb9f32 Kees Cook      2021-08-02  134  	if (size) {
a28a6e860c6cf2 Francis Laniel 2021-02-25  135  		if (len >= p_size)
a28a6e860c6cf2 Francis Laniel 2021-02-25  136  			fortify_panic(__func__);
a28a6e860c6cf2 Francis Laniel 2021-02-25 @137  		__underlying_memcpy(p, q, len);
a28a6e860c6cf2 Francis Laniel 2021-02-25  138  		p[len] = '\0';
a28a6e860c6cf2 Francis Laniel 2021-02-25  139  	}
3009f891bb9f32 Kees Cook      2021-08-02  140  	return q_len;
a28a6e860c6cf2 Francis Laniel 2021-02-25  141  }
a28a6e860c6cf2 Francis Laniel 2021-02-25  142  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

^ permalink raw reply	[flat|nested] 47+ messages in thread

end of thread, other threads:[~2021-12-17 13:34 UTC | newest]

Thread overview: 47+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-13 22:33 [PATCH 00/17] Enable strict compile-time memcpy() fortify checks Kees Cook
2021-12-13 22:33 ` [PATCH 01/17] KVM: x86: Replace memset() "optimization" with normal per-field writes Kees Cook
2021-12-13 22:33 ` [PATCH 02/17] net/mlx5e: Avoid field-overflowing memcpy() Kees Cook
2021-12-13 22:33 ` [PATCH 03/17] net/mlx5e: Use struct_group() for memcpy() region Kees Cook
2021-12-13 22:33 ` [PATCH 04/17] media: omap3isp: " Kees Cook
2021-12-13 22:33 ` [PATCH 05/17] sata_fsl: " Kees Cook
2021-12-13 22:33 ` [PATCH 06/17] fortify: Detect struct member overflows in memcpy() at compile-time Kees Cook
2021-12-14  3:56   ` kernel test robot
2021-12-14  8:46   ` kernel test robot
2021-12-14 11:50   ` kernel test robot
2021-12-14 16:32   ` kernel test robot
2021-12-14 19:06   ` kernel test robot
2021-12-16  8:56   ` kernel test robot
2021-12-16 11:08   ` Mark Rutland
2021-12-16 11:21     ` Mark Rutland
2021-12-16 18:00     ` Kees Cook
2021-12-17 13:34       ` Mark Rutland
2021-12-13 22:33 ` [PATCH 07/17] fortify: Detect struct member overflows in memmove() " Kees Cook
2021-12-13 22:33 ` [PATCH 08/17] ath11k: Use memset_startat() for clearing queue descriptors Kees Cook
2021-12-13 22:33   ` Kees Cook
2021-12-14  6:02   ` Kalle Valo
2021-12-14  6:02     ` Kalle Valo
2021-12-14 15:46     ` Kalle Valo
2021-12-14 15:46       ` Kalle Valo
2021-12-14 17:05       ` Kees Cook
2021-12-14 17:05         ` Kees Cook
2021-12-16 13:50         ` Kalle Valo
2021-12-16 13:50           ` Kalle Valo
2021-12-13 22:33 ` [PATCH 09/17] RDMA/mlx5: Use memset_after() to zero struct mlx5_ib_mr Kees Cook
2021-12-13 22:33 ` [PATCH 10/17] drbd: Use struct_group() to zero algs Kees Cook
2021-12-13 22:33   ` [Drbd-dev] " Kees Cook
2021-12-13 22:33 ` [dm-devel] [PATCH 11/17] dm integrity: Use struct_group() to zero struct journal_sector Kees Cook
2021-12-13 22:33   ` Kees Cook
2021-12-13 22:33 ` [PATCH 12/17] iw_cxgb4: Use memset_startat() for cpl_t5_pass_accept_rpl Kees Cook
2021-12-13 22:33 ` [PATCH 13/17] intel_th: msu: Use memset_startat() for clearing hw header Kees Cook
2021-12-13 22:33 ` [PATCH 14/17] IB/mthca: Use memset_startat() for clearing mpt_entry Kees Cook
2021-12-13 22:33 ` [PATCH 15/17] scsi: lpfc: Use struct_group() to initialize struct lpfc_cgn_info Kees Cook
2021-12-13 22:33 ` [PATCH 16/17] fortify: Detect struct member overflows in memset() at compile-time Kees Cook
2021-12-14 12:31   ` kernel test robot
2021-12-13 22:33 ` [PATCH 17/17] fortify: Work around Clang inlining bugs Kees Cook
2021-12-14 13:22   ` kernel test robot
2021-12-14 13:22     ` kernel test robot
2021-12-15  0:26 ` [PATCH 00/17] Enable strict compile-time memcpy() fortify checks Jason Gunthorpe
2021-12-17  4:04 ` Martin K. Petersen
  -- strict thread matches above, loose matches on Subject: below --
2021-12-15  3:25 [PATCH 17/17] fortify: Work around Clang inlining bugs kernel test robot
2021-12-15  3:25 kernel test robot
2021-12-16 15:37 kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.