Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1385799lqd; Thu, 25 Apr 2024 14:04:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXGrDcnEvjiEGL2Cpvp306w7SV/Ueb1gvmB/S4P+rsumeas51Dka28t1rJoUQqUmVUKRVo+ABMwxUqpXqfE5Ku78cUcW6Yy4vFOEp49NA== X-Google-Smtp-Source: AGHT+IFBRognHZoChDpzont4lcRIJ0FgfVwwgDEB5+1E2wZ+Zm9tCHrQtQm6ZfalCFFm8FHWS0Oz X-Received: by 2002:a17:902:a714:b0:1e0:dc6e:45d6 with SMTP id w20-20020a170902a71400b001e0dc6e45d6mr736840plq.60.1714079077568; Thu, 25 Apr 2024 14:04:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714079077; cv=pass; d=google.com; s=arc-20160816; b=cXiqbydef2Chqpc/1ZdyupFEjBVumbXalEPnrTtO+ypNlBRK59Pp/osYxHqbfG7D/i gNNIi1nkiMLFQw5pjU6UVw0PV9n85SlVzl920uVXU98SJMmNLz0NXbd35SI5fDA4Jh6r tQZeM1WmTDnQd62PdS1J1HM8Z1n1TgwWnY3X7VuLyBuV7roYQYTVM4rgsuAcsQUNC5ZY gvcrlpBkIL8HEOXwmZuZs887TeyfMPc17lcJN58/8cuE38XjVJMZxcA+rM//U51XLUf+ LtWWlJjXok2bsf8ZrzMuOKXN/Te1qhSUtU7W9EzJITffD15MA4VwUKTaRzb0jsGJhcmZ rywg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=ISz6479faSwg2T6S4jx3WNpGT6tzmgyY9eqAE3NqtuI=; fh=KQuHqREAW5SqLH6Gmq7C60MUEI4572+RpWapaWaWToY=; b=YOizrTaH2I8w4ji9AjP3gCfoKKuSm5jFfhY5oiNz9nm3BopMO1ZYG6vp1nuqAperEi Cu2XLmYLkqXabzOcYVlUvNOg+1TaMr31a0jk0sg9yf8RNRfmpa+SVYY4wIbnm7HGhxfy fD2/GHosT64ecDEgmhhjAhCaOWzPMcdhlLH7K9BOhCqQOsqRoGDzaJiw3chtxY+E8nGj +ZhkZGXv1MRuU5ShBfaee6evqmfWWdYeirAASS59TK/DA153ykK35qJN0ogYEtirLgbr Chcg9Q71DEsiKdVZHpgbzlzoxeEUr6T9cRBUXGZT2RINZbWivzjy3+fQSpAL5MSM/Yng eK4A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=CaJ1lSq+; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-159171-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159171-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id p17-20020a170902f09100b001e014db7dafsi12977353pla.163.2024.04.25.14.04.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 14:04:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-159171-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=CaJ1lSq+; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-159171-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159171-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 47480B26B87 for ; Thu, 25 Apr 2024 20:55:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 18547154BFC; Thu, 25 Apr 2024 20:55:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="CaJ1lSq+" Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (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 BD526AD2D for ; Thu, 25 Apr 2024 20:55:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714078527; cv=none; b=ehH4xNYw15tciZb9R/mOU/4V1U2o+dvbDCdvuIjOCylIwgSWGL6ZlLLA4ioI+5qf1LJx3TAg+1TrdYSXHeZe21sEpKND4c9gCUMq0rUads8XVhIUlcfVrwmxfExpJ5ueZNMXsTKFh4xkwdh9ZZe7/aji5fSpACGhz+jZO1CCvKU= 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.216.41 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 Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2ab791bce6fso1069140a91.1 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=fjWF3SnidlxYSZmv7MYa1qWot5I+ClCxq/4xKnZmFCy1Csyx48XSMkoRt8dpgyAYy7 RmA0JdbZGomW7fCgc5VDqLgGzUT5/BR1NPwkrxClMwQQ3iIuZTJvFudKVHNEMXkDgPyd aO6ZXGzjYcPZwqNqfrCiuTVw14jhS6VMXQdPh+PU4gNHH9AFezh98hMs+LCGY3jVOWl/ +ScMXi3va99Lvl/iWXQ4gMotwvRUGL1356eLi3S6U4oLX2KFFCBVKEY+xSS1vbmm2Tdb 2L8lLyjXbsu+UcVDFe04y6arl425E7rFfFhWOjyMRK3J1RTBMj8B1/GI+SsGotY5PT2H wJbg== X-Forwarded-Encrypted: i=1; AJvYcCXvzuMLCSos7q8Cj4cxW8FvQ1qRFxhjYK9bbDlmI2K8D0wmJbtFF66V5czyn7BA9FQSNDoqvN4zgGUBZVeII/K3/ymjJzJULTbJCsRQ X-Gm-Message-State: AOJu0YxsXQ7KdCpHjC0ymiS/bM+BIOtwhCalaJpK/j5fPUjswYcJeuJb JQteaClgpZHqFbT+YLyYtzi1G7TgHLAN1QoAu37VCKwLJbnRoEVfM1PU0nyOZQ== 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-kernel@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 Content-Transfer-Encoding: 8bit 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 --- 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) -- 2.34.1