From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Lv Zheng <lv.zheng@intel.com>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
Len Brown <len.brown@intel.com>, Corey Minyard <minyard@acm.org>,
Zhao Yakui <yakui.zhao@intel.com>,
linux-kernel@vger.kernel.org, stable@vger.kernel.org,
linux-acpi@vger.kernel.org,
openipmi-developer@lists.sourceforge.net
Subject: Re: [PATCH 03/13] ACPI/IPMI: Fix race caused by the unprotected ACPI IPMI transfers
Date: Thu, 25 Jul 2013 01:38:15 +0200 [thread overview]
Message-ID: <1520893.BbRK6T3F73@vostro.rjw.lan> (raw)
In-Reply-To: <970a8a7108e4c95ce09e34eee03eb5731645729f.1374566394.git.lv.zheng@intel.com>
On Tuesday, July 23, 2013 04:09:15 PM Lv Zheng wrote:
> This patch fixes races caused by unprotected ACPI IPMI transfers.
>
> We can see the following crashes may occur:
> 1. There is no tx_msg_lock held for iterating tx_msg_list in
> ipmi_flush_tx_msg() while it is parellel unlinked on failure in
> acpi_ipmi_space_handler() under protection of tx_msg_lock.
> 2. There is no lock held for freeing tx_msg in acpi_ipmi_space_handler()
> while it is parellel accessed in ipmi_flush_tx_msg() and
> ipmi_msg_handler().
>
> This patch enhances tx_msg_lock to protect all tx_msg accesses to solve
> this issue. Then tx_msg_lock is always held around complete() and tx_msg
> accesses.
> Calling smp_wmb() before setting msg_done flag so that messages completed
> due to flushing will not be handled as 'done' messages while their contents
> are not vaild.
>
> Signed-off-by: Lv Zheng <lv.zheng@intel.com>
> Cc: Zhao Yakui <yakui.zhao@intel.com>
> Reviewed-by: Huang Ying <ying.huang@intel.com>
> ---
> drivers/acpi/acpi_ipmi.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/acpi/acpi_ipmi.c b/drivers/acpi/acpi_ipmi.c
> index b37c189..527ee43 100644
> --- a/drivers/acpi/acpi_ipmi.c
> +++ b/drivers/acpi/acpi_ipmi.c
> @@ -230,11 +230,14 @@ static void ipmi_flush_tx_msg(struct acpi_ipmi_device *ipmi)
> struct acpi_ipmi_msg *tx_msg, *temp;
> int count = HZ / 10;
> struct pnp_dev *pnp_dev = ipmi->pnp_dev;
> + unsigned long flags;
>
> + spin_lock_irqsave(&ipmi->tx_msg_lock, flags);
> list_for_each_entry_safe(tx_msg, temp, &ipmi->tx_msg_list, head) {
> /* wake up the sleep thread on the Tx msg */
> complete(&tx_msg->tx_complete);
> }
> + spin_unlock_irqrestore(&ipmi->tx_msg_lock, flags);
>
> /* wait for about 100ms to flush the tx message list */
> while (count--) {
> @@ -268,13 +271,12 @@ static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data)
> break;
> }
> }
> - spin_unlock_irqrestore(&ipmi_device->tx_msg_lock, flags);
>
> if (!msg_found) {
> dev_warn(&pnp_dev->dev,
> "Unexpected response (msg id %ld) is returned.\n",
> msg->msgid);
> - goto out_msg;
> + goto out_lock;
> }
>
> /* copy the response data to Rx_data buffer */
> @@ -286,10 +288,14 @@ static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data)
> }
> tx_msg->rx_len = msg->msg.data_len;
> memcpy(tx_msg->data, msg->msg.data, tx_msg->rx_len);
> + /* tx_msg content must be valid before setting msg_done flag */
> + smp_wmb();
That's suspicious.
If you need the write barrier here, you'll most likely need a read barrier
somewhere else. Where's that?
> tx_msg->msg_done = 1;
>
> out_comp:
> complete(&tx_msg->tx_complete);
> +out_lock:
> + spin_unlock_irqrestore(&ipmi_device->tx_msg_lock, flags);
> out_msg:
> ipmi_free_recv_msg(msg);
> }
Rafael
--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
next prev parent reply other threads:[~2013-07-24 23:28 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1370652213.git.lv.zheng@intel.com>
2013-07-23 8:08 ` [PATCH 00/13] ACPI/IPMI: Fix several issues in the current codes Lv Zheng
2013-07-23 8:08 ` [PATCH 01/13] ACPI/IPMI: Fix potential response buffer overflow Lv Zheng
2013-07-23 14:54 ` Greg KH
2013-07-24 0:21 ` Zheng, Lv
2013-07-24 0:44 ` Zheng, Lv
2013-07-23 8:09 ` [PATCH 02/13] ACPI/IPMI: Fix atomic context requirement of ipmi_msg_handler() Lv Zheng
2013-07-23 8:09 ` [PATCH 03/13] ACPI/IPMI: Fix race caused by the unprotected ACPI IPMI transfers Lv Zheng
2013-07-24 23:38 ` Rafael J. Wysocki [this message]
2013-07-25 3:09 ` Zheng, Lv
2013-07-25 12:06 ` Rafael J. Wysocki
2013-07-25 18:12 ` Corey Minyard
2013-07-25 19:32 ` Rafael J. Wysocki
2013-07-26 0:18 ` Zheng, Lv
2013-07-26 0:16 ` Zheng, Lv
2013-07-26 0:48 ` Corey Minyard
2013-07-26 1:30 ` Zheng, Lv
2013-07-26 0:09 ` Zheng, Lv
2013-07-23 8:09 ` [PATCH 04/13] ACPI/IPMI: Fix race caused by the unprotected ACPI IPMI user Lv Zheng
2013-07-25 21:59 ` Rafael J. Wysocki
2013-07-26 1:17 ` Zheng, Lv
2013-07-23 8:09 ` [PATCH 05/13] ACPI/IPMI: Fix issue caused by the per-device registration of the IPMI operation region handler Lv Zheng
2013-07-23 8:09 ` [PATCH 06/13] ACPI/IPMI: Add reference counting for ACPI operation region handlers Lv Zheng
2013-07-25 20:27 ` Rafael J. Wysocki
2013-07-26 0:47 ` Zheng, Lv
2013-07-26 8:09 ` Zheng, Lv
2013-07-26 14:00 ` Rafael J. Wysocki
2013-07-29 1:43 ` Zheng, Lv
2013-07-25 21:29 ` Rafael J. Wysocki
2013-07-26 1:54 ` Zheng, Lv
2013-07-26 8:15 ` Zheng, Lv
2013-07-26 14:49 ` Rafael J. Wysocki
2013-07-29 1:56 ` Zheng, Lv
2013-07-23 8:09 ` [PATCH 07/13] ACPI/IPMI: Add reference counting for ACPI IPMI transfers Lv Zheng
2013-07-25 22:23 ` Rafael J. Wysocki
2013-07-26 1:21 ` Zheng, Lv
2013-07-26 13:41 ` Rafael J. Wysocki
2013-07-23 8:10 ` [PATCH 08/13] ACPI/IPMI: Cleanup several acpi_ipmi_device members Lv Zheng
2013-07-25 22:25 ` Rafael J. Wysocki
2013-07-26 1:25 ` Zheng, Lv
2013-07-26 13:38 ` Rafael J. Wysocki
2013-07-29 1:12 ` Zheng, Lv
2013-07-23 8:10 ` [PATCH 09/13] ACPI/IPMI: Cleanup some initialization codes Lv Zheng
2013-07-23 8:10 ` [PATCH 10/13] ACPI/IPMI: Cleanup some inclusion codes Lv Zheng
2013-07-23 8:10 ` [PATCH 11/13] ACPI/IPMI: Cleanup some Kconfig codes Lv Zheng
2013-07-23 8:10 ` [PATCH 12/13] Testing: Add module load/unload test suite Lv Zheng
2013-07-23 8:10 ` [PATCH 13/13] ACPI/IPMI: Add IPMI operation region test device driver Lv Zheng
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=1520893.BbRK6T3F73@vostro.rjw.lan \
--to=rjw@sisk.pl \
--cc=len.brown@intel.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lv.zheng@intel.com \
--cc=minyard@acm.org \
--cc=openipmi-developer@lists.sourceforge.net \
--cc=rafael.j.wysocki@intel.com \
--cc=stable@vger.kernel.org \
--cc=yakui.zhao@intel.com \
/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®