From mboxrd@z Thu Jan 1 00:00:00 1970 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 376A51917DD; Tue, 10 Sep 2024 10:40:21 +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=1725964821; cv=none; b=C9F/WUL2yAuZCU9Dly3doF8TmA/Bd7tkajCh7O7uyNb7iDQ70dK/6NkG7gFoPWqNU763rakics9/B4upz4BY46whNA2QVOktBgy1MpYZCF53D/oKlpZP2NTVLMXtZTtR5VOcGgY8B1bw4gv3BSGzUzPVbNQIUz+JCQ5xyMHu+rs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725964821; c=relaxed/simple; bh=N5bFS1rKIKjN/64NgzSlFVclkrdTGyFYePA0Du+qISI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C5Fpeh30KORpAYuTIp2t7ffiwyy/Gawyw//Kz1QcZPSoA7/HRxK/hxf2o/qUZNzkufK6xm8m9RozXpKQWdqfdo6YT2aelPogtNoLI6Zl/eaUYX1mnRLVJ2JC9f1XH/J+K9S4rlybsCEfuRI2rLijVt0vTreVTObMPVmGkPh6dmg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=oNn/65XU; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="oNn/65XU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B214BC4CECE; Tue, 10 Sep 2024 10:40:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1725964821; bh=N5bFS1rKIKjN/64NgzSlFVclkrdTGyFYePA0Du+qISI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oNn/65XUIUCv/Sum52XKLktKOEL5Muj9gERoamhE+9LPjSbyf8MB4myfn6d0EMJPE VjoCTGYGS1cGXxaqZp2HPByWyJb5DjDtc0URMksA3Ieda52XxDXMYIeuv3GGDQBZKX 5v0BoR77FFxGLRSL0obBHpSp/z7D5EIIyD82Leh4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ricardo Ribalda , Laurent Pinchart , Sasha Levin Subject: [PATCH 5.10 043/186] media: uvcvideo: Enforce alignment of frame and interval Date: Tue, 10 Sep 2024 11:32:18 +0200 Message-ID: <20240910092556.303056003@linuxfoundation.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240910092554.645718780@linuxfoundation.org> References: <20240910092554.645718780@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ricardo Ribalda [ Upstream commit c8931ef55bd325052ec496f242aea7f6de47dc9c ] Struct uvc_frame and interval (u32*) are packaged together on streaming->formats on a single contiguous allocation. Right now they are allocated right after uvc_format, without taking into consideration their required alignment. This is working fine because both structures have a field with a pointer, but it will stop working when the sizeof() of any of those structs is not a multiple of the sizeof(void*). Enforce that alignment during the allocation. Signed-off-by: Ricardo Ribalda Reviewed-by: Laurent Pinchart Link: https://lore.kernel.org/r/20240404-uvc-align-v2-1-9e104b0ecfbd@chromium.org Signed-off-by: Laurent Pinchart Signed-off-by: Sasha Levin --- drivers/media/usb/uvc/uvc_driver.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index 6334f99f1854..cfbc7595cd0b 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -948,16 +948,26 @@ static int uvc_parse_streaming(struct uvc_device *dev, goto error; } - size = nformats * sizeof(*format) + nframes * sizeof(*frame) + /* + * Allocate memory for the formats, the frames and the intervals, + * plus any required padding to guarantee that everything has the + * correct alignment. + */ + size = nformats * sizeof(*format); + size = ALIGN(size, __alignof__(*frame)) + nframes * sizeof(*frame); + size = ALIGN(size, __alignof__(*interval)) + nintervals * sizeof(*interval); + format = kzalloc(size, GFP_KERNEL); - if (format == NULL) { + if (!format) { ret = -ENOMEM; goto error; } - frame = (struct uvc_frame *)&format[nformats]; - interval = (u32 *)&frame[nframes]; + frame = (void *)format + nformats * sizeof(*format); + frame = PTR_ALIGN(frame, __alignof__(*frame)); + interval = (void *)frame + nframes * sizeof(*frame); + interval = PTR_ALIGN(interval, __alignof__(*interval)); streaming->format = format; streaming->nformats = nformats; -- 2.43.0