From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 58F3826C3A0; Fri, 30 May 2025 12:41:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748608883; cv=none; b=iMUIA041BrsQqjtgnNAOCN+S4lIxb/gsyUHA980Z0FMnB1wvBhFcI57cSsIW4Ct2iBNxzKgeeZ7yNc5+G8opM98yRuygXsB6LLVkcsF6SRdm4oCxRH357OGBceCT421Jf8/x2INXX8vHf2cpwyuwy6uOWHE+hvIVf3y70qnSLVk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748608883; c=relaxed/simple; bh=7Rao4ioxGqiBh9nwmLmh0IwTV5dELYXBN6GpPuGKPhc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=kpIdrdyVrbw6QskPUbl6VUu6mDdYhF8p5mOr8eJx9Wwdy+xAUyeqrZvwo2en3QHzP35TOw5SgP41kaVtxWkbNKUGEO3kOiQtVlrkqg0Sp4V9p4zn3opYWkm6lnN56crpd+hCCwX7XCPgmr2MK69XUg+esbgp6cKO7isXnDBDkLY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BMQlnUqK; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BMQlnUqK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0BDDC4CEEF; Fri, 30 May 2025 12:41:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1748608882; bh=7Rao4ioxGqiBh9nwmLmh0IwTV5dELYXBN6GpPuGKPhc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BMQlnUqK3EVepNM/dobzupNPfxXGlK55Tq3/i4xY1GGEjsoyyj5WsMxQYcx0hHtRi LujCzYaRvFG+f2Wpi7V8kDfTTjdFn4w0Hm7lrRjVG9VOzuOwLsW+rrHNLyXxB7ar1S ngXz6gLpYc33oK40GvLxQnJG3IVA8ENuUcw4VI6jAj9ulu6MseTkxnmGYh0VjdD7fJ oRjmoE+k0IGVajR1djwLAge17KQtf7lyIW91Wr8Sm/nLrC7RNcvPADRrGWNY4NfqL0 Yh6fbwI3+BD09PQ6yR9GI+kbGUESH9D1fNaATCCiuQ6/UVVvPqmIReI0jXkX4A/Xpl m7xIK4IOMKlAw== From: Sasha Levin To: patches@lists.linux.dev, stable@vger.kernel.org Cc: Armin Wolf , "Rafael J . Wysocki" , Sasha Levin , rjw@rjwysocki.net, lenb@kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH AUTOSEL 6.1 07/13] ACPI: bus: Bail out if acpi_kobj registration fails Date: Fri, 30 May 2025 08:41:06 -0400 Message-Id: <20250530124112.2576343-7-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250530124112.2576343-1-sashal@kernel.org> References: <20250530124112.2576343-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.1.140 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Armin Wolf [ Upstream commit 94a370fc8def6038dbc02199db9584b0b3690f1a ] The ACPI sysfs code will fail to initialize if acpi_kobj is NULL, together with some ACPI drivers. Follow the other firmware subsystems and bail out if the kobject cannot be registered. Signed-off-by: Armin Wolf Link: https://patch.msgid.link/20250518185111.3560-2-W_Armin@gmx.de Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- **YES** This commit should be backported to stable kernel trees. Here's my extensive analysis: ## Code Change Analysis The commit changes the behavior in `acpi_init()` when `kobject_create_and_add("acpi", firmware_kobj)` fails: **Before:** - If `acpi_kobj` creation fails, only prints a debug message and continues execution - The function proceeds to initialize ACPI subsystems with a NULL `acpi_kobj` - This leads to potential crashes/failures in other ACPI components **After:** - If `acpi_kobj` creation fails, prints an error message and returns `-ENOMEM` - Prevents initialization of ACPI subsystems with a NULL `acpi_kobj` - Follows proper error handling patterns ## Evidence from Kernel Code Investigation From examining the kernel repository, I found multiple critical usages of `acpi_kobj` that would fail catastrophically if it's NULL: 1. **drivers/acpi/sysfs.c:514**: `kobject_create_and_add("tables", acpi_kobj)` - NULL parent causes undefined behavior 2. **drivers/acpi/sysfs.c:924**: `sysfs_create_group(acpi_kobj, &interrupt_stats_attr_group)` - NULL kobject crashes 3. **drivers/acpi/platform_profile.c**: Multiple `sysfs_notify(acpi_kobj, ...)` calls that would crash with NULL 4. **drivers/acpi/platform_profile.c**: `sysfs_create_group(acpi_kobj, &platform_profile_group)` would fail ## Backport Criteria Assessment ✅ **Fixes a real bug**: Yes - prevents crashes when kobject creation fails ✅ **Small and contained**: Yes - only 4 lines changed in one function ✅ **Clear side effects**: Yes - prevents ACPI initialization on memory allocation failure ✅ **No architectural changes**: Yes - just proper error handling ✅ **Critical subsystem**: Yes - ACPI is core kernel infrastructure ✅ **Minimal regression risk**: Yes - only affects rare failure path ✅ **Follows stable rules**: Yes - important bugfix with minimal risk ## Comparison with Historical Examples This commit closely matches **Similar Commit #1** (Status: YES) which also: - Fixed error handling in ACPI initialization code - Added proper cleanup/error handling when kobject operations fail - Was considered suitable for backporting The commit differs significantly from the "NO" examples which were: - Code cleanup/style changes (Similar Commits #2, #3, #4) - Refactoring without fixing actual bugs (Similar Commit #4) ## Risk Assessment **Low Risk**: The change only affects the extremely rare case where `kobject_create_and_add()` fails due to memory allocation failure. In such cases: - **Current behavior**: System continues with broken ACPI, leading to crashes - **New behavior**: ACPI initialization fails cleanly, system may still boot without ACPI ## Conclusion This is a critical bug fix that prevents crashes in ACPI subsystems when memory allocation fails during boot. It transforms undefined behavior/crashes into clean failure handling, making it an ideal candidate for stable backporting. drivers/acpi/bus.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index a16b7de73d164..fafa15507b141 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -1389,8 +1389,10 @@ static int __init acpi_init(void) } acpi_kobj = kobject_create_and_add("acpi", firmware_kobj); - if (!acpi_kobj) - pr_debug("%s: kset create error\n", __func__); + if (!acpi_kobj) { + pr_err("Failed to register kobject\n"); + return -ENOMEM; + } init_prmt(); acpi_init_pcc(); -- 2.39.5