mm/kasan/report.c:637 kasan_non_canonical_hook() warn: unsigned 'addr' is never less than zero.

From: kernel test robot
Date: Sun Nov 26 2023 - 19:37:31 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: d2da77f431ac49b5763b88751a75f70daa46296c
commit: babddbfb7d7d70ae7f10fedd75a45d8ad75fdddf kasan: print the original fault addr when access invalid shadow
date: 6 weeks ago
config: loongarch-randconfig-r071-20231126 (https://download.01.org/0day-ci/archive/20231127/202311270743.3oTCwYPd-lkp@xxxxxxxxx/config)
compiler: loongarch64-linux-gcc (GCC) 13.2.0
reproduce: (https://download.01.org/0day-ci/archive/20231127/202311270743.3oTCwYPd-lkp@xxxxxxxxx/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@xxxxxxxxx>
| Closes: https://lore.kernel.org/oe-kbuild-all/202311270743.3oTCwYPd-lkp@xxxxxxxxx/

smatch warnings:
mm/kasan/report.c:637 kasan_non_canonical_hook() warn: unsigned 'addr' is never less than zero.

vim +/addr +637 mm/kasan/report.c

bb2f967ce2130b Andrey Konovalov 2022-03-24 623
2f004eea0fc8f8 Jann Horn 2019-12-19 624 /*
babddbfb7d7d70 Haibo Li 2023-10-09 625 * With CONFIG_KASAN, accesses to bogus pointers (outside the high
2f004eea0fc8f8 Jann Horn 2019-12-19 626 * canonical half of the address space) cause out-of-bounds shadow memory reads
2f004eea0fc8f8 Jann Horn 2019-12-19 627 * before the actual access. For addresses in the low canonical half of the
2f004eea0fc8f8 Jann Horn 2019-12-19 628 * address space, as well as most non-canonical addresses, that out-of-bounds
2f004eea0fc8f8 Jann Horn 2019-12-19 629 * shadow memory access lands in the non-canonical part of the address space.
2f004eea0fc8f8 Jann Horn 2019-12-19 630 * Help the user figure out what the original bogus pointer was.
2f004eea0fc8f8 Jann Horn 2019-12-19 631 */
2f004eea0fc8f8 Jann Horn 2019-12-19 632 void kasan_non_canonical_hook(unsigned long addr)
2f004eea0fc8f8 Jann Horn 2019-12-19 633 {
2f004eea0fc8f8 Jann Horn 2019-12-19 634 unsigned long orig_addr;
2f004eea0fc8f8 Jann Horn 2019-12-19 635 const char *bug_type;
2f004eea0fc8f8 Jann Horn 2019-12-19 636
2f004eea0fc8f8 Jann Horn 2019-12-19 @637 if (addr < KASAN_SHADOW_OFFSET)

:::::: The code at line 637 was first introduced by commit
:::::: 2f004eea0fc8f86b45dfc2007add2d4986de8d02 x86/kasan: Print original address on #GP

:::::: TO: Jann Horn <jannh@xxxxxxxxxx>
:::::: CC: Borislav Petkov <bp@xxxxxxx>

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki