fbdev: put module after running driver callback
Subsystems (2)
PATCH 1/1 fbdev: put module after running driver callback
Currently, for each open() on an fbdev device, we pin the underlying fbdev device and driver module. On close(), we release both. This guarantees that the fbdev object stays around until the last FD is released (even though it might be unregistered already).
However, currently we call module_put() *before* calling put_fb_info(). This has the side-effect that the driver module might be unloaded before put_fb_info() calls into fbinfo->fbops->fb_destroy().
Fix this by keeping the module pinned until after we release our fbdev reference. Note that register_framebuffer() and unregister_framebuffer() are special as we require the driver to unregister device before unloading. Hence, they don't need to pin the module. However, all open handlers *have to*.
--- drivers/video/fbdev/core/fbmem.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/video/fbdev/core/fbmem.c +4 -1
@@ -1482,13 +1482,16 @@ __acquires(&info->lock) __releases(&info->lock) {struct fb_info *const info = file->private_data; +struct module *owner;mutex_lock (&info->lock);if (info->fbops->fb_release) info->fbops->fb_release (info,1 ); -module_put (info->fbops->owner); + owner = info->fbops->owner;mutex_unlock (&info->lock); +put_fb_info (info); +module_put (owner);return 0 ; }
Signature · 1 line
2.5.1
Quoted 31 lines · David Herrmann
Currently, for each
open()on an fbdev device, we pin the underlying fbdev device and driver module. Onclose(), we release both. This guarantees that the fbdev object stays around until the last FD is released (even though it might be unregistered already).However, currently we call
module_put()*before* callingput_fb_info(). This has the side-effect that the driver module might be unloaded beforeput_fb_info()calls intofbinfo->fbops->fb_destroy().Fix this by keeping the module pinned until after we release our fbdev reference. Note that
register_framebuffer()andunregister_framebuffer()are special as we require the driver to unregister device before unloading. Hence, they don't need to pin the module. However, all open handlers *have to*.Signed-off-by David Herrmann <[email protected]>--- drivers/video/fbdev/core/fbmem.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/video/fbdev/core/fbmem.c +1
-0@@ -1482,13 +1482,16 @@ __acquires(&info->lock) __releases(&info->lock) {struct fb_info *const info = file->private_data; +struct module *owner;mutex_lock (&info->lock);
drivers/video/fbdev/core/fbmem.c __acquires(&info->lock) · line 1496
Quoted 10 lines
drivers/video/fbdev/core/fbmem.c +3
-1if (info->fbops->fb_release) info->fbops->fb_release (info,1 ); -module_put (info->fbops->owner); + owner = info->fbops->owner;mutex_unlock (&info->lock); +put_fb_info (info); +module_put (owner);return 0 ; }
Looking at fb_open(), in error case it calls module_put() followed by put_fb_info(). Is that broken also?
Have you hit this bug, or did you just find it by looking at the code? In other words, is this for 4.3 fixes, or 4.4. I guess the user needs to unload the module just at the right time to trigger this bug.
Tomi
Hi
Quoted 32 lines · Tomi Valkeinen
Quoted 30 lines · David Herrmann
Currently, for each
open()on an fbdev device, we pin the underlying fbdev device and driver module. Onclose(), we release both. This guarantees that the fbdev object stays around until the last FD is released (even though it might be unregistered already).However, currently we call
module_put()*before* callingput_fb_info(). This has the side-effect that the driver module might be unloaded beforeput_fb_info()calls intofbinfo->fbops->fb_destroy().Fix this by keeping the module pinned until after we release our fbdev reference. Note that
register_framebuffer()andunregister_framebuffer()are special as we require the driver to unregister device before unloading. Hence, they don't need to pin the module. However, all open handlers *have to*.Signed-off-by David Herrmann <[email protected]>--- drivers/video/fbdev/core/fbmem.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/video/fbdev/core/fbmem.c +1
-0@@ -1482,13 +1482,16 @@ __acquires(&info->lock) __releases(&info->lock) {struct fb_info *const info = file->private_data; +struct module *owner;
Quoted 14 lines
drivers/video/fbdev/core/fbmem.c __acquires(&info->lock) · line 1496
Quoted 11 lines
drivers/video/fbdev/core/fbmem.c +3
-1mutex_lock (&info->lock);if (info->fbops->fb_release) info->fbops->fb_release (info,1 ); -module_put (info->fbops->owner); + owner = info->fbops->owner;mutex_unlock (&info->lock); +put_fb_info (info); +module_put (owner);return 0 ; }Looking at
fb_open(), in error case it callsmodule_put()followed byput_fb_info(). Is that broken also?
Indeed, same issue here. I will send v2 which fixes both.
Quoted 3 lines
Have you hit this bug, or did you just find it by looking at the code? In other words, is this for 4.3 fixes, or 4.4. I guess the user needs to unload the module just at the right time to trigger this bug.
Theoretical issue. It's almost impossible to trigger, as module unloading takes ages compared to the time required to release the fbinfo.
Thanks
David