From nobody Fri Aug 14 15:49:21 2026 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (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 6AE484749FF for ; Fri, 14 Aug 2026 13:40:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786714828; cv=none; b=as1tGUcwfeaLv/Wp0EPtHlVZTDppZ+VaSlg8QSuVqqW0ICQzU1frcnvV/AyME8u2Cs8QUBbymvzYSg7+7K65pGtH6OibrBMJokIzkVpoGfYIUnwsmBXqORqC/lH0jqVi5Zqm1urEtrkIEh/CuV0hbeJ8/zTy2XPWTDTYP4mp17o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786714828; c=relaxed/simple; bh=I0ehPNrXJOJkMeTxKViwPYPFiiyE4jE0P6GPf6p2P9M=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=XiNz2wTzKMp4adk17C0q8AiF3qd/HZ87bsmIT1/QO0HrcbGBc5pBe8DMWV2XKAi4e2JJ76K1Np7Div+4XODgKTPBnC7uL5HWYmP8VjqAjNYiuO7kj4JfYf7uTejTa/+n1MAggX5DbrJAs9bCgGQTqCeJ2ZuMRLYed3CQZutrIws= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dBlujz+8; arc=none smtp.client-ip=209.85.210.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dBlujz+8" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-84830c774a0so868298b3a.1 for ; Fri, 14 Aug 2026 06:40:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786714827; x=1787319627; 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:content-type; bh=pJeUUwL/0Zl20dgmzl6BoaeGKZrww8etqxc3eB5Gpwk=; b=dBlujz+8XYm2h+Xp2dp/02T723qTJXHNRAMMP9sM9IWhAbJOnsWVZrDRX3A5HljcC8 GFv3qGTLaQGXn7y8HWzm7+VtXIdI0g8ENyRNAHiPc2+6vvtH14rZ57mOLX6a679RW+La UXQymzFCkTQoWRAa8MG/6v8ZPssnUWmtvucXVpLSqeWM29HS0L7rO6NnBQA2VRerT8/F 3NIlbFWojRHyCUdrcCFxatJ4Uz77Vq73WDy3+v6sG1ilOZc8ydMBow2Un8N86p6iSRLW tzM2TAmtlY2lsAaBqhmYbgRvGMxBnD6qMjvh9wws/kFXf7ROByFgMPpyowTjo+GLUbmL HKkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786714827; x=1787319627; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=pJeUUwL/0Zl20dgmzl6BoaeGKZrww8etqxc3eB5Gpwk=; b=pw3LFwJ3fCBrtYQPcOb2mLUND7W1k1whtZPwxI6GCt54CmD/js+FbGycGaarZC2d8K YZd9jqZ8DNvQscXyy46668nV8DZ8P8jzMXszvO6nl39UK++7X//FzSEHDkhxucuegKF4 27tYH90UG7nPY7JR3Bdx9Mxxiy8v9lIftsxbmYhyw0Cp1BnV1gLRkgjUuN19IyAm2Can MSm9ulMrUlFtYeZGvxl9BPBstuqykARtaUFk1+4UYgQjfF+2XFDxb5DwM+0f+BqHD46o wewibdqfwysfTZ2A/sXdJG9ia8hsl0thLr8c5CIyd5sHaR8zObv1sVGVAM+xcREBzDiR XYag== X-Forwarded-Encrypted: i=1; AHgh+RopB9LQ0P29Iv3hOJWM/zIKnLGjBYEMFwtRToUg4bDji8mbPDj0QwvjqBIUepNI53bsl6ntRij8rsYFMAc=@vger.kernel.org X-Gm-Message-State: AOJu0YzykUaf9llstRzl0cdefBvnJP+T/Cz5rQnGWrqMppsmdEO7K3Fh iinv5FpQ8yYb0nkKdHUQjPRa0IIx19AxhX3VuX+8ylTMe6dtS2qfWXWa X-Gm-Gg: AR+sD12lvQEz+9iz2KMDzS6xMUWG1OT2GyldcZo7KNzJtmJvgww8uoJh//9YOuKFN6K 8MLtNX4y1MQGbV8LCHTGDQwByt7oWx3EYmgSIFvn/JtQr40/T5UAfM3RaSnwQ+zEPIrRmvsqyFs 7O4gG9WnqUajJ9xg7HXOBWyR39r5Pw82Fih8tq7N+F1cMjc16g4PxFH6y/tv0YtgB/Ib7yRZgN/ uYw6BXYND1zDNpUX6+qAI3kj6CIfzCZARcyzUIqUk9A/VotWs8THZ/BqpKCR5FWAFKDo7u5Ve57 dOSwHioj/kpJGdxe5Ip5QinMSvThqrPVk4rYBoRbrVsGcyGUV1pVnHmq6J+b9llX5RPQyfvCKAP X6JgXT+sPMFa4lO2U/QmFfeE75k613C/E14qgaIjNmTecDRUqAmnPuMufBf3/eGHubnYxh46JQM v3xQdwj8jfuaBtis3Vxlg6GXbEuLxfmePlCHmNcsHodkFayiwNYP/PGjuZRCAoyTuxtCS6ZhWVH z1qwqeR8n3qEvT9avI= X-Received: by 2002:a05:6a00:4193:b0:847:9315:fb8b with SMTP id d2e1a72fcca58-84fde1500e7mr6682127b3a.6.1786714826670; Fri, 14 Aug 2026 06:40:26 -0700 (PDT) Received: from haichao.tail057a43.ts.net ([2001:da8:e000:1206:e9af:7c0e:be31:2c3f]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-cc08f388356sm659953a12.2.2026.08.14.06.40.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Aug 2026 06:40:26 -0700 (PDT) From: Ruoyu Wang To: Jarkko Sakkinen , Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" Cc: x86@kernel.org, linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org, Ruoyu Wang Subject: [PATCH] x86/sgx: Drop enclave reference on MMU notifier registration failure Date: Fri, 14 Aug 2026 21:40:20 +0800 Message-ID: <20260814134020.1386599-1-ruoyuw560@gmail.com> X-Mailer: git-send-email 2.51.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Each sgx_encl_mm instance holds an enclave reference so the enclave outlives its MMU notifier. sgx_encl_mm_add() acquires that reference before calling __mmu_notifier_register(). Notifier registration can fail while allocating subscription state or when mm_take_all_locks() is interrupted. In that case no notifier or mm_list entry takes ownership of encl_mm. The error path frees encl_mm but leaves the enclave reference behind, preventing the enclave and its resources from being released. Drop the enclave reference before freeing the unpublished encl_mm. This balances the acquisition without changing the successful registration and teardown paths. This issue was found by a static analysis checker and confirmed by manual source review. Fixes: 2ade0d60939b ("x86/sgx: Maintain encl->refcount for each encl->mm_li= st entry") Signed-off-by: Ruoyu Wang --- arch/x86/kernel/cpu/sgx/encl.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c index 3f0222d10f6e6..04fbf7e703e1e 100644 --- a/arch/x86/kernel/cpu/sgx/encl.c +++ b/arch/x86/kernel/cpu/sgx/encl.c @@ -866,6 +866,7 @@ int sgx_encl_mm_add(struct sgx_encl *encl, struct mm_st= ruct *mm) =20 ret =3D __mmu_notifier_register(&encl_mm->mmu_notifier, mm); if (ret) { + kref_put(&encl->refcount, sgx_encl_release); kfree(encl_mm); return ret; } --=20 2.51.0