unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [DMD] [PATCH] service: Change gid before uid when dropping privileges.
@ 2015-12-03 15:37 David Thompson
  2015-12-04  8:00 ` Ricardo Wurmus
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: David Thompson @ 2015-12-03 15:37 UTC (permalink / raw)
  To: guix-devel

[-- Attachment #1: Type: text/plain, Size: 96 bytes --]

Found this little order of operations issue when trying to button up the
Transmission service.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-service-Change-gid-before-uid-when-dropping-privileg.patch --]
[-- Type: text/x-patch, Size: 1650 bytes --]

From 552eafe882e3c059525e79c0f222becb9d73eb93 Mon Sep 17 00:00:00 2001
From: David Thompson <dthompson2@worcester.edu>
Date: Thu, 3 Dec 2015 10:09:34 -0500
Subject: [PATCH] service: Change gid before uid when dropping privileges.

---
 modules/dmd/service.scm | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/modules/dmd/service.scm b/modules/dmd/service.scm
index aece069..34826b1 100644
--- a/modules/dmd/service.scm
+++ b/modules/dmd/service.scm
@@ -614,23 +614,25 @@ false."
            (catch-system-error (close-fdes i))
            (loop (+ i 1)))))
 
-     (when user
+     ;; setgid must be done *before* setuid, otherwise the user will
+     ;; likely no longer have permissions to setgid.
+     (when group
        (catch #t
          (lambda ()
-           (setuid (passwd:uid (getpw user))))
+           (setgid (group:gid (getgr group))))
          (lambda (key . args)
            (format (current-error-port)
-                   "failed to change to user ~s:~%" user)
+                   "failed to change to group ~s:~%" group)
            (print-exception (current-error-port) #f key args)
            (primitive-exit 1))))
 
-     (when group
+     (when user
        (catch #t
          (lambda ()
-           (setgid (group:gid (getgr group))))
+           (setuid (passwd:uid (getpw user))))
          (lambda (key . args)
            (format (current-error-port)
-                   "failed to change to group ~s:~%" group)
+                   "failed to change to user ~s:~%" user)
            (print-exception (current-error-port) #f key args)
            (primitive-exit 1))))
 
-- 
2.5.0


[-- Attachment #3: Type: text/plain, Size: 38 bytes --]


-- 
David Thompson
GPG Key: 0FF1D807

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [DMD] [PATCH] service: Change gid before uid when dropping privileges.
  2015-12-03 15:37 [DMD] [PATCH] service: Change gid before uid when dropping privileges David Thompson
@ 2015-12-04  8:00 ` Ricardo Wurmus
  2015-12-04 19:08   ` Thompson, David
  2015-12-04 14:27 ` Ludovic Courtès
  2016-01-06 22:53 ` Ludovic Courtès
  2 siblings, 1 reply; 9+ messages in thread
From: Ricardo Wurmus @ 2015-12-04  8:00 UTC (permalink / raw)
  To: David Thompson; +Cc: guix-devel


David Thompson <dthompson2@worcester.edu> writes:

> Found this little order of operations issue when trying to button up the
> Transmission service.

Looks fine to me.

~~ Ricardo

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [DMD] [PATCH] service: Change gid before uid when dropping privileges.
  2015-12-03 15:37 [DMD] [PATCH] service: Change gid before uid when dropping privileges David Thompson
  2015-12-04  8:00 ` Ricardo Wurmus
@ 2015-12-04 14:27 ` Ludovic Courtès
  2016-01-06 22:53 ` Ludovic Courtès
  2 siblings, 0 replies; 9+ messages in thread
From: Ludovic Courtès @ 2015-12-04 14:27 UTC (permalink / raw)
  To: David Thompson; +Cc: guix-devel

David Thompson <dthompson2@worcester.edu> skribis:

> Found this little order of operations issue when trying to button up the
> Transmission service.

Indeed, good catch!

> From 552eafe882e3c059525e79c0f222becb9d73eb93 Mon Sep 17 00:00:00 2001
> From: David Thompson <dthompson2@worcester.edu>
> Date: Thu, 3 Dec 2015 10:09:34 -0500
> Subject: [PATCH] service: Change gid before uid when dropping privileges.
>

