Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8fb91b33 authored by Martin Rubli's avatar Martin Rubli Committed by Mauro Carvalho Chehab
Browse files

[media] uvcvideo: Remove sysadmin requirements for UVCIOC_CTRL_MAP



This patch removes the sysadmin requirements for UVCIOC_CTRL_MAP (and the stub
implementation of UVCIOC_CTRL_ADD). This requirement no longer makes sense with
the new XU control access mechanisms since XU controls can be accessed without
adding control mappings first.

A maximum number (currently 1024) of control mappings per device is enforced to
avoid excess memory consumption caused by careless user space applications.

Signed-off-by: default avatarMartin Rubli <martin_rubli@logitech.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent ba2fa996
Loading
Loading
Loading
Loading
+14 −0
Original line number Original line Diff line number Diff line
@@ -1435,6 +1435,7 @@ int uvc_ctrl_add_mapping(struct uvc_video_chain *chain,
	struct uvc_entity *entity;
	struct uvc_entity *entity;
	struct uvc_control *ctrl;
	struct uvc_control *ctrl;
	int found = 0;
	int found = 0;
	int ret;


	if (mapping->id & ~V4L2_CTRL_ID_MASK) {
	if (mapping->id & ~V4L2_CTRL_ID_MASK) {
		uvc_trace(UVC_TRACE_CONTROL, "Can't add mapping '%s', control "
		uvc_trace(UVC_TRACE_CONTROL, "Can't add mapping '%s', control "
@@ -1478,7 +1479,20 @@ int uvc_ctrl_add_mapping(struct uvc_video_chain *chain,
		}
		}
	}
	}


	/* Prevent excess memory consumption */
	if (atomic_inc_return(&dev->nmappings) > UVC_MAX_CONTROL_MAPPINGS) {
		atomic_dec(&dev->nmappings);
		uvc_trace(UVC_TRACE_CONTROL, "Can't add mapping '%s', maximum "
			"mappings count (%u) exceeded.\n", mapping->name,
			UVC_MAX_CONTROL_MAPPINGS);
		ret = -ENOMEM;
		goto done;
	}

	ret = __uvc_ctrl_add_mapping(dev, ctrl, mapping);
	ret = __uvc_ctrl_add_mapping(dev, ctrl, mapping);
	if (ret < 0)
		atomic_dec(&dev->nmappings);

done:
done:
	mutex_unlock(&chain->ctrl_mutex);
	mutex_unlock(&chain->ctrl_mutex);
	return ret;
	return ret;
+1 −0
Original line number Original line Diff line number Diff line
@@ -1760,6 +1760,7 @@ static int uvc_probe(struct usb_interface *intf,
	INIT_LIST_HEAD(&dev->streams);
	INIT_LIST_HEAD(&dev->streams);
	atomic_set(&dev->nstreams, 0);
	atomic_set(&dev->nstreams, 0);
	atomic_set(&dev->users, 0);
	atomic_set(&dev->users, 0);
	atomic_set(&dev->nmappings, 0);


	dev->udev = usb_get_dev(udev);
	dev->udev = usb_get_dev(udev);
	dev->intf = usb_get_intf(intf);
	dev->intf = usb_get_intf(intf);
+0 −6
Original line number Original line Diff line number Diff line
@@ -1025,16 +1025,10 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
	/* Dynamic controls. */
	/* Dynamic controls. */
	case UVCIOC_CTRL_ADD:
	case UVCIOC_CTRL_ADD:
		/* Legacy ioctl, kept for API compatibility reasons */
		/* Legacy ioctl, kept for API compatibility reasons */
		if (!capable(CAP_SYS_ADMIN))
			return -EPERM;

		return -EEXIST;
		return -EEXIST;


	case UVCIOC_CTRL_MAP_OLD:
	case UVCIOC_CTRL_MAP_OLD:
	case UVCIOC_CTRL_MAP:
	case UVCIOC_CTRL_MAP:
		if (!capable(CAP_SYS_ADMIN))
			return -EPERM;

		return uvc_ioctl_ctrl_map(chain, arg,
		return uvc_ioctl_ctrl_map(chain, arg,
					  cmd == UVCIOC_CTRL_MAP_OLD);
					  cmd == UVCIOC_CTRL_MAP_OLD);


+4 −0
Original line number Original line Diff line number Diff line
@@ -172,6 +172,9 @@ struct uvc_xu_control {
#define UVC_CTRL_CONTROL_TIMEOUT	300
#define UVC_CTRL_CONTROL_TIMEOUT	300
#define UVC_CTRL_STREAMING_TIMEOUT	5000
#define UVC_CTRL_STREAMING_TIMEOUT	5000


/* Maximum allowed number of control mappings per device */
#define UVC_MAX_CONTROL_MAPPINGS	1024

/* Devices quirks */
/* Devices quirks */
#define UVC_QUIRK_STATUS_INTERVAL	0x00000001
#define UVC_QUIRK_STATUS_INTERVAL	0x00000001
#define UVC_QUIRK_PROBE_MINMAX		0x00000002
#define UVC_QUIRK_PROBE_MINMAX		0x00000002
@@ -472,6 +475,7 @@ struct uvc_device {


	enum uvc_device_state state;
	enum uvc_device_state state;
	atomic_t users;
	atomic_t users;
	atomic_t nmappings;


	/* Video control interface */
	/* Video control interface */
	__u16 uvc_version;
	__u16 uvc_version;