Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp889633pxb; Thu, 15 Apr 2021 08:51:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvvvEO+PhwaKMIC6aYc7rbnr2Ku6O4XSF6+l0xvNMbN5p3Vm+7LDLT9aYTfUITFEdnmxgn X-Received: by 2002:a63:4f0a:: with SMTP id d10mr4108878pgb.418.1618501895032; Thu, 15 Apr 2021 08:51:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618501895; cv=none; d=google.com; s=arc-20160816; b=v7Dgw5+BQo911SH235t4qjBQLHHeFwWQEMaYPW2UuCFtSm7bVSoXCh3WyZkk2mlAiI QzxK9CmbENP0w3IHKGuXveWXi3gftrD7atemUm6SJnhxedgvQllPE/5+FpIYuJ0Rub5e 6zJQR9EXUhRX3IAxAksHPQZmobMWVD3uEYbcOw7BqFnXuANoICSOhecliTkoJPKANged pQpn5xHNLyGPHinUwTO46QDOWIcmNOuw3247syOH70a7CZFx5htHjv7s3IaQ1XyqxuCs f+mr523yUMKIiDevrjicClpL+qZamzB245b702QzeklFxsmoIhpGODeAg2C4Swgf/ngI Zm5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=+dkZ0uTh0EkuJ5Dfw5BS8kwPx+XalwiTz0jnYCI5MsI=; b=s8mILppszOhHfEIg9BsuarHU4SeYlINe6iDxDDbGDjrueOmcCBgEubW+HCyTVmeAR4 JoTifkTCFgt3u66Kjl208QPFu807avdkcHzr7ic1FPurXH24DG3V/+bl4hLq4TZ0hUBT fYWe/h3Cx27OqUHjbdiGMnqrOosw5Zsm0HSCjs0BvQuQT2TRqEL3PF1huSUPYcVL4Kdq vCBVOpYGECsqExuWfc7PrF1rwOPrtBzHhzLvKwl/IfBIqkbUd1eShmB5rI33+WNRpbID aexWf5Btp+euei/KZOxoNwBaUF2L2d9cUudGZ5mF97w+vvn6U6tMgKA3x5CXWvR7DAm9 E7Tw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b21si3342061pgg.319.2021.04.15.08.51.21; Thu, 15 Apr 2021 08:51:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233748AbhDOPvJ (ORCPT + 99 others); Thu, 15 Apr 2021 11:51:09 -0400 Received: from mga05.intel.com ([192.55.52.43]:36388 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233052AbhDOPvJ (ORCPT ); Thu, 15 Apr 2021 11:51:09 -0400 IronPort-SDR: qfDxdRRWlHEDuZKMHpVifT1jRu0JvRBWnpG6UoM3sMD7KgBsF7QpNDbGJdoddn4NNgKzWlfWjh ktZ5VgtA7MxA== X-IronPort-AV: E=McAfee;i="6200,9189,9955"; a="280192772" X-IronPort-AV: E=Sophos;i="5.82,225,1613462400"; d="scan'208";a="280192772" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Apr 2021 08:50:43 -0700 IronPort-SDR: lhluqeXrSSgzmFMmrkJm9YGQF6Ah1BYE/QTlAHpmuvIDMXRnpQoJV872zukMofZbYqmeIddV2D 7MvpaAqiXWDg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,225,1613462400"; d="scan'208";a="384053803" Received: from stinkbox.fi.intel.com (HELO stinkbox) ([10.237.72.171]) by orsmga006.jf.intel.com with SMTP; 15 Apr 2021 08:50:38 -0700 Received: by stinkbox (sSMTP sendmail emulation); Thu, 15 Apr 2021 18:50:37 +0300 Date: Thu, 15 Apr 2021 18:50:37 +0300 From: Ville =?iso-8859-1?Q?Syrj=E4l=E4?= To: Jisheng Zhang Cc: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , David Airlie , Daniel Vetter , Jon Bloomfield , Chris Wilson , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] drm/i915: Fix "mitigations" parsing if i915 is builtin Message-ID: References: <20210414140643.620c3adb@xhacker.debian> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210414140643.620c3adb@xhacker.debian> X-Patchwork-Hint: comment Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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