<div dir="ltr">Well, I'm sure this is a question for experienced kernel engineers - so I just stay tuned.<div><br></div><div>But as a side note:<br>My approach was only to get the single commit 49f2d2419d60 in as smooth as possible,<br>means with as few changes as possible (incl. context),<br>so that potential further cherry-picks or backports in that area are not harmed (or at least as little as possible).<br><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Oct 5, 2021 at 4:10 PM Kleber Souza <<a href="mailto:kleber.souza@canonical.com">kleber.souza@canonical.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 05.10.21 08:32, <a href="mailto:frank.heimes@canonical.com" target="_blank">frank.heimes@canonical.com</a> wrote:<br>
> From: Vlastimil Babka <<a href="mailto:vbabka@suse.cz" target="_blank">vbabka@suse.cz</a>><br>
> <br>
> BugLink: <a href="https://bugs.launchpad.net/bugs/1913442" rel="noreferrer" target="_blank">https://bugs.launchpad.net/bugs/1913442</a><br>
> <br>
> Upstream commit : 49f2d2419d60a103752e5fbaf158cf8d07c0d884<br>
> <br>
> We have seen a "usercopy: Kernel memory overwrite attempt detected to<br>
> SLUB object 'dma-kmalloc-1 k' (offset 0, size 11)!" error on s390x, as<br>
> IUCV uses kmalloc() with __GFP_DMA because of memory address<br>
> restrictions. The issue has been discussed [2] and it has been noted<br>
> that if all the kmalloc caches are marked as usercopy, there's little<br>
> reason not to mark dma-kmalloc caches too. The 'dma' part merely means<br>
> that __GFP_DMA is used to restrict memory address range.<br>
> <br>
> As Jann Horn put it [3]:<br>
> "I think dma-kmalloc slabs should be handled the same way as normal<br>
> kmalloc slabs. When a dma-kmalloc allocation is freshly created, it is<br>
> just normal kernel memory - even if it might later be used for DMA -,<br>
> and it should be perfectly fine to copy_from_user() into such<br>
> allocations at that point, and to copy_to_user() out of them at the<br>
> end. If you look at the places where such allocations are created, you<br>
> can see things like kmemdup(), memcpy() and so on - all normal<br>
> operations that shouldn't conceptually be different from usercopy in<br>
> any relevant way."<br>
> <br>
> Thus this patch marks the dma-kmalloc-* caches as usercopy.<br>
> <br>
> [1] <a href="https://bugzilla.suse.com/show_bug.cgi?id=1156053" rel="noreferrer" target="_blank">https://bugzilla.suse.com/show_bug.cgi?id=1156053</a><br>
> [2] <a href="https://lore.kernel.org/kernel-hardening/bfca96db-bbd0-d958-7732-76e36c667c68@suse.cz/" rel="noreferrer" target="_blank">https://lore.kernel.org/kernel-hardening/bfca96db-bbd0-d958-7732-76e36c667c68@suse.cz/</a><br>
> [3] <a href="https://lore.kernel.org/kernel-hardening/CAG48ez1a4waGk9kB0WLaSbs4muSoK0AYAVk8=XYaKj4_+6e6Hg@mail.gmail.com/" rel="noreferrer" target="_blank">https://lore.kernel.org/kernel-hardening/CAG48ez1a4waGk9kB0WLaSbs4muSoK0AYAVk8=XYaKj4_+6e6Hg@mail.gmail.com/</a><br>
> <br>
> Signed-off-by: Vlastimil Babka <<a href="mailto:vbabka@suse.cz" target="_blank">vbabka@suse.cz</a>><br>
> Signed-off-by: Andrew Morton <<a href="mailto:akpm@linux-foundation.org" target="_blank">akpm@linux-foundation.org</a>><br>
> Acked-by: Christian Borntraeger <<a href="mailto:borntraeger@de.ibm.com" target="_blank">borntraeger@de.ibm.com</a>><br>
> Acked-by: Jiri Slaby <<a href="mailto:jslaby@suse.cz" target="_blank">jslaby@suse.cz</a>><br>
> Cc: Jann Horn <<a href="mailto:jannh@google.com" target="_blank">jannh@google.com</a>><br>
> Cc: Christoph Hellwig <<a href="mailto:hch@infradead.org" target="_blank">hch@infradead.org</a>><br>
> Cc: Christopher Lameter <<a href="mailto:cl@linux.com" target="_blank">cl@linux.com</a>><br>
> Cc: Julian Wiedmann <<a href="mailto:jwi@linux.ibm.com" target="_blank">jwi@linux.ibm.com</a>><br>
> Cc: Ursula Braun <<a href="mailto:ubraun@linux.ibm.com" target="_blank">ubraun@linux.ibm.com</a>><br>
> Cc: Alexander Viro <<a href="mailto:viro@zeniv.linux.org.uk" target="_blank">viro@zeniv.linux.org.uk</a>><br>
> Cc: David Windsor <<a href="mailto:dave@nullcore.net" target="_blank">dave@nullcore.net</a>><br>
> Cc: Pekka Enberg <<a href="mailto:penberg@kernel.org" target="_blank">penberg@kernel.org</a>><br>
> Cc: David Rientjes <<a href="mailto:rientjes@google.com" target="_blank">rientjes@google.com</a>><br>
> Cc: Joonsoo Kim <<a href="mailto:iamjoonsoo.kim@lge.com" target="_blank">iamjoonsoo.kim@lge.com</a>><br>
> Cc: Andy Lutomirski <<a href="mailto:luto@kernel.org" target="_blank">luto@kernel.org</a>><br>
> Cc: "David S. Miller" <<a href="mailto:davem@davemloft.net" target="_blank">davem@davemloft.net</a>><br>
> Cc: Laura Abbott <<a href="mailto:labbott@redhat.com" target="_blank">labbott@redhat.com</a>><br>
> Cc: Mark Rutland <<a href="mailto:mark.rutland@arm.com" target="_blank">mark.rutland@arm.com</a>><br>
> Cc: "Martin K. Petersen" <<a href="mailto:martin.petersen@oracle.com" target="_blank">martin.petersen@oracle.com</a>><br>
> Cc: Paolo Bonzini <<a href="mailto:pbonzini@redhat.com" target="_blank">pbonzini@redhat.com</a>><br>
> Cc: Christoffer Dall <<a href="mailto:christoffer.dall@linaro.org" target="_blank">christoffer.dall@linaro.org</a>><br>
> Cc: Dave Kleikamp <<a href="mailto:dave.kleikamp@oracle.com" target="_blank">dave.kleikamp@oracle.com</a>><br>
> Cc: Jan Kara <<a href="mailto:jack@suse.cz" target="_blank">jack@suse.cz</a>><br>
> Cc: Luis de Bethencourt <<a href="mailto:luisbg@kernel.org" target="_blank">luisbg@kernel.org</a>><br>
> Cc: Marc Zyngier <<a href="mailto:marc.zyngier@arm.com" target="_blank">marc.zyngier@arm.com</a>><br>
> Cc: Rik van Riel <<a href="mailto:riel@surriel.com" target="_blank">riel@surriel.com</a>><br>
> Cc: Matthew Garrett <<a href="mailto:mjg59@google.com" target="_blank">mjg59@google.com</a>><br>
> Cc: Michal Kubecek <<a href="mailto:mkubecek@suse.cz" target="_blank">mkubecek@suse.cz</a>><br>
> Link: <a href="http://lkml.kernel.org/r/7d810f6d-8085-ea2f-7805-47ba3842dc50@suse.cz" rel="noreferrer" target="_blank">http://lkml.kernel.org/r/7d810f6d-8085-ea2f-7805-47ba3842dc50@suse.cz</a><br>
> Signed-off-by: Linus Torvalds <<a href="mailto:torvalds@linux-foundation.org" target="_blank">torvalds@linux-foundation.org</a>><br>
> (backported from commit 49f2d2419d60a103752e5fbaf158cf8d07c0d884)<br>
> Signed-off-by: Frank Heimes <<a href="mailto:frank.heimes@canonical.com" target="_blank">frank.heimes@canonical.com</a>><br>
> ---<br>
> mm/slab_common.c | 2 +-<br>
> 1 file changed, 1 insertion(+), 1 deletion(-)<br>
> <br>
> diff --git a/mm/slab_common.c b/mm/slab_common.c<br>
> index 8c1ffbf7de45..76433e2187d0 100644<br>
> --- a/mm/slab_common.c<br>
> +++ b/mm/slab_common.c<br>
> @@ -1296,7 +1296,7 @@ void __init create_kmalloc_caches(slab_flags_t flags)<br>
> <br>
> BUG_ON(!n);<br>
> kmalloc_caches[KMALLOC_DMA][i] = create_kmalloc_cache(<br>
> - n, size, SLAB_CACHE_DMA | flags, 0, 0);<br>
> + n, size, SLAB_CACHE_DMA | flags, 0, kmalloc_info[i].size);<br>
<br>
Although this is probably functionally the same, I'm wondering if we should<br>
keep both "size" and "usersize" parameters passed to create_kmalloc_cache()<br>
consistent.<br>
<br>
In the original patch (49f2d2419d60), the "size" is not calculated anymore using<br>
"kmalloc_size(i)", which was removed by dc0a7f7558dd (mm, slab: remove unused<br>
kmalloc_size()), but passing "kmalloc_info[i].size" instead. The same is passed<br>
as the "usersize" then.<br>
<br>
Both ways of calculating "usersize" seem equivalent (using either "kmalloc_size(i)"<br>
or "kmalloc_info[i].size"), but I didn't look very deeply to check if any patch<br>
changed any of them in the meantime. So in my opinion we should also use "size" for<br>
the backport to be on the safe side and do something like:<br>
<br>
kmalloc_caches[KMALLOC_DMA][i] = create_kmalloc_cache(<br>
- n, size, SLAB_CACHE_DMA | flags, 0, 0);<br>
+ n, size, SLAB_CACHE_DMA | flags, 0, size);<br>
<br>
<br>
I'll not ACK nor NACK for now and wait for someone else to weight in.<br>
<br>
<br>
Kleber<br>
</blockquote></div>