fb: fix potential deadlock between lock_fb_info and console_lock
PATCH 1/1 fb: fix potential deadlock between lock_fb_info and console_lock
From: Andrea Righi <[email protected]>
Subject: fb: fix potential deadlock between lock_fb_info and console_lock
fb_set_suspend() must be called with the console semaphore held, which means the code path coming in here will first take the console_lock() and then call lock_fb_info().
However several framebuffer ioctl commands acquire these locks in reverse order (lock_fb_info() and then console_lock()). This gives rise to potential AB-BA deadlock.
Fix this by changing the order of acquisition in the ioctl commands that make use of console_lock().
---
drivers/video/fbmem.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-)
drivers/video/fbmem.c renamed from drivers/video/fbmem.c~fb-fix-potential-deadlock-between-lock_fb_info-and-console_lock +15 -9
@@ -1076,14 +1076,16 @@ static long do_fb_ioctl(struct fb_info *case FBIOPUT_VSCREENINFO :if (copy_from_user (&var, argp,sizeof (var)))return -EFAULT ; -if (!lock_fb_info (info)) -return -ENODEV ;console_lock (); +if (!lock_fb_info (info)) { +console_unlock (); +return -ENODEV ; + } info->flags |=FBINFO_MISC_USEREVENT ; ret =fb_set_var (info, &var); info->flags &= ~FBINFO_MISC_USEREVENT ; -console_unlock ();unlock_fb_info (info); +console_unlock ();if (!ret &©_to_user (argp, &var,sizeof (var))) ret = -EFAULT ;break ;
@@ -1112,12 +1114,14 @@ static long do_fb_ioctl(struct fb_info *case FBIOPAN_DISPLAY :if (copy_from_user (&var, argp,sizeof (var)))return -EFAULT ; -if (!lock_fb_info (info)) -return -ENODEV ;console_lock (); +if (!lock_fb_info (info)) { +console_unlock (); +return -ENODEV ; + } ret =fb_pan_display (info, &var); -console_unlock ();unlock_fb_info (info); +console_unlock ();if (ret =0 &©_to_user (argp, &var,sizeof (var)))return -EFAULT ;break ;
@@ -1159,14 +1163,16 @@ static long do_fb_ioctl(struct fb_info *unlock_fb_info (info);break ;case FBIOBLANK : -if (!lock_fb_info (info)) -return -ENODEV ;console_lock (); +if (!lock_fb_info (info)) { +console_unlock (); +return -ENODEV ; + } info->flags |=FBINFO_MISC_USEREVENT ; ret =fb_blank (info, arg); info->flags &= ~FBINFO_MISC_USEREVENT ; -console_unlock ();unlock_fb_info (info); +console_unlock ();break ;default :if (!lock_fb_info (info))
_
Re: [patch 1/1] fb: fix potential deadlock between lock_fb_info and
Hi Andrew,
Quoted 7 lines · On 09/20/2011 09:11 PM, [email protected] wrote:
From: Andrea Righi <[email protected]>
Subject: fb: fix potential deadlock betweenlock_fb_infoandconsole_lock
fb_set_suspend()must be called with the console semaphore held, which means the code path coming in here will first take theconsole_lock()and then calllock_fb_info().
Quoted 6 lines
However several framebuffer ioctl commands acquire these locks in reverse order (
lock_fb_info()and thenconsole_lock()). This gives rise to potential AB-BA deadlock.Fix this by changing the order of acquisition in the ioctl commands that make use of
console_lock().
I already have another patch [1] that fixes the same issue in a different way. It looks less risky than yours and got more feedback.
Best regards,
Florian Tobias Schandinat
[1] http://marc.info/?l=linux-kernel&m0833638508657&w=2
Quoted 75 lines
Signed-off-by Andrea Righi <[email protected]>Reported-by Peter Nordström (Palm GBU) <[email protected]>Cc Geert Uytterhoeven <[email protected]>Cc <[email protected]>Signed-off-by Andrew Morton <[email protected]>---
drivers/video/fbmem.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-)diff -puN
drivers/video/fbmem.c~fb-fix-potential-deadlock-between-lock_fb_info-and-console_lockdrivers/video/fbmem.cdrivers/video/fbmem.c renamed from drivers/video/fbmem.c~fb-fix-potential-deadlock-between-lock_fb_info-and-console_lock +15
-9@@ -1076,14 +1076,16 @@ static long do_fb_ioctl(struct fb_info *case FBIOPUT_VSCREENINFO :if (copy_from_user (&var, argp,sizeof (var)))return -EFAULT ; -if (!lock_fb_info (info)) -return -ENODEV ;console_lock (); +if (!lock_fb_info (info)) { +console_unlock (); +return -ENODEV ; + } info->flags |=FBINFO_MISC_USEREVENT ; ret =fb_set_var (info, &var); info->flags &= ~FBINFO_MISC_USEREVENT ; -console_unlock ();unlock_fb_info (info); +console_unlock ();if (!ret &©_to_user (argp, &var,sizeof (var))) ret = -EFAULT ;break ;@@ -1112,12 +1114,14 @@ static long do_fb_ioctl(struct fb_info *case FBIOPAN_DISPLAY :if (copy_from_user (&var, argp,sizeof (var)))return -EFAULT ; -if (!lock_fb_info (info)) -return -ENODEV ;console_lock (); +if (!lock_fb_info (info)) { +console_unlock (); +return -ENODEV ; + } ret =fb_pan_display (info, &var); -console_unlock ();unlock_fb_info (info); +console_unlock ();if (ret =0 &©_to_user (argp, &var,sizeof (var)))return -EFAULT ;break ;@@ -1159,14 +1163,16 @@ static long do_fb_ioctl(struct fb_info *unlock_fb_info (info);break ;case FBIOBLANK : -if (!lock_fb_info (info)) -return -ENODEV ;console_lock (); +if (!lock_fb_info (info)) { +console_unlock (); +return -ENODEV ; + } info->flags |=FBINFO_MISC_USEREVENT ; ret =fb_blank (info, arg); info->flags &= ~FBINFO_MISC_USEREVENT ; -console_unlock ();unlock_fb_info (info); +console_unlock ();break ;default :if (!lock_fb_info (info))_
Re: [patch 1/1] fb: fix potential deadlock between lock_fb_info and
In reply to [email protected]Quoted 21 lines · Florian Tobias Schandinat
Hi Andrew,
Quoted 7 lines · On 09/20/2011 09:11 PM, [email protected] wrote:
From: Andrea Righi <[email protected]>
Subject: fb: fix potential deadlock betweenlock_fb_infoandconsole_lock
fb_set_suspend()must be called with the console semaphore held, which means the code path coming in here will first take theconsole_lock()and then calllock_fb_info().Quoted 6 lines
However several framebuffer ioctl commands acquire these locks in reverse order (
lock_fb_info()and thenconsole_lock()). This gives rise to potential AB-BA deadlock.Fix this by changing the order of acquisition in the ioctl commands that make use of
console_lock().I already have another patch [1] that fixes the same issue in a different way. It looks less risky than yours and got more feedback.
Quoted 6 lines
Best regards,
Florian Tobias Schandinat
Looks better than my version.
For what it's worth it:
Thanks,
-Andrea