Bug 233 - User can not cancel sudo when using PAM
User can not cancel sudo when using PAM
Status: RESOLVED FIXED
Product: Sudo
Classification: Unclassified
Component: Sudo
1.6.8
All All
: low normal
Assigned To: Todd C. Miller
: 366 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2007-02-19 16:57 MST by Doug Engert
Modified: 2009-08-31 15:10 MDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Doug Engert 2007-02-19 16:57:11 MST
When presented with the prompt to enter a password the user can not
cancel the operation even with ^C. sud0_conv() in auth/pam.c calls 
tgetpass. If user enters ^C tgetpass returns a NULL, but the sudo_conv() 
sends back a zero length string to PAM. It should return something like PAM_CONV_ERR, so PAM will quit processing and return to sudo with an error.  

Some PAM modules will accept the zero length password, and try and process 
it. Radius for example may use this to start a challenge response sequence,
which will call sudo_conv() again, which the user can not cancel.
Eventually after a few more attempts at prompting the user PAM will give
up, but the user's account may now be flaged, or even locked.  
 
This fails on  at least Solaris 10, and Ubuntu with sudo-1.6.8p12.

Attached is a patch to return PAM_CONV_ERR if tgetpass returns NULL.

--- ,pam.c	Sat Feb  5 12:03:15 2005
+++ pam.c	Mon Feb 19 11:33:37 2007
@@ -218,6 +218,7 @@
     char *pass;
     int n, flags;
     extern int nil_pw;
+    int ret = PAM_SUCCESS;
 
     if ((*response = malloc(num_msg * sizeof(struct pam_response))) == NULL)
 	return(PAM_CONV_ERR);
@@ -240,6 +241,8 @@
 		    nil_pw = 1;		/* empty password */
 		else
 		    zero_bytes(pass, strlen(pass));
+		if (pass == NULL) /* Interupted, user wants out clean up */
+		    ret = PAM_CONV_ERR; /* Solaris also has PAM_CONV_INTERUPT */
 		break;
 	    case PAM_TEXT_INFO:
 		if (pm->msg)
@@ -252,6 +255,9 @@
 		}
 		break;
 	    default:
+	    ret = PAM_CONV_ERR;
+	}
+	if (ret != PAM_SUCCESS) {
 		/* Zero and free allocated memory and return an error. */
 		for (pr = *response, n = num_msg; n--; pr++) {
 		    if (pr->resp != NULL) {
@@ -263,7 +269,7 @@
 		zero_bytes(*response, num_msg * sizeof(struct pam_response));
 		free(*response);
 		*response = NULL;
-		return(PAM_CONV_ERR);
+		return(ret);
 	}
     }
Comment 1 Todd C. Miller 2007-04-24 13:59:23 MDT
A fix for this already exists in the sudo cvs tree.
Comment 2 Todd C. Miller 2009-08-31 15:10:19 MDT
*** Bug 366 has been marked as a duplicate of this bug. ***