Skip to contentSkip to conversation

media: usb: pwc-uncompress: Use flex array destination for memcpy()

PATCH In review Gustavo A. R. Silva 2 participants 2 messages Sep 7, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: usb: pwc-uncompress: Use flex array destination for memcpy()

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;

---
 drivers/media/usb/pwc/pwc-uncompress.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/pwc/pwc-uncompress.c +1 -1
index faf44cdeb268..cf2591a9675c 100644
@@ -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;
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines · Gustavo A. R. Silva

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
Quoted 8 lines

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;

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

Signature · 1 line
Kees Cook