From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F73BC433EF for ; Wed, 23 Feb 2022 23:45:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 039AE8D0002; Wed, 23 Feb 2022 18:45:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F2C048D0001; Wed, 23 Feb 2022 18:45:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DCDA58D0002; Wed, 23 Feb 2022 18:45:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0195.hostedemail.com [216.40.44.195]) by kanga.kvack.org (Postfix) with ESMTP id B8D7C8D0001 for ; Wed, 23 Feb 2022 18:45:47 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 4CD78181C9905 for ; Wed, 23 Feb 2022 23:45:47 +0000 (UTC) X-FDA: 79175679534.17.899BC83 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by imf10.hostedemail.com (Postfix) with ESMTP id 69B1DC0008 for ; Wed, 23 Feb 2022 23:43:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645659835; x=1677195835; h=date:from:to:cc:subject:message-id:mime-version; bh=EP/cxWxSY2BPsDYO/Ne+Bkz6iXl8Och+674LWcxezuU=; b=Shqd3SSeAKKMKnAgcNOaDydLtsrayTg2cfsxrHjzHX5BS5OgB/1eZiDd Zz15x2y/KmjzIvT4dJlUXh/UxiE4U5SN1sVhP89meGlNCxbd+kAlDwCrA 6Iv+2oJ36cPVMlBQskW8GM4G3lE+RaFL0oIHuJlEspUyFQNtjo6F/WTcu 0UcQHhbF0wGP52hJDyyqHl/BjhNeV9iejt2uXCL7n6rfFEZwU77bn3/Ii qnlcqjtNT+DQOFLuF9vMsVVivekVge3QhZyYsHqfZyd8UP8ZE719wt01b D2eKRhcAwFMGJrwxhb+zgtYqvHAt3BP/XHKv7HlPVKpMjcz+zugLkkwD3 Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10267"; a="276731846" X-IronPort-AV: E=Sophos;i="5.88,392,1635231600"; d="scan'208";a="276731846" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2022 15:43:54 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,392,1635231600"; d="scan'208";a="783802826" Received: from lkp-server01.sh.intel.com (HELO 788b1cd46f0d) ([10.239.97.150]) by fmsmga005.fm.intel.com with ESMTP; 23 Feb 2022 15:43:52 -0800 Received: from kbuild by 788b1cd46f0d with local (Exim 4.92) (envelope-from ) id 1nN1IV-0001y1-Tu; Wed, 23 Feb 2022 23:43:51 +0000 Date: Thu, 24 Feb 2022 07:43:17 +0800 From: kernel test robot To: Kees Cook Cc: llvm@lists.linux.dev, kbuild-all@lists.01.org, Linux Memory Management List , Nick Desaulniers Subject: [linux-next:master 4926/7526] include/linux/fortify-string.h:336:4: warning: call to __read_overflow2_field declared with 'warning' attribute: detected read beyond size of field (2nd parameter); maybe use struct_group()? Message-ID: <202202240750.ZC6gMTEp-lkp@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Shqd3SSe; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf10.hostedemail.com: domain of lkp@intel.com has no SPF policy when checking 192.55.52.88) smtp.mailfrom=lkp@intel.com X-Rspam-User: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 69B1DC0008 X-Stat-Signature: 1zq4g1niegitrjhrmgmkgzy94q7hr4tb X-HE-Tag: 1645659835-298145 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: tree: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master head: 196d330d7fb1e7cc0d85641c89ce4602cb36f12e commit: 281d0c962752fb40866dd8d4cade68656f34bd1f [4926/7526] fortify: Add Clang support config: x86_64-randconfig-a001 (https://download.01.org/0day-ci/archive/20220224/202202240750.ZC6gMTEp-lkp@intel.com/config) compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project d271fc04d5b97b12e6b797c6067d3c96a8d7470e) 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://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=281d0c962752fb40866dd8d4cade68656f34bd1f git remote add linux-next https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git git fetch --no-tags linux-next master git checkout 281d0c962752fb40866dd8d4cade68656f34bd1f # save the config file to linux build tree mkdir build_dir COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/spi/ net/core/ If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot All warnings (new ones prefixed by >>): In file included from net/core/flow_dissector.c:3: In file included from include/linux/skbuff.h:15: In file included from include/linux/time.h:60: In file included from include/linux/time32.h:13: In file included from include/linux/timex.h:65: In file included from arch/x86/include/asm/timex.h:5: In file included from arch/x86/include/asm/processor.h:22: In file included from arch/x86/include/asm/msr.h:11: In file included from arch/x86/include/asm/cpumask.h:5: In file included from include/linux/cpumask.h:12: In file included from include/linux/bitmap.h:11: In file included from include/linux/string.h:253: >> include/linux/fortify-string.h:336:4: warning: call to __read_overflow2_field declared with 'warning' attribute: detected read beyond size of field (2nd parameter); maybe use struct_group()? [-Wattribute-warning] __read_overflow2_field(q_size_field, size); ^ 1 warning generated. vim +/warning +336 include/linux/fortify-string.h 28e77cc1c06866 Kees Cook 2021-06-16 267 28e77cc1c06866 Kees Cook 2021-06-16 268 /* 28e77cc1c06866 Kees Cook 2021-06-16 269 * __builtin_object_size() must be captured here to avoid evaluating argument 28e77cc1c06866 Kees Cook 2021-06-16 270 * side-effects further into the macro layers. 28e77cc1c06866 Kees Cook 2021-06-16 271 */ 28e77cc1c06866 Kees Cook 2021-06-16 272 #define memset(p, c, s) __fortify_memset_chk(p, c, s, \ 28e77cc1c06866 Kees Cook 2021-06-16 273 __builtin_object_size(p, 0), __builtin_object_size(p, 1)) a28a6e860c6cf2 Francis Laniel 2021-02-25 274 f68f2ff91512c1 Kees Cook 2021-04-20 275 /* f68f2ff91512c1 Kees Cook 2021-04-20 276 * To make sure the compiler can enforce protection against buffer overflows, f68f2ff91512c1 Kees Cook 2021-04-20 277 * memcpy(), memmove(), and memset() must not be used beyond individual f68f2ff91512c1 Kees Cook 2021-04-20 278 * struct members. If you need to copy across multiple members, please use f68f2ff91512c1 Kees Cook 2021-04-20 279 * struct_group() to create a named mirror of an anonymous struct union. f68f2ff91512c1 Kees Cook 2021-04-20 280 * (e.g. see struct sk_buff.) Read overflow checking is currently only f68f2ff91512c1 Kees Cook 2021-04-20 281 * done when a write overflow is also present, or when building with W=1. f68f2ff91512c1 Kees Cook 2021-04-20 282 * f68f2ff91512c1 Kees Cook 2021-04-20 283 * Mitigation coverage matrix f68f2ff91512c1 Kees Cook 2021-04-20 284 * Bounds checking at: f68f2ff91512c1 Kees Cook 2021-04-20 285 * +-------+-------+-------+-------+ f68f2ff91512c1 Kees Cook 2021-04-20 286 * | Compile time | Run time | f68f2ff91512c1 Kees Cook 2021-04-20 287 * memcpy() argument sizes: | write | read | write | read | f68f2ff91512c1 Kees Cook 2021-04-20 288 * dest source length +-------+-------+-------+-------+ f68f2ff91512c1 Kees Cook 2021-04-20 289 * memcpy(known, known, constant) | y | y | n/a | n/a | f68f2ff91512c1 Kees Cook 2021-04-20 290 * memcpy(known, unknown, constant) | y | n | n/a | V | f68f2ff91512c1 Kees Cook 2021-04-20 291 * memcpy(known, known, dynamic) | n | n | B | B | f68f2ff91512c1 Kees Cook 2021-04-20 292 * memcpy(known, unknown, dynamic) | n | n | B | V | f68f2ff91512c1 Kees Cook 2021-04-20 293 * memcpy(unknown, known, constant) | n | y | V | n/a | f68f2ff91512c1 Kees Cook 2021-04-20 294 * memcpy(unknown, unknown, constant) | n | n | V | V | f68f2ff91512c1 Kees Cook 2021-04-20 295 * memcpy(unknown, known, dynamic) | n | n | V | B | f68f2ff91512c1 Kees Cook 2021-04-20 296 * memcpy(unknown, unknown, dynamic) | n | n | V | V | f68f2ff91512c1 Kees Cook 2021-04-20 297 * +-------+-------+-------+-------+ f68f2ff91512c1 Kees Cook 2021-04-20 298 * f68f2ff91512c1 Kees Cook 2021-04-20 299 * y = perform deterministic compile-time bounds checking f68f2ff91512c1 Kees Cook 2021-04-20 300 * n = cannot perform deterministic compile-time bounds checking f68f2ff91512c1 Kees Cook 2021-04-20 301 * n/a = no run-time bounds checking needed since compile-time deterministic f68f2ff91512c1 Kees Cook 2021-04-20 302 * B = can perform run-time bounds checking (currently unimplemented) f68f2ff91512c1 Kees Cook 2021-04-20 303 * V = vulnerable to run-time overflow (will need refactoring to solve) f68f2ff91512c1 Kees Cook 2021-04-20 304 * f68f2ff91512c1 Kees Cook 2021-04-20 305 */ f68f2ff91512c1 Kees Cook 2021-04-20 306 __FORTIFY_INLINE void fortify_memcpy_chk(__kernel_size_t size, f68f2ff91512c1 Kees Cook 2021-04-20 307 const size_t p_size, f68f2ff91512c1 Kees Cook 2021-04-20 308 const size_t q_size, f68f2ff91512c1 Kees Cook 2021-04-20 309 const size_t p_size_field, f68f2ff91512c1 Kees Cook 2021-04-20 310 const size_t q_size_field, f68f2ff91512c1 Kees Cook 2021-04-20 311 const char *func) a28a6e860c6cf2 Francis Laniel 2021-02-25 312 { a28a6e860c6cf2 Francis Laniel 2021-02-25 313 if (__builtin_constant_p(size)) { f68f2ff91512c1 Kees Cook 2021-04-20 314 /* f68f2ff91512c1 Kees Cook 2021-04-20 315 * Length argument is a constant expression, so we f68f2ff91512c1 Kees Cook 2021-04-20 316 * can perform compile-time bounds checking where f68f2ff91512c1 Kees Cook 2021-04-20 317 * buffer sizes are known. f68f2ff91512c1 Kees Cook 2021-04-20 318 */ f68f2ff91512c1 Kees Cook 2021-04-20 319 f68f2ff91512c1 Kees Cook 2021-04-20 320 /* Error when size is larger than enclosing struct. */ f68f2ff91512c1 Kees Cook 2021-04-20 321 if (p_size > p_size_field && p_size < size) a28a6e860c6cf2 Francis Laniel 2021-02-25 322 __write_overflow(); f68f2ff91512c1 Kees Cook 2021-04-20 323 if (q_size > q_size_field && q_size < size) a28a6e860c6cf2 Francis Laniel 2021-02-25 324 __read_overflow2(); f68f2ff91512c1 Kees Cook 2021-04-20 325 f68f2ff91512c1 Kees Cook 2021-04-20 326 /* Warn when write size argument larger than dest field. */ f68f2ff91512c1 Kees Cook 2021-04-20 327 if (p_size_field < size) f68f2ff91512c1 Kees Cook 2021-04-20 328 __write_overflow_field(p_size_field, size); f68f2ff91512c1 Kees Cook 2021-04-20 329 /* f68f2ff91512c1 Kees Cook 2021-04-20 330 * Warn for source field over-read when building with W=1 f68f2ff91512c1 Kees Cook 2021-04-20 331 * or when an over-write happened, so both can be fixed at f68f2ff91512c1 Kees Cook 2021-04-20 332 * the same time. f68f2ff91512c1 Kees Cook 2021-04-20 333 */ f68f2ff91512c1 Kees Cook 2021-04-20 334 if ((IS_ENABLED(KBUILD_EXTRA_WARN1) || p_size_field < size) && f68f2ff91512c1 Kees Cook 2021-04-20 335 q_size_field < size) f68f2ff91512c1 Kees Cook 2021-04-20 @336 __read_overflow2_field(q_size_field, size); a28a6e860c6cf2 Francis Laniel 2021-02-25 337 } f68f2ff91512c1 Kees Cook 2021-04-20 338 /* f68f2ff91512c1 Kees Cook 2021-04-20 339 * At this point, length argument may not be a constant expression, f68f2ff91512c1 Kees Cook 2021-04-20 340 * so run-time bounds checking can be done where buffer sizes are f68f2ff91512c1 Kees Cook 2021-04-20 341 * known. (This is not an "else" because the above checks may only f68f2ff91512c1 Kees Cook 2021-04-20 342 * be compile-time warnings, and we want to still warn for run-time f68f2ff91512c1 Kees Cook 2021-04-20 343 * overflows.) f68f2ff91512c1 Kees Cook 2021-04-20 344 */ f68f2ff91512c1 Kees Cook 2021-04-20 345 f68f2ff91512c1 Kees Cook 2021-04-20 346 /* f68f2ff91512c1 Kees Cook 2021-04-20 347 * Always stop accesses beyond the struct that contains the f68f2ff91512c1 Kees Cook 2021-04-20 348 * field, when the buffer's remaining size is known. f68f2ff91512c1 Kees Cook 2021-04-20 349 * (The -1 test is to optimize away checks where the buffer f68f2ff91512c1 Kees Cook 2021-04-20 350 * lengths are unknown.) f68f2ff91512c1 Kees Cook 2021-04-20 351 */ f68f2ff91512c1 Kees Cook 2021-04-20 352 if ((p_size != (size_t)(-1) && p_size < size) || f68f2ff91512c1 Kees Cook 2021-04-20 353 (q_size != (size_t)(-1) && q_size < size)) f68f2ff91512c1 Kees Cook 2021-04-20 354 fortify_panic(func); a28a6e860c6cf2 Francis Laniel 2021-02-25 355 } a28a6e860c6cf2 Francis Laniel 2021-02-25 356 :::::: The code at line 336 was first introduced by commit :::::: f68f2ff91512c199ec24883001245912afc17873 fortify: Detect struct member overflows in memcpy() at compile-time :::::: TO: Kees Cook :::::: CC: Kees Cook --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org