* [PATCH v2] drm/i915: Fix "mitigations" parsing if i915 is builtin
@ 2021-04-14 6:06 Jisheng Zhang
2021-04-15 15:50 ` Ville Syrjälä
0 siblings, 1 reply; 2+ messages in thread
From: Jisheng Zhang @ 2021-04-14 6:06 UTC (permalink / raw)
To: Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, David Airlie,
Daniel Vetter, Jon Bloomfield, Chris Wilson,
Ville Syrjälä
Cc: intel-gfx, dri-devel, linux-kernel
I met below error during boot with i915 builtin if pass
"i915.mitigations=off":
[ 0.015589] Booting kernel: `off' invalid for parameter `i915.mitigations'
The reason is slab subsystem isn't ready at that time, so kstrdup()
returns NULL. Fix this issue by using stack var instead of kstrdup().
Fixes: 984cadea032b ("drm/i915: Allow the sysadmin to override security mitigations")
Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
---
Since v1:
- Ensure "str" is properly terminated. Thanks Ville for pointing this out.
drivers/gpu/drm/i915/i915_mitigations.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_mitigations.c b/drivers/gpu/drm/i915/i915_mitigations.c
index 84f12598d145..231aad5ff46c 100644
--- a/drivers/gpu/drm/i915/i915_mitigations.c
+++ b/drivers/gpu/drm/i915/i915_mitigations.c
@@ -29,15 +29,14 @@ bool i915_mitigate_clear_residuals(void)
static int mitigations_set(const char *val, const struct kernel_param *kp)
{
unsigned long new = ~0UL;
- char *str, *sep, *tok;
+ char str[64], *sep, *tok;
bool first = true;
int err = 0;
BUILD_BUG_ON(ARRAY_SIZE(names) >= BITS_PER_TYPE(mitigations));
- str = kstrdup(val, GFP_KERNEL);
- if (!str)
- return -ENOMEM;
+ strncpy(str, val, sizeof(str) - 1);
+ str[sizeof(str) - 1] = '\0';
for (sep = str; (tok = strsep(&sep, ","));) {
bool enable = true;
@@ -86,7 +85,6 @@ static int mitigations_set(const char *val, const struct kernel_param *kp)
break;
}
}
- kfree(str);
if (err)
return err;
--
2.31.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] drm/i915: Fix "mitigations" parsing if i915 is builtin
2021-04-14 6:06 [PATCH v2] drm/i915: Fix "mitigations" parsing if i915 is builtin Jisheng Zhang
@ 2021-04-15 15:50 ` Ville Syrjälä
0 siblings, 0 replies; 2+ messages in thread
From: Ville Syrjälä @ 2021-04-15 15:50 UTC (permalink / raw)
To: Jisheng Zhang
Cc: Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, David Airlie,
Daniel Vetter, Jon Bloomfield, Chris Wilson, intel-gfx, dri-devel,
linux-kernel
On Wed, Apr 14, 2021 at 02:06:43PM +0800, Jisheng Zhang wrote:
> I met below error during boot with i915 builtin if pass
> "i915.mitigations=off":
> [ 0.015589] Booting kernel: `off' invalid for parameter `i915.mitigations'
>
> The reason is slab subsystem isn't ready at that time, so kstrdup()
> returns NULL. Fix this issue by using stack var instead of kstrdup().
>
> Fixes: 984cadea032b ("drm/i915: Allow the sysadmin to override security mitigations")
> Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
> ---
> Since v1:
> - Ensure "str" is properly terminated. Thanks Ville for pointing this out.
>
> drivers/gpu/drm/i915/i915_mitigations.c | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_mitigations.c b/drivers/gpu/drm/i915/i915_mitigations.c
> index 84f12598d145..231aad5ff46c 100644
> --- a/drivers/gpu/drm/i915/i915_mitigations.c
> +++ b/drivers/gpu/drm/i915/i915_mitigations.c
> @@ -29,15 +29,14 @@ bool i915_mitigate_clear_residuals(void)
> static int mitigations_set(const char *val, const struct kernel_param *kp)
> {
> unsigned long new = ~0UL;
> - char *str, *sep, *tok;
> + char str[64], *sep, *tok;
> bool first = true;
> int err = 0;
>
> BUILD_BUG_ON(ARRAY_SIZE(names) >= BITS_PER_TYPE(mitigations));
>
> - str = kstrdup(val, GFP_KERNEL);
> - if (!str)
> - return -ENOMEM;
> + strncpy(str, val, sizeof(str) - 1);
> + str[sizeof(str) - 1] = '\0';
Looks correct, however strscpy() seems to be the thing we should
be using these days.
>
> for (sep = str; (tok = strsep(&sep, ","));) {
> bool enable = true;
> @@ -86,7 +85,6 @@ static int mitigations_set(const char *val, const struct kernel_param *kp)
> break;
> }
> }
> - kfree(str);
> if (err)
> return err;
>
> --
> 2.31.0
--
Ville Syrjälä
Intel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-04-15 15:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-14 6:06 [PATCH v2] drm/i915: Fix "mitigations" parsing if i915 is builtin Jisheng Zhang
2021-04-15 15:50 ` Ville Syrjälä
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox