adding pthread support to gssd
Subsystems (2)
PATCH v4 3/3 gssd: always call gss_krb5_ccache_name
In reply to Olga KornievskaiaPreviously the location of the credential cache was passed in either using environment variable KRB5CCNAME or gss_krb5_ccache_name() if supported. For threaded-gssd, we can't use an environment variable as it's shared among all thread. Thus always use the api call.
--- utils/gssd/gssd_proc.c | 12 +++++++++-- utils/gssd/krb5_util.c | 56 +++++++++----------------------------------------- utils/gssd/krb5_util.h | 1 - 3 files changed, 20 insertions(+), 49 deletions(-)
utils/gssd/gssd_proc.c +10 -2
@@ -554,7 +554,15 @@ krb5_use_machine_creds(struct clnt_info *clp, uid_t uid, char *tgtname, goto out; }for (ccname = credlist; ccname && *ccname; ccname++) { -gssd_setup_krb5_machine_gss_ccache (*ccname); +u_int min_stat; + +if (gss_krb5_ccache_name (&min_stat, *ccname,NULL ) != +GSS_S_COMPLETE ) { +printerr (1 ,"WARNING: gss_krb5_ccache_name " +"with name '%s' failed (%s)\n" , + *ccname,error_message (min_stat)); +continue ; + } if ((create_auth_rpc_client(clp, tgtname, rpc_clnt, &auth, uid, AUTHTYPE_KRB5,
@@ -575,7 +583,7 @@ krb5_use_machine_creds(struct clnt_info *clp, uid_t uid, char *tgtname,"recreate cache for server %s\n" , clp->servername); }else { -printerr (1 ,"WARNING: Failed to create machine" +printerr (0 ,"ERROR: Failed to create machine" "krb5 context with any credentials" "cache for server %s\n" , clp->servername);
utils/gssd/krb5_util.c +10 -46
75 lines not on this page · raw message
utils/gssd/krb5_util.h +0 -1
@@ -27,7 +27,6 @@ int gssd_setup_krb5_user_gss_ccache(uid_t uid, char *servername, char *dirname);int gssd_get_krb5_machine_cred_list (char ***list);void gssd_free_krb5_machine_cred_list (char **list); -void gssd_setup_krb5_machine_gss_ccache (char *servername);void gssd_destroy_krb5_machine_creds (void ); int gssd_refresh_krb5_machine_credential(char *hostname, struct gssd_k5_kt_princ *ple,
Signature · 1 line
1.8.3.1
v4 cover adding pthread support to gssd
Adding support for multi-threaded gssd and allow for parallel upcalls. For each upcall create a thread, detach to allow for automatic cleanup. Communicate location of credential cache with gss api function instead of an environmental variable. Use syscall api instead of libc setuid() to change user identity.
Previously parent thread after detaching from child thread would call yield to let the child thread run and consume the event from the fd. Instead, use synchronization variables to signal parent after reading from fd and have parent thread wait for the event.
Olga Kornievskaia (3):
gssd: use pthreads to handle upcalls
gssd: using syscalls directly to change thread's identity
gssd: always call gss_krb5_ccache_name
aclocal/libpthread.m4 | 13 ++++++++++ configure.ac | 3 +++ utils/gssd/Makefile.am | 3 ++- utils/gssd/gssd.c | 44 ++++++++++++++++++++++++++++++--- utils/gssd/gssd.h | 5 ++++ utils/gssd/gssd_proc.c | 66 +++++++++++++++++++++++--------------------------- utils/gssd/krb5_util.c | 59 ++++++++++---------------------------------- utils/gssd/krb5_util.h | 1 - 8 files changed, 106 insertions(+), 88 deletions(-) create mode 100644 aclocal/libpthread.m4
Signature · 1 line
1.8.3.1
PATCH v4 2/3 gssd: using syscalls directly to change thread's identity
For the threaded version we have to set uid,gid per thread instead of per process. glibc setresuid() when called from a thread, it'll send a signal to all other threads to synchronize the uid in all other threads. To bypass this, we have to call syscall() directly.
--- utils/gssd/gssd_proc.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
utils/gssd/gssd_proc.c +9 -3
@@ -69,6 +69,7 @@#include <netdb.h> #include <sys/types.h> #include <sys/wait.h> +#include <syscall.h> #include "gssd.h" #include "err_util.h"
@@ -436,7 +437,7 @@ change_identity(uid_t uid)struct passwd *pw;/* drop list of supplimentary groups first */ -if (setgroups (0 ,NULL ) !=0 ) { +if (syscall (SYS_setgroups,0 ,0 ) !=0 ) {printerr (0 ,"WARNING: unable to drop supplimentary groups!" );return errno; }
@@ -457,7 +458,12 @@ change_identity(uid_t uid)* Switch the GIDs. Note that we leave the saved-set-gid alone in an * attempt to prevent attacks via ptrace() */ -if (setresgid (pw->pw_gid, pw->pw_gid,-1 ) !=0 ) { +/* For the threaded version we have to set uid,gid per thread instead +* of per process. glibc setresuid() when called from a thread, it'll +* send a signal to all other threads to synchronize the uid in all +* other threads. To bypass this, we have to call syscall() directly. +*/ +if (syscall (SYS_setresgid, pw->pw_gid,-1 ,-1 ) !=0 ) {printerr (0 ,"WARNING: failed to set gid to %u!\n" , pw->pw_gid);return errno; }
@@ -466,7 +472,7 @@ change_identity(uid_t uid)* Switch UIDs, but leave saved-set-uid alone to prevent ptrace() by * other processes running with this uid. */ -if (setresuid (uid, uid,-1 ) !=0 ) { +if (syscall (SYS_setresuid, uid,-1 ,-1 ) !=0 ) {printerr (0 ,"WARNING: Failed to setuid for user with uid %u\n" , uid);return errno;
Signature · 1 line
1.8.3.1
PATCH v4 1/3 gssd: use pthreads to handle upcalls
In reply to Olga KornievskaiaCurrently, to persevere global data over multiple mounts, the root process does not fork when handling an upcall. Instead on not-forking create a pthread to handle the upcall since global data can be shared among threads.
--- aclocal/libpthread.m4 | 13 +++++++++++++ configure.ac | 3 +++ utils/gssd/Makefile.am | 3 ++- utils/gssd/gssd.c | 45 ++++++++++++++++++++++++++++++++++++++++----- utils/gssd/gssd.h | 5 +++++ utils/gssd/gssd_proc.c | 49 ++++++++++++++++++------------------------------- utils/gssd/krb5_util.c | 3 +++ 7 files changed, 84 insertions(+), 37 deletions(-) create mode 100644 aclocal/libpthread.m4
aclocal/libpthread.m4 new file +13 -0
@@ -0,0 +1,13 @@ +dnl Checks for pthreads library and headers +dnl +AC_DEFUN([AC_LIBPTHREAD], [ + + dnl Check for library, but do not add -lpthreads to LIBS + AC_CHECK_LIB([pthread], [pthread_create], [LIBPTHREAD=-lpthread], + [AC_MSG_ERROR([libpthread not found.])]) + AC_SUBST(LIBPTHREAD) + + AC_CHECK_HEADERS([pthread.h], , + [AC_MSG_ERROR([libpthread headers not found.])]) + +])dnl
configure.ac +3 -0
@@ -385,6 +385,9 @@ if test "$enable_gss" = yes; then dnl Invoked after AC_KERBEROS_V5; AC_LIBRPCSECGSS needs to have KRBLIBS set AC_LIBRPCSECGSS + dnl Check for pthreads + AC_LIBPTHREAD + dnl librpcsecgss already has a dependency on libgssapi, dnl but we need to make sure we get the right version if test "$enable_gss" = yes; then
utils/gssd/Makefile.am +2 -1
@@ -49,7 +49,8 @@ gssd_LDADD = \ $(RPCSECGSS_LIBS) \ $(KRBLIBS) \ $(GSSAPI_LIBS) \ - $(LIBTIRPC) + $(LIBTIRPC) \ + $(LIBPTHREAD) gssd_LDFLAGS = \ $(KRBLDFLAGS)
utils/gssd/gssd.c +40 -5
67 lines not on this page · raw message
utils/gssd/gssd.h +5 -0
@@ -36,6 +36,7 @@#include <gssapi/gssapi.h> #include <event.h> #include <stdbool.h> +#include <pthread.h> #ifndef GSSD_PIPEFS_DIR #define GSSD_PIPEFS_DIR "/var/lib/nfs/rpc_pipefs"
@@ -61,6 +62,10 @@ extern int root_uses_machine_creds;extern unsigned int context_timeout;extern unsigned int rpc_timeout;extern char *preferred_realm; +extern pthread_mutex_t ple_lock; +extern pthread_cond_t pcond; +extern pthread_mutex_t pmutex; +extern int thread_started;struct clnt_info {TAILQ_ENTRY (clnt_info) list;
utils/gssd/gssd_proc.c +18 -31
72 lines not on this page · raw message
utils/gssd/krb5_util.c +3 -0
@@ -128,6 +128,7 @@/* Global list of principals/cache file names for machine credentials */ struct gssd_k5_kt_princ *gssd_k5_kt_princ_list =NULL ; +pthread_mutex_t ple_lock =PTHREAD_MUTEX_INITIALIZER ;#ifdef HAVE_SET_ALLOWABLE_ENCTYPES int limit_to_legacy_enctypes =0 ;
@@ -586,10 +587,12 @@ get_ple_by_princ(krb5_context context, krb5_principal princ)/* Need to serialize list if we ever become multi-threaded! */ +pthread_mutex_lock (&ple_lock); ple =find_ple_by_princ (context, princ);if (ple ==NULL ) { ple =new_ple (context, princ); } +pthread_mutex_unlock (&ple_lock);return ple; }
Signature · 1 line
1.8.3.1
Re: [PATCH v4 2/3] gssd: using syscalls directly to change thread's identity
In reply to Olga KornievskaiaQuoted 47 lines · Olga Kornievskaia
For the threaded version we have to set uid,gid per thread instead of per process. glibc
setresuid()when called from a thread, it'll send a signal to all other threads to synchronize the uid in all other threads. To bypass this, we have to callsyscall()directly.Signed-off-by Olga Kornievskaia <[email protected]>Reviewed-by Steve Dickson <[email protected]>---
utils/gssd/gssd_proc.c | 12 +++++++++---1 file changed, 9 insertions(+), 3 deletions(-)utils/gssd/gssd_proc.c +1
-0@@ -69,6 +69,7 @@ #include #include #include +#include
#include "gssd.h"
#include "err_util.h"utils/gssd/gssd_proc.c +0
-0@@ -436,7 +437,7 @@ change_identity(uid_t uid) struct passwd *pw;
/* drop list of supplimentary groups first */utils/gssd/gssd_proc.c +1
-1-if (setgroups (0 ,NULL ) !=0 ) { +if (syscall (SYS_setgroups,0 ,0 ) !=0 ) {
printerr(0, "WARNING: unable to drop supplimentary groups!"); return errno;
}utils/gssd/gssd_proc.c +6
-1@@ -457,7 +458,12 @@ change_identity(uid_t uid)* Switch the GIDs. Note that we leave the saved-set-gid alone in an * attempt to prevent attacks via ptrace() */ -if (setresgid (pw->pw_gid, pw->pw_gid,-1 ) !=0 ) { +/* For the threaded version we have to set uid,gid per thread instead +* of per process. glibc setresuid() when called from a thread, it'll +* send a signal to all other threads to synchronize the uid in all +* other threads. To bypass this, we have to call syscall() directly. +*/ +if (syscall (SYS_setresgid, pw->pw_gid,-1 ,-1 ) !=0 ) { printerr(0, "WARNING: failed to set gid to %u!\n", pw->pw_gid); return errno; }
utils/gssd/gssd_proc.c change_identity(uid_t uid) · line 478
Quoted 8 lines
utils/gssd/gssd_proc.c +1
-1@@ -466,7 +472,7 @@ change_identity(uid_t uid)* Switch UIDs, but leave saved-set-uid alone to prevent ptrace() by * other processes running with this uid. */ -if (setresuid (uid, uid,-1 ) !=0 ) { +if (syscall (SYS_setresuid, uid,-1 ,-1 ) !=0 ) { printerr(0, "WARNING: Failed to setuid for user with uid %u\n", uid); return errno;
Note that the old code set both real and effective uid/gid. Here you're changing it to just set the real uid. Is that change deliberate? I think you probably want to set the euid/egid as well.
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH v4 2/3] gssd: using syscalls directly to change thread's identity
Quoted 52 lines · Jeff Layton
Quoted 51 lines · Olga Kornievskaia
For the threaded version we have to set uid,gid per thread instead of per process. glibc
setresuid()when called from a thread, it'll send a signal to all other threads to synchronize the uid in all other threads. To bypass this, we have to callsyscall()directly.Signed-off-by Olga Kornievskaia <[email protected]>Reviewed-by Steve Dickson <[email protected]>--- utils/gssd/gssd_proc.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)utils/gssd/gssd_proc.c +8
-3@@ -69,6 +69,7 @@ #include #include #include +#include#include "gssd.h" #include "err_util.h" @@ -436,7 +437,7 @@ change_identity(uid_t uid)struct passwd *pw;/* drop list of supplimentary groups first */ -if (setgroups (0 ,NULL ) !=0 ) { +if (syscall (SYS_setgroups,0 ,0 ) !=0 ) {printerr (0 ,"WARNING: unable to drop supplimentary groups!" );return errno; }@@ -457,7 +458,12 @@ change_identity(uid_t uid)* Switch the GIDs. Note that we leave the saved-set-gid alone in an * attempt to prevent attacks via ptrace() */ -if (setresgid (pw->pw_gid, pw->pw_gid,-1 ) !=0 ) { +/* For the threaded version we have to set uid,gid per thread instead +* of per process. glibc setresuid() when called from a thread, it'll +* send a signal to all other threads to synchronize the uid in all +* other threads. To bypass this, we have to call syscall() directly. +*/ +if (syscall (SYS_setresgid, pw->pw_gid,-1 ,-1 ) !=0 ) {printerr (0 ,"WARNING: failed to set gid to %u!\n" , pw->pw_gid);return errno; }@@ -466,7 +472,7 @@ change_identity(uid_t uid)* Switch UIDs, but leave saved-set-uid alone to prevent ptrace() by * other processes running with this uid. */ -if (setresuid (uid, uid,-1 ) !=0 ) {
Quoted 8 lines
utils/gssd/gssd_proc.c change_identity(uid_t uid) · line 478
Quoted 4 lines
utils/gssd/gssd_proc.c +1
-0+if (syscall (SYS_setresuid, uid,-1 ,-1 ) !=0 ) {printerr (0 ,"WARNING: Failed to setuid for user with uid %u\n" , uid);return errno;Note that the old code set both real and effective uid/gid. Here you're changing it to just set the real uid. Is that change deliberate? I think you probably want to set the euid/egid as well.
It was a typo (cthon tests ran fine though which is confusing since kerberos code does geteuid()). Now I'm thinking that given that we don't touch saved uid, perhaps the code should call SYS_setreuid instead of SYS_setresuid?
Quoted 7 lines
--
Jeff Layton <[email protected]>
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v4 2/3] gssd: using syscalls directly to change thread's identity
Quoted 76 lines · Olga Kornievskaia
Quoted 65 lines · Jeff Layton
Quoted 64 lines · Olga Kornievskaia
For the threaded version we have to set uid,gid per thread instead
of per process. glibcsetresuid()when called from a thread, it'll
send a signal to all other threads to synchronize the uid in all other threads. To bypass this, we have to callsyscall()directly.Signed-off-by Olga Kornievskaia <[email protected]>Reviewed-by Steve Dickson <[email protected]>---
utils/gssd/gssd_proc.c | 12 +++++++++---1 file changed, 9 insertions(+), 3 deletions(-)utils/gssd/gssd_proc.c +2
-1@@ -69,6 +69,7 @@ #include #include #include +#include #include "gssd.h" #include "err_util.h"@@ -436,7 +437,7 @@ change_identity(uid_t uid) struct passwd *pw; /* drop list of supplimentary groups first */ - if (setgroups(0, NULL) != 0) { + if (syscall(SYS_setgroups, 0, 0) != 0) {printerr(0, "WARNING: unable to drop supplimentary groups!");
return errno;
}utils/gssd/gssd_proc.c +0
-0@@ -457,7 +458,12 @@ change_identity(uid_t uid) * Switch the GIDs. Note that we leave the saved-set-gidalone in an
* attempt to prevent attacks viaptrace()
*/
- if (setresgid(pw->pw_gid, pw->pw_gid, -1)!= 0) { + /* For the threaded version we have to set uid,gid per thread instead
+ * of per process. glibcsetresuid()when called from a thread, it'll
+ * send a signal to all other threads to synchronize the uid in all
+ * other threads. To bypass this, we have to callsyscall()directly.
+ */
+ if (syscall(SYS_setresgid, pw->pw_gid, -1, -1)!= 0) {printerr(0, "WARNING: failed to set gid to %u!\n", pw->pw_gid);
return errno;
}utils/gssd/gssd_proc.c +0
-0@@ -466,7 +472,7 @@ change_identity(uid_t uid) * Switch UIDs, but leave saved-set-uid alone to prevent
ptrace()by
* other processes running with this uid.
*/
- if (setresuid(uid, uid, -1)!= 0) {
+ if (syscall(SYS_setresuid, uid, -1, -1)!= 0) { printerr(0, "WARNING: Failed to setuid for userQuoted 8 lines
Quoted 3 lines
with uid %u\n",
uid);
return errno;Note that the old code set both real and effective uid/gid. Here you're
changing it to just set the real uid. Is that change deliberate? I think you probably want to set the euid/egid as well.
Quoted 5 lines
It was a typo (cthon tests ran fine though which is confusing since kerberos code does
geteuid()). Now I'm thinking that given that we don't touch saved uid, perhaps the code should callSYS_setreuidinstead ofSYS_setresuid?
Yes, good point. Either that or just set all 3 to "uid", I'd think.
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH v4 2/3] gssd: using syscalls directly to change thread's identity
DQo+IE9uIEFwciAyNywgMjAxNiwgYXQgMTA6MTMgQU0sIEplZmYgTGF5dG9uIDxqbGF5dG9uQHBv b2NoaWVyZWRzLm5ldD4gd3JvdGU6DQo+IA0KPiBPbiBXZWQsIDIwMTYtMDQtMjcgYXQgMTA6MDkg LTA0MDAsIE9sZ2EgS29ybmlldnNrYWlhIHdyb3RlOg0KPj4gT24gVHVlLCBBcHIgMjYsIDIwMTYg YXQgMTI6NTEgUE0sIEplZmYgTGF5dG9uIDxqbGF5dG9uQHBvb2NoaWVyZWRzLm5lDQo+PiB0PiB3 cm90ZToNCj4+PiBPbiBUdWUsIDIwMTYtMDQtMjYgYXQgMDk6MzQgLTA0MDAsIE9sZ2EgS29ybmll dnNrYWlhIHdyb3RlOg0KPj4+PiBGb3IgdGhlIHRocmVhZGVkIHZlcnNpb24gd2UgaGF2ZSB0byBz ZXQgdWlkLGdpZCBwZXIgdGhyZWFkDQo+Pj4+IGluc3RlYWQNCj4+Pj4gb2YgcGVyIHByb2Nlc3Mu IGdsaWJjIHNldHJlc3VpZCgpIHdoZW4gY2FsbGVkIGZyb20gYSB0aHJlYWQsDQo+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SBwcmVj b25maWd1cmVkIHRvIHByZXZlbnQgcHRyYWNlIGZyb20gYXR0YWNoaW5nIHRvIGFueXRoaW5nIG90 aGVyIHRoYW4gdGhlIHRyYWNlZCBwcm9jZXNz4oCZIHBhcmVudCAodGhhdCBzaG91bGQgYWRkcmVz cyB0aGUgY29tbWVudCkuDQoNCj4gDQo+IC0tIA0KPiBKZWZmIExheXRvbiA8amxheXRvbkBwb29j aGllcmVkcy5uZXQ+DQoNCg==
Re: [PATCH v4 2/3] gssd: using syscalls directly to change thread's identity
Quoted 86 lines · Olga
Quoted 86 lines · Jeff Layton
Quoted 81 lines · Olga Kornievskaia
Quoted 65 lines · Jeff Layton
Quoted 64 lines · Olga Kornievskaia
For the threaded version we have to set uid,gid per thread instead
of per process. glibcsetresuid()when called from a thread, it'll
send a signal to all other threads to synchronize the uid in all other threads. To bypass this, we have to callsyscall()directly.Signed-off-by Olga Kornievskaia <[email protected]>Reviewed-by Steve Dickson <[email protected]>--- utils/gssd/gssd_proc.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)utils/gssd/gssd_proc.c +2
-1@@ -69,6 +69,7 @@ #include #include #include +#include#include "gssd.h" #include "err_util.h" @@ -436,7 +437,7 @@ change_identity(uid_t uid)struct passwd *pw;/* drop list of supplimentary groups first */ -if (setgroups (0 ,NULL ) !=0 ) { +if (syscall (SYS_setgroups,0 ,0 ) !=0 ) {printerr (0 ,"WARNING: unable to drop supplimentary groups!");return errno;}utils/gssd/gssd_proc.c +0
-0@@ -457,7 +458,12 @@ change_identity(uid_t uid)* Switch the GIDs. Note that we leave the saved-set-gid alone in an
* attempt to prevent attacks viaptrace()
*/utils/gssd/gssd_proc.c +1
-1-if (setresgid (pw->pw_gid, pw->pw_gid,-1 ) !=0 ) { +/* For the threaded version we have to set uid,gid per thread instead
+ * of per process. glibcsetresuid()when called from a
thread, it'll
+ * send a signal to all other threads to synchronize the
uid in all
+ * other threads. To bypass this, we have to callsyscall()
directly.utils/gssd/gssd_proc.c +2
-0+*/ +if (syscall (SYS_setresgid, pw->pw_gid,-1 ,-1 ) !=0 ) { printerr(0, "WARNING: failed to set gid to %u!\n",pw->pw_gid); return errno; }utils/gssd/gssd_proc.c +0
-0@@ -466,7 +472,7 @@ change_identity(uid_t uid)* Switch UIDs, but leave saved-set-uid alone to prevent
ptrace()by
* other processes running with this uid.
*/utils/gssd/gssd_proc.c +1
-1-if (setresuid (uid, uid,-1 ) !=0 ) { +if (syscall (SYS_setresuid, uid,-1 ,-1 ) !=0 ) { printerr(0, "WARNING: Failed to setuid for userQuoted 8 lines
Quoted 3 lines
with uid %u\n",
uid); return errno;Note that the old code set both real and effective uid/gid. Here you're
changing it to just set the real uid. Is that change deliberate? I think you probably want to set the euid/egid as well.It was a typo (cthon tests ran fine though which is confusing since kerberos code does
geteuid()). Now I'm thinking that given that we don't touch saved uid, perhaps the code should callSYS_setreuidinstead ofSYS_setresuid?
Quoted 5 lines
Quoted 1 line
Yes, good point. Either that or just set all 3 to "uid", I'd think.
There is a comment above saying leaving save-set-uid alone prevents ptrace from tracing us? Do we still care about this? ptrace wiki says that a kernel can be preconfigured to prevent ptrace from attaching to anything other than the traced process’ parent (that should address the comment).
I would guess not...
steved.
Quoted 5 lines
Quoted 4 lines
Signature · 2 lines
-- Jeff Layton <[email protected]>