Skip to content

Commit 7e9081c

Browse files
committed
drm/fence: fix memory overwrite when setting out_fence fd
Currently if the userspace declares a int variable to store the out_fence fd and pass it to OUT_FENCE_PTR the kernel will overwrite the 32 bits above the int variable on 64 bits systems. Fix this by making the internal storage of out_fence in the kernel a s32 pointer. Reported-by: Chad Versace <[email protected]> Signed-off-by: Gustavo Padovan <[email protected]> Fixes: beaf5af ("drm/fence: add out-fences support") Cc: Daniel Vetter <[email protected]> Cc: Rafael Antognolli <[email protected]> Cc: Laurent Pinchart <[email protected]> Acked-by: Laurent Pinchart <[email protected]> Reviewed-and-Tested-by: Chad Versace <[email protected]> Link: http://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 3846fd9 commit 7e9081c

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

drivers/gpu/drm/drm_atomic.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,15 @@ drm_atomic_get_crtc_state(struct drm_atomic_state *state,
291291
EXPORT_SYMBOL(drm_atomic_get_crtc_state);
292292

293293
static void set_out_fence_for_crtc(struct drm_atomic_state *state,
294-
struct drm_crtc *crtc, s64 __user *fence_ptr)
294+
struct drm_crtc *crtc, s32 __user *fence_ptr)
295295
{
296296
state->crtcs[drm_crtc_index(crtc)].out_fence_ptr = fence_ptr;
297297
}
298298

299-
static s64 __user *get_out_fence_for_crtc(struct drm_atomic_state *state,
299+
static s32 __user *get_out_fence_for_crtc(struct drm_atomic_state *state,
300300
struct drm_crtc *crtc)
301301
{
302-
s64 __user *fence_ptr;
302+
s32 __user *fence_ptr;
303303

304304
fence_ptr = state->crtcs[drm_crtc_index(crtc)].out_fence_ptr;
305305
state->crtcs[drm_crtc_index(crtc)].out_fence_ptr = NULL;
@@ -512,7 +512,7 @@ int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
512512
state->color_mgmt_changed |= replaced;
513513
return ret;
514514
} else if (property == config->prop_out_fence_ptr) {
515-
s64 __user *fence_ptr = u64_to_user_ptr(val);
515+
s32 __user *fence_ptr = u64_to_user_ptr(val);
516516

517517
if (!fence_ptr)
518518
return 0;
@@ -1915,7 +1915,7 @@ EXPORT_SYMBOL(drm_atomic_clean_old_fb);
19151915
*/
19161916

19171917
struct drm_out_fence_state {
1918-
s64 __user *out_fence_ptr;
1918+
s32 __user *out_fence_ptr;
19191919
struct sync_file *sync_file;
19201920
int fd;
19211921
};
@@ -1952,7 +1952,7 @@ static int prepare_crtc_signaling(struct drm_device *dev,
19521952
return 0;
19531953

19541954
for_each_crtc_in_state(state, crtc, crtc_state, i) {
1955-
u64 __user *fence_ptr;
1955+
s32 __user *fence_ptr;
19561956

19571957
fence_ptr = get_out_fence_for_crtc(crtc_state->state, crtc);
19581958

include/drm/drm_atomic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ struct __drm_crtcs_state {
144144
struct drm_crtc *ptr;
145145
struct drm_crtc_state *state;
146146
struct drm_crtc_commit *commit;
147-
s64 __user *out_fence_ptr;
147+
s32 __user *out_fence_ptr;
148148
};
149149

150150
struct __drm_connnectors_state {

include/drm/drm_mode_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ struct drm_mode_config {
488488
/**
489489
* @prop_out_fence_ptr: Sync File fd pointer representing the
490490
* outgoing fences for a CRTC. Userspace should provide a pointer to a
491-
* value of type s64, and then cast that pointer to u64.
491+
* value of type s32, and then cast that pointer to u64.
492492
*/
493493
struct drm_property *prop_out_fence_ptr;
494494
/**

0 commit comments

Comments
 (0)