All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH v3 06/46] asm-generic: instrument usercopy in cacheflush.h
       [not found] <202204281316.B64baqtO-lkp@intel.com>
@ 2022-06-02 11:41 ` Alexander Potapenko
  0 siblings, 0 replies; 2+ messages in thread
From: Alexander Potapenko @ 2022-06-02 11:41 UTC (permalink / raw)
  To: kbuild-all

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

On Thu, Apr 28, 2022 at 7:34 AM kernel test robot <lkp@intel.com> wrote:
>
> Hi Alexander,

Hi,

> I love your patch! Perhaps something to improve:
>
> [auto build test WARNING on tip/x86/core]
> [also build test WARNING on tip/x86/mm linus/master v5.18-rc4 next-20220427]
> [cannot apply to hnaz-mm/master]
> [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/intel-lab-lkp/linux/commits/Alexander-Potapenko/Add-KernelMemorySanitizer-infrastructure/20220427-004851
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 203d8919a9eda5d1bc68ac3cd7637588334c9dc1
> config: i386-randconfig-s002-20220425 (https://download.01.org/0day-ci/archive/20220428/202204281316.B64baqtO-lkp(a)intel.com/config)
> compiler: gcc-11 (Debian 11.2.0-20) 11.2.0
> reproduce:
>         # apt-get install sparse
>         # sparse version: v0.6.4-dirty
>         # https://github.com/intel-lab-lkp/linux/commit/7ab236390b96b8606acf877ddea4e3a14f58bfd2
>         git remote add linux-review https://github.com/intel-lab-lkp/linux
>         git fetch --no-tags linux-review Alexander-Potapenko/Add-KernelMemorySanitizer-infrastructure/20220427-004851
>         git checkout 7ab236390b96b8606acf877ddea4e3a14f58bfd2
>         # save the config file
>         mkdir build_dir && cp config build_dir/.config
>         make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=i386 SHELL=/bin/bash
>
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>

The mentioned reports are irrelevant to this patch and are
reproducible without it.
Also, my patch does not touch memory.c

>
> sparse warnings: (new ones prefixed by >>)
> >> mm/memory.c:5221:33: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void [noderef] __user *to @@     got void * @@
>    mm/memory.c:5221:33: sparse:     expected void [noderef] __user *to
>    mm/memory.c:5221:33: sparse:     got void *
> >> mm/memory.c:5225:33: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void const [noderef] __user *from @@     got void * @@
>    mm/memory.c:5225:33: sparse:     expected void const [noderef] __user *from
>    mm/memory.c:5225:33: sparse:     got void *
> >> mm/memory.c:5225:33: sparse: sparse: incorrect type in argument 2 (different address spaces) @@     expected void const [noderef] __user *from @@     got void * @@
>    mm/memory.c:5225:33: sparse:     expected void const [noderef] __user *from
>    mm/memory.c:5225:33: sparse:     got void *
>    mm/memory.c:1024:17: sparse: sparse: context imbalance in 'copy_pte_range' - different lock contexts for basic block
>    mm/memory.c:1752:16: sparse: sparse: context imbalance in '__get_locked_pte' - different lock contexts for basic block
>    mm/memory.c:1800:9: sparse: sparse: context imbalance in 'insert_page' - different lock contexts for basic block
>    mm/memory.c:2302:17: sparse: sparse: context imbalance in 'remap_pte_range' - different lock contexts for basic block
>    mm/memory.c:2558:17: sparse: sparse: context imbalance in 'apply_to_pte_range' - unexpected unlock
>    mm/memory.c:2847:9: sparse: sparse: context imbalance in 'wp_page_copy' - different lock contexts for basic block
>    mm/memory.c:3185:17: sparse: sparse: context imbalance in 'wp_pfn_shared' - unexpected unlock
>    mm/memory.c:3248:19: sparse: sparse: context imbalance in 'do_wp_page' - different lock contexts for basic block
>    mm/memory.c:4952:5: sparse: sparse: context imbalance in 'follow_invalidate_pte' - wrong count at exit
>    mm/memory.c:5073:23: sparse: sparse: context imbalance in 'follow_pfn' - unexpected unlock
>    mm/memory.c:5103:9: sparse: sparse: context imbalance in 'follow_phys' - unexpected unlock
>    mm/memory.c:5137:9: sparse: sparse: context imbalance in 'generic_access_phys' - unexpected unlock
>
> vim +5221 mm/memory.c
>
> 28b2ee20c7cba81 Rik van Riel          2008-07-23  5173
> 0ec76a110f432e9 David Howells         2006-09-27  5174  /*
> d3f5ffcacd15287 John Hubbard          2020-12-14  5175   * Access another process' address space as given in mm.
> 0ec76a110f432e9 David Howells         2006-09-27  5176   */
> d3f5ffcacd15287 John Hubbard          2020-12-14  5177  int __access_remote_vm(struct mm_struct *mm, unsigned long addr, void *buf,
> d3f5ffcacd15287 John Hubbard          2020-12-14  5178                         int len, unsigned int gup_flags)
> 0ec76a110f432e9 David Howells         2006-09-27  5179  {
> 0ec76a110f432e9 David Howells         2006-09-27  5180          struct vm_area_struct *vma;
> 0ec76a110f432e9 David Howells         2006-09-27  5181          void *old_buf = buf;
> 442486ec1096781 Lorenzo Stoakes       2016-10-13  5182          int write = gup_flags & FOLL_WRITE;
> 0ec76a110f432e9 David Howells         2006-09-27  5183
> d8ed45c5dcd455f Michel Lespinasse     2020-06-08  5184          if (mmap_read_lock_killable(mm))
> 1e426fe28261b03 Konstantin Khlebnikov 2019-07-11  5185                  return 0;
> 1e426fe28261b03 Konstantin Khlebnikov 2019-07-11  5186
> 183ff22bb6bd818 Simon Arlott          2007-10-20  5187          /* ignore errors, just check how much was successfully transferred */
> 0ec76a110f432e9 David Howells         2006-09-27  5188          while (len) {
> 0ec76a110f432e9 David Howells         2006-09-27  5189                  int bytes, ret, offset;
> 0ec76a110f432e9 David Howells         2006-09-27  5190                  void *maddr;
> 28b2ee20c7cba81 Rik van Riel          2008-07-23  5191                  struct page *page = NULL;
> 0ec76a110f432e9 David Howells         2006-09-27  5192
> 64019a2e467a288 Peter Xu              2020-08-11  5193                  ret = get_user_pages_remote(mm, addr, 1,
> 5b56d49fc31dbb0 Lorenzo Stoakes       2016-12-14  5194                                  gup_flags, &page, &vma, NULL);
> 28b2ee20c7cba81 Rik van Riel          2008-07-23  5195                  if (ret <= 0) {
> dbffcd03d77a3fb Rik van Riel          2014-08-06  5196  #ifndef CONFIG_HAVE_IOREMAP_PROT
> dbffcd03d77a3fb Rik van Riel          2014-08-06  5197                          break;
> dbffcd03d77a3fb Rik van Riel          2014-08-06  5198  #else
> 28b2ee20c7cba81 Rik van Riel          2008-07-23  5199                          /*
> 28b2ee20c7cba81 Rik van Riel          2008-07-23  5200                           * Check if this is a VM_IO | VM_PFNMAP VMA, which
> 28b2ee20c7cba81 Rik van Riel          2008-07-23  5201                           * we can access using slightly different code.
> 28b2ee20c7cba81 Rik van Riel          2008-07-23  5202                           */
> 3e418f9888463a8 Liam Howlett          2021-06-28  5203                          vma = vma_lookup(mm, addr);
> 3e418f9888463a8 Liam Howlett          2021-06-28  5204                          if (!vma)
> 28b2ee20c7cba81 Rik van Riel          2008-07-23  5205                                  break;
> 28b2ee20c7cba81 Rik van Riel          2008-07-23  5206                          if (vma->vm_ops && vma->vm_ops->access)
> 28b2ee20c7cba81 Rik van Riel          2008-07-23  5207                                  ret = vma->vm_ops->access(vma, addr, buf,
> 28b2ee20c7cba81 Rik van Riel          2008-07-23  5208                                                            len, write);
> 0ec76a110f432e9 David Howells         2006-09-27  5209                          if (ret <= 0)
> 0ec76a110f432e9 David Howells         2006-09-27  5210                                  break;
> 28b2ee20c7cba81 Rik van Riel          2008-07-23  5211                          bytes = ret;
> dbffcd03d77a3fb Rik van Riel          2014-08-06  5212  #endif
> 28b2ee20c7cba81 Rik van Riel          2008-07-23  5213                  } else {
> 0ec76a110f432e9 David Howells         2006-09-27  5214                          bytes = len;
> 0ec76a110f432e9 David Howells         2006-09-27  5215                          offset = addr & (PAGE_SIZE-1);
> 0ec76a110f432e9 David Howells         2006-09-27  5216                          if (bytes > PAGE_SIZE-offset)
> 0ec76a110f432e9 David Howells         2006-09-27  5217                                  bytes = PAGE_SIZE-offset;
> 0ec76a110f432e9 David Howells         2006-09-27  5218
> 0ec76a110f432e9 David Howells         2006-09-27  5219                          maddr = kmap(page);
> 0ec76a110f432e9 David Howells         2006-09-27  5220                          if (write) {
> 0ec76a110f432e9 David Howells         2006-09-27 @5221                                  copy_to_user_page(vma, page, addr,
> 0ec76a110f432e9 David Howells         2006-09-27  5222                                                    maddr + offset, buf, bytes);
> 0ec76a110f432e9 David Howells         2006-09-27  5223                                  set_page_dirty_lock(page);
> 0ec76a110f432e9 David Howells         2006-09-27  5224                          } else {
> 0ec76a110f432e9 David Howells         2006-09-27 @5225                                  copy_from_user_page(vma, page, addr,
> 0ec76a110f432e9 David Howells         2006-09-27  5226                                                      buf, maddr + offset, bytes);
> 0ec76a110f432e9 David Howells         2006-09-27  5227                          }
> 0ec76a110f432e9 David Howells         2006-09-27  5228                          kunmap(page);
> 09cbfeaf1a5a67b Kirill A. Shutemov    2016-04-01  5229                          put_page(page);
> 28b2ee20c7cba81 Rik van Riel          2008-07-23  5230                  }
> 0ec76a110f432e9 David Howells         2006-09-27  5231                  len -= bytes;
> 0ec76a110f432e9 David Howells         2006-09-27  5232                  buf += bytes;
> 0ec76a110f432e9 David Howells         2006-09-27  5233                  addr += bytes;
> 0ec76a110f432e9 David Howells         2006-09-27  5234          }
> d8ed45c5dcd455f Michel Lespinasse     2020-06-08  5235          mmap_read_unlock(mm);
> 0ec76a110f432e9 David Howells         2006-09-27  5236
> 0ec76a110f432e9 David Howells         2006-09-27  5237          return buf - old_buf;
> 0ec76a110f432e9 David Howells         2006-09-27  5238  }
> 03252919b798910 Andi Kleen            2008-01-30  5239
>
> --
> 0-DAY CI Kernel Test Service
> https://01.org/lkp



-- 
Alexander Potapenko
Software Engineer

Google Germany GmbH
Erika-Mann-Straße, 33
80636 München

Geschäftsführer: Paul Manicle, Liana Sebastian
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg

Diese E-Mail ist vertraulich. Falls Sie diese fälschlicherweise
erhalten haben sollten, leiten Sie diese bitte nicht an jemand anderes
weiter, löschen Sie alle Kopien und Anhänge davon und lassen Sie mich
bitte wissen, dass die E-Mail an die falsche Person gesendet wurde.


This e-mail is confidential. If you received this communication by
mistake, please don't forward it to anyone else, please erase all
copies and attachments, and please let me know that it has gone to the
wrong person.

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

* [PATCH v3 06/46] asm-generic: instrument usercopy in cacheflush.h
  2022-04-26 16:42 [PATCH v3 00/46] Add KernelMemorySanitizer infrastructure Alexander Potapenko
@ 2022-04-26 16:42 ` Alexander Potapenko
  0 siblings, 0 replies; 2+ messages in thread