Commit log please.  :-)

Could you send an updated patch?

I think we should also do:

  (setgroups #())

before calling ‘setgid’, and probably factorize exception handling.

Would you like to do that?

Thank you,
Ludo’.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [DMD] [PATCH] service: Change gid before uid when dropping privileges.
  2015-12-04  8:00 ` Ricardo Wurmus
@ 2015-12-04 19:08   ` Thompson, David
  2015-12-06 21:56     ` Ludovic Courtès
  0 siblings, 1 reply; 9+ messages in thread
From: Thompson, David @ 2015-12-04 19:08 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

On Fri, Dec 4, 2015 at 3:00 AM, Ricardo Wurmus
<ricardo.wurmus@mdc-berlin.de> wrote:
>
> David Thompson <dthompson2@worcester.edu> writes:
>
>> Found this little order of operations issue when trying to button up the
>> Transmission service.
>
> Looks fine to me.

Thanks.  Now I need someone with commit access to dmd to apply it. :)

- Dave

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [DMD] [PATCH] service: Change gid before uid when dropping privileges.
  2015-12-04 19:08   ` Thompson, David
@ 2015-12-06 21:56     ` Ludovic Courtès
  2015-12-07 13:22       ` Thompson, David
  0 siblings, 1 reply; 9+ messages in thread
From: Ludovic Courtès @ 2015-12-06 21:56 UTC (permalink / raw)
  To: Thompson, David; +Cc: guix-devel

"Thompson, David" <dthompson2@worcester.edu> skribis:

> On Fri, Dec 4, 2015 at 3:00 AM, Ricardo Wurmus
> <ricardo.wurmus@mdc-berlin.de> wrote:
>>
>> David Thompson <dthompson2@worcester.edu> writes:
>>
>>> Found this little order of operations issue when trying to button up the
>>> Transmission service.
>>
>> Looks fine to me.
>
> Thanks.  Now I need someone with commit access to dmd to apply it. :)

Good point, should be fixed now!  (With the admin bit, even.  ;-))

Please take a look at the comments I made earlier.

Thanks,
Ludo’.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [DMD] [PATCH] service: Change gid before uid when dropping privileges.
  2015-12-06 21:56     ` Ludovic Courtès
@ 2015-12-07 13:22       ` Thompson, David
  2015-12-07 14:08         ` Thompson, David
  0 siblings, 1 reply; 9+ messages in thread
From: Thompson, David @ 2015-12-07 13:22 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel

On Sun, Dec 6, 2015 at 4:56 PM, Ludovic Courtès <ludo@gnu.org> wrote:
> "Thompson, David" <dthompson2@worcester.edu> skribis:
>
>> On Fri, Dec 4, 2015 at 3:00 AM, Ricardo Wurmus
>> <ricardo.wurmus@mdc-berlin.de> wrote:
>>>
>>> David Thompson <dthompson2@worcester.edu> writes:
>>>
>>>> Found this little order of operations issue when trying to button up the
>>>> Transmission service.
>>>
>>> Looks fine to me.
>>
>> Thanks.  Now I need someone with commit access to dmd to apply it. :)
>
> Good point, should be fixed now!  (With the admin bit, even.  ;-))

Thank you, Ludo.

> Please take a look at the comments I made earlier.

Noted.  You just beat me to addressing them. :)

- Dave

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [DMD] [PATCH] service: Change gid before uid when dropping privileges.
  2015-12-07 13:22       ` Thompson, David
@ 2015-12-07 14:08         ` Thompson, David
  2015-12-08 17:09           ` Ludovic Courtès
  0 siblings, 1 reply; 9+ messages in thread
From: Thompson, David @ 2015-12-07 14:08 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel

