Commit 62d50add authored by Trent Piepho's avatar Trent Piepho Committed by Mauro Carvalho Chehab

V4L/DVB (5163): Add checks for CAP_SYS_ADMIN to VIDIOC_DBG_G_REGISTER

Before, root privileges were only needed to set hardware registers, not
to read them.  On some hardware, reading from the wrong place at the
wrong time can hang the machine.  So, to be consistent, root privileges
are required to read registers on all hardware.
Signed-off-by: default avatarTrent Piepho <xyzzy@speakeasy.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@infradead.org>
parent e7b58f52
...@@ -629,15 +629,6 @@ static int cx25840_command(struct i2c_client *client, unsigned int cmd, ...@@ -629,15 +629,6 @@ static int cx25840_command(struct i2c_client *client, unsigned int cmd,
/* ioctls to allow direct access to the /* ioctls to allow direct access to the
* cx25840 registers for testing */ * cx25840 registers for testing */
case VIDIOC_DBG_G_REGISTER: case VIDIOC_DBG_G_REGISTER:
{
struct v4l2_register *reg = arg;
if (reg->i2c_id != I2C_DRIVERID_CX25840)
return -EINVAL;
reg->val = cx25840_read(client, reg->reg & 0x0fff);
break;
}
case VIDIOC_DBG_S_REGISTER: case VIDIOC_DBG_S_REGISTER:
{ {
struct v4l2_register *reg = arg; struct v4l2_register *reg = arg;
...@@ -646,6 +637,9 @@ static int cx25840_command(struct i2c_client *client, unsigned int cmd, ...@@ -646,6 +637,9 @@ static int cx25840_command(struct i2c_client *client, unsigned int cmd,
return -EINVAL; return -EINVAL;
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EPERM; return -EPERM;
if (cmd == VIDIOC_DBG_G_REGISTER)
reg->val = cx25840_read(client, reg->reg & 0x0fff);
else
cx25840_write(client, reg->reg & 0x0fff, reg->val & 0xff); cx25840_write(client, reg->reg & 0x0fff, reg->val & 0xff);
break; break;
} }
......
...@@ -1418,15 +1418,6 @@ static int saa711x_command(struct i2c_client *client, unsigned int cmd, void *ar ...@@ -1418,15 +1418,6 @@ static int saa711x_command(struct i2c_client *client, unsigned int cmd, void *ar
#ifdef CONFIG_VIDEO_ADV_DEBUG #ifdef CONFIG_VIDEO_ADV_DEBUG
case VIDIOC_DBG_G_REGISTER: case VIDIOC_DBG_G_REGISTER:
{
struct v4l2_register *reg = arg;
if (reg->i2c_id != I2C_DRIVERID_SAA711X)
return -EINVAL;
reg->val = saa711x_read(client, reg->reg & 0xff);
break;
}
case VIDIOC_DBG_S_REGISTER: case VIDIOC_DBG_S_REGISTER:
{ {
struct v4l2_register *reg = arg; struct v4l2_register *reg = arg;
...@@ -1435,6 +1426,9 @@ static int saa711x_command(struct i2c_client *client, unsigned int cmd, void *ar ...@@ -1435,6 +1426,9 @@ static int saa711x_command(struct i2c_client *client, unsigned int cmd, void *ar
return -EINVAL; return -EINVAL;
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EPERM; return -EPERM;
if (cmd == VIDIOC_DBG_G_REGISTER)
reg->val = saa711x_read(client, reg->reg & 0xff);
else
saa711x_write(client, reg->reg & 0xff, reg->val & 0xff); saa711x_write(client, reg->reg & 0xff, reg->val & 0xff);
break; break;
} }
......
...@@ -615,15 +615,6 @@ static int saa7127_command(struct i2c_client *client, ...@@ -615,15 +615,6 @@ static int saa7127_command(struct i2c_client *client,
#ifdef CONFIG_VIDEO_ADV_DEBUG #ifdef CONFIG_VIDEO_ADV_DEBUG
case VIDIOC_DBG_G_REGISTER: case VIDIOC_DBG_G_REGISTER:
{
struct v4l2_register *reg = arg;
if (reg->i2c_id != I2C_DRIVERID_SAA7127)
return -EINVAL;
reg->val = saa7127_read(client, reg->reg & 0xff);
break;
}
case VIDIOC_DBG_S_REGISTER: case VIDIOC_DBG_S_REGISTER:
{ {
struct v4l2_register *reg = arg; struct v4l2_register *reg = arg;
...@@ -632,6 +623,9 @@ static int saa7127_command(struct i2c_client *client, ...@@ -632,6 +623,9 @@ static int saa7127_command(struct i2c_client *client,
return -EINVAL; return -EINVAL;
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EPERM; return -EPERM;
if (cmd == VIDIOC_DBG_G_REGISTER)
reg->val = saa7127_read(client, reg->reg & 0xff);
else
saa7127_write(client, reg->reg & 0xff, reg->val & 0xff); saa7127_write(client, reg->reg & 0xff, reg->val & 0xff);
break; break;
} }
......
...@@ -951,15 +951,6 @@ static int tvp5150_command(struct i2c_client *c, ...@@ -951,15 +951,6 @@ static int tvp5150_command(struct i2c_client *c,
#ifdef CONFIG_VIDEO_ADV_DEBUG #ifdef CONFIG_VIDEO_ADV_DEBUG
case VIDIOC_DBG_G_REGISTER: case VIDIOC_DBG_G_REGISTER:
{
struct v4l2_register *reg = arg;
if (reg->i2c_id != I2C_DRIVERID_TVP5150)
return -EINVAL;
reg->val = tvp5150_read(c, reg->reg & 0xff);
break;
}
case VIDIOC_DBG_S_REGISTER: case VIDIOC_DBG_S_REGISTER:
{ {
struct v4l2_register *reg = arg; struct v4l2_register *reg = arg;
...@@ -968,6 +959,9 @@ static int tvp5150_command(struct i2c_client *c, ...@@ -968,6 +959,9 @@ static int tvp5150_command(struct i2c_client *c,
return -EINVAL; return -EINVAL;
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EPERM; return -EPERM;
if (cmd == VIDIOC_DBG_G_REGISTER)
reg->val = tvp5150_read(c, reg->reg & 0xff);
else
tvp5150_write(c, reg->reg & 0xff, reg->val & 0xff); tvp5150_write(c, reg->reg & 0xff, reg->val & 0xff);
break; break;
} }
......
...@@ -163,26 +163,18 @@ static int upd64031a_command(struct i2c_client *client, unsigned int cmd, void * ...@@ -163,26 +163,18 @@ static int upd64031a_command(struct i2c_client *client, unsigned int cmd, void *
#ifdef CONFIG_VIDEO_ADV_DEBUG #ifdef CONFIG_VIDEO_ADV_DEBUG
case VIDIOC_DBG_G_REGISTER: case VIDIOC_DBG_G_REGISTER:
{
struct v4l2_register *reg = arg;
if (reg->i2c_id != I2C_DRIVERID_UPD64031A)
return -EINVAL;
reg->val = upd64031a_read(client, reg->reg & 0xff);
break;
}
case VIDIOC_DBG_S_REGISTER: case VIDIOC_DBG_S_REGISTER:
{ {
struct v4l2_register *reg = arg; struct v4l2_register *reg = arg;
u8 addr = reg->reg & 0xff;
u8 val = reg->val & 0xff;
if (reg->i2c_id != I2C_DRIVERID_UPD64031A) if (reg->i2c_id != I2C_DRIVERID_UPD64031A)
return -EINVAL; return -EINVAL;
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EPERM; return -EPERM;
upd64031a_write(client, addr, val); if (cmd == VIDIOC_DBG_G_REGISTER)
reg->val = upd64031a_read(client, reg->reg & 0xff);
else
upd64031a_write(client, reg->reg & 0xff, reg->val & 0xff);
break; break;
} }
#endif #endif
......
...@@ -140,26 +140,18 @@ static int upd64083_command(struct i2c_client *client, unsigned int cmd, void *a ...@@ -140,26 +140,18 @@ static int upd64083_command(struct i2c_client *client, unsigned int cmd, void *a
#ifdef CONFIG_VIDEO_ADV_DEBUG #ifdef CONFIG_VIDEO_ADV_DEBUG
case VIDIOC_DBG_G_REGISTER: case VIDIOC_DBG_G_REGISTER:
{
struct v4l2_register *reg = arg;
if (reg->i2c_id != I2C_DRIVERID_UPD64083)
return -EINVAL;
reg->val = upd64083_read(client, reg->reg & 0xff);
break;
}
case VIDIOC_DBG_S_REGISTER: case VIDIOC_DBG_S_REGISTER:
{ {
struct v4l2_register *reg = arg; struct v4l2_register *reg = arg;
u8 addr = reg->reg & 0xff;
u8 val = reg->val & 0xff;
if (reg->i2c_id != I2C_DRIVERID_UPD64083) if (reg->i2c_id != I2C_DRIVERID_UPD64083)
return -EINVAL; return -EINVAL;
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EPERM; return -EPERM;
upd64083_write(client, addr, val); if (cmd == VIDIOC_DBG_G_REGISTER)
reg->val = upd64083_read(client, reg->reg & 0xff);
else
upd64083_write(client, reg->reg & 0xff, reg->val & 0xff);
break; break;
} }
#endif #endif
......
...@@ -520,25 +520,6 @@ static int usbvision_v4l2_do_ioctl(struct inode *inode, struct file *file, ...@@ -520,25 +520,6 @@ static int usbvision_v4l2_do_ioctl(struct inode *inode, struct file *file,
#ifdef CONFIG_VIDEO_ADV_DEBUG #ifdef CONFIG_VIDEO_ADV_DEBUG
/* ioctls to allow direct acces to the NT100x registers */ /* ioctls to allow direct acces to the NT100x registers */
case VIDIOC_DBG_G_REGISTER: case VIDIOC_DBG_G_REGISTER:
{
struct v4l2_register *reg = arg;
int errCode;
if (reg->i2c_id != 0)
return -EINVAL;
/* NT100x has a 8-bit register space */
errCode = usbvision_read_reg(usbvision, reg->reg&0xff);
if (errCode < 0) {
err("%s: VIDIOC_DBG_G_REGISTER failed: error %d", __FUNCTION__, errCode);
}
else {
reg->val=(unsigned char)errCode;
PDEBUG(DBG_IOCTL, "VIDIOC_DBG_G_REGISTER reg=0x%02X, value=0x%02X",
(unsigned int)reg->reg, reg->val);
errCode = 0; // No error
}
return errCode;
}
case VIDIOC_DBG_S_REGISTER: case VIDIOC_DBG_S_REGISTER:
{ {
struct v4l2_register *reg = arg; struct v4l2_register *reg = arg;
...@@ -548,15 +529,22 @@ static int usbvision_v4l2_do_ioctl(struct inode *inode, struct file *file, ...@@ -548,15 +529,22 @@ static int usbvision_v4l2_do_ioctl(struct inode *inode, struct file *file,
return -EINVAL; return -EINVAL;
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EPERM; return -EPERM;
/* NT100x has a 8-bit register space */
if (cmd == VIDIOC_DBG_G_REGISTER)
errCode = usbvision_read_reg(usbvision, reg->reg&0xff);
else
errCode = usbvision_write_reg(usbvision, reg->reg&0xff, reg->val); errCode = usbvision_write_reg(usbvision, reg->reg&0xff, reg->val);
if (errCode < 0) { if (errCode < 0) {
err("%s: VIDIOC_DBG_S_REGISTER failed: error %d", __FUNCTION__, errCode); err("%s: VIDIOC_DBG_%c_REGISTER failed: error %d", __FUNCTION__,
cmd == VIDIOC_DBG_G_REGISTER ? 'G' : 'S', errCode);
return errCode;
} }
else { if (cmd == VIDIOC_DBG_S_REGISTER)
PDEBUG(DBG_IOCTL, "VIDIOC_DBG_S_REGISTER reg=0x%02X, value=0x%02X", reg->val = (u8)errCode;
PDEBUG(DBG_IOCTL, "VIDIOC_DBG_%c_REGISTER reg=0x%02X, value=0x%02X",
cmd == VIDIOC_DBG_G_REGISTER ? 'G' : 'S',
(unsigned int)reg->reg, reg->val); (unsigned int)reg->reg, reg->val);
errCode = 0;
}
return 0; return 0;
} }
#endif #endif
......
...@@ -1457,7 +1457,9 @@ static int __video_do_ioctl(struct inode *inode, struct file *file, ...@@ -1457,7 +1457,9 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
case VIDIOC_DBG_G_REGISTER: case VIDIOC_DBG_G_REGISTER:
{ {
struct v4l2_register *p=arg; struct v4l2_register *p=arg;
if (vfd->vidioc_g_register) if (!capable(CAP_SYS_ADMIN))
ret=-EPERM;
else if (vfd->vidioc_g_register)
ret=vfd->vidioc_g_register(file, fh, p); ret=vfd->vidioc_g_register(file, fh, p);
break; break;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment