Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp237537lqr; Wed, 5 Jun 2024 04:51:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXAtDVttpqXrx3lhAK5xLe5VIYzhDdcHVKzm76+Mj5M3FF55MPCGhzK4s1hRBEHKlC6fQZukx0Kf9UopGyhIdgG5yQouHSDCGjbI92Zmg== X-Google-Smtp-Source: AGHT+IEdtCVPemZLiPbjZ40LNy6kyOIv+wm3OkGOM5/W1g5BZcKNAm60VDcpoaNqN3jyvyAw7YTl X-Received: by 2002:a17:902:e847:b0:1f6:77e3:774a with SMTP id d9443c01a7336-1f6a5a6aee4mr28331705ad.52.1717588302781; Wed, 05 Jun 2024 04:51:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717588302; cv=pass; d=google.com; s=arc-20160816; b=qNLx2ReBOUcnEWfcimA3vt18SgYFxwg5Y0iHn9FBqg4MsIu1JPTqRpsVbCJWp0UY7s Q+5maLj15ji2ZQbkeJ4/GZjQts5aZEfC63CrmIKu9frcRD02VA9ozFK4fflVKenhUrBB /yTBFi511IOhAmMZQiHEaUW306qd//6zHYzvN96GB+O2GPZviFh4LPJfD1hgkPwgJKHx Op01smDFFTDfm4rTaW2MdcWDQn/yC9tFXViZ3VpFHaCKaDndKwoSjj9MN5Z/j/oHabfa RDKVMMhp9Tmjo1gmr8xccWlzqESdGrp7LW10aBkB+riDTirS8JIKh0U05mA+jqtHXiB0 3p1w== 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=KHPvqre86MmdYNWZMV+l12v9GOKQzQF7RMQDQCCFPAI=; fh=pTOwnHfXX24czgpPrPvBMhqEj/ZbvVujqb7Rzb6AwUs=; b=V/KwPCuFSpKQUR9XUc1lRtv3PxmTjxiPV55vypWlgiCHAEzmHnu8oRl4oINQupDd5T Isw6X70tt8je84Kgro/LFdj34raZBteoLMAB/fMCjaAQTQ5HcxYa8Bq6UfQ6FJCKyAGd ng3MbTZdjDMOXMYf0KkJ62R52NS4rBkYiF+nQKawjClDu41sIOPcjpEAZhHXV5kjLonx IoyZUilmduBgOuBLjgqpS4BCV/k8/ECdLBmy+aRNJ1WJmVLBjaBnPujB/XCnvVMFG38M D+xtZhfU9zsw4MJ78y3CqETy6W++Sg7bYQcDvab31e/GCmPEF8nGmfdUAjm0C/eWy6Fk S1OQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pEs2GZSj; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202297-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202297-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-1f6323dd06asi28185015ad.310.2024.06.05.04.51.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 04:51:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-202297-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=pEs2GZSj; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202297-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202297-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 8C8C8B23AB8 for ; Wed, 5 Jun 2024 11:49:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7808E1922E3; Wed, 5 Jun 2024 11:49:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pEs2GZSj" 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 87CAD27459; Wed, 5 Jun 2024 11:49:29 +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=1717588169; cv=none; b=tyaWtF4vd3wOY6DMV2VTwfqtg9Q2Bpu0YhG0VCcQ+DqSG7oofWeGJAwlN9nsZje5OzZi4HWHXrdQvuPOmKRB2cOksibsSbr1umbNXisamZx3yWKb0I3wi3rd9yeBuO3G+onpotRjosIzwB1RnBtz4nxwXoEszvpOc2xGe2VdmpQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717588169; c=relaxed/simple; bh=JJbEb6Be+uGFHcPPviUGo9V6PlBpgcCgy8HtnK62XBI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=r1FdoSJgJKLgx+qSVyM8WKbxHyvZujmWAVudn/7eQaikWoBjp5tpK3D8N5v8Y+fRQLLI5W6efr+4R23gs5SHn2EUZJw+grMKxAmGxclmVHt0CIwYH9/NhX7tv3qVGfqWVtS2ZObx4vm15jm5fTfhgxKilXv42EBVv8twExKp/eM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pEs2GZSj; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B860C3277B; Wed, 5 Jun 2024 11:49:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717588169; bh=JJbEb6Be+uGFHcPPviUGo9V6PlBpgcCgy8HtnK62XBI=; h=From:To:Cc:Subject:Date:From; b=pEs2GZSjhoI052k+119dcqpUX79fqtUZbcUG4n6w9FV2UUUKuNlAsLb/hSVy1s5f7 y/zYf9LDXhBBdnlDr7uM6tKidngWplu810MKaiZfI3yfop34E7kP39r/8nnq/EYFMP nU5JsSIo1ElUB7R/Jpwhqi8jufL910rYRit3mv4l+ULMLFBAxBx6MRfY6jYeUy/hi8 1jHr8mtKWL4VRXzuwbU9uzWLG4xpoQdFFVjD7lycMjKIAascSwkai4HvOqWMjfsfoT JqfR2eaGYfjW+PwnhzpRbhogTIHNkS2WvBWOl8vk4tO1gWjQD6ZTFjYDFE0oJAGULA PktPuU2rrCZvQ== 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.9 01/28] usb: gadget: uvc: configfs: ensure guid to be valid before set Date: Wed, 5 Jun 2024 07:48:30 -0400 Message-ID: <20240605114927.2961639-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.9.3 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 a4377df612f51..6fac696ea8463 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