Skip to content

Commit c47747f

Browse files
committed
fbmem: make read/write/ioctl use the frame buffer at open time
read/write/ioctl on a fbcon file descriptor has traditionally used the fbcon not when it was opened, but as it was at the time of the call. That makes no sense, but the lack of sense is much more obvious now that we properly ref-count the usage - it means that the ref-counting doesn't actually protect operations we do on the frame buffer. This changes it to look at the fb_info that we got at open time, but in order to avoid using a frame buffer long after it has been unregistered, we do verify that it is still current, and return -ENODEV if not. Acked-by: Tim Gardner <tim.gardner@canonical.com> Tested-by: Daniel J Blueman <daniel.blueman@gmail.com> Tested-by: Anca Emanuel <anca.emanuel@gmail.com> Cc: Bruno Prémont <bonbons@linux-vserver.org> Cc: Alan Cox <alan@lxorguk.ukuu.org.uk> Cc: Paul Mundt <lethal@linux-sh.org> Cc: Dave Airlie <airlied@redhat.com> Cc: Andy Whitcroft <andy.whitcroft@canonical.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 698b368 commit c47747f

1 file changed

Lines changed: 34 additions & 16 deletions

File tree

‎drivers/video/fbmem.c‎

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -717,13 +717,30 @@ static const struct file_operations fb_proc_fops = {
717717
.release = seq_release,
718718
};
719719

720-
static ssize_t
721-
fb_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
720+
/*
721+
* We hold a reference to the fb_info in file->private_data,
722+
* but if the current registered fb has changed, we don't
723+
* actually want to use it.
724+
*
725+
* So look up the fb_info using the inode minor number,
726+
* and just verify it against the reference we have.
727+
*/
728+
static struct fb_info *file_fb_info(struct file *file)
722729
{
723-
unsigned long p = *ppos;
724730
struct inode *inode = file->f_path.dentry->d_inode;
725731
int fbidx = iminor(inode);
726732
struct fb_info *info = registered_fb[fbidx];
733+
734+
if (info != file->private_data)
735+
info = NULL;
736+
return info;
737+
}
738+
739+
static ssize_t
740+
fb_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
741+
{
742+
unsigned long p = *ppos;
743+
struct fb_info *info = file_fb_info(file);
727744
u8 *buffer, *dst;
728745
u8 __iomem *src;
729746
int c, cnt = 0, err = 0;
@@ -788,9 +805,7 @@ static ssize_t
788805
fb_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
789806
{
790807
unsigned long p = *ppos;
791-
struct inode *inode = file->f_path.dentry->d_inode;
792-
int fbidx = iminor(inode);
793-
struct fb_info *info = registered_fb[fbidx];
808+
struct fb_info *info = file_fb_info(file);
794809
u8 *buffer, *src;
795810
u8 __iomem *dst;
796811
int c, cnt = 0, err = 0;
@@ -1168,10 +1183,10 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
11681183

11691184
static long fb_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
11701185
{
1171-
struct inode *inode = file->f_path.dentry->d_inode;
1172-
int fbidx = iminor(inode);
1173-
struct fb_info *info = registered_fb[fbidx];
1186+
struct fb_info *info = file_fb_info(file);
11741187

1188+
if (!info)
1189+
return -ENODEV;
11751190
return do_fb_ioctl(info, cmd, arg);
11761191
}
11771192

@@ -1292,12 +1307,13 @@ static int fb_get_fscreeninfo(struct fb_info *info, unsigned int cmd,
12921307
static long fb_compat_ioctl(struct file *file, unsigned int cmd,
12931308
unsigned long arg)
12941309
{
1295-
struct inode *inode = file->f_path.dentry->d_inode;
1296-
int fbidx = iminor(inode);
1297-
struct fb_info *info = registered_fb[fbidx];
1298-
struct fb_ops *fb = info->fbops;
1310+
struct fb_info *info = file_fb_info(file);
1311+
struct fb_ops *fb;
12991312
long ret = -ENOIOCTLCMD;
13001313

1314+
if (!info)
1315+
return -ENODEV;
1316+
fb = info->fbops;
13011317
switch(cmd) {
13021318
case FBIOGET_VSCREENINFO:
13031319
case FBIOPUT_VSCREENINFO:
@@ -1330,16 +1346,18 @@ static long fb_compat_ioctl(struct file *file, unsigned int cmd,
13301346
static int
13311347
fb_mmap(struct file *file, struct vm_area_struct * vma)
13321348
{
1333-
int fbidx = iminor(file->f_path.dentry->d_inode);
1334-
struct fb_info *info = registered_fb[fbidx];
1335-
struct fb_ops *fb = info->fbops;
1349+
struct fb_info *info = file_fb_info(file);
1350+
struct fb_ops *fb;
13361351
unsigned long off;
13371352
unsigned long start;
13381353
u32 len;
13391354

1355+
if (!info)
1356+
return -ENODEV;
13401357
if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
13411358
return -EINVAL;
13421359
off = vma->vm_pgoff << PAGE_SHIFT;
1360+
fb = info->fbops;
13431361
if (!fb)
13441362
return -ENODEV;
13451363
mutex_lock(&info->mm_lock);

0 commit comments

Comments
 (0)