From: Mariusz Kozlowski <mk@lab.zgora.pl>
To: Len Brown <lenb@kernel.org>
Cc: Kyle McMartin <kyle@redhat.com>,
linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org,
Mariusz Kozlowski <mk@lab.zgora.pl>
Subject: [PATCH] ACPI battery: fix possible use after free in acpi_battery_add()
Date: Sat, 26 Mar 2011 19:18:26 +0100 [thread overview]
Message-ID: <1301163506-7236-1-git-send-email-mk@lab.zgora.pl> (raw)
When acpi_battery_add_fs() fails 'battery' will be kfreed and then
used again.
Signed-off-by: Mariusz Kozlowski <mk@lab.zgora.pl>
---
drivers/acpi/battery.c | 15 ++++++---------
1 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index fcc13ac..27375e7 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -978,18 +978,15 @@ static int acpi_battery_add(struct acpi_device *device)
acpi_battery_update(battery);
#ifdef CONFIG_ACPI_PROCFS_POWER
result = acpi_battery_add_fs(device);
-#endif
- if (!result) {
- printk(KERN_INFO PREFIX "%s Slot [%s] (battery %s)\n",
- ACPI_BATTERY_DEVICE_NAME, acpi_device_bid(device),
- device->status.battery_present ? "present" : "absent");
- } else {
-#ifdef CONFIG_ACPI_PROCFS_POWER
+ if (result) {
acpi_battery_remove_fs(device);
-#endif
kfree(battery);
+ return result;
}
-
+#endif
+ printk(KERN_INFO PREFIX "%s Slot [%s] (battery %s)\n",
+ ACPI_BATTERY_DEVICE_NAME, acpi_device_bid(device),
+ device->status.battery_present ? "present" : "absent");
battery->pm_nb.notifier_call = battery_notify;
register_pm_notifier(&battery->pm_nb);
--
1.7.0.4
reply other threads:[~2011-03-26 18:18 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1301163506-7236-1-git-send-email-mk@lab.zgora.pl \
--to=mk@lab.zgora.pl \
--cc=kyle@redhat.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®