# \[PATCH 00/43\] Add KernelMemorySanitizer infrastructure (page 2 of 2)

- Subsystems: EXEC \& BINFMT API, ELF, MEMORY MANAGEMENT, MEMORY MANAGEMENT - CORE, MEMORY MANAGEMENT - GUP (GET USER PAGES), MEMORY MANAGEMENT - MEMORY MAP, MEMORY MANAGEMENT - PAGE ALLOCATOR, MEMORY MANAGEMENT - SLAB ALLOCATOR, MMU GATHER AND TLB INVALIDATION, PAGE CACHE, VMALLOC, 9P FILE SYSTEM, AMD DISPLAY CORE, BLOCK LAYER, CLANG/LLVM BUILD SUPPORT, COMPILER ATTRIBUTES, CRYPTO API, DMA MAPPING HELPERS, DOCUMENTATION, DOCUMENTATION PROCESS, DRM DRIVERS, EXTENSIBLE FIRMWARE INTERFACE (EFI), FILESYSTEMS (VFS and infrastructure), FORTIFY\_SOURCE, GENERIC ENTRY CODE, GENERIC INCLUDE/ASM HEADER FILES, GENERIC STRING LIBRARY, I2C SUBSYSTEM, INPUT (KEYBOARD, MOUSE, JOYSTICK, TOUCHSCREEN) DRIVERS, KASAN, KCOV, KCSAN, KERNEL BUILD + files below scripts/ (unless maintained elsewhere), KERNEL HARDENING (not covered by other areas), KMSAN, KVM PARAVIRT (KVM/paravirt), LIBNVDIMM: NON-VOLATILE MEMORY DEVICE SUBSYSTEM, LIBRARY CODE, LOCKING PRIMITIVES, NETWORKING DRIVERS, NETWORKING \[GENERAL\], OBJTOOL, PRINTK, RADEON and AMDGPU DRM DRIVERS, RANDOM NUMBER DRIVER, S390 ARCHITECTURE, SCHEDULER, SCSI SUBSYSTEM, SECURITY SUBSYSTEM, SOUND, SPARSE CHECKER, TC subsystem, THE REST, UPROBES, USB SUBSYSTEM, USERSPACE COPYIN/COPYOUT (UIOVEC), VIRTIO CORE, X86 ARCHITECTURE (32-BIT AND 64-BIT), X86 ENTRY CODE, X86 MCE INFRASTRUCTURE, X86 MM, X86 STACK UNWINDING, X86 VDSO
- Maintainers: Kees Cook, Andrew Morton, David Hildenbrand, Muchun Song, Mike Rapoport, Vlastimil Babka, Johannes Weiner, Harry Yoo, Will Deacon, "Aneesh Kumar K.V", Nick Piggin, Peter Zijlstra, Matthew Wilcox, Jan Kara, Uladzislau Rezki, Eric Van Hensbergen, Latchesar Ionkov, Dominique Martinet, Harry Wentland, Leo Li, Jens Axboe, Nathan Chancellor, Miguel Ojeda, Herbert Xu, "David S. Miller", Marek Szyprowski, Jonathan Corbet, David Airlie, Simona Vetter, Ard Biesheuvel, Alexander Viro, Christian Brauner, Thomas Gleixner, Andy Lutomirski, Arnd Bergmann, Andi Shyti, Dmitry Torokhov, Andrey Ryabinin, Marco Elver, Nicolas Schier, Alexander Potapenko, Paolo Bonzini, Dan Williams, Vishal Verma, Dave Jiang, Alison Schofield, Ingo Molnar, Boqun Feng, Andrew Lunn, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Josh Poimboeuf, Petr Mladek, John Ogness, Alex Deucher, Christian König, "Theodore Ts'o", Jason A. Donenfeld, Heiko Carstens, Vasily Gorbik, Alexander Gordeev, Juri Lelli, Vincent Guittot, "James E.J. Bottomley", "Martin K. Petersen", Paul Moore, James Morris, "Serge E. Hallyn", Jaroslav Kysela, Takashi Iwai, Chris Li, Jamal Hadi Salim, Jiri Pirko, Linus Torvalds, Masami Hiramatsu, Oleg Nesterov, Greg Kroah-Hartman, "Michael S. Tsirkin", Jason Wang, Eugenio Pérez, Borislav Petkov, Dave Hansen, Tony Luck
- Series: 43 patches touching 95 files, +4,062/-68
- Status: SUPERSEDED (Superseded by v7 posted 2022-09-15)
- Superseded by v7 (posted 2022-09-15).
- Revision v1 (7 revisions archived).
- List: linux-mm
- 77 messages, 8 authors
- Page: https://ratatoskr.run/linux-mm/2021/12/1608321/t/2
- Previous page: https://ratatoskr.run/linux-mm/2021/12/1608321/t.md

