diff options
author | Roland Dreier <rolandd@cisco.com> | 2010-04-09 20:13:50 -0400 |
---|---|---|
committer | Roland Dreier <rolandd@cisco.com> | 2010-04-21 15:17:38 -0400 |
commit | bc1db9af731a74c7eca04df5936214c800774113 (patch) | |
tree | 52ca4cf47e7eac41cc0f743d325ba1dfd0950350 /drivers/infiniband | |
parent | 0eddb519b9127c73d53db4bf3ec1d45b13f844d1 (diff) |
IB: Explicitly rule out llseek to avoid BKL in default_llseek()
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>
Diffstat (limited to 'drivers/infiniband')
-rw-r--r-- | drivers/infiniband/core/ucm.c | 3 | ||||
-rw-r--r-- | drivers/infiniband/core/ucma.c | 4 | ||||
-rw-r--r-- | drivers/infiniband/core/user_mad.c | 12 | ||||
-rw-r--r-- | drivers/infiniband/core/uverbs_main.c | 11 |
4 files changed, 20 insertions, 10 deletions
diff --git a/drivers/infiniband/core/ucm.c b/drivers/infiniband/core/ucm.c index 512b1c43460c..46474842cfe9 100644 --- a/drivers/infiniband/core/ucm.c +++ b/drivers/infiniband/core/ucm.c | |||
@@ -1181,7 +1181,7 @@ static int ib_ucm_open(struct inode *inode, struct file *filp) | |||
1181 | file->filp = filp; | 1181 | file->filp = filp; |
1182 | file->device = container_of(inode->i_cdev, struct ib_ucm_device, cdev); | 1182 | file->device = container_of(inode->i_cdev, struct ib_ucm_device, cdev); |
1183 | 1183 | ||
1184 | return 0; | 1184 | return nonseekable_open(inode, filp); |
1185 | } | 1185 | } |
1186 | 1186 | ||
1187 | static int ib_ucm_close(struct inode *inode, struct file *filp) | 1187 | static int ib_ucm_close(struct inode *inode, struct file *filp) |
@@ -1229,6 +1229,7 @@ static const struct file_operations ucm_fops = { | |||
1229 | .release = ib_ucm_close, | 1229 | .release = ib_ucm_close, |
1230 | .write = ib_ucm_write, | 1230 | .write = ib_ucm_write, |
1231 | .poll = ib_ucm_poll, | 1231 | .poll = ib_ucm_poll, |
1232 | .llseek = no_llseek, | ||
1232 | }; | 1233 | }; |
1233 | 1234 | ||
1234 | static ssize_t show_ibdev(struct device *dev, struct device_attribute *attr, | 1235 | static ssize_t show_ibdev(struct device *dev, struct device_attribute *attr, |
diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c index 46185084121e..ac7edc24165c 100644 --- a/drivers/infiniband/core/ucma.c +++ b/drivers/infiniband/core/ucma.c | |||
@@ -1220,7 +1220,8 @@ static int ucma_open(struct inode *inode, struct file *filp) | |||
1220 | 1220 | ||
1221 | filp->private_data = file; | 1221 | filp->private_data = file; |
1222 | file->filp = filp; | 1222 | file->filp = filp; |
1223 | return 0; | 1223 | |
1224 | return nonseekable_open(inode, filp); | ||
1224 | } | 1225 | } |
1225 | 1226 | ||
1226 | static int ucma_close(struct inode *inode, struct file *filp) | 1227 | static int ucma_close(struct inode *inode, struct file *filp) |
@@ -1250,6 +1251,7 @@ static const struct file_operations ucma_fops = { | |||
1250 | .release = ucma_close, | 1251 | .release = ucma_close, |
1251 | .write = ucma_write, | 1252 | .write = ucma_write, |
1252 | .poll = ucma_poll, | 1253 | .poll = ucma_poll, |
1254 | .llseek = no_llseek, | ||
1253 | }; | 1255 | }; |
1254 | 1256 | ||
1255 | static struct miscdevice ucma_misc = { | 1257 | static struct miscdevice ucma_misc = { |
diff --git a/drivers/infiniband/core/user_mad.c b/drivers/infiniband/core/user_mad.c index e7db054fb1c8..6babb72b39fc 100644 --- a/drivers/infiniband/core/user_mad.c +++ b/drivers/infiniband/core/user_mad.c | |||
@@ -781,7 +781,7 @@ static int ib_umad_open(struct inode *inode, struct file *filp) | |||
781 | { | 781 | { |
782 | struct ib_umad_port *port; | 782 | struct ib_umad_port *port; |
783 | struct ib_umad_file *file; | 783 | struct ib_umad_file *file; |
784 | int ret = 0; | 784 | int ret; |
785 | 785 | ||
786 | port = container_of(inode->i_cdev, struct ib_umad_port, cdev); | 786 | port = container_of(inode->i_cdev, struct ib_umad_port, cdev); |
787 | if (port) | 787 | if (port) |
@@ -814,6 +814,8 @@ static int ib_umad_open(struct inode *inode, struct file *filp) | |||
814 | 814 | ||
815 | list_add_tail(&file->port_list, &port->file_list); | 815 | list_add_tail(&file->port_list, &port->file_list); |
816 | 816 | ||
817 | ret = nonseekable_open(inode, filp); | ||
818 | |||
817 | out: | 819 | out: |
818 | mutex_unlock(&port->file_mutex); | 820 | mutex_unlock(&port->file_mutex); |
819 | return ret; | 821 | return ret; |
@@ -866,7 +868,8 @@ static const struct file_operations umad_fops = { | |||
866 | .compat_ioctl = ib_umad_compat_ioctl, | 868 | .compat_ioctl = ib_umad_compat_ioctl, |
867 | #endif | 869 | #endif |
868 | .open = ib_umad_open, | 870 | .open = ib_umad_open, |
869 | .release = ib_umad_close | 871 | .release = ib_umad_close, |
872 | .llseek = no_llseek, | ||
870 | }; | 873 | }; |
871 | 874 | ||
872 | static int ib_umad_sm_open(struct inode *inode, struct file *filp) | 875 | 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) | |||
903 | 906 | ||
904 | filp->private_data = port; | 907 | filp->private_data = port; |
905 | 908 | ||
906 | return 0; | 909 | return nonseekable_open(inode, filp); |
907 | 910 | ||
908 | fail: | 911 | fail: |
909 | kref_put(&port->umad_dev->ref, ib_umad_release_dev); | 912 | 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) | |||
933 | static const struct file_operations umad_sm_fops = { | 936 | static const struct file_operations umad_sm_fops = { |
934 | .owner = THIS_MODULE, | 937 | .owner = THIS_MODULE, |
935 | .open = ib_umad_sm_open, | 938 | .open = ib_umad_sm_open, |
936 | .release = ib_umad_sm_close | 939 | .release = ib_umad_sm_close, |
940 | .llseek = no_llseek, | ||
937 | }; | 941 | }; |
938 | 942 | ||
939 | static struct ib_client umad_client = { | 943 | static struct ib_client umad_client = { |
diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c index fb3526254426..ec83e9fe387b 100644 --- a/drivers/infiniband/core/uverbs_main.c +++ b/drivers/infiniband/core/uverbs_main.c | |||
@@ -369,7 +369,8 @@ static const struct file_operations uverbs_event_fops = { | |||
369 | .read = ib_uverbs_event_read, | 369 | .read = ib_uverbs_event_read, |
370 | .poll = ib_uverbs_event_poll, | 370 | .poll = ib_uverbs_event_poll, |
371 | .release = ib_uverbs_event_close, | 371 | .release = ib_uverbs_event_close, |
372 | .fasync = ib_uverbs_event_fasync | 372 | .fasync = ib_uverbs_event_fasync, |
373 | .llseek = no_llseek, | ||
373 | }; | 374 | }; |
374 | 375 | ||
375 | void ib_uverbs_comp_handler(struct ib_cq *cq, void *cq_context) | 376 | 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) | |||
623 | 624 | ||
624 | filp->private_data = file; | 625 | filp->private_data = file; |
625 | 626 | ||
626 | return 0; | 627 | return nonseekable_open(inode, filp); |
627 | 628 | ||
628 | err_module: | 629 | err_module: |
629 | module_put(dev->ib_dev->owner); | 630 | module_put(dev->ib_dev->owner); |
@@ -651,7 +652,8 @@ static const struct file_operations uverbs_fops = { | |||
651 | .owner = THIS_MODULE, | 652 | .owner = THIS_MODULE, |
652 | .write = ib_uverbs_write, | 653 | .write = ib_uverbs_write, |
653 | .open = ib_uverbs_open, | 654 | .open = ib_uverbs_open, |
654 | .release = ib_uverbs_close | 655 | .release = ib_uverbs_close, |
656 | .llseek = no_llseek, | ||
655 | }; | 657 | }; |
656 | 658 | ||
657 | static const struct file_operations uverbs_mmap_fops = { | 659 | static const struct file_operations uverbs_mmap_fops = { |
@@ -659,7 +661,8 @@ static const struct file_operations uverbs_mmap_fops = { | |||
659 | .write = ib_uverbs_write, | 661 | .write = ib_uverbs_write, |
660 | .mmap = ib_uverbs_mmap, | 662 | .mmap = ib_uverbs_mmap, |
661 | .open = ib_uverbs_open, | 663 | .open = ib_uverbs_open, |
662 | .release = ib_uverbs_close | 664 | .release = ib_uverbs_close, |
665 | .llseek = no_llseek, | ||
663 | }; | 666 | }; |
664 | 667 | ||
665 | static struct ib_client uverbs_client = { | 668 | static struct ib_client uverbs_client = { |