* [PATCH] ipmi: code cleanup and prevent potential issue.
@ 2020-06-09 6:04 wu000273
2020-06-09 12:18 ` Corey Minyard
0 siblings, 1 reply; 2+ messages in thread
From: wu000273 @ 2020-06-09 6:04 UTC (permalink / raw)
To: kjlu
Cc: wu000273, Corey Minyard, Arnd Bergmann, Greg Kroah-Hartman,
openipmi-developer, linux-kernel
From: Qiushi Wu <wu000273@umn.edu>
All the previous get/put operations against intf->refcount are
inside the mutex. Thus, put the last kref_put() also inside mutex
to make sure get/put functions execute in order and prevent the
potential race condition.
Signed-off-by: Qiushi Wu <wu000273@umn.edu>
---
drivers/char/ipmi/ipmi_msghandler.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index e1b22fe0916c..d34343e34272 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -2583,10 +2583,11 @@ static int __bmc_get_device_id(struct ipmi_smi *intf, struct bmc_device *bmc,
*guid = bmc->guid;
}
+ kref_put(&intf->refcount, intf_free);
+
mutex_unlock(&bmc->dyn_mutex);
mutex_unlock(&intf->bmc_reg_mutex);
- kref_put(&intf->refcount, intf_free);
return rv;
}
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ipmi: code cleanup and prevent potential issue.
2020-06-09 6:04 [PATCH] ipmi: code cleanup and prevent potential issue wu000273
@ 2020-06-09 12:18 ` Corey Minyard
0 siblings, 0 replies; 2+ messages in thread
From: Corey Minyard @ 2020-06-09 12:18 UTC (permalink / raw)
To: wu000273
Cc: kjlu, Arnd Bergmann, Greg Kroah-Hartman, openipmi-developer,
linux-kernel
On Tue, Jun 09, 2020 at 01:04:10AM -0500, wu000273@umn.edu wrote:
> From: Qiushi Wu <wu000273@umn.edu>
>
> All the previous get/put operations against intf->refcount are
> inside the mutex. Thus, put the last kref_put() also inside mutex
> to make sure get/put functions execute in order and prevent the
> potential race condition.
No, this can result in a crash. intf and intf->bmc_reg_mutex will
be freed by intf_free. In fact, every call to kref_put() on intf
better be outside any mutex/lock in intf. If you saw any, that
is a bug, please report that. kref_get() is fine inside the
mutex.
Plus, this is not a race condition. get/put is atomic.
-corey
>
> Signed-off-by: Qiushi Wu <wu000273@umn.edu>
> ---
> drivers/char/ipmi/ipmi_msghandler.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
> index e1b22fe0916c..d34343e34272 100644
> --- a/drivers/char/ipmi/ipmi_msghandler.c
> +++ b/drivers/char/ipmi/ipmi_msghandler.c
> @@ -2583,10 +2583,11 @@ static int __bmc_get_device_id(struct ipmi_smi *intf, struct bmc_device *bmc,
> *guid = bmc->guid;
> }
>
> + kref_put(&intf->refcount, intf_free);
> +
> mutex_unlock(&bmc->dyn_mutex);
> mutex_unlock(&intf->bmc_reg_mutex);
>
> - kref_put(&intf->refcount, intf_free);
> return rv;
> }
>
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-06-09 12:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-09 6:04 [PATCH] ipmi: code cleanup and prevent potential issue wu000273
2020-06-09 12:18 ` Corey Minyard
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.