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 X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 553F5C48BDF for ; Sun, 20 Jun 2021 11:44:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C8FF86113E for ; Sun, 20 Jun 2021 11:44:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C8FF86113E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5BA176B006E; Sun, 20 Jun 2021 07:44:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 56A5B6B0070; Sun, 20 Jun 2021 07:44:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 40B246B0072; Sun, 20 Jun 2021 07:44:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0109.hostedemail.com [216.40.44.109]) by kanga.kvack.org (Postfix) with ESMTP id 0B2606B006E for ; Sun, 20 Jun 2021 07:44:37 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 9A14512606 for ; Sun, 20 Jun 2021 11:44:37 +0000 (UTC) X-FDA: 78273919794.24.9062AFA Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) by imf15.hostedemail.com (Postfix) with ESMTP id DAC96A0021C5 for ; Sun, 20 Jun 2021 11:44:35 +0000 (UTC) Received: by mail-ed1-f42.google.com with SMTP id t7so14962496edd.5 for ; Sun, 20 Jun 2021 04:44:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=mNS466MM1+gmAZ7m5R3iU35irMmXL7Fyl0Gd5MfDyU0=; b=V8xhXvADThnRUl5Z/GN4V7kkWVMOh21CEhMCxPhPk4pXpdj2pBkXN64CNh0jfRqWa+ TQNkMLrqkB97dWasSKYAK0qyI7S4qFanRdOk+ceL7C1ppmTbU1IGd+5qrw1t1tMlbImv e1aSkBkhsg2npBnTSUrnko9JPp1TsWbR94GBB1F9RdsXC/X41VM2epBeXK7I0LDpPlPX ndG0+CC6y3a1iQbj+vaDRtz9bsGv6BIBTCXOf6BSyZ3Bnp/3kJ4kZl7Ful4oOAanVxc2 olTBuT9h3GZ43bnCbok7n39Tnr5BY/+tPd5I4gE4MVBpn6R78S/c/ayN4yw52l0OHg1A qlhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=mNS466MM1+gmAZ7m5R3iU35irMmXL7Fyl0Gd5MfDyU0=; b=C+qlFB8curXeAbjox36v/aqF/3x7OSbo31G5tznIQX5lYrsi6Gv+/GCQUKVzS5YwXU qjnpAbIxC+3Teol7ihqqGIal2gQIpG3YUNdOsr1ATCEpbMvmkQaKzKMjxKLMDSmyHtay SKprmd+5Qjdhwi2eWE2VNz0tu7ZzFWnXrDRkxiDnEArcGPBq2CTeYHzQ/j2DhdRPrJxY uq5e3iaDQO8b7YjQX7pN4vNDTU1jdqrm7wv9A7IwX3GD7WJnLwIzWipGtcErBwWSXdFh knwP79qEeSIale8rjRsZffS5zA5UQqCFs8F9N/ex0jV3omyaS4L6WZav46bs7Wctvvs3 TtrA== X-Gm-Message-State: AOAM532fxi0riJP88cKJkP/uJ1DTYXd4S+MRxmDTyEHlxaBkX50hwDKG zabJQ8MZ43YOMJGYelI1D+e5A9UW3YFe6yVygqE= X-Google-Smtp-Source: ABdhPJwZjNrZTIvdI6NdVI0nQr4uYCujxGI5gRMvVK3EfKSSc6HFukplCGZSgfO7e4M8bVEaHDNoRjvVYb/P55Iq9mY= X-Received: by 2002:a05:6402:1d11:: with SMTP id dg17mr2680200edb.30.1624189476065; Sun, 20 Jun 2021 04:44:36 -0700 (PDT) MIME-Version: 1.0 References: <20210617081330.98629-1-dja@axtens.net> In-Reply-To: <20210617081330.98629-1-dja@axtens.net> From: Andrey Konovalov Date: Sun, 20 Jun 2021 14:44:17 +0300 Message-ID: Subject: Re: [PATCH] mm/vmalloc: unbreak kasan vmalloc support To: Daniel Axtens Cc: LKML , Linux Memory Management List , kasan-dev , Andrew Morton , Nicholas Piggin , David Gow , Dmitry Vyukov , Uladzislau Rezki Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=V8xhXvAD; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf15.hostedemail.com: domain of andreyknvl@gmail.com designates 209.85.208.42 as permitted sender) smtp.mailfrom=andreyknvl@gmail.com X-Stat-Signature: ee1ahuo3ux3uc3xp7itysojhh18kedoy X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: DAC96A0021C5 X-HE-Tag: 1624189475-406310 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: On Thu, Jun 17, 2021 at 11:13 AM Daniel Axtens wrote: > > In commit 121e6f3258fe ("mm/vmalloc: hugepage vmalloc mappings"), > __vmalloc_node_range was changed such that __get_vm_area_node was no > longer called with the requested/real size of the vmalloc allocation, but > rather with a rounded-up size. > > This means that __get_vm_area_node called kasan_unpoision_vmalloc() with > a rounded up size rather than the real size. This led to it allowing > access to too much memory and so missing vmalloc OOBs and failing the > kasan kunit tests. > > Pass the real size and the desired shift into __get_vm_area_node. This > allows it to round up the size for the underlying allocators while > still unpoisioning the correct quantity of shadow memory. > > Adjust the other call-sites to pass in PAGE_SHIFT for the shift value. > > Cc: Nicholas Piggin > Cc: David Gow > Cc: Dmitry Vyukov > Cc: Andrey Konovalov > Cc: Uladzislau Rezki (Sony) > Link: https://bugzilla.kernel.org/show_bug.cgi?id=213335 > Fixes: 121e6f3258fe ("mm/vmalloc: hugepage vmalloc mappings") > Signed-off-by: Daniel Axtens > --- > mm/vmalloc.c | 24 ++++++++++++++---------- > 1 file changed, 14 insertions(+), 10 deletions(-) > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > index aaad569e8963..3471cbeb083c 100644 > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -2362,15 +2362,16 @@ static void clear_vm_uninitialized_flag(struct vm_struct *vm) > } > > static struct vm_struct *__get_vm_area_node(unsigned long size, > - unsigned long align, unsigned long flags, unsigned long start, > - unsigned long end, int node, gfp_t gfp_mask, const void *caller) > + unsigned long align, unsigned long shift, unsigned long flags, > + unsigned long start, unsigned long end, int node, > + gfp_t gfp_mask, const void *caller) > { > struct vmap_area *va; > struct vm_struct *area; > unsigned long requested_size = size; > > BUG_ON(in_interrupt()); > - size = PAGE_ALIGN(size); > + size = ALIGN(size, 1ul << shift); > if (unlikely(!size)) > return NULL; > > @@ -2402,8 +2403,8 @@ struct vm_struct *__get_vm_area_caller(unsigned long size, unsigned long flags, > unsigned long start, unsigned long end, > const void *caller) > { > - return __get_vm_area_node(size, 1, flags, start, end, NUMA_NO_NODE, > - GFP_KERNEL, caller); > + return __get_vm_area_node(size, 1, PAGE_SHIFT, flags, start, end, > + NUMA_NO_NODE, GFP_KERNEL, caller); > } > > /** > @@ -2419,7 +2420,8 @@ struct vm_struct *__get_vm_area_caller(unsigned long size, unsigned long flags, > */ > struct vm_struct *get_vm_area(unsigned long size, unsigned long flags) > { > - return __get_vm_area_node(size, 1, flags, VMALLOC_START, VMALLOC_END, > + return __get_vm_area_node(size, 1, PAGE_SHIFT, flags, > + VMALLOC_START, VMALLOC_END, > NUMA_NO_NODE, GFP_KERNEL, > __builtin_return_address(0)); > } > @@ -2427,7 +2429,8 @@ struct vm_struct *get_vm_area(unsigned long size, unsigned long flags) > struct vm_struct *get_vm_area_caller(unsigned long size, unsigned long flags, > const void *caller) > { > - return __get_vm_area_node(size, 1, flags, VMALLOC_START, VMALLOC_END, > + return __get_vm_area_node(size, 1, PAGE_SHIFT, flags, > + VMALLOC_START, VMALLOC_END, > NUMA_NO_NODE, GFP_KERNEL, caller); > } > > @@ -2949,9 +2952,9 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align, > } > > again: > - size = PAGE_ALIGN(size); > - area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | > - vm_flags, start, end, node, gfp_mask, caller); > + area = __get_vm_area_node(real_size, align, shift, VM_ALLOC | > + VM_UNINITIALIZED | vm_flags, start, end, node, > + gfp_mask, caller); > if (!area) { > warn_alloc(gfp_mask, NULL, > "vmalloc error: size %lu, vm_struct allocation failed", > @@ -2970,6 +2973,7 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align, > */ > clear_vm_uninitialized_flag(area); > > + size = PAGE_ALIGN(size); > kmemleak_vmalloc(area, size, gfp_mask); > > return addr; > -- > 2.30.2 > This fixes the vmalloc_oob test for me. Thank you, Daniel! Tested-by: Andrey Konovalov Acked-by: Andrey Konovalov