]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
IB/ipath: Prevent random program use of diags interface
authorBryan O'Sullivan <bos@pathscale.com>
Thu, 15 Mar 2007 21:45:10 +0000 (14:45 -0700)
committerRoland Dreier <rolandd@cisco.com>
Thu, 19 Apr 2007 03:20:59 +0000 (20:20 -0700)
To prevent random utility reads and writes of the diag interface to the
chip, we first require a handshake of reading from offset 0 and writing
to offset 0 before any other reads or writes can be done through the
diags device.   Otherwise chip errors can be triggered.

Signed-off-by: Dave Olson <dave.olson@qlogic.com>
Signed-off-by: Bryan O'Sullivan <bryan.osullivan@qlogic.com>
Signed-off-by: Roland Dreier <rolandd@cisco.com>
drivers/infiniband/hw/ipath/ipath_diag.c

index 0f13a2182cc7d1bd0707058dc435f07343b2162f..63e8368b0e95260011a0ad8733624ce064d54f0a 100644 (file)
@@ -296,7 +296,7 @@ static int ipath_diag_open(struct inode *in, struct file *fp)
        }
 
        fp->private_data = dd;
-       ipath_diag_inuse = 1;
+       ipath_diag_inuse = -2;
        diag_set_link = 0;
        ret = 0;
 
@@ -461,6 +461,8 @@ static ssize_t ipath_diag_read(struct file *fp, char __user *data,
        else if ((count % 4) || (*off % 4))
                /* address or length is not 32-bit aligned, hence invalid */
                ret = -EINVAL;
+       else if (ipath_diag_inuse < 1 && (*off || count != 8))
+               ret = -EINVAL;  /* prevent cat /dev/ipath_diag* */
        else if ((count % 8) || (*off % 8))
                /* address or length not 64-bit aligned; do 32-bit reads */
                ret = ipath_read_umem32(dd, data, kreg_base + *off, count);
@@ -470,6 +472,8 @@ static ssize_t ipath_diag_read(struct file *fp, char __user *data,
        if (ret >= 0) {
                *off += count;
                ret = count;
+               if (ipath_diag_inuse == -2)
+                       ipath_diag_inuse++;
        }
 
        return ret;
@@ -489,6 +493,9 @@ static ssize_t ipath_diag_write(struct file *fp, const char __user *data,
        else if ((count % 4) || (*off % 4))
                /* address or length is not 32-bit aligned, hence invalid */
                ret = -EINVAL;
+       else if ((ipath_diag_inuse == -1 && (*off || count != 8)) ||
+                ipath_diag_inuse == -2)  /* read qw off 0, write qw off 0 */
+               ret = -EINVAL;  /* before any other write allowed */
        else if ((count % 8) || (*off % 8))
                /* address or length not 64-bit aligned; do 32-bit writes */
                ret = ipath_write_umem32(dd, kreg_base + *off, data, count);
@@ -498,6 +505,8 @@ static ssize_t ipath_diag_write(struct file *fp, const char __user *data,
        if (ret >= 0) {
                *off += count;
                ret = count;
+               if (ipath_diag_inuse == -1)
+                       ipath_diag_inuse = 1; /* all read/write OK now */
        }
 
        return ret;