Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dma-buf: Move BUG_ON from _add_shared_fence to _add_shared_inplace

Fixes the BUG_ON spuriously triggering under the following
circumstances:

* reservation_object_reserve_shared is called with shared_count ==
shared_max - 1, so obj->staged is freed in preparation of an in-place
update.

* reservation_object_add_shared_fence is called with the first fence,
after which shared_count == shared_max.

* reservation_object_add_shared_fence is called with a follow-up fence
from the same context.

In the second reservation_object_add_shared_fence call, the BUG_ON
triggers. However, nothing bad would happen in
reservation_object_add_shared_inplace, since both fences are from the
same context, so they only occupy a single slot.

Prevent this by moving the BUG_ON to where an overflow would actually
happen (e.g. if a buggy caller didn't call
reservation_object_reserve_shared before).

v2:
* Fix description of breaking scenario (Christian König)
* Add bugzilla reference

Cc: stable@vger.kernel.org
Bugzilla: https://bugs.freedesktop.org/106418
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk> # v1
Reviewed-by: Christian König <christian.koenig@amd.com> # v1
Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20180704151405.10357-1-michel@daenzer.net

authored by

Michel Dänzer and committed by
Sumit Semwal
7f43ef9f 3273fc63

+3 -3
+3 -3
drivers/dma-buf/reservation.c
··· 141 141 if (signaled) { 142 142 RCU_INIT_POINTER(fobj->shared[signaled_idx], fence); 143 143 } else { 144 + BUG_ON(fobj->shared_count >= fobj->shared_max); 144 145 RCU_INIT_POINTER(fobj->shared[fobj->shared_count], fence); 145 146 fobj->shared_count++; 146 147 } ··· 231 230 old = reservation_object_get_list(obj); 232 231 obj->staged = NULL; 233 232 234 - if (!fobj) { 235 - BUG_ON(old->shared_count >= old->shared_max); 233 + if (!fobj) 236 234 reservation_object_add_shared_inplace(obj, old, fence); 237 - } else 235 + else 238 236 reservation_object_add_shared_replace(obj, old, fobj, fence); 239 237 } 240 238 EXPORT_SYMBOL(reservation_object_add_shared_fence);