linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] media: usb: pwc-uncompress: Use flex array destination for memcpy()
@ 2022-09-07 18:55 Gustavo A. R. Silva
  2022-09-07 22:25 ` Kees Cook
  0 siblings, 1 reply; 2+ messages in thread
From: Gustavo A. R. Silva @ 2022-09-07 18:55 UTC (permalink / raw)
  To: Hans Verkuil, Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel, Gustavo A. R. Silva, linux-hardening

In preparation for FORTIFY_SOURCE performing run-time destination buffer
bounds checking for memcpy(), specify the destination output buffer
explicitly, instead of asking memcpy() to write past the end of what looked
like a fixed-size object.

Notice that raw_frame is a pointer to a structure that contains
flexible-array member rawframe[]:

drivers/media/usb/pwc/pwc.h:
190 struct pwc_raw_frame {
191         __le16 type;            /* type of the webcam */
192         __le16 vbandlength;     /* Size of 4 lines compressed (used by the
193                                    decompressor) */
194         __u8   cmd[4];          /* the four byte of the command (in case of
195                                    nala, only the first 3 bytes is filled) */
196         __u8   rawframe[];      /* frame_size = H / 4 * vbandlength */
197 } __packed;

Link: https://github.com/KSPP/linux/issues/200
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 drivers/media/usb/pwc/pwc-uncompress.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/usb/pwc/pwc-uncompress.c b/drivers/media/usb/pwc/pwc-uncompress.c
index faf44cdeb268..cf2591a9675c 100644
--- a/drivers/media/usb/pwc/pwc-uncompress.c
+++ b/drivers/media/usb/pwc/pwc-uncompress.c
@@ -39,7 +39,7 @@ int pwc_decompress(struct pwc_device *pdev, struct pwc_frame_buf *fbuf)
 			 * first 3 bytes is filled (Nala case). We can
 			 * determine this using the type of the webcam */
 		memcpy(raw_frame->cmd, pdev->cmd_buf, 4);
-		memcpy(raw_frame+1, yuv, pdev->frame_size);
+		memcpy(raw_frame->rawframe, yuv, pdev->frame_size);
 		vb2_set_plane_payload(&fbuf->vb.vb2_buf, 0,
 			struct_size(raw_frame, rawframe, pdev->frame_size));
 		return 0;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH][next] media: usb: pwc-uncompress: Use flex array destination for memcpy()
  2022-09-07 18:55 [PATCH][next] media: usb: pwc-uncompress: Use flex array destination for memcpy() Gustavo A. R. Silva
@ 2022-09-07 22:25 ` Kees Cook
  0 siblings, 0 replies; 2+ messages in thread
From: Kees Cook @ 2022-09-07 22:25 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Hans Verkuil, Mauro Carvalho Chehab, linux-media, linux-kernel,
	linux-hardening

On Wed, Sep 07, 2022 at 07:55:44PM +0100, Gustavo A. R. Silva wrote:
> In preparation for FORTIFY_SOURCE performing run-time destination buffer
> bounds checking for memcpy(), specify the destination output buffer
> explicitly, instead of asking memcpy() to write past the end of what looked
> like a fixed-size object.
> 
> Notice that raw_frame is a pointer to a structure that contains
> flexible-array member rawframe[]:
> 
> drivers/media/usb/pwc/pwc.h:
> 190 struct pwc_raw_frame {
> 191         __le16 type;            /* type of the webcam */
> 192         __le16 vbandlength;     /* Size of 4 lines compressed (used by the
> 193                                    decompressor) */
> 194         __u8   cmd[4];          /* the four byte of the command (in case of
> 195                                    nala, only the first 3 bytes is filled) */
> 196         __u8   rawframe[];      /* frame_size = H / 4 * vbandlength */
> 197 } __packed;
> 
> Link: https://github.com/KSPP/linux/issues/200
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks! Yeah, this looks very similar to other transformations like
this. And this one even had the flex array already! :)

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-07 22:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-07 18:55 [PATCH][next] media: usb: pwc-uncompress: Use flex array destination for memcpy() Gustavo A. R. Silva
2022-09-07 22:25 ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).