lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2025091354-query-oblivion-9d18@gregkh>
Date: Sat, 13 Sep 2025 08:05:13 +0200
From: Greg KH <gregkh@...uxfoundation.org>
To: GuangFei Luo <luogf2025@....com>
Cc: rafael@...nel.org, dan.carpenter@...aro.org, lenb@...nel.org,
	linux-acpi@...r.kernel.org, linux-kernel@...r.kernel.org,
	linux-pm@...r.kernel.org, lkp@...el.com, sre@...nel.org,
	stable@...r.kernel.org
Subject: Re: [PATCH v3] ACPI: battery: prevent sysfs_add_battery re-entry on
 rapid events

On Sat, Sep 13, 2025 at 12:25:16AM +0800, GuangFei Luo wrote:
> Hi Greg,
> 
> Thanks for your review and suggestion.
> 
> I've updated sysfs_add_battery() to address your comment.
> The locking is now applied explicitly inside the function
> to prevent re-entry issues, while keeping the function
> self-contained for all call sites.
> 
> Patch version: v3
> 
> Thanks,
> GuangFei
> 
> v3:
>   - Modified the earlier approach: since sysfs_add_battery() is invoked
>     from multiple places, the most reliable way is to add the lock inside
>     the function itself.
>   - sysfs_remove_battery() had a similar race issue in the past, which was
>     fixed by adding a lock as well. Reference:
>     https://lore.kernel.org/all/9c921c22a7f33397a6774d7fa076db9b6a0fd669
> 	.1312318300.git.len.brown@...el.com/
> 
> v2:
>  - Fix missing mutex_unlock in acpi_battery_update()
>    (Reported-by: kernel test robot)
> 
> v1:
> When removing and reinserting the laptop battery, ACPI can trigger
> two notifications in quick succession:

Note, none of the above should be here in the changelog body, it should
be below the --- line.

> diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
> index 6905b56bf3e4..f6d4a8b39a9c 100644
> --- a/drivers/acpi/battery.c
> +++ b/drivers/acpi/battery.c
> @@ -850,6 +850,12 @@ static void __exit battery_hook_exit(void)
>  
>  static int sysfs_add_battery(struct acpi_battery *battery)
>  {
> +	mutex_lock(&battery->sysfs_lock);

Again, can you use guard() to make this logic simpler?  That would turn
this into a much smaller patch.

thanks,

greg k-h

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