Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2656679pxa; Mon, 17 Aug 2020 15:41:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyIGF6SetSmCJdoPbSRmU+LimI1B92VWGTHoAV8OXkvFsfGDGNdQ73eYL45wYT4Au/l/mKB X-Received: by 2002:a05:6402:30a5:: with SMTP id df5mr16723710edb.18.1597704118212; Mon, 17 Aug 2020 15:41:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597704118; cv=none; d=google.com; s=arc-20160816; b=pNr7nHINJffINJqOzkWwwASNeZmgzrLNWRnCiSwDNB8HB7qda9QiytOjXlrKGRPEfg GVjgUsVySSh4XWw9zyCWa2XsCly7zNV4vrI4AhSp5ZEFGvazOB4Z6oJkeAw8wwJFi9/o MZZ/4Qy3r+BUooV+UPouEO41fMSugi6g/PbU09T5n7/tsPDE9EDm3LdZ48yRQRsKX8z/ CHbs3OLTBrH24OHFGRsiNorn5wp+GC2Npr4U3qxM0iLN0OMVlVkbyaSr7Ia/gg/M45Vd Zj5o/dMuE4io1YXbwIYzqKxsK9mBXOFB1+N9VO32GC+etuTo4zXM0MRvNSxbpTnXTD9D wrfA== 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=tDH9oKNbKYLs7toJ1Yxe5Kc8zzHQ1UPQKahz5Nu2iJvFEvkx/LdbRFuqhK6RNlmQlU 6fMukdSSn79ipO8QsrLL7PcnsYyF7aPZ4fFvj4uDLmOAu74Zpcs05YybvaRACPJ7fAb+ Q3cVIy1Ma2Pq+Vg7EfPE8Y0zQrTG0YDMkJsonajcX9BBGBns4SFBQhaEczr925a05Xjj w8ino9D6qry3WPOr2kmgQzrykrejMYAM7/lC5JsAlTo2qaVMTDV0/XzHQfrOZMlT8a0X A5o0pTWA6o17P7SzaS7PFYaEc3Mtoss+di2utZXQlQ4nJCziwq14oLu6xFElEBx2RMhM /Rbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ca9LiBUQ; 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 i20si11806433edx.426.2020.08.17.15.41.35; Mon, 17 Aug 2020 15:41:58 -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=ca9LiBUQ; 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 S2390675AbgHQSPh (ORCPT + 99 others); Mon, 17 Aug 2020 14:15:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:53970 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730528AbgHQQGE (ORCPT ); Mon, 17 Aug 2020 12:06:04 -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 4A63820866; Mon, 17 Aug 2020 16:06:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597680363; bh=/1ramI7N/PC/FCx1+3BMK/mKLPfXJVkRCE13JhUik0U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ca9LiBUQ92g453SXnJ916Qsk4tnS/tKC7Bu3AI5txOmqWMF3W4tl7OEHUVdw5NjW4 IiqV5+IqeoonqkomWdlhDaoRqzoLnoYVzd5+LpqCz/stVKIFPkJBk6m+hUIHbHc4A3 pVKa016qWEweSsEf2IfjajaezySmue2vhfwLvJpA= 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.4 156/270] usb: core: fix quirks_param_set() writing to a const pointer Date: Mon, 17 Aug 2020 17:15:57 +0200 Message-Id: <20200817143803.596772999@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143755.807583758@linuxfoundation.org> References: <20200817143755.807583758@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