From: Alexander Potapenko @ 2022-04-26 16:42 UTC (permalink / raw)
  To: glider
  Cc: Alexander Viro, Andrew Morton, Andrey Konovalov, Andy Lutomirski,
	Arnd Bergmann, Borislav Petkov, Christoph Hellwig,
	Christoph Lameter, David Rientjes, Dmitry Vyukov, Eric Dumazet,
	Greg Kroah-Hartman, Herbert Xu, Ilya Leoshkevich, Ingo Molnar,
	Jens Axboe, Joonsoo Kim, Kees Cook, Marco Elver, Mark Rutland,
	Matthew Wilcox, Michael S. Tsirkin, Pekka Enberg, Peter Zijlstra,
	Petr Mladek, Steven Rostedt, Thomas Gleixner, Vasily Gorbik,
	Vegard Nossum, Vlastimil Babka, kasan-dev, linux-mm, linux-arch,
	linux-kernel

Notify memory tools about usercopy events in copy_to_user_page() and
copy_from_user_page().

Signed-off-by: Alexander Potapenko <glider@google.com>
---
Link: https://linux-review.googlesource.com/id/Ic1ee8da1886325f46ad67f52176f48c2c836c48f
---
 include/asm-generic/cacheflush.h | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/include/asm-generic/cacheflush.h b/include/asm-generic/cacheflush.h
