From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85204C3A5A1 for ; Thu, 22 Aug 2019 17:12:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 57747233FC for ; Thu, 22 Aug 2019 17:12:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566493954; bh=QP3HuzaSzdQSwx9etGMNtBBAU3azKIgzaKrJyoa/5Nk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=f9WEfaZKxYSGSn/sH2lWzIVjqFxl3ZATQ7OfsCWOz6vfzQIxOmIfeKxfZYtjmbTwu XauyzVDtZMss4Tp5q0LdJeIoJ4cev0lUMIJXriLkv0tZ4b6qSaOmemCy0sp2BVJQS7 CI+Uj6Rwy01HOATI3y68OSBoLSYynv5MeFUR5EhY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391005AbfHVRMd (ORCPT ); Thu, 22 Aug 2019 13:12:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:59306 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390668AbfHVRJH (ORCPT ); Thu, 22 Aug 2019 13:09:07 -0400 Received: from sasha-vm.mshome.net (wsip-184-188-36-2.sd.sd.cox.net [184.188.36.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8CF0C23404; Thu, 22 Aug 2019 17:09:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566493746; bh=QP3HuzaSzdQSwx9etGMNtBBAU3azKIgzaKrJyoa/5Nk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZEDrZktsrQ9kbwxnok09Dmwv35efG1cF00XytJTPqh0BN+HaM+tYMjNJ0Uk/KFjd6 yL6E32DbAjrWSZ9UJhZZ2O8x9BVHmM2RcW5RzxtBpZTizsI5sAwlHDgxh0EH48GOPT TywfX6h8dOfl97RYGLBE8nUdoX+kg/Qo/Fx/jhWk= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Yoshihiro Shimoda , Geert Uytterhoeven , Felipe Balbi , Greg Kroah-Hartman Subject: [PATCH 5.2 096/135] usb: gadget: udc: renesas_usb3: Fix sysfs interface of "role" Date: Thu, 22 Aug 2019 13:07:32 -0400 Message-Id: <20190822170811.13303-97-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190822170811.13303-1-sashal@kernel.org> References: <20190822170811.13303-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.2.10-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.2.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.2.10-rc1 X-KernelTest-Deadline: 2019-08-24T17:07+00:00 X-stable: review X-Patchwork-Hint: Ignore 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(-) diff --git a/drivers/usb/gadget/udc/renesas_usb3.c b/drivers/usb/gadget/udc/renesas_usb3.c index 7dc248546fd4f..b6eec81b6a40f 100644 --- a/drivers/usb/gadget/udc/renesas_usb3.c +++ b/drivers/usb/gadget/udc/renesas_usb3.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -2378,9 +2379,9 @@ static ssize_t role_store(struct device *dev, struct device_attribute *attr, 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; -- 2.20.1