Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp253146lqr; Wed, 5 Jun 2024 05:17:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXMz6pM0q6v4YH+CZElO+Hii5CrOG9ilNTG6iGkLl6Yr9MK22C46G5pn5fXJKcAogAp1lPz9jQFNnxXELQ5j2wbuRxstHE5PM1eu0kMUw== X-Google-Smtp-Source: AGHT+IER6q0AOASsZAmJhKRqf2bq/SMsBYJA9VEAUNwaJJuSSbCeweQr1baXNGymlA5Z8TzZUHhK X-Received: by 2002:a17:902:e892:b0:1f3:b9d:87e6 with SMTP id d9443c01a7336-1f6a5a052a4mr29158205ad.8.1717589865305; Wed, 05 Jun 2024 05:17:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717589865; cv=pass; d=google.com; s=arc-20160816; b=eo/SIx61iigN5Anb2SvsTgBu7kClosvM72ou+gh34SaYJZzlGYej6NxLDbB2uduLf2 ke8qCUlEsaLKRMn494pRuiomw928s73WTnCA39jDLFeCjRAxHzP5bYsMs5zm1F6OSi2e yO3gMeUxcOhpOCEeOg2YJb4aIaCY37gBs86VLJn0Dk53EDuCDnva/XRvdfjIL0x1Pg/Z 1fIbwkLuhRXTjcR+LbdXIDJTznSXGcYD8sGqpzq/BQvZ6O+M56vT8D+r/F2IPh0ckEOo LvT376sfbhYXKO4vdj8xftqrdVIK+srOWltutuXPDUIbrYv+Ey0ONi73jLM5Lx5fuwfI bgpw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=QqcdcXNNmCyfUde93BG0iVD42utHWy4pq27VnVfsi6E=; fh=pTOwnHfXX24czgpPrPvBMhqEj/ZbvVujqb7Rzb6AwUs=; b=o9y1m6yEabfiMG+hj6koMtMfIWcM9+ao1hdYm8yITYQrmkdv1AEDa8oGxC5KXLgVQY TEo5IJVWMV0RSwQuIPQCLZ2uAXInyEeZSABqUT56A85bYXr5jNltTU3/fs3hHc3STIdz lv0spGE4/IwA3yQc9+dS3l9AzQ758K9GvbsDBUC06smAxelzbVtEtsvXtlV7kQOAQCpX SZxiPzrMAWQRIsdN6E1PorZce3c3phs2FiraYBHfxNPqj6jZ+rMn1hGxkkTqmJDSnKa8 6feeosMHXQR1LNykDYhVW9kA2DNSosYl83LITuQnQaPQpgxxbQnt7QtL6dPAJVL4mI+q BsMw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DfbtH53N; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202356-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202356-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id d9443c01a7336-1f65a5239ebsi72283795ad.480.2024.06.05.05.17.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 05:17:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-202356-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DfbtH53N; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202356-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202356-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 42E04B258F2 for ; Wed, 5 Jun 2024 12:04:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D18711A3BD1; Wed, 5 Jun 2024 11:52:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DfbtH53N" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F11B2188CA4; Wed, 5 Jun 2024 11:52:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717588348; cv=none; b=TA9mtrUH+WVxBqUU9jVB9QpRqssBZg5+RJAYKAyfd+lr8O1J1w9eG4SX5sBOXXIsQ7/7j+KQyUdpaLElcHC5zKUNYnfmjzucptmKwKVdETjkAe+qN8HT9gfGw2JZq9RkAWmHNk0RIb4wDEZJ+ktlVTLxH4UxqwKy0ATvatu431Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717588348; c=relaxed/simple; bh=QtB8mv8E4Dukpym+yLaodLWDBwrg6sLR/LVpNwBmWvE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=MZLzjDfNy9kD5NZ4zD9w0E7D3y2MXNUdNoHUDobAbQdtOxv+idycTyPcoqwSQG2GbP8eDO5ho6UbZDTo5V7lZgNlRu6+uHLM1K1rATwDb3g+Oq+8t+eMjoNYJbxwKqrdBbKtWMaHwUpOg0ehrSR4KolgCIsE0fnU3dbPiWoCOn4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DfbtH53N; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FA46C3277B; Wed, 5 Jun 2024 11:52:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717588347; bh=QtB8mv8E4Dukpym+yLaodLWDBwrg6sLR/LVpNwBmWvE=; h=From:To:Cc:Subject:Date:From; b=DfbtH53NTlSGdu6f6dhxLIrRXxHtb3D4RZnr6U+AuxpMp7mjC0sFL5Paez8PK2uLk IDledi4JmJ1XbdTuMArv1Y3wEGCAia2fjCXAG4k8HL2nquZ54KqAbrL3iSL8LrrQSk EKStR88/wywIjMtLYBn7G6tvwYihY3C8aPalrqjxwjOZ4gYS1NrkSmnblM0EJN8yCr rPYJB8olo9ZfC8Wtx67vVV5BQdorBsEIXznju9x40Eyx+AdTW/5PQD/byeK72rZpYo LVIV3Bc5jmjdzb94sMWKIaCgxG/kq0C8HpMo6AhcG0Bxu5IaRGFHXHQmHScq4AeRbI QL7lCP/e8h+Dw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Michael Grzeschik , Greg Kroah-Hartman , Sasha Levin , laurent.pinchart@ideasonboard.com, dan.scally@ideasonboard.com, linux-usb@vger.kernel.org Subject: [PATCH AUTOSEL 6.6 01/20] usb: gadget: uvc: configfs: ensure guid to be valid before set Date: Wed, 5 Jun 2024 07:51:44 -0400 Message-ID: <20240605115225.2963242-1-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.6.32 Content-Transfer-Encoding: 8bit From: Michael Grzeschik [ Upstream commit f7a7f80ccc8df017507e2b1e1dd652361374d25b ] When setting the guid via configfs it is possible to test if its value is one of the kernel supported ones by calling uvc_format_by_guid on it. If the result is NULL, we know the guid is unsupported and can be ignored. Signed-off-by: Michael Grzeschik Link: https://lore.kernel.org/r/20240221-uvc-gadget-configfs-guid-v1-1-f0678ca62ebb@pengutronix.de Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/gadget/function/uvc_configfs.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/uvc_configfs.c b/drivers/usb/gadget/function/uvc_configfs.c index d16c04d2961b6..4acf336e946d6 100644 --- a/drivers/usb/gadget/function/uvc_configfs.c +++ b/drivers/usb/gadget/function/uvc_configfs.c @@ -13,6 +13,7 @@ #include "uvc_configfs.h" #include +#include #include /* ----------------------------------------------------------------------------- @@ -2260,6 +2261,8 @@ static ssize_t uvcg_uncompressed_guid_format_store(struct config_item *item, struct f_uvc_opts *opts; struct config_item *opts_item; struct mutex *su_mutex = &ch->fmt.group.cg_subsys->su_mutex; + const struct uvc_format_desc *format; + u8 tmpguidFormat[sizeof(ch->desc.guidFormat)]; int ret; mutex_lock(su_mutex); /* for navigating configfs hierarchy */ @@ -2273,7 +2276,16 @@ static ssize_t uvcg_uncompressed_guid_format_store(struct config_item *item, goto end; } - memcpy(ch->desc.guidFormat, page, + memcpy(tmpguidFormat, page, + min(sizeof(tmpguidFormat), len)); + + format = uvc_format_by_guid(tmpguidFormat); + if (!format) { + ret = -EINVAL; + goto end; + } + + memcpy(ch->desc.guidFormat, tmpguidFormat, min(sizeof(ch->desc.guidFormat), len)); ret = sizeof(ch->desc.guidFormat); -- 2.43.0