]> git.karo-electronics.de Git - linux-beck.git/commitdiff
IB: Explicitly rule out llseek to avoid BKL in default_llseek()
authorRoland Dreier <rolandd@cisco.com>
Sat, 10 Apr 2010 00:13:50 +0000 (17:13 -0700)
committerRoland Dreier <rolandd@cisco.com>
Wed, 21 Apr 2010 19:17:38 +0000 (12:17 -0700)
Several RDMA user-access drivers have file_operations structures with
no .llseek method set.  None of the drivers actually do anything with
f_pos, so this means llseek is essentially a NOP, instead of returning
an error as leaving other file_operations methods unimplemented would
do.  This is mostly harmless, except that a NULL .llseek means that
default_llseek() is used, and this function grabs the BKL, which we
would like to avoid.

Since llseek does nothing useful on these files, we would like it to
return an error to userspace instead of silently grabbing the BKL and
succeeding.  For nearly all of the file types, we take the
belt-and-suspenders approach of setting the .llseek method to
no_llseek and also calling nonseekable_open(); the exception is the
uverbs_event files, which are created with anon_inode_getfile(), which
already sets f_mode the same way as nonseekable_open() would.

This work is motivated by Arnd Bergmann's bkl-removal tree.

Signed-off-by: Roland Dreier <rolandd@cisco.com>
drivers/infiniband/core/ucm.c
drivers/infiniband/core/ucma.c
drivers/infiniband/core/user_mad.c
drivers/infiniband/core/uverbs_main.c

index 512b1c43460c2d40dfb5c410996dff1905ec56df..46474842cfe9a8cd92bebf77170ae7ec02048bb2 100644 (file)
@@ -1181,7 +1181,7 @@ static int ib_ucm_open(struct inode *inode, struct file *filp)
        file->filp = filp;
        file->device = container_of(inode->i_cdev, struct ib_ucm_device, cdev);
 
-       return 0;
+       return nonseekable_open(inode, filp);
 }
 
 static int ib_ucm_close(struct inode *inode, struct file *filp)
@@ -1229,6 +1229,7 @@ static const struct file_operations ucm_fops = {
        .release = ib_ucm_close,
        .write   = ib_ucm_write,
        .poll    = ib_ucm_poll,
+       .llseek  = no_llseek,
 };
 
 static ssize_t show_ibdev(struct device *dev, struct device_attribute *attr,
index 46185084121e28b7cd233ccd9df581d4579106d0..ac7edc24165cd5902d1557df18a0e130cf7f5458 100644 (file)
@@ -1220,7 +1220,8 @@ static int ucma_open(struct inode *inode, struct file *filp)
 
        filp->private_data = file;
        file->filp = filp;
-       return 0;
+
+       return nonseekable_open(inode, filp);
 }
 
 static int ucma_close(struct inode *inode, struct file *filp)
@@ -1250,6 +1251,7 @@ static const struct file_operations ucma_fops = {
        .release = ucma_close,
        .write   = ucma_write,
        .poll    = ucma_poll,
+       .llseek  = no_llseek,
 };
 
 static struct miscdevice ucma_misc = {
index e7db054fb1c888900c9e9a1df4e136e6cd7910d1..6babb72b39fc462b8c36b9101871524e9c6c3657 100644 (file)
@@ -781,7 +781,7 @@ static int ib_umad_open(struct inode *inode, struct file *filp)
 {
        struct ib_umad_port *port;
        struct ib_umad_file *file;
-       int ret = 0;
+       int ret;
 
        port = container_of(inode->i_cdev, struct ib_umad_port, cdev);
        if (port)
@@ -814,6 +814,8 @@ static int ib_umad_open(struct inode *inode, struct file *filp)
 
        list_add_tail(&file->port_list, &port->file_list);
 
+       ret = nonseekable_open(inode, filp);
+
 out:
        mutex_unlock(&port->file_mutex);
        return ret;
@@ -866,7 +868,8 @@ static const struct file_operations umad_fops = {
        .compat_ioctl   = ib_umad_compat_ioctl,
 #endif
        .open           = ib_umad_open,
-       .release        = ib_umad_close
+       .release        = ib_umad_close,
+       .llseek         = no_llseek,
 };
 
 static int ib_umad_sm_open(struct inode *inode, struct file *filp)
@@ -903,7 +906,7 @@ static int ib_umad_sm_open(struct inode *inode, struct file *filp)
 
        filp->private_data = port;
 
-       return 0;
+       return nonseekable_open(inode, filp);
 
 fail:
        kref_put(&port->umad_dev->ref, ib_umad_release_dev);
@@ -933,7 +936,8 @@ static int ib_umad_sm_close(struct inode *inode, struct file *filp)
 static const struct file_operations umad_sm_fops = {
        .owner   = THIS_MODULE,
        .open    = ib_umad_sm_open,
-       .release = ib_umad_sm_close
+       .release = ib_umad_sm_close,
+       .llseek  = no_llseek,
 };
 
 static struct ib_client umad_client = {
index fb35262544260144c52cd7c583a1750cebd730e4..ec83e9fe387bd9112266d984254a9f00200e7652 100644 (file)
@@ -369,7 +369,8 @@ static const struct file_operations uverbs_event_fops = {
        .read    = ib_uverbs_event_read,
        .poll    = ib_uverbs_event_poll,
        .release = ib_uverbs_event_close,
-       .fasync  = ib_uverbs_event_fasync
+       .fasync  = ib_uverbs_event_fasync,
+       .llseek  = no_llseek,
 };
 
 void ib_uverbs_comp_handler(struct ib_cq *cq, void *cq_context)
@@ -623,7 +624,7 @@ static int ib_uverbs_open(struct inode *inode, struct file *filp)
 
        filp->private_data = file;
 
-       return 0;
+       return nonseekable_open(inode, filp);
 
 err_module:
        module_put(dev->ib_dev->owner);
@@ -651,7 +652,8 @@ static const struct file_operations uverbs_fops = {
        .owner   = THIS_MODULE,
        .write   = ib_uverbs_write,
        .open    = ib_uverbs_open,
-       .release = ib_uverbs_close
+       .release = ib_uverbs_close,
+       .llseek  = no_llseek,
 };
 
 static const struct file_operations uverbs_mmap_fops = {
@@ -659,7 +661,8 @@ static const struct file_operations uverbs_mmap_fops = {
        .write   = ib_uverbs_write,
        .mmap    = ib_uverbs_mmap,
        .open    = ib_uverbs_open,
-       .release = ib_uverbs_close
+       .release = ib_uverbs_close,
+       .llseek  = no_llseek,
 };
 
 static struct ib_client uverbs_client = {