Skip to content

scsi: target: tcmu: Fix memory leak

Bodo Stroesser linux-scsi target-devel 1 version Applied

Status from this message: Applied to 5.12/scsi-staging, thanks!

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 3 repliesApplied

Patches in v1 Applied

#Subject and filesSizeRepliesApplied
1/2scsi: target: tcmu: Move some functions without code changedrivers/target/target_core_user.c+80 -800 replies
2/2scsi: target: tcmu: Fix memory leak caused by wrong uio usagedrivers/target/target_core_user.c+26 -30 replies

Reviews trailers per patch

None of the 2 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchMike Christie
SeriesR-b
1/2
2/2

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/2] scsi: target: tcmu: Fix memory leak

This small series applies to Martin's for-next.

This is the third attempt to fix a severe memory leak in tcmu. Previous patches:
https://lore.kernel.org/linux-scsi/[email protected]/
and
https://lore.kernel.org/linux-scsi/[email protected]/

Tcmu's refcounting relies on tcmu_open and tcmu_release being called symmetrically by uio. But that is not true if userspace daemon holds the uio device open or mmap'ed while tcmu calls uio_unregister device. So refcount can stay above 0 for ever, which means that tcmu does not free resources of a tcmu device. In extreme cases the amount of memory leaked can be > 1 GB for a single destroyed tcmu device.

This new patch series fixes the problem by moving refcounting from tcmu_open/tcmu_release to new vm_operations_struct::open/*::close handlers, which are called under all conditions.

Bodo Stroesser (2):
scsi: target: tcmu: Move some functions without code change
scsi: target: tcmu: Fix memory leak caused by wrong uio usage

 drivers/target/target_core_user.c | 189 +++++++++++++++++++++-----------------
 1 file changed, 106 insertions(+), 83 deletions(-)
Signature · 1 line
2.12.3