summaryrefslogtreecommitdiff
path: root/tools/lib/python
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2025-11-14 02:18:22 -0500
committerAl Viro <viro@zeniv.linux.org.uk>2025-11-17 23:54:42 -0500
commite5bf5ee266633cb18fff6f98f0b7d59a62819eee (patch)
treec721823ca9d46d092f462727b3b7004031e5f84e /tools/lib/python
parent1544775687f093e799439fca5519340b88c84e2c (diff)
functionfs: fix the open/removal races
ffs_epfile_open() can race with removal, ending up with file->private_data pointing to freed object. There is a total count of opened files on functionfs (both ep0 and dynamic ones) and when it hits zero, dynamic files get removed. Unfortunately, that removal can happen while another thread is in ffs_epfile_open(), but has not incremented the count yet. In that case open will succeed, leaving us with UAF on any subsequent read() or write(). The root cause is that ffs->opened is misused; atomic_dec_and_test() vs. atomic_add_return() is not a good idea, when object remains visible all along. To untangle that * serialize openers on ffs->mutex (both for ep0 and for dynamic files) * have dynamic ones use atomic_inc_not_zero() and fail if we had zero ->opened; in that case the file we are opening is doomed. * have the inodes of dynamic files marked on removal (from the callback of simple_recursive_removal()) - clear ->i_private there. * have open of dynamic ones verify they hadn't been already removed, along with checking that state is FFS_ACTIVE. Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'tools/lib/python')
0 files changed, 0 insertions, 0 deletions