Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp103391ybl; Thu, 22 Aug 2019 20:47:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqzBBUflmPrOY9cNYRkzQPeoX0WzGJrGdSJqvUKJ61mJIpIXyg1OfnWujzrx/KbmNljJF6QK X-Received: by 2002:a63:6c4:: with SMTP id 187mr1924335pgg.401.1566532023952; Thu, 22 Aug 2019 20:47:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566532023; cv=none; d=google.com; s=arc-20160816; b=PFbwEs44GFUmpjVzHxsU97rnqDQf30vZ73zI2PQVHwE372YeIqMZNHIzIRBeEXyHpS T1M4E6K6y2bD6AOQoARZURFOzk43L8lHt05PLW+2Fy7UQG3eLM0xKoF3uciPRNV+Eqq+ ybSuGNB/Bb+YBoWTp+1iW5JF65QSkI2FVkOSpCjGpw5/B0vHr88U1rEJ7wnE0EzjDe18 FmHeiVVtcYSNias5U+c/mlrrRcUC2LLatkGqawFmBPlRK/ME4SQZcBzPgKJ/drFzOC77 5QXHkmv1ariYJmaGktu+PT7lCGiY7VLcaWGYY1XUH4v8qnCamdu8k+ppqCQL8SjK8YdW gKIg== 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=rU13mgTqG/S25o3DZAY8A+jHc6nylI2rQxlfeoQYDvU=; b=DXzLpQuLs9eqUPMpMNrGE5PU+ybgiYU2B1UbnxYWXAlnau3DE5kk/B8vR9ymjBS08M sihRaSRlRXdg6u0HZcrW+dSuEazra0OeACvaTG+orkIDC7XiA/NU4JbkIGAPFClrio2w 48ifrEVOaXKrRXFEP0neA1wT/2df9A+TjXiVD5nOATQZw2+5ES1HHzumqJ2yXOkAbbC+ 5m57hdJdfYPfLg+LLXbv7LokzgxE2UG7FUW5GUjS1EDxDAWeczh3PdBM8J6O9EEfCKds 3kOUPco5Jxxulrj+VRzJHD9DklLTmsZ3aDTWu3+ndQN4f0tNzZjMIT1NdQTW0vzMCjx/ HvMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=w0kXytcK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 85si908442pgb.583.2019.08.22.20.46.48; Thu, 22 Aug 2019 20:47:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=w0kXytcK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404135AbfHVRei (ORCPT + 99 others); Thu, 22 Aug 2019 13:34:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:48446 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404372AbfHVRZS (ORCPT ); Thu, 22 Aug 2019 13:25:18 -0400 Received: from localhost (wsip-184-188-36-2.sd.sd.cox.net [184.188.36.2]) (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 23496206DD; Thu, 22 Aug 2019 17:25:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566494718; bh=LdEnyO9tKd0qgPoiJi5ySVpeoiZm3yCzkrV6/xj0118=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w0kXytcKir79WNusZeu/8qmPN6VH0c8re5mMWRYUJA91xFco6UkbW51I2ge2EpRUs 8czPwZkOv9pl6mm30n8bMJR/O4nHcotq486gWP7x8erqv8ZMDafnqYXSmHIJGeNU00 5kP3h1cC9ODf/56fzk/uWHIXGhexbBDUDij8UBAw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Geert Uytterhoeven , Yoshihiro Shimoda , Felipe Balbi Subject: [PATCH 4.14 47/71] usb: gadget: udc: renesas_usb3: Fix sysfs interface of "role" Date: Thu, 22 Aug 2019 10:19:22 -0700 Message-Id: <20190822171729.899786297@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190822171726.131957995@linuxfoundation.org> References: <20190822171726.131957995@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: Yoshihiro Shimoda commit 5dac665cf403967bb79a7aeb8c182a621fe617ff upstream. Since the role_store() uses strncmp(), it's possible to refer out-of-memory if the sysfs data size is smaller than strlen("host"). This patch fixes it by using sysfs_streq() instead of strncmp(). Fixes: cc995c9ec118 ("usb: gadget: udc: renesas_usb3: add support for usb role swap") Cc: # v4.12+ Reviewed-by: Geert Uytterhoeven Signed-off-by: Yoshihiro Shimoda Signed-off-by: Felipe Balbi Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/udc/renesas_usb3.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/drivers/usb/gadget/udc/renesas_usb3.c +++ b/drivers/usb/gadget/udc/renesas_usb3.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -2315,9 +2316,9 @@ static ssize_t role_store(struct device if (usb3->forced_b_device) return -EBUSY; - if (!strncmp(buf, "host", strlen("host"))) + if (sysfs_streq(buf, "host")) new_mode_is_host = true; - else if (!strncmp(buf, "peripheral", strlen("peripheral"))) + else if (sysfs_streq(buf, "peripheral")) new_mode_is_host = false; else return -EINVAL;