aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/rdma
diff options
context:
space:
mode:
authorDean Luick <dean.luick@intel.com>2016-02-18 11:12:51 -0800
committerDoug Ledford <dledford@redhat.com>2016-03-10 20:45:45 -0500
commit7b47622d784311bff8218d03754fbf20529c1a71 (patch)
tree57f6a3bbbc296040c31c1e4ed60684905dab2b3b /drivers/staging/rdma
parentIB/rdamvt: fix cross build with rdmavt (diff)
downloadlinux-dev-7b47622d784311bff8218d03754fbf20529c1a71.tar.xz
linux-dev-7b47622d784311bff8218d03754fbf20529c1a71.zip
staging/rdma/hfi1: Guard i2c access against cp
An attempt to cp or cat /sys/kernel/debug/hfi1/hfi1_0/i2c1 produces this message: hfi1 0000:81:00.0: hfi1_0: IB0:1 I2C failed even retrying Fix the issue by explicitly rejecting a simple cat/cp with an -EINVAL error return. Reviewed-by: Easwar Hariharan <easwar.hariharan@intel.com> Signed-off-by: Dean Luick <dean.luick@intel.com> Signed-off-by: Doug Ledford <dledford@redhat.com>
Diffstat (limited to 'drivers/staging/rdma')
-rw-r--r--drivers/staging/rdma/hfi1/debugfs.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/drivers/staging/rdma/hfi1/debugfs.c b/drivers/staging/rdma/hfi1/debugfs.c
index 4fd58e374bb7..07c16b343ba0 100644
--- a/drivers/staging/rdma/hfi1/debugfs.c
+++ b/drivers/staging/rdma/hfi1/debugfs.c
@@ -446,6 +446,16 @@ static ssize_t __i2c_debugfs_write(struct file *file, const char __user *buf,
rcu_read_lock();
ppd = private2ppd(file);
+ /* byte offset format: [offsetSize][i2cAddr][offsetHigh][offsetLow] */
+ i2c_addr = (*ppos >> 16) & 0xffff;
+ offset = *ppos & 0xffff;
+
+ /* explicitly reject invalid address 0 to catch cp and cat */
+ if (i2c_addr == 0) {
+ ret = -EINVAL;
+ goto _return;
+ }
+
buff = kmalloc(count, GFP_KERNEL);
if (!buff) {
ret = -ENOMEM;
@@ -458,10 +468,6 @@ static ssize_t __i2c_debugfs_write(struct file *file, const char __user *buf,
goto _free;
}
- /* byte offset format: [offsetSize][i2cAddr][offsetHigh][offsetLow] */
- i2c_addr = (*ppos >> 16) & 0xffff;
- offset = *ppos & 0xffff;
-
total_written = i2c_write(ppd, target, i2c_addr, offset, buff, count);
if (total_written < 0) {
ret = total_written;
@@ -507,16 +513,22 @@ static ssize_t __i2c_debugfs_read(struct file *file, char __user *buf,
rcu_read_lock();
ppd = private2ppd(file);
+ /* byte offset format: [offsetSize][i2cAddr][offsetHigh][offsetLow] */
+ i2c_addr = (*ppos >> 16) & 0xffff;
+ offset = *ppos & 0xffff;
+
+ /* explicitly reject invalid address 0 to catch cp and cat */
+ if (i2c_addr == 0) {
+ ret = -EINVAL;
+ goto _return;
+ }
+
buff = kmalloc(count, GFP_KERNEL);
if (!buff) {
ret = -ENOMEM;
goto _return;
}
- /* byte offset format: [offsetSize][i2cAddr][offsetHigh][offsetLow] */
- i2c_addr = (*ppos >> 16) & 0xffff;
- offset = *ppos & 0xffff;
-
total_read = i2c_read(ppd, target, i2c_addr, offset, buff, count);
if (total_read < 0) {
ret = total_read;