Skip to content

Commit cf6fa21

Browse files
DemiMariesmb49
authored andcommitted
block: increment diskseq on all media change events
BugLink: https://bugs.launchpad.net/bugs/2032689 commit b90ecc0 upstream. Currently, associating a loop device with a different file descriptor does not increment its diskseq. This allows the following race condition: 1. Program X opens a loop device 2. Program X gets the diskseq of the loop device. 3. Program X associates a file with the loop device. 4. Program X passes the loop device major, minor, and diskseq to something. 5. Program X exits. 6. Program Y detaches the file from the loop device. 7. Program Y attaches a different file to the loop device. 8. The opener finally gets around to opening the loop device and checks that the diskseq is what it expects it to be. Even though the diskseq is the expected value, the result is that the opener is accessing the wrong file. From discussions with Christoph Hellwig, it appears that disk_force_media_change() was supposed to call inc_diskseq(), but in fact it does not. Adding a Fixes: tag to indicate this. Christoph's Reported-by is because he stated that disk_force_media_change() calls inc_diskseq(), which is what led me to discover that it should but does not. Reported-by: Christoph Hellwig <[email protected]> Signed-off-by: Demi Marie Obenour <[email protected]> Fixes: e6138dc ("block: add a helper to raise a media changed event") Cc: [email protected] # 5.15+ Reviewed-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Kamal Mostafa <[email protected]> Signed-off-by: Stefan Bader <[email protected]>
1 parent 7f43888 commit cf6fa21

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

block/disk-events.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ bool disk_force_media_change(struct gendisk *disk, unsigned int events)
307307
if (!(events & DISK_EVENT_MEDIA_CHANGE))
308308
return false;
309309

310+
inc_diskseq(disk);
310311
if (__invalidate_device(disk->part0, true))
311312
pr_warn("VFS: busy inodes on changed media %s\n",
312313
disk->disk_name);

0 commit comments

Comments
 (0)