PERFORCE change 150165 for review

Hans Petter Selasky hselasky at FreeBSD.org
Sat Sep 20 12:55:14 UTC 2008


http://perforce.freebsd.org/chv.cgi?CH=150165

Change 150165 by hselasky at hselasky_laptop001 on 2008/09/20 12:54:43

	
	Fix suser() to priv_check() conversion. TODO: We need
	a set of USB privileges which are currently marked
	PRIV_ROOT.

Affected files ...

.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_dev.c#34 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_generic.c#27 edit

Differences ...

==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_dev.c#34 (text+ko) ====

@@ -261,11 +261,12 @@
 	uint32_t devloc;
 	int error;
 
-	/* only super-user can set permissions */
-	error = suser(curthread);
+	/* check if the current thread can change USB permissions. */
+	error = priv_check(curthread, PRIV_ROOT);
 	if (error) {
 		return (error);
 	}
+	/* range check device location */
 	if ((psrc->bus_index >= USB_BUS_MAX) ||
 	    (psrc->dev_index >= USB_DEV_MAX) ||
 	    (psrc->iface_index >= USB_IFACE_MAX)) {

==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_generic.c#27 (text+ko) ====

@@ -869,6 +869,8 @@
 static int
 ugen_check_request(struct usb2_device_request *req)
 {
+	int error;
+
 	/*
 	 * Avoid requests that would damage the bus integrity:
 	 */
@@ -878,8 +880,12 @@
 	    (req->bRequest == UR_SET_CONFIG)) ||
 	    ((req->bmRequestType == UT_WRITE_INTERFACE) &&
 	    (req->bRequest == UR_SET_INTERFACE))) {
-		if (suser(curthread)) {
-			return (EPERM);
+		/*
+		 * These requests can be useful for testing USB drivers.
+		 */
+		error = priv_check(curthread, PRIV_DRIVER);
+		if (error) {
+			return (error);
 		}
 	}
 	/*
@@ -887,8 +893,9 @@
 	 * not update the data toggle value in "struct usb2_pipe" !
 	 */
 	if (req->bmRequestType == UT_WRITE_ENDPOINT) {
-		if (suser(curthread)) {
-			return (EPERM);
+		error = priv_check(curthread, PRIV_DRIVER);
+		if (error) {
+			return (error);
 		}
 	}
 	/* TODO: add more checks to verify the interface index */
@@ -946,8 +953,12 @@
 		/* control endpoint only */
 		return (EINVAL);
 	}
-	if (suser(curthread)) {
-		return (EPERM);
+	/*
+	 * This request can be useful for testing USB drivers:
+	 */
+	error = priv_check(curthread, PRIV_DRIVER);
+	if (error) {
+		return (error);
 	}
 	mtx_lock(f->priv_mtx);
 	error = usb2_req_re_enumerate(udev, f->priv_mtx);
@@ -1738,8 +1749,9 @@
 	    (udev->parent_hub == NULL)) {
 		return (EINVAL);
 	}
-	if (suser(curthread)) {
-		return (EPERM);
+	err = priv_check(curthread, PRIV_ROOT);
+	if (err) {
+		return (err);
 	}
 	switch (mode) {
 	case USB_POWER_MODE_OFF:
@@ -1805,8 +1817,9 @@
 	struct usb2_hub *hub;
 	int err;
 
-	if (suser(curthread)) {
-		return (EPERM);
+	err = priv_check(curthread, PRIV_ROOT);
+	if (err) {
+		return (err);
 	}
 	if (port_no == 0) {
 		return (EINVAL);
@@ -2115,10 +2128,11 @@
 
 	case USB_IFACE_DRIVER_DETACH:
 		/* TODO */
-		if (suser(curthread))
-			error = EPERM;
-		else
-			error = EINVAL;
+		error = priv_check(curthread, PRIV_DRIVER);
+		if (error) {
+			break;
+		}
+		error = EINVAL;
 		break;
 
 	case USB_SET_POWER_MODE:


More information about the p4-projects mailing list