## Re: \[PATCH 13/43\] kmsan: add KMSAN runtime core

- From: Alexander Potapenko \<glider@google.com\>
- Date: 2022-03-21 14:24:32 
- Message: https://ratatoskr.run/linux-mm/2022/03/1711375.md

```text
> >
> > Just to make sure I don't misunderstand - for example for "kmsan: mm:
> > call KMSAN hooks from SLUB code", would it be better to pull the code
> > in mm/kmsan/core.c implementing kmsan_slab_alloc() and
> > kmsan_slab_free() into that patch?
>
> Yes.
>
> > I thought maintainers would prefer to have patches to their code
> > separated from KMSAN code, but if it's not true, I can surely fix
> > that.
>
> As a maintainer, I want to know what the function call that you just
> added to my subsystem to call does.  Wouldn't you?  Put it all in the
> same patch.

Ok, will be done in v2, thanks!

> Think about submitting a patch series as telling a story.  You need to
> show the progression forward of the feature so that everyone can
> understand what is going on.  To just throw tiny snippets at us is
> impossible to follow along with what your goal is.
>
> You want reviewers to be able to easily see if the things you describe
> being done in the changelog actually are implemented in the diff.
> Dividing stuff up by files does not show that at all.
>
> thanks,
>
> greg k-h



-- 
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.

```

## Re: \[PATCH 16/43\] kmsan: mm: call KMSAN hooks from SLUB code

- From: Alexander Potapenko \<glider@google.com\>
- Date: 2022-03-25 13:16:01 
- Message: https://ratatoskr.run/linux-mm/2022/03/1715817.md

```text
> >  static inline void *get_freepointer(struct kmem_cache *s, void *object)
> >  {
> >       object = kasan_reset_tag(object);
> > -     return freelist_dereference(s, object + s->offset);
> > +     return kmsan_init(freelist_dereference(s, object + s->offset));
>
> ... but I don't see why it applies to get_freepointer() too? What am I missing?

Agreed, kmsan_init() is not needed here.

> >  }
> >
> >  static void prefetch_freepointer(const struct kmem_cache *s, void *object)
> > @@ -357,18 +361,28 @@ static void prefetch_freepointer(const struct kmem_cache *s, void *object)
> >       prefetchw(object + s->offset);
> >  }
> >
> > +/*
> > + * When running under KMSAN, get_freepointer_safe() may return an uninitialized
> > + * pointer value in the case the current thread loses the race for the next
> > + * memory chunk in the freelist. In that case this_cpu_cmpxchg_double() in
> > + * slab_alloc_node() will fail, so the uninitialized value won't be used, but
> > + * KMSAN will still check all arguments of cmpxchg because of imperfect
> > + * handling of inline assembly.
> > + * To work around this problem, use kmsan_init() to force initialize the
> > + * return value of get_freepointer_safe().
> > + */
> >  static inline void *get_freepointer_safe(struct kmem_cache *s, void *object)
> >  {
> >       unsigned long freepointer_addr;
> >       void *p;
> >
> >       if (!debug_pagealloc_enabled_static())
> > -             return get_freepointer(s, object);
> > +             return kmsan_init(get_freepointer(s, object));
>
> So here kmsan_init() is done twice?

Yeah, removing it from get_freepointer() does not introduce new
errors. I'll fix this in v2.

```
