From patchwork Sun Jul 5 21:53:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kars Mulder X-Patchwork-Id: 11644685 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C8B0A739 for ; Sun, 5 Jul 2020 21:53:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B9E4620658 for ; Sun, 5 Jul 2020 21:53:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728611AbgGEVxb convert rfc822-to-8bit (ORCPT ); Sun, 5 Jul 2020 17:53:31 -0400 Received: from relay1-d.mail.gandi.net ([217.70.183.193]:12389 "EHLO relay1-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728127AbgGEVxa (ORCPT ); Sun, 5 Jul 2020 17:53:30 -0400 Received: from sogo3.sd4.0x35.net (sogo3.sd4.0x35.net [10.200.201.53]) (Authenticated sender: kerneldev@karsmulder.nl) by relay1-d.mail.gandi.net (Postfix) with ESMTPA id 8C598240004; Sun, 5 Jul 2020 21:53:27 +0000 (UTC) From: "Kars Mulder" In-Reply-To: <20200704115538.GD16083@amd> X-Forward: 127.0.0.1 Date: Sun, 05 Jul 2020 23:53:27 +0200 Cc: "David Laight" , "Greg Kroah-Hartman" , "Kai-Heng Feng" , "Pavel Machek" , "Andy Shevchenko" , "Oliver Neukum" To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org MIME-Version: 1.0 Message-ID: <3212-5f024c00-215-220fe080@174542169> Subject: =?utf-8?b?W1BBVENIXSB1c2I6IGNvcmU6?= fix =?utf-8?b?cXVpcmtzX3BhcmFt?= =?utf-8?b?X3NldCgp?= writing to a const pointer User-Agent: SOGoMail 4.3.2 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The function quirks_param_set() takes as argument a const char* pointer to the new value of the usbcore.quirks parameter. It then casts this pointer to a non-const char* pointer and passes it to the strsep() function, which overwrites the value. Fix this by copying the value to a local buffer on the stack and letting that buffer be written to by strsep(). Fixes: 027bd6cafd9a ("usb: core: Add "quirks" parameter for usbcore") Signed-off-by: Kars Mulder --- drivers/usb/core/quirks.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c index e0b77674869c..86b1a6739b4e 100644 --- a/drivers/usb/core/quirks.c +++ b/drivers/usb/core/quirks.c @@ -12,6 +12,8 @@ #include #include "usb.h" +#define QUIRKS_PARAM_SIZE 128 + struct quirk_entry { u16 vid; u16 pid; @@ -23,19 +25,21 @@ static DEFINE_MUTEX(quirk_mutex); static struct quirk_entry *quirk_list; static unsigned int quirk_count; -static char quirks_param[128]; +static char quirks_param[QUIRKS_PARAM_SIZE]; -static int quirks_param_set(const char *val, const struct kernel_param *kp) +static int quirks_param_set(const char *value, const struct kernel_param *kp) { + char val[QUIRKS_PARAM_SIZE]; char *p, *field; u16 vid, pid; u32 flags; size_t i; int err; - err = param_set_copystring(val, kp); + err = param_set_copystring(value, kp); if (err) return err; + strscpy(val, value, sizeof(val)); mutex_lock(&quirk_mutex);