Message ID | 20221025233421.you.825-kees@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1275281wru; Tue, 25 Oct 2022 16:38:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4ZuFVKQ48xz0SW8aU43arlJyL71KTTrJHFU7JQHlja6C03FER5ujcevilZTrj7B2wvwBR1 X-Received: by 2002:a63:a06:0:b0:458:2853:45e4 with SMTP id 6-20020a630a06000000b00458285345e4mr33972475pgk.20.1666741112516; Tue, 25 Oct 2022 16:38:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666741112; cv=none; d=google.com; s=arc-20160816; b=iNYs2mlrbGHtDk3dk5XloSps+MmVZgM5yDsnHA4npc8+Txi5CwZ5IwNKGjcxzdDgMh 05rDCXvsHtj2Lg7xXfEQ5tNYFBvVMvC6IgLFRKUDGR9Jl/QXDTGa9zUR8uS9xjvJ+vp3 yzyZ3Al4xeiKwPIOjWxVvGLOUXAVEXw7dODRXr/oP5ZcQ9bnscw815/2ZpCvc63biKI6 fWWFs/tD2dYDoH9JtS1v/NSaDKmyiRBIqqivOsHVhte3qJH/ZNEhqMu7SKt83kCR2BJ5 JFHeVODmQAJK3vh1h7kPExeeXs+GGNyD3XVlqN1AtWzMfuHHZqeK1jh1LjDpOdx8CIgT +XMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=AGtKXigXG9GEUy3d0vDj3qy0ftcRaftXZM1jOrI1Icc=; b=h5HVuwOLiMpvXrcBJiekMYmeI2PBn6xlLEWc8pvTcDLf2yzDjYskod6J5Z7Xeffnv9 wT/802pyjPR4EClfFOMCegSUpUBY4UPAcA9OiRHJw74a3lHdtLtnqOsmBBADYVSBUpm5 PjQ5cOCzoMH/aASWdttuco3O1xJBVzoQABTn98aEauy65Vf8p6eyL5KHI61ihONgeHOW GgbdLH/66gp46F1j3CYwNpOiCWLiSx/Jjt0cPx+D3iFBNrKf8D79lLITAR+FWi4JYlQI 3mGy7WrjPwVgqxzYJSd1A2s45yAgTQ60v/7WeBcNWoAJbaBBsRlo3Vd/xEVdt0nqXDTk Uxgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dNQjW5t3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g1-20020a170902fe0100b00178a33faa42si4242179plj.66.2022.10.25.16.38.18; Tue, 25 Oct 2022 16:38:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dNQjW5t3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232334AbiJYXga (ORCPT <rfc822;pwkd43@gmail.com> + 99 others); Tue, 25 Oct 2022 19:36:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231544AbiJYXg1 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 25 Oct 2022 19:36:27 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 795DAF973B for <linux-kernel@vger.kernel.org>; Tue, 25 Oct 2022 16:36:26 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id p3so11442330pld.10 for <linux-kernel@vger.kernel.org>; Tue, 25 Oct 2022 16:36:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=AGtKXigXG9GEUy3d0vDj3qy0ftcRaftXZM1jOrI1Icc=; b=dNQjW5t3D8tfppJYPI4FhUKWrCRWqRl5vraJjM+XSqyyGfsQCqbtXk/IzGLlout0kL 9rC8n0q9VaV2x87PLzOOrnQFXpT1q5NfhXz+WExks9ljvBvt4Y1Cu90Uf2nkHbjZsdwb AFh/N2qcgtcQTg3qkkF3HuHldDD8YYah0PSSA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AGtKXigXG9GEUy3d0vDj3qy0ftcRaftXZM1jOrI1Icc=; b=xQVV+xWJnQxsDDL9QthjimoNtYpSJV6eieZnge1gJ+PebBL/qx4C535gq1yUP9+Imu oWkUXbdzn6cl1zuUi+P7INhwd8bVHx+DEbxwSD2Ps/Ga5aJyZQ1CXOUhy4i55YD4TGTP ARTg1eoIwcvYALt2C8PeKbXqBaj17/06Ye2Y9ZFsJsu2Aya4HhUziv2OutloVywZoBzW 76m8A6Qit4Rvyd3PvHfMYgDqKutS0/088a2CWp6ldKkFXeBiw2QiVDUXZARI6fEWz7+e hXUzz6d5ZKJTbf3RI86FODiOZkBB9tYIPuAsJVWe1oW4rnCa01u+vk6RubtmjyVeMidj h0fQ== X-Gm-Message-State: ACrzQf0YzXGvm/zrZrhRmGZ6aoi/ntBrDH4EA2Rl7tESYCf5ITmqBdpu VDZ7iq7ZAXL1VPXL827uvgvouA== X-Received: by 2002:a17:90b:4c52:b0:20d:489b:5607 with SMTP id np18-20020a17090b4c5200b0020d489b5607mr883820pjb.40.1666740986031; Tue, 25 Oct 2022 16:36:26 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id j10-20020a170902da8a00b00186b5c1a715sm1697455plx.182.2022.10.25.16.36.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Oct 2022 16:36:25 -0700 (PDT) From: Kees Cook <keescook@chromium.org> To: Vlastimil Babka <vbabka@suse.cz> Cc: Kees Cook <keescook@chromium.org>, Andrey Konovalov <andreyknvl@gmail.com>, David Rientjes <rientjes@google.com>, Marco Elver <elver@google.com>, Vincenzo Frascino <vincenzo.frascino@arm.com>, Andrew Morton <akpm@linux-foundation.org>, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v3] mempool: Do not use ksize() for poisoning Date: Tue, 25 Oct 2022 16:36:22 -0700 Message-Id: <20221025233421.you.825-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2548; h=from:subject:message-id; bh=DzRLzcBQvhCrbv8dqqugqEjPL6g0B/ORdhfzQm5GdoI=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBjWHL23XANz0fyOFVUEswQiVca2LWQjEpYhi04g7Qf yhp2li+JAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCY1hy9gAKCRCJcvTf3G3AJgJmD/ 0YsgEIllXxuFczQPOKT5OyXY2E91me/tQO8Z6Gu/9W2iMlsKclcMR9Rv4FAOtfHdgvDip4FLJOLJLc /CKVJKqpYcqOOgMNYRay9vB3WFaRROjtfbxaSRGuqYJaaKlAuMMN6SzsvGcYElMES2eZ5ehr1Z7JSv 0qXKGztFjZqHHEdCxKO4no9wkVm7H7jqcAFN8EnmfqFdTCmXdelGOjUP4QQaOG8HQzfIpTooL6O4lO GT5A3Z6HOoLpxQqP59yMR3MVnHEAMhrTnm2DtZjivUlnCGoTESBO+j6itl18bIgJyfTUIpGUbCAVT2 FNugjNDHkfvzwsObrx7H2wCEJl6IlvQhJ+3zUQD2RKOfhEhs59gKDmwWY2KvgPi7iIZLdkYG4iqYuC HdvUImlPGL34J+keBIuU5AqFua5IhXdCcbDkUuu21mtbAAjApTF5aEdGoxL7TMd1f/c/W+NHv1tIQI ZlMFK7WnxeUdJkvU2MdvWfmQQOQ8Bq4LOkNy5gVle6JSJiT8+rntb6gYRZPQ2F16KPELAwO41z8yRR pRowiBKTghX6N7f5WT7DJistKtwKeWYTPTU6rAQ39FNBx0X5jjLho1958siE1P41CmtPkIHp22AOlL sNopLfijMyInV7h6SkihdcGY+JLhZuH1blJP2c44Qzvf7Pb5St67DbTPx3mw== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747704729108068733?= X-GMAIL-MSGID: =?utf-8?q?1747704729108068733?= |
Series |
[v3] mempool: Do not use ksize() for poisoning
|
|
Commit Message
Kees Cook
Oct. 25, 2022, 11:36 p.m. UTC
Nothing appears to be using ksize() within the kmalloc-backed mempools
except the mempool poisoning logic. Use the actual pool size instead
of the ksize() to avoid needing any special handling of the memory as
needed by KASAN, UBSAN_BOUNDS, nor FORTIFY_SOURCE.
Suggested-by: Vlastimil Babka <vbabka@suse.cz>
Link: https://lore.kernel.org/lkml/f4fc52c4-7c18-1d76-0c7a-4058ea2486b9@suse.cz/
Cc: Andrey Konovalov <andreyknvl@gmail.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Marco Elver <elver@google.com>
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
v3: remove ksize() calls instead of adding kmalloc_roundup_size() calls (vbabka)
v2: https://lore.kernel.org/lkml/20221018090323.never.897-kees@kernel.org/
v1: https://lore.kernel.org/lkml/20220923202822.2667581-14-keescook@chromium.org/
---
mm/mempool.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
Comments
On 10/26/22 01:36, Kees Cook wrote: > Nothing appears to be using ksize() within the kmalloc-backed mempools > except the mempool poisoning logic. Use the actual pool size instead > of the ksize() to avoid needing any special handling of the memory as > needed by KASAN, UBSAN_BOUNDS, nor FORTIFY_SOURCE. > > Suggested-by: Vlastimil Babka <vbabka@suse.cz> > Link: https://lore.kernel.org/lkml/f4fc52c4-7c18-1d76-0c7a-4058ea2486b9@suse.cz/ > Cc: Andrey Konovalov <andreyknvl@gmail.com> > Cc: David Rientjes <rientjes@google.com> > Cc: Marco Elver <elver@google.com> > Cc: Vincenzo Frascino <vincenzo.frascino@arm.com> > Cc: Andrew Morton <akpm@linux-foundation.org> > Cc: linux-mm@kvack.org > Signed-off-by: Kees Cook <keescook@chromium.org> Acked-by: Vlastimil Babka <vbabka@suse.cz> > --- > v3: remove ksize() calls instead of adding kmalloc_roundup_size() calls (vbabka) > v2: https://lore.kernel.org/lkml/20221018090323.never.897-kees@kernel.org/ > v1: https://lore.kernel.org/lkml/20220923202822.2667581-14-keescook@chromium.org/ > --- > mm/mempool.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/mm/mempool.c b/mm/mempool.c > index 96488b13a1ef..54204065037d 100644 > --- a/mm/mempool.c > +++ b/mm/mempool.c > @@ -58,7 +58,7 @@ static void check_element(mempool_t *pool, void *element) > { > /* Mempools backed by slab allocator */ > if (pool->free == mempool_free_slab || pool->free == mempool_kfree) { > - __check_element(pool, element, ksize(element)); > + __check_element(pool, element, (size_t)pool->pool_data); > } else if (pool->free == mempool_free_pages) { > /* Mempools backed by page allocator */ > int order = (int)(long)pool->pool_data; > @@ -81,7 +81,7 @@ static void poison_element(mempool_t *pool, void *element) > { > /* Mempools backed by slab allocator */ > if (pool->alloc == mempool_alloc_slab || pool->alloc == mempool_kmalloc) { > - __poison_element(element, ksize(element)); > + __poison_element(element, (size_t)pool->pool_data); > } else if (pool->alloc == mempool_alloc_pages) { > /* Mempools backed by page allocator */ > int order = (int)(long)pool->pool_data; > @@ -112,7 +112,7 @@ static __always_inline void kasan_poison_element(mempool_t *pool, void *element) > static void kasan_unpoison_element(mempool_t *pool, void *element) > { > if (pool->alloc == mempool_alloc_slab || pool->alloc == mempool_kmalloc) > - kasan_unpoison_range(element, __ksize(element)); > + kasan_unpoison_range(element, (size_t)pool->pool_data); > else if (pool->alloc == mempool_alloc_pages) > kasan_unpoison_pages(element, (unsigned long)pool->pool_data, > false);
On 10/26/22 12:02, Vlastimil Babka wrote: > On 10/26/22 01:36, Kees Cook wrote: >> Nothing appears to be using ksize() within the kmalloc-backed mempools >> except the mempool poisoning logic. Use the actual pool size instead >> of the ksize() to avoid needing any special handling of the memory as >> needed by KASAN, UBSAN_BOUNDS, nor FORTIFY_SOURCE. >> >> Suggested-by: Vlastimil Babka <vbabka@suse.cz> >> Link: https://lore.kernel.org/lkml/f4fc52c4-7c18-1d76-0c7a-4058ea2486b9@suse.cz/ >> Cc: Andrey Konovalov <andreyknvl@gmail.com> >> Cc: David Rientjes <rientjes@google.com> >> Cc: Marco Elver <elver@google.com> >> Cc: Vincenzo Frascino <vincenzo.frascino@arm.com> >> Cc: Andrew Morton <akpm@linux-foundation.org> >> Cc: linux-mm@kvack.org >> Signed-off-by: Kees Cook <keescook@chromium.org> > > Acked-by: Vlastimil Babka <vbabka@suse.cz> Ah and since the subject was updated too, note this is supposed to replace/fixup the patch in mm-unstable: mempool-use-kmalloc_size_roundup-to-match-ksize-usage.patch >> --- >> v3: remove ksize() calls instead of adding kmalloc_roundup_size() calls (vbabka) >> v2: https://lore.kernel.org/lkml/20221018090323.never.897-kees@kernel.org/ >> v1: https://lore.kernel.org/lkml/20220923202822.2667581-14-keescook@chromium.org/ >> --- >> mm/mempool.c | 6 +++--- >> 1 file changed, 3 insertions(+), 3 deletions(-) >> >> diff --git a/mm/mempool.c b/mm/mempool.c >> index 96488b13a1ef..54204065037d 100644 >> --- a/mm/mempool.c >> +++ b/mm/mempool.c >> @@ -58,7 +58,7 @@ static void check_element(mempool_t *pool, void *element) >> { >> /* Mempools backed by slab allocator */ >> if (pool->free == mempool_free_slab || pool->free == mempool_kfree) { >> - __check_element(pool, element, ksize(element)); >> + __check_element(pool, element, (size_t)pool->pool_data); >> } else if (pool->free == mempool_free_pages) { >> /* Mempools backed by page allocator */ >> int order = (int)(long)pool->pool_data; >> @@ -81,7 +81,7 @@ static void poison_element(mempool_t *pool, void *element) >> { >> /* Mempools backed by slab allocator */ >> if (pool->alloc == mempool_alloc_slab || pool->alloc == mempool_kmalloc) { >> - __poison_element(element, ksize(element)); >> + __poison_element(element, (size_t)pool->pool_data); >> } else if (pool->alloc == mempool_alloc_pages) { >> /* Mempools backed by page allocator */ >> int order = (int)(long)pool->pool_data; >> @@ -112,7 +112,7 @@ static __always_inline void kasan_poison_element(mempool_t *pool, void *element) >> static void kasan_unpoison_element(mempool_t *pool, void *element) >> { >> if (pool->alloc == mempool_alloc_slab || pool->alloc == mempool_kmalloc) >> - kasan_unpoison_range(element, __ksize(element)); >> + kasan_unpoison_range(element, (size_t)pool->pool_data); >> else if (pool->alloc == mempool_alloc_pages) >> kasan_unpoison_pages(element, (unsigned long)pool->pool_data, >> false); >
Greeting, FYI, we noticed WARNING:at_kernel/locking/lockdep.c:#__lock_acquire due to commit (built with clang-14): commit: 216fd003b5aca1c27d62df679cd722730b886919 ("[PATCH v3] mempool: Do not use ksize() for poisoning") url: https://github.com/intel-lab-lkp/linux/commits/Kees-Cook/mempool-Do-not-use-ksize-for-poisoning/20221026-073834 base: https://git.kernel.org/cgit/linux/kernel/git/kees/linux.git for-next/pstore patch link: https://lore.kernel.org/linux-mm/20221025233421.you.825-kees@kernel.org patch subject: [PATCH v3] mempool: Do not use ksize() for poisoning in testcase: boot on test machine: qemu-system-x86_64 -enable-kvm -cpu SandyBridge -smp 2 -m 16G caused below changes (please refer to attached dmesg/kmsg for entire log/backtrace): If you fix the issue, kindly add following tag | Reported-by: kernel test robot <oliver.sang@intel.com> | Link: https://lore.kernel.org/oe-lkp/202210271449.445fce6-oliver.sang@intel.com [ 4.181184][ T1] ------------[ cut here ]------------ [ 4.181613][ T1] DEBUG_LOCKS_WARN_ON(1) [ 4.181613][ T1] WARNING: CPU: 1 PID: 1 at kernel/locking/lockdep.c:231 __lock_acquire (lockdep.c:?) [ 4.181613][ T1] Modules linked in: [ 4.181613][ T1] CPU: 1 PID: 1 Comm: swapper/0 Not tainted 6.1.0-rc1-00012-g216fd003b5ac #1 [ 4.181613][ T1] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.0-debian-1.16.0-4 04/01/2014 [ 4.181613][ T1] EIP: __lock_acquire (lockdep.c:?) [ 4.181613][ T1] Code: bd 96 00 85 c0 0f 84 b4 02 00 00 83 3d b8 c0 4c 45 00 0f 85 a7 02 00 00 68 c3 07 29 44 68 44 7b 13 44 e8 a7 53 f8 ff 83 c4 08 <0f> 0b 8b 4d f0 eb 09 6b c0 64 8d b0 10 38 71 45 8a 5e 60 b8 ff 1f All code ======== 0: bd 96 00 85 c0 mov $0xc0850096,%ebp 5: 0f 84 b4 02 00 00 je 0x2bf b: 83 3d b8 c0 4c 45 00 cmpl $0x0,0x454cc0b8(%rip) # 0x454cc0ca 12: 0f 85 a7 02 00 00 jne 0x2bf 18: 68 c3 07 29 44 pushq $0x442907c3 1d: 68 44 7b 13 44 pushq $0x44137b44 22: e8 a7 53 f8 ff callq 0xfffffffffff853ce 27: 83 c4 08 add $0x8,%esp 2a:* 0f 0b ud2 <-- trapping instruction 2c: 8b 4d f0 mov -0x10(%rbp),%ecx 2f: eb 09 jmp 0x3a 31: 6b c0 64 imul $0x64,%eax,%eax 34: 8d b0 10 38 71 45 lea 0x45713810(%rax),%esi 3a: 8a 5e 60 mov 0x60(%rsi),%bl 3d: b8 .byte 0xb8 3e: ff 1f lcall *(%rdi) Code starting with the faulting instruction =========================================== 0: 0f 0b ud2 2: 8b 4d f0 mov -0x10(%rbp),%ecx 5: eb 09 jmp 0x10 7: 6b c0 64 imul $0x64,%eax,%eax a: 8d b0 10 38 71 45 lea 0x45713810(%rax),%esi 10: 8a 5e 60 mov 0x60(%rsi),%bl 13: b8 .byte 0xb8 14: ff 1f lcall *(%rdi) [ 4.181613][ T1] EAX: 00000016 EBX: 00080000 ECX: 00000000 EDX: 00000000 [ 4.181613][ T1] ESI: 00000000 EDI: 403e0610 EBP: 40397ad0 ESP: 40397a30 [ 4.181613][ T1] DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068 EFLAGS: 00010016 [ 4.181613][ T1] CR0: 80050033 CR2: 00000000 CR3: 05654000 CR4: 00000690 [ 4.181613][ T1] Call Trace: [ 4.181613][ T1] ? __lock_acquire (lockdep.c:?) [ 4.181613][ T1] ? update_cfs_rq_load_avg (fair.c:?) [ 4.181613][ T1] ? lock_acquire (??:?) [ 4.181613][ T1] ? ___slab_alloc (slub.c:?) [ 4.181613][ T1] ? _raw_spin_lock_irqsave (??:?) [ 4.181613][ T1] ? ___slab_alloc (slub.c:?) [ 4.181613][ T1] ? __cond_resched (??:?) [ 4.181613][ T1] ? slab_pre_alloc_hook (slub.c:?) [ 4.181613][ T1] ? kmem_cache_alloc (??:?) [ 4.181613][ T1] ? mempool_alloc_slab (??:?) [ 4.181613][ T1] ? mempool_init_node (??:?) [ 4.181613][ T1] ? mempool_init (??:?) [ 4.181613][ T1] ? mempool_alloc_slab (??:?) [ 4.181613][ T1] ? bioset_init (??:?) [ 4.181613][ T1] ? mempool_alloc_slab (??:?) [ 4.181613][ T1] ? init_bio (bio.c:?) [ 4.181613][ T1] ? blkdev_init (bio.c:?) [ 4.181613][ T1] ? do_one_initcall (??:?) [ 4.181613][ T1] ? blkdev_init (bio.c:?) [ 4.181613][ T1] ? do_initcall_level (main.c:?) [ 4.181613][ T1] ? do_initcalls (main.c:?) [ 4.181613][ T1] ? do_basic_setup (main.c:?) [ 4.181613][ T1] ? kernel_init_freeable (main.c:?) [ 4.181613][ T1] ? rest_init (main.c:?) [ 4.181613][ T1] ? kernel_init (main.c:?) [ 4.181613][ T1] ? rest_init (main.c:?) [ 4.181613][ T1] ? ret_from_fork (??:?) [ 4.181613][ T1] irq event stamp: 52976 [ 4.181613][ T1] hardirqs last enabled at (52975): __schedule (core.c:?) [ 4.181613][ T1] hardirqs last disabled at (52976): _raw_spin_lock_irqsave (??:?) [ 4.181613][ T1] softirqs last enabled at (52954): __do_softirq (??:?) [ 4.181613][ T1] softirqs last disabled at (52949): do_softirq_own_stack (??:?) [ 4.181613][ T1] ---[ end trace 0000000000000000 ]--- To reproduce: # build kernel cd linux cp config-6.1.0-rc1-00012-g216fd003b5ac .config make HOSTCC=clang-14 CC=clang-14 ARCH=i386 olddefconfig prepare modules_prepare bzImage modules make HOSTCC=clang-14 CC=clang-14 ARCH=i386 INSTALL_MOD_PATH=<mod-install-dir> modules_install cd <mod-install-dir> find lib/ | cpio -o -H newc --quiet | gzip > modules.cgz git clone https://github.com/intel/lkp-tests.git cd lkp-tests bin/lkp qemu -k <bzImage> -m modules.cgz job-script # job-script is attached in this email # if come across any failure that blocks the test, # please remove ~/.lkp and /lkp dir to run from a clean state.
On Wed, Oct 26, 2022 at 1:36 AM Kees Cook <keescook@chromium.org> wrote: > > Nothing appears to be using ksize() within the kmalloc-backed mempools > except the mempool poisoning logic. Use the actual pool size instead > of the ksize() to avoid needing any special handling of the memory as > needed by KASAN, UBSAN_BOUNDS, nor FORTIFY_SOURCE. > > Suggested-by: Vlastimil Babka <vbabka@suse.cz> > Link: https://lore.kernel.org/lkml/f4fc52c4-7c18-1d76-0c7a-4058ea2486b9@suse.cz/ > Cc: Andrey Konovalov <andreyknvl@gmail.com> > Cc: David Rientjes <rientjes@google.com> > Cc: Marco Elver <elver@google.com> > Cc: Vincenzo Frascino <vincenzo.frascino@arm.com> > Cc: Andrew Morton <akpm@linux-foundation.org> > Cc: linux-mm@kvack.org > Signed-off-by: Kees Cook <keescook@chromium.org> > --- > v3: remove ksize() calls instead of adding kmalloc_roundup_size() calls (vbabka) > v2: https://lore.kernel.org/lkml/20221018090323.never.897-kees@kernel.org/ > v1: https://lore.kernel.org/lkml/20220923202822.2667581-14-keescook@chromium.org/ > --- > mm/mempool.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/mm/mempool.c b/mm/mempool.c > index 96488b13a1ef..54204065037d 100644 > --- a/mm/mempool.c > +++ b/mm/mempool.c > @@ -58,7 +58,7 @@ static void check_element(mempool_t *pool, void *element) > { > /* Mempools backed by slab allocator */ > if (pool->free == mempool_free_slab || pool->free == mempool_kfree) { > - __check_element(pool, element, ksize(element)); > + __check_element(pool, element, (size_t)pool->pool_data); > } else if (pool->free == mempool_free_pages) { > /* Mempools backed by page allocator */ > int order = (int)(long)pool->pool_data; > @@ -81,7 +81,7 @@ static void poison_element(mempool_t *pool, void *element) > { > /* Mempools backed by slab allocator */ > if (pool->alloc == mempool_alloc_slab || pool->alloc == mempool_kmalloc) { > - __poison_element(element, ksize(element)); > + __poison_element(element, (size_t)pool->pool_data); > } else if (pool->alloc == mempool_alloc_pages) { > /* Mempools backed by page allocator */ > int order = (int)(long)pool->pool_data; > @@ -112,7 +112,7 @@ static __always_inline void kasan_poison_element(mempool_t *pool, void *element) > static void kasan_unpoison_element(mempool_t *pool, void *element) > { > if (pool->alloc == mempool_alloc_slab || pool->alloc == mempool_kmalloc) > - kasan_unpoison_range(element, __ksize(element)); > + kasan_unpoison_range(element, (size_t)pool->pool_data); > else if (pool->alloc == mempool_alloc_pages) > kasan_unpoison_pages(element, (unsigned long)pool->pool_data, > false); > -- > 2.34.1 > For the KASAN change: Reviewed-by: Andrey Konovalov <andreyknvl@gmail.com> Thanks!
diff --git a/mm/mempool.c b/mm/mempool.c index 96488b13a1ef..54204065037d 100644 --- a/mm/mempool.c +++ b/mm/mempool.c @@ -58,7 +58,7 @@ static void check_element(mempool_t *pool, void *element) { /* Mempools backed by slab allocator */ if (pool->free == mempool_free_slab || pool->free == mempool_kfree) { - __check_element(pool, element, ksize(element)); + __check_element(pool, element, (size_t)pool->pool_data); } else if (pool->free == mempool_free_pages) { /* Mempools backed by page allocator */ int order = (int)(long)pool->pool_data; @@ -81,7 +81,7 @@ static void poison_element(mempool_t *pool, void *element) { /* Mempools backed by slab allocator */ if (pool->alloc == mempool_alloc_slab || pool->alloc == mempool_kmalloc) { - __poison_element(element, ksize(element)); + __poison_element(element, (size_t)pool->pool_data); } else if (pool->alloc == mempool_alloc_pages) { /* Mempools backed by page allocator */ int order = (int)(long)pool->pool_data; @@ -112,7 +112,7 @@ static __always_inline void kasan_poison_element(mempool_t *pool, void *element) static void kasan_unpoison_element(mempool_t *pool, void *element) { if (pool->alloc == mempool_alloc_slab || pool->alloc == mempool_kmalloc) - kasan_unpoison_range(element, __ksize(element)); + kasan_unpoison_range(element, (size_t)pool->pool_data); else if (pool->alloc == mempool_alloc_pages) kasan_unpoison_pages(element, (unsigned long)pool->pool_data, false);