Skip to content

Commit fad2783

Browse files
committed
media: omap3isp: Use struct_group() for memcpy() region
In preparation for FORTIFY_SOURCE performing compile-time and run-time field bounds checking for memcpy(), memmove(), and memset(), avoid intentionally writing across neighboring fields. Wrap the target region in struct_group(). This additionally fixes a theoretical misalignment of the copy (since the size of "buf" changes between 64-bit and 32-bit, but this is likely never built for 64-bit). FWIW, I think this code is totally broken on 64-bit (which appears to not be a "real" build configuration): it would either always fail (with an uninitialized data->buf_size) or would cause corruption in userspace due to the copy_to_user() in the call path against an uninitialized data->buf value: omap3isp_stat_request_statistics_time32(...) struct omap3isp_stat_data data64; ... omap3isp_stat_request_statistics(stat, &data64); int omap3isp_stat_request_statistics(struct ispstat *stat, struct omap3isp_stat_data *data) ... buf = isp_stat_buf_get(stat, data); static struct ispstat_buffer *isp_stat_buf_get(struct ispstat *stat, struct omap3isp_stat_data *data) ... if (buf->buf_size > data->buf_size) { ... return ERR_PTR(-EINVAL); } ... rval = copy_to_user(data->buf, buf->virt_addr, buf->buf_size); Regardless, additionally initialize data64 to be zero-filled to avoid undefined behavior. Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Cc: Mauro Carvalho Chehab <mchehab@kernel.org> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Sakari Ailus <sakari.ailus@linux.intel.com> Cc: linux-media@vger.kernel.org Fixes: 378e3f8 ("media: omap3isp: support 64-bit version of omap3isp_stat_data") Cc: stable@vger.kernel.org Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org> Link: https://lore.kernel.org/lkml/20211215220505.GB21862@embeddedor Signed-off-by: Kees Cook <keescook@chromium.org>
1 parent e52432e commit fad2783

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

drivers/media/platform/omap3isp/ispstat.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ int omap3isp_stat_request_statistics(struct ispstat *stat,
512512
int omap3isp_stat_request_statistics_time32(struct ispstat *stat,
513513
struct omap3isp_stat_data_time32 *data)
514514
{
515-
struct omap3isp_stat_data data64;
515+
struct omap3isp_stat_data data64 = { };
516516
int ret;
517517

518518
ret = omap3isp_stat_request_statistics(stat, &data64);
@@ -521,7 +521,8 @@ int omap3isp_stat_request_statistics_time32(struct ispstat *stat,
521521

522522
data->ts.tv_sec = data64.ts.tv_sec;
523523
data->ts.tv_usec = data64.ts.tv_usec;
524-
memcpy(&data->buf, &data64.buf, sizeof(*data) - sizeof(data->ts));
524+
data->buf = (uintptr_t)data64.buf;
525+
memcpy(&data->frame, &data64.frame, sizeof(data->frame));
525526

526527
return 0;
527528
}

include/uapi/linux/omap3isp.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ struct omap3isp_h3a_aewb_config {
162162
* struct omap3isp_stat_data - Statistic data sent to or received from user
163163
* @ts: Timestamp of returned framestats.
164164
* @buf: Pointer to pass to user.
165+
* @buf_size: Size of buffer.
165166
* @frame_number: Frame number of requested stats.
166167
* @cur_frame: Current frame number being processed.
167168
* @config_counter: Number of the configuration associated with the data.
@@ -176,10 +177,12 @@ struct omap3isp_stat_data {
176177
struct timeval ts;
177178
#endif
178179
void __user *buf;
179-
__u32 buf_size;
180-
__u16 frame_number;
181-
__u16 cur_frame;
182-
__u16 config_counter;
180+
__struct_group(/* no tag */, frame, /* no attrs */,
181+
__u32 buf_size;
182+
__u16 frame_number;
183+
__u16 cur_frame;
184+
__u16 config_counter;
185+
);
183186
};
184187

185188
#ifdef __KERNEL__
@@ -189,10 +192,12 @@ struct omap3isp_stat_data_time32 {
189192
__s32 tv_usec;
190193
} ts;
191194
__u32 buf;
192-
__u32 buf_size;
193-
__u16 frame_number;
194-
__u16 cur_frame;
195-
__u16 config_counter;
195+
__struct_group(/* no tag */, frame, /* no attrs */,
196+
__u32 buf_size;
197+
__u16 frame_number;
198+
__u16 cur_frame;
199+
__u16 config_counter;
200+
);
196201
};
197202
#endif
198203

0 commit comments

Comments
 (0)