changeset 10617:ae54b3d31f50

6875432 Xorg doesn't see newly plugged in USB keyboards after non-root user has logged in.
author pengcheng chen - Sun Microsystems - Beijing China <Pengcheng.Chen@Sun.COM>
date Wed, 23 Sep 2009 10:29:53 +0800
parents 3be00c4a6835
children 0a7bd81cff1c
files usr/src/uts/common/io/conskbd.c usr/src/uts/common/io/kb8042/kb8042.c usr/src/uts/common/io/kbtrans/kbtrans_streams.c usr/src/uts/common/io/usb/clients/usbkbm/usbkbm.c usr/src/uts/common/sys/kbtrans.h
diffstat 5 files changed, 26 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/uts/common/io/conskbd.c	Tue Sep 22 22:04:45 2009 -0400
+++ b/usr/src/uts/common/io/conskbd.c	Wed Sep 23 10:29:53 2009 +0800
@@ -20,7 +20,7 @@
  */
 
 /*
- * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -563,10 +563,13 @@
 	 */
 	conskbd_consqueue = q;
 
+	if (secpolicy_console(crp) != 0)
+		return (EPERM);
+
 	/*
 	 * initialize kbtrans module for conskbd
 	 */
-	err = kbtrans_streams_init(q, sflag, crp, (struct kbtrans_hardware *)
+	err = kbtrans_streams_init(q, sflag, (struct kbtrans_hardware *)
 	    &conskbd, &conskbd_callbacks, &conskbd.conskbd_kbtrans, 0, 0);
 	if (err != 0)
 		return (err);
--- a/usr/src/uts/common/io/kb8042/kb8042.c	Tue Sep 22 22:04:45 2009 -0400
+++ b/usr/src/uts/common/io/kb8042/kb8042.c	Wed Sep 23 10:29:53 2009 +0800
@@ -55,6 +55,7 @@
 #include <sys/promif.h>
 #include <sys/beep.h>
 #include <sys/inttypes.h>
+#include <sys/policy.h>
 
 /*
  * For any keyboard, there is a unique code describing the position
@@ -663,13 +664,24 @@
 kb8042_open(queue_t *qp, dev_t *devp, int flag, int sflag, cred_t *credp)
 {
 	struct kb8042	*kb8042;
-	int err;
+	int err = 0;
 	int initial_leds;
 	int initial_led_mask;
 
 	kb8042 = &Kdws;
 
 	mutex_enter(&kb8042->w_hw_mutex);
+	if (qp->q_ptr) {
+		kb8042->w_dev = *devp;
+		mutex_exit(&kb8042->w_hw_mutex);
+		return (0);
+	}
+
+	if (secpolicy_console(credp) != 0) {
+		mutex_exit(&kb8042->w_hw_mutex);
+		return (EPERM);
+	}
+
 	while (kb8042->suspended) {
 		if (cv_wait_sig(&kb8042->suspend_cv, &kb8042->w_hw_mutex) ==
 		    0) {
@@ -679,11 +691,6 @@
 	}
 
 	kb8042->w_dev = *devp;
-
-	if (qp->q_ptr) {
-		mutex_exit(&kb8042->w_hw_mutex);
-		return (0);
-	}
 	qp->q_ptr = (caddr_t)kb8042;
 	WR(qp)->q_ptr = qp->q_ptr;
 	if (!kb8042->w_qp)
@@ -694,12 +701,12 @@
 	mutex_exit(&kb8042->w_hw_mutex);
 
 	kb8042_get_initial_leds(kb8042, &initial_leds, &initial_led_mask);
-	err = kbtrans_streams_init(qp, sflag, credp,
+	err = kbtrans_streams_init(qp, sflag,
 	    (struct kbtrans_hardware *)kb8042, &kb8042_callbacks,
 	    &kb8042->hw_kbtrans,
 	    initial_leds, initial_led_mask);
 	if (err != 0)
-		return (err);
+		goto out;
 
 	kbtrans_streams_set_keyboard(kb8042->hw_kbtrans, KB_PC, &keyindex_pc);
 
@@ -723,6 +730,7 @@
 
 	kbtrans_streams_enable(kb8042->hw_kbtrans);
 
+out:
 	mutex_enter(&kb8042->w_hw_mutex);
 	ASSERT(kb8042->ops > 0);
 	kb8042->ops--;
@@ -730,7 +738,7 @@
 		cv_broadcast(&kb8042->ops_cv);
 	mutex_exit(&kb8042->w_hw_mutex);
 
-	return (0);
+	return (err);
 }
 
 /*ARGSUSED1*/
--- a/usr/src/uts/common/io/kbtrans/kbtrans_streams.c	Tue Sep 22 22:04:45 2009 -0400
+++ b/usr/src/uts/common/io/kbtrans/kbtrans_streams.c	Wed Sep 23 10:29:53 2009 +0800
@@ -226,7 +226,6 @@
 kbtrans_streams_init(
 	queue_t 			*q,
 	int 				sflag,
-	cred_t				*crp,
 	struct kbtrans_hardware 	*hw,
 	struct kbtrans_callbacks 	*hw_cb,
 	struct kbtrans 			**ret_kbd,
@@ -235,7 +234,6 @@
 {
 	struct kbtrans *upper;
 	struct kbtrans_lower *lower;
-	int err;
 	kthread_t *tid;
 
 	/*
@@ -253,17 +251,6 @@
 		kbtrans_repeat_delay = hz/2;
 	}
 
-	/*
-	 * Only allow open requests to succeed for privileged users.  This
-	 * necessary to prevent users from pushing the this module again
-	 * on the stream associated with /dev/kbd.
-	 */
-	err = secpolicy_console(crp);
-
-	if (err != 0) {
-		return (err);
-	}
-
 	switch (sflag) {
 
 	case MODOPEN:
--- a/usr/src/uts/common/io/usb/clients/usbkbm/usbkbm.c	Tue Sep 22 22:04:45 2009 -0400
+++ b/usr/src/uts/common/io/usb/clients/usbkbm/usbkbm.c	Wed Sep 23 10:29:53 2009 +0800
@@ -46,7 +46,6 @@
 #include <sys/kbtrans.h>
 #include <sys/usb/clients/usbkbm/usbkbm.h>
 #include <sys/beep.h>
-#include <sys/policy.h>
 #include <sys/inttypes.h>
 
 /* debugging information */
@@ -392,14 +391,6 @@
 		return (0); /* already opened */
 	}
 
-	/*
-	 * Only allow open requests to succeed for privileged users.  This
-	 * necessary to prevent users from pushing the "usbkbm" module again
-	 * on the stream associated with /dev/kbd.
-	 */
-	if (secpolicy_console(crp) != 0)
-		return (EPERM);
-
 	switch (sflag) {
 
 	case MODOPEN:
@@ -436,7 +427,7 @@
 	q->q_ptr = (caddr_t)usbkbmd;
 	WR(q)->q_ptr = (caddr_t)usbkbmd;
 
-	error = kbtrans_streams_init(q, sflag, crp,
+	error = kbtrans_streams_init(q, sflag,
 	    (struct kbtrans_hardware *)usbkbmd, &kbd_usb_callbacks,
 	    &usbkbmd->usbkbm_kbtrans, usbkbm_led_state, 0);
 
--- a/usr/src/uts/common/sys/kbtrans.h	Tue Sep 22 22:04:45 2009 -0400
+++ b/usr/src/uts/common/sys/kbtrans.h	Wed Sep 23 10:29:53 2009 +0800
@@ -20,15 +20,13 @@
  */
 
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
 #ifndef _SYS_KBTRANS_H
 #define	_SYS_KBTRANS_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * Interface between hardware keyboard driver and generic keyboard
  * translation module.
@@ -101,9 +99,6 @@
  *   	- int sflag
  *        	sflag from the streams open routine
  *
- *   	- cred_t *crp
- *        	credentials from open
- *
  *   	- struct kbtrans_hardware *hw
  *       	hardware-specific data, passed to hardware callbacks
  *
@@ -122,9 +117,8 @@
  *        	retain the existing state of NumLock across the transition
  *       	from firmware to the OS.
  */
-extern int kbtrans_streams_init(queue_t *, int, cred_t *,
-	struct kbtrans_hardware *, struct kbtrans_callbacks *,
-	struct kbtrans **, int, int);
+extern int kbtrans_streams_init(queue_t *, int, struct kbtrans_hardware *,
+	struct kbtrans_callbacks *, struct kbtrans **, int, int);
 
 /*
  * kbtrans_streams_fini():