Skip to content

Commit 5510bd8

Browse files
nicolincjgunthorpe
authored andcommitted
iommufd: Do not allow _iommufd_object_alloc_ucmd if abort op is set
An abort op was introduced to allow its caller to invoke it within a lock in the caller's function. On the other hand, _iommufd_object_alloc_ucmd() would invoke the abort op in iommufd_object_abort_and_destroy() that must be outside the caller's lock. So, these two cannot work together. Add a validation in the _iommufd_object_alloc_ucmd(). Pick -EOPNOTSUPP to reject the function call, indicating that the object allocator is buggy. Link: https://patch.msgid.link/r/[email protected] Suggested-by: Xu Yilun <[email protected]> Signed-off-by: Nicolin Chen <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Reviewed-by: Xu Yilun <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 32b2d3a commit 5510bd8

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

drivers/iommu/iommufd/main.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ struct iommufd_object *_iommufd_object_alloc_ucmd(struct iommufd_ucmd *ucmd,
7171
if (WARN_ON(ucmd->new_obj))
7272
return ERR_PTR(-EBUSY);
7373

74+
/*
75+
* An abort op means that its caller needs to invoke it within a lock in
76+
* the caller. So it doesn't work with _iommufd_object_alloc_ucmd() that
77+
* will invoke the abort op in iommufd_object_abort_and_destroy(), which
78+
* must be outside the caller's lock.
79+
*/
80+
if (WARN_ON(iommufd_object_ops[type].abort))
81+
return ERR_PTR(-EOPNOTSUPP);
82+
7483
new_obj = _iommufd_object_alloc(ucmd->ictx, size, type);
7584
if (IS_ERR(new_obj))
7685
return new_obj;

0 commit comments

Comments
 (0)