index 4f07afacbc239..0f63eb325025f 100644
--- a/include/asm-generic/cacheflush.h
+++ b/include/asm-generic/cacheflush.h
@@ -2,6 +2,8 @@
 #ifndef _ASM_GENERIC_CACHEFLUSH_H
 #define _ASM_GENERIC_CACHEFLUSH_H
 
+#include <linux/instrumented.h>
+
 struct mm_struct;
 struct vm_area_struct;
 struct page;
@@ -105,6 +107,7 @@ static inline void flush_cache_vunmap(unsigned long start, unsigned long end)
 #ifndef copy_to_user_page
 #define copy_to_user_page(vma, page, vaddr, dst, src, len)	\
 	do { \
+		instrument_copy_to_user(dst, src, len); \
 		memcpy(dst, src, len); \
 		flush_icache_user_page(vma, page, vaddr, len); \
 	} while (0)
@@ -112,7 +115,11 @@ static inline void flush_cache_vunmap(unsigned long start, unsigned long end)
 
 #ifndef copy_from_user_page
 #define copy_from_user_page(vma, page, vaddr, dst, src, len) \
-	memcpy(dst, src, len)
+	do { \
+		instrument_copy_from_user_before(dst, src, len); \
+		memcpy(dst, src, len); \
+		instrument_copy_from_user_after(dst, src, len, 0); \
+	} while (0)
 #endif
 
 #endif /* _ASM_GENERIC_CACHEFLUSH_H */
-- 
2.36.0.rc2.479.g8af0fa9b8e-goog


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

end of thread, other threads:[~2022-06-02 11:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <202204281316.B64baqtO-lkp@intel.com>
2022-06-02 11:41 ` [PATCH v3 06/46] asm-generic: instrument usercopy in cacheflush.h Alexander Potapenko
2022-04-26 16:42 [PATCH v3 00/46] Add KernelMemorySanitizer infrastructure Alexander Potapenko
2022-04-26 16:42 ` [PATCH v3 06/46] asm-generic: instrument usercopy in cacheflush.h Alexander Potapenko

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.