From patchwork Thu Apr 25 20:55:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13643751 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C90F1153811 for ; Thu, 25 Apr 2024 20:55:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714078527; cv=none; b=edNL1KhNKQgPFxeN8ZleygUuquoaevYHyCTKYYHjOUpO10HBP1mjTIXzySFO2ZCCbCvG0hMiIGO4qIajObTX3cVpLGI6dxDbEWq/0AqzLZTlCV7wEVBeShIa+py7YCVChMoPskB0+EjnDA3N9FWttzFqojmUFJMMIKpK65KtAkk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714078527; c=relaxed/simple; bh=wgzxsbZYA35UmV3+kDlEwfXFaeOy97jxAsm3UECTe0s=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=rfCSqK17xTQ1i7xIJfAGYiNNqqHJ5IjIRqwg52icpegO6wHwHssC448V52exwyOLfQnCraFlGdzA2FKMHtUaeIQpzmndFUj2rUQCXnknk9faAQYdiRaJvJB/GfaMPlOGr8LyoQOuBK8qvlADmeSrs6ppyDHHWsAu/aScf01VCWw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=CaJ1lSq+; arc=none smtp.client-ip=209.85.215.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="CaJ1lSq+" Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-5d8b887bb0cso1198916a12.2 for ; Thu, 25 Apr 2024 13:55:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1714078525; x=1714683325; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ISz6479faSwg2T6S4jx3WNpGT6tzmgyY9eqAE3NqtuI=; b=CaJ1lSq+Gqzw4/LuxmkVsFvpwIdsIGo9M6Yf+Bd92mSxeEjrBMyh3e6Q69/BHMCeY4 hgMpb4ZlKGaWJuhxt5Zr+6hPR4SBa++Wz5AZlui54vm5NCMdtfDA1NGvCvTLTWiyPHI6 gDMq5majUry4ndbAJwiZ5t+ulVVeOmjJBVCnU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714078525; x=1714683325; 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=ISz6479faSwg2T6S4jx3WNpGT6tzmgyY9eqAE3NqtuI=; b=MPbJqvAhlrsGWuV3NPeS3NhDrvUmqX8pCf8GQm+IWf/jSuwI7vPwcoHVsOzPOie1VW e+1FAKEt1ZPNcgrWCAbkr6IgQK9WLKpU9jLF5BnP+w1MvOve3XrU4uvVsciqj/xWhp7n cYdakOINdtTE0A7Q07Zu9lecmaBluFzStZmn12EHlzJL0UrpgV6XVRZVFqAn2Hr+0Ag9 Ylp1LUtJtkhVwRmDbqj5qQ3LSJkxeg1nM9GSEXpV/y1UAOt5giHrZdkAG6vgi54O1su5 lStbDt57cuzzmEsciQRgFH2eiKrC4dAHzms565aZNmHmcti3PuWa1S4l5I/a4Tm6f6gX adxA== X-Forwarded-Encrypted: i=1; AJvYcCWZXCInvQ+CskRHkEkCODpvFRxtd//Byq9HpgOcLUG6hLIdLR4NTe1zfL197eo/7X8f0Akli8nRbnEocA48iqS9F1sQtK02Am+bkIu7E81x X-Gm-Message-State: AOJu0YynSubAJcRlTN/4vcUzQ+XBLJMpw07xiEoFYtrXpXI8ocnfYpUL BoT5jWM4OKpFhESXj4K0X3FcrTrvBgWyA6Ol14zF4j+F0u0wynEfrhto/dkZ/A== X-Google-Smtp-Source: AGHT+IGuak1A5s4buRECAohF0iWefXrhA28ayIjCoI5pRSndED0RKVF3MGtMAQ81PA5K/hyZWPPbQg== X-Received: by 2002:a17:90a:654c:b0:2ac:dbec:2d6f with SMTP id f12-20020a17090a654c00b002acdbec2d6fmr783550pjs.39.1714078525060; Thu, 25 Apr 2024 13:55:25 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id cn19-20020a17090af09300b002a2b06ce909sm14996316pjb.17.2024.04.25.13.55.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 13:55:24 -0700 (PDT) From: Kees Cook To: Suren Baghdasaryan Cc: Kees Cook , Kent Overstreet , Catalin Marinas , Andrew Morton , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Vlastimil Babka , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH] mm/slub: Avoid recursive loop with kmemleak Date: Thu, 25 Apr 2024 13:55:23 -0700 Message-Id: <20240425205516.work.220-kees@kernel.org> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2235; i=keescook@chromium.org; h=from:subject:message-id; bh=wgzxsbZYA35UmV3+kDlEwfXFaeOy97jxAsm3UECTe0s=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBmKsM6HVptwlfHLpIq5pI6IWcjLcoSkU3RtMyDq ARbu9SC/s2JAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZirDOgAKCRCJcvTf3G3A JuDSEAC0l2PUgYlxj4pnnLraH/55sLfoMFhtLob3K/MWGueyTyye50pQtaI15ClOF/OhkH+MqSK rzq16NGHmNk78CCUeoVXnLRz9PDmsolxQD9MigPFQP6eKHIK5hFcWhPCR5ijm7oZf9bPp1jTOYa dlVKyNyeuZek6H1+X90JoyTdyg7UT9ls3CRTTRV8aGcBUtxlG+QsWB6atAvQRpPggUqSovoR/CJ 8Y6GBikQb/3K85EQNcSwFF1cL63srGhveek31TGCFAF24rPFhbzyH4qS58OOW0R7tBjnESSQJTr XXmlqcmRWv/eWjNtTjcJD7R4Fw6iBhUelgzjDMsXw6wtGiV89VGe5wXxC8KheuUfihbSGwQAVdZ EH2koc3B9KhvYljNjnUQroDA3BASbFktma2rYYcScRfDi80Vnpt8/1OYjtqFj9wOLx4RF23WfXQ dOBKxl+1oxl4icrWM9Fw7jfXr4w00CMTwXYDYqrKRm4AQ3pl8gYFEwDUiPDxKpoHs0j5OKrGGNA aK3HASaKRX7fb6aMPPqsfg3fdiCk/rhiLzVCk7KbjibPt1r4nhpPwTe3Giu31YIdYbYKFCji2ZP plrAm71N0FQ2N/FetOqaIoPsvbc2H4NzOu8ysPNslnEFA7Z+Fp+MnCYzu/VJi0jjB7mSIN9ZynJ +ysUJzG Op1iR2+w== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 The system will immediate fill up stack and crash when both CONFIG_DEBUG_KMEMLEAK and CONFIG_MEM_ALLOC_PROFILING are enabled. Avoid allocation tagging of kmemleak caches, otherwise recursive allocation tracking occurs. Fixes: 279bb991b4d9 ("mm/slab: add allocation accounting into slab allocation and free paths") Signed-off-by: Kees Cook Acked-by: Catalin Marinas --- Cc: Suren Baghdasaryan Cc: Kent Overstreet Cc: Catalin Marinas Cc: Andrew Morton Cc: Christoph Lameter Cc: Pekka Enberg Cc: David Rientjes Cc: Joonsoo Kim Cc: Vlastimil Babka Cc: Roman Gushchin Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com> Cc: linux-mm@kvack.org --- mm/kmemleak.c | 4 ++-- mm/slub.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index c55c2cbb6837..fdcf01f62202 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -463,7 +463,7 @@ static struct kmemleak_object *mem_pool_alloc(gfp_t gfp) /* try the slab allocator first */ if (object_cache) { - object = kmem_cache_alloc(object_cache, gfp_kmemleak_mask(gfp)); + object = kmem_cache_alloc_noprof(object_cache, gfp_kmemleak_mask(gfp)); if (object) return object; } @@ -947,7 +947,7 @@ static void add_scan_area(unsigned long ptr, size_t size, gfp_t gfp) untagged_objp = (unsigned long)kasan_reset_tag((void *)object->pointer); if (scan_area_cache) - area = kmem_cache_alloc(scan_area_cache, gfp_kmemleak_mask(gfp)); + area = kmem_cache_alloc_noprof(scan_area_cache, gfp_kmemleak_mask(gfp)); raw_spin_lock_irqsave(&object->lock, flags); if (!area) { diff --git a/mm/slub.c b/mm/slub.c index a94a0507e19c..9ae032ed17ed 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2016,7 +2016,7 @@ prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p) if (!p) return NULL; - if (s->flags & SLAB_NO_OBJ_EXT) + if (s->flags & (SLAB_NO_OBJ_EXT | SLAB_NOLEAKTRACE)) return NULL; if (flags & __GFP_NO_OBJ_EXT)