Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2662686pxa; Mon, 17 Aug 2020 15:54:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPdQvH2Zds9xkXK46ZJ2KPjU17TtoMpWiLMocX8G2YI+VwUaGWHyL+V4Xd1x4lg8+duUrM X-Received: by 2002:a50:ed84:: with SMTP id h4mr17333695edr.278.1597704845640; Mon, 17 Aug 2020 15:54:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597704845; cv=none; d=google.com; s=arc-20160816; b=wDiPolMaDz7E/x9z4soTtgvqQC4PTVr+jV+BlOAFNfO/UG2JUGNjkpyWMVdXJy0Tpr q+k3Lb9UFb/YZzRZDphJzScye0JU2P7plTcUQWPy3nZefsE/PP0ImCw+Gp8v4hFdBi7v BB/jWzLXj914KFwRsULfiUvVt+NAVW1L56+eOzI/qoPup5nBz48E0ttykoFk4fqLNkav XD3Hg1N/l44xmI61pNHY1xW8MZGeiaRCq1gl/P5rEwsgPxxN85PxXRCIDAlPTq0Gs29d ylguD6y3n2EsXMhGLakhUZmb3bxeDPP6iZl92JgRURqLP44mTWBkmHQ+MkX0MaOiTyRY JZjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mTg5/jcsHjol0PF89lZbsLismVnh1M28yk7z4mJ6Cd4=; b=y0Sm9hFeNHtOePNg7EXYmnmfNTiqHez+drsCVSy3TPQU6dX3OZpDIMg4SBjyQrHwSk 04sYVyceU/yPlnX/5bNvc5R0ImPSY/Ea1ysF26rRPwZ8NTiEjlZFv2+Ql113nEqEtj3h aDn20ZxfFGiwYz3p5PbTRJ1jJgX1/dax3yfKUKjs/M4K8haikkGcqUeY/UXT7JE5t7Hp yFSvQBDQ8aDQ+i7ZnjB+PqC8O2krXjxovNZUZ5BcUj8W4/elLc32sd/qgRELPJorX9LC dtLKPuOZy31VBXaLWCUI7cI7ibgdLrxS3IuOFObo/0a+5mKiTtTZdA/s9pLJInLIHv3G w4KA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Tj/JQE32"; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l6si13807760ede.331.2020.08.17.15.53.42; Mon, 17 Aug 2020 15:54:05 -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; dkim=pass header.i=@kernel.org header.s=default header.b="Tj/JQE32"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730214AbgHQTeG (ORCPT + 99 others); Mon, 17 Aug 2020 15:34:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:51462 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730150AbgHQPaW (ORCPT ); Mon, 17 Aug 2020 11:30:22 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 50EFD23B40; Mon, 17 Aug 2020 15:30:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597678221; bh=/1ramI7N/PC/FCx1+3BMK/mKLPfXJVkRCE13JhUik0U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tj/JQE32iSpX2A/ZLV7mq0/ieOaJp4YR7DBauX0agfPUMRIRwaLJfvu/A/W/XdUok 2k+zaRJxXQ/mi0qUDOPPwKgACyyRSbVmS+AUYYpqIeUCF5tJKiF7/C7A8K1I/ynFO+ 7EWGD3BZsNBBcozMZqHg0wZT/DcLN8dOfkDM1gH0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kars Mulder , Sasha Levin Subject: [PATCH 5.8 260/464] usb: core: fix quirks_param_set() writing to a const pointer Date: Mon, 17 Aug 2020 17:13:33 +0200 Message-Id: <20200817143846.244948105@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143833.737102804@linuxfoundation.org> References: <20200817143833.737102804@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kars Mulder [ Upstream commit b1b6bed3b5036509b449b5965285d5057ba42527 ] 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 creating a copy of the value using kstrdup() and letting that copy be written to by strsep(). Fixes: 027bd6cafd9a ("usb: core: Add "quirks" parameter for usbcore") Signed-off-by: Kars Mulder Link: https://lore.kernel.org/r/5ee2-5f048a00-21-618c5c00@230659773 Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/core/quirks.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c index e0b77674869ce..c96c50faccf72 100644 --- a/drivers/usb/core/quirks.c +++ b/drivers/usb/core/quirks.c @@ -25,17 +25,23 @@ static unsigned int quirk_count; static char quirks_param[128]; -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 *p, *field; + char *val, *p, *field; u16 vid, pid; u32 flags; size_t i; int err; + val = kstrdup(value, GFP_KERNEL); + if (!val) + return -ENOMEM; + err = param_set_copystring(val, kp); - if (err) + if (err) { + kfree(val); return err; + } mutex_lock(&quirk_mutex); @@ -60,10 +66,11 @@ static int quirks_param_set(const char *val, const struct kernel_param *kp) if (!quirk_list) { quirk_count = 0; mutex_unlock(&quirk_mutex); + kfree(val); return -ENOMEM; } - for (i = 0, p = (char *)val; p && *p;) { + for (i = 0, p = val; p && *p;) { /* Each entry consists of VID:PID:flags */ field = strsep(&p, ":"); if (!field) @@ -144,6 +151,7 @@ static int quirks_param_set(const char *val, const struct kernel_param *kp) unlock: mutex_unlock(&quirk_mutex); + kfree(val); return 0; } -- 2.25.1