public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH V10] devcoredump: add context check in dev_coredumpm
@ 2022-09-26  6:51 Duoming Zhou
  2022-09-26  8:36 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Duoming Zhou @ 2022-09-26  6:51 UTC (permalink / raw)
  To: gregkh, linux-kernel; +Cc: johannes, rafael, Duoming Zhou

The dev_coredumpm(), dev_coredumpv() and dev_coredumpsg() could not
be used in atomic context, because they call kvasprintf_const() and
kstrdup() with GFP_KERNEL parameter. The process is shown below:

dev_coredumpv(.., gfp_t gfp)
  dev_coredumpm(.., gfp_t gfp)
    dev_set_name
      kobject_set_name_vargs
        kvasprintf_const(GFP_KERNEL, ...); //may sleep
          kstrdup(s, GFP_KERNEL); //may sleep

This patch adds context check in dev_coredumpm() in order to show
dev_coredumpm() and its callers could not be used in atomic context.

What's more, this change can allow the api to evolve and will not
influence the users that call this api.

Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
---
Changes since v9:
  - v9: Add context check in dev_coredumpm().
  - v10: Remove the "Fixes" tag.

 drivers/base/devcoredump.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/base/devcoredump.c b/drivers/base/devcoredump.c
index f4d794d6bb8..806ee872f5f 100644
--- a/drivers/base/devcoredump.c
+++ b/drivers/base/devcoredump.c
@@ -255,6 +255,9 @@ void dev_coredumpm(struct device *dev, struct module *owner,
 	struct devcd_entry *devcd;
 	struct device *existing;
 
+	if (!gfpflags_normal_context(gfp))
+		goto free;
+
 	if (devcd_disabled)
 		goto free;
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH V10] devcoredump: add context check in dev_coredumpm
  2022-09-26  6:51 [PATCH V10] devcoredump: add context check in dev_coredumpm Duoming Zhou
@ 2022-09-26  8:36 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2022-09-26  8:36 UTC (permalink / raw)
  To: Duoming Zhou; +Cc: linux-kernel, johannes, rafael

On Mon, Sep 26, 2022 at 02:51:26PM +0800, Duoming Zhou wrote:
> The dev_coredumpm(), dev_coredumpv() and dev_coredumpsg() could not
> be used in atomic context, because they call kvasprintf_const() and
> kstrdup() with GFP_KERNEL parameter. The process is shown below:
> 
> dev_coredumpv(.., gfp_t gfp)
>   dev_coredumpm(.., gfp_t gfp)
>     dev_set_name
>       kobject_set_name_vargs
>         kvasprintf_const(GFP_KERNEL, ...); //may sleep
>           kstrdup(s, GFP_KERNEL); //may sleep
> 
> This patch adds context check in dev_coredumpm() in order to show
> dev_coredumpm() and its callers could not be used in atomic context.
> 
> What's more, this change can allow the api to evolve and will not
> influence the users that call this api.
> 
> Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
> ---
> Changes since v9:
>   - v9: Add context check in dev_coredumpm().
>   - v10: Remove the "Fixes" tag.
> 
>  drivers/base/devcoredump.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/base/devcoredump.c b/drivers/base/devcoredump.c
> index f4d794d6bb8..806ee872f5f 100644
> --- a/drivers/base/devcoredump.c
> +++ b/drivers/base/devcoredump.c
> @@ -255,6 +255,9 @@ void dev_coredumpm(struct device *dev, struct module *owner,
>  	struct devcd_entry *devcd;
>  	struct device *existing;
>  
> +	if (!gfpflags_normal_context(gfp))
> +		goto free;

I still do not know why this is needed at all as there are no in-kernel
abusers of this api.

We do not add code to the kernel for out-of-tree users, or "future
users" at all, otherwise it would be unmaintable.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-26  8:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-26  6:51 [PATCH V10] devcoredump: add context check in dev_coredumpm Duoming Zhou
2022-09-26  8:36 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox