From patchwork Fri Apr 22 18:38:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Dickson X-Patchwork-Id: 8915171 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E28B4BF29F for ; Fri, 22 Apr 2016 18:38:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 13E2C201F2 for ; Fri, 22 Apr 2016 18:38:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 13377200F3 for ; Fri, 22 Apr 2016 18:38:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752064AbcDVSin (ORCPT ); Fri, 22 Apr 2016 14:38:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54720 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751718AbcDVSil (ORCPT ); Fri, 22 Apr 2016 14:38:41 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 30EE17822B; Fri, 22 Apr 2016 18:38:41 +0000 (UTC) Received: from steved.boston.devel.redhat.com (vpn-56-10.rdu2.redhat.com [10.10.56.10]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3MIceOa027400; Fri, 22 Apr 2016 14:38:40 -0400 Subject: Re: [RFC PATCH v2 2/3] gssd: using syscalls directly to change thread's identity To: Olga Kornievskaia References: <1461186721-64008-1-git-send-email-kolga@netapp.com> <1461186721-64008-3-git-send-email-kolga@netapp.com> Cc: linux-nfs@vger.kernel.org From: Steve Dickson Message-ID: <571A6FB0.8080709@RedHat.com> Date: Fri, 22 Apr 2016 14:38:40 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.1 MIME-Version: 1.0 In-Reply-To: <1461186721-64008-3-git-send-email-kolga@netapp.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 04/20/2016 05:12 PM, Olga Kornievskaia wrote: > 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. > > Signed-off-by: Olga Kornievskaia > Reviewed-by: Steve Dickson > --- > utils/gssd/gssd_proc.c | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) > > diff --git a/utils/gssd/gssd_proc.c b/utils/gssd/gssd_proc.c > index 581a125..5d9a6db 100644 > --- a/utils/gssd/gssd_proc.c > +++ b/utils/gssd/gssd_proc.c > @@ -69,6 +69,7 @@ > #include > #include > #include > +#include > > #include "gssd.h" > #include "err_util.h" > @@ -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) != 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) != 0) { > printerr(0, "WARNING: Failed to setuid for user with uid %u\n", > uid); > return errno; > We also have to do the same thing to the setgroups() call at the top of change_identity(). So add the following diff to this patch and we are good to go... steved. --- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/utils/gssd/gssd_proc.c b/utils/gssd/gssd_proc.c index e651d71..2f9f8ab 100644 --- a/utils/gssd/gssd_proc.c +++ b/utils/gssd/gssd_proc.c @@ -437,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) { printerr(0, "WARNING: unable to drop supplimentary groups!"); return errno; }