On Mon, Dec 7, 2015 at 8:22 AM, Thompson, David
<dthompson2@worcester.edu> wrote:
> On Sun, Dec 6, 2015 at 4:56 PM, Ludovic Courtès <ludo@gnu.org> wrote:
>> "Thompson, David" <dthompson2@worcester.edu> skribis:
>>
>>> On Fri, Dec 4, 2015 at 3:00 AM, Ricardo Wurmus
>>> <ricardo.wurmus@mdc-berlin.de> wrote:
>>>>
>>>> David Thompson <dthompson2@worcester.edu> writes:
>>>>
>>>>> Found this little order of operations issue when trying to button up the
>>>>> Transmission service.
>>>>
>>>> Looks fine to me.
>>>
>>> Thanks.  Now I need someone with commit access to dmd to apply it. :)
>>
>> Good point, should be fixed now!  (With the admin bit, even.  ;-))
>
> Thank you, Ludo.
>
>> Please take a look at the comments I made earlier.
>
> Noted.  You just beat me to addressing them. :)

Oh, nevermind.  I thought that you fixed my commit for me, but you
just gave me commit access.  ;)

Thanks!

- Dave

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [DMD] [PATCH] service: Change gid before uid when dropping privileges.
  2015-12-07 14:08         ` Thompson, David
@ 2015-12-08 17:09           ` Ludovic Courtès
  0 siblings, 0 replies; 9+ messages in thread
From: Ludovic Courtès @ 2015-12-08 17:09 UTC (permalink / raw)
  To: Thompson, David; +Cc: guix-devel

"Thompson, David" <dthompson2@worcester.edu> skribis:

> On Mon, Dec 7, 2015 at 8:22 AM, Thompson, David
> <dthompson2@worcester.edu> wrote:
>> On Sun, Dec 6, 2015 at 4:56 PM, Ludovic Courtès <ludo@gnu.org> wrote:
>>> "Thompson, David" <dthompson2@worcester.edu> skribis:
>>>
>>>> On Fri, Dec 4, 2015 at 3:00 AM, Ricardo Wurmus
>>>> <ricardo.wurmus@mdc-berlin.de> wrote:
>>>>>
>>>>> David Thompson <dthompson2@worcester.edu> writes:
>>>>>
>>>>>> Found this little order of operations issue when trying to button up the
>>>>>> Transmission service.
>>>>>
>>>>> Looks fine to me.
>>>>
>>>> Thanks.  Now I need someone with commit access to dmd to apply it. :)
>>>
>>> Good point, should be fixed now!  (With the admin bit, even.  ;-))
>>
>> Thank you, Ludo.
>>
>>> Please take a look at the comments I made earlier.
>>
>> Noted.  You just beat me to addressing them. :)
>
> Oh, nevermind.  I thought that you fixed my commit for me, but you
> just gave me commit access.  ;)

There’s no free lunch.  :-)

Ludo’.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [DMD] [PATCH] service: Change gid before uid when dropping privileges.
  2015-12-03 15:37 [DMD] [PATCH] service: Change gid before uid when dropping privileges David Thompson
  2015-12-04  8:00 ` Ricardo Wurmus
  2015-12-04 14:27 ` Ludovic Courtès
@ 2016-01-06 22:53 ` Ludovic Courtès
  2 siblings, 0 replies; 9+ messages in thread
From: Ludovic Courtès @ 2016-01-06 22:53 UTC (permalink / raw)
  To: David Thompson; +Cc: guix-devel

David Thompson <dthompson2@worcester.edu> skribis:

> From 552eafe882e3c059525e79c0f222becb9d73eb93 Mon Sep 17 00:00:00 2001
> From: David Thompson <dthompson2@worcester.edu>
> Date: Thu, 3 Dec 2015 10:09:34 -0500
> Subject: [PATCH] service: Change gid before uid when dropping privileges.

Pushed with a commit log.

Thanks,
Ludo’.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-01-06 22:54 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-03 15:37 [DMD] [PATCH] service: Change gid before uid when dropping privileges David Thompson
2015-12-04  8:00 ` Ricardo Wurmus
2015-12-04 19:08   ` Thompson, David
2015-12-06 21:56     ` Ludovic Courtès
2015-12-07 13:22       ` Thompson, David
2015-12-07 14:08         ` Thompson, David
2015-12-08 17:09           ` Ludovic Courtès
2015-12-04 14:27 ` Ludovic Courtès
2016-01-06 22:53 ` Ludovic Courtès

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).