All of lore.kernel.org
 help / color / mirror / Atom feed
From: George Dunlap <george.dunlap@citrix.com>
To: Ian Jackson <ian.jackson@citrix.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
	Wei Liu <wei.liu2@citrix.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Tim Deegan <tim@xen.org>,
	Ross Lagerwall <ross.lagerwall@citrix.com>,
	Julien Grall <julien.grall@arm.com>,
	Jan Beulich <jbeulich@suse.com>,
	Anthony Perard <anthony.perard@citrix.com>,
	xen-devel@lists.xenproject.org
Subject: Re: [PATCH] docs/qemu-deprivilege: Revise and update with status and future plans
Date: Tue, 27 Mar 2018 15:24:33 +0100	[thread overview]
Message-ID: <df2b93b0-eae0-88f0-a13e-90f4b7600271@citrix.com> (raw)
In-Reply-To: <1a845c55-df25-1754-3e14-bdc47e658da8@citrix.com>

On 03/27/2018 03:15 PM, George Dunlap wrote:
> On 03/27/2018 02:33 PM, Ian Jackson wrote:
>>>>> +### Namespaces for unused functionality
>> ...
>>>>> +    unshare(CLONE_NEWNS | CLONE_NEWIPC)
>>>>
>>>> This would mean we would have to pass qemu fds for both the network
>>>> tap devices and any vnc consoles.  That makes life considerably more
>>>> complicated.  I think we should perhaps revisit this upstream.
>>>
>>> You haven't read this very carefully (nor do you seem to have read the
>>> discussion with Ross before responding).  I split the "Namespaces"
>>> restriction Ross suggested internally to us into two parts:
>>>  - Namespace restrictions for unused functionality
>>>  - Network namespacing
>>
>> Oh, sorry.  Yes.
> 
> Actually, sorry for being a bit 'pointy' here; upon reflection it
> occured to me that you probably actually did read the whole thread, but
> when you went back to respond you meant to respond to the other section,
> but stopped scanning when you got a match with "namespace".
> 
>>> I now realize that it might be that the limit will follow the current
>>> uid of the process, in which case "setrlimit -> setuid" might have the
>>> expected behavior.  But a quick Google search shows that the interaction
>>> of RLIMIT_NPROC and setuid() is tricky[1][2], and may vary from
>>> implementation to implementation; relying on the interaction to be
>>> correct (and stay correct) seems somewhat risky (unless POSIX has
>>> explicitly documented what should happen in that case, which again a
>>> quick Google search hasn't turned up).
>>
>> RLIMIT_NPROC is not in SuS:
>>  http://pubs.opengroup.org/onlinepubs/9699919799/functions/setrlimit.html
>>
>> FreeBSD does not have any of this madness:
>>  https://www.unix.com/man-page/freebsd/2/setuid/
>>
>> Anyway IMO we should set RLIMIT_NPROC after fork and before execve.
>> If this causes setuid to fail in qemu, qemu will crash.  But this
>> could only be the case if the new uid already has other processes,
>> which it shouldn't do.  (If it does, the new uid is probably
>> contaminated by a previous domain with the same domid.)
> 
> I was more worried about the limit not having the expected effect after
> the setuid().
> 
>>>>> +### libxl UID cleanup
>>>> ...
>>>>> +kill(-1,sig) sends a signal to "every process to which the calling
>>>>> +process has permission to send a signal".  So in theory:
>>>>> +  setuid(X)
>>>>> +  kill(-1,KILL)
>>>>> +should do the trick.
>>>>
>>>> We need to check whether a malicious qemu process could kill this
>>>> one.
>>>
>>> Hmm, in theory it probably could.
>>
>> I could find nothing in SuS explaining when process A may send signals
>> to process B.  So I resorted to the BSD manpages:
>>
>>   https://www.unix.com/man-page/freebsd/2/kill/
>>
>>   For a process to have permission to send a signal to a process
>>   designated by pid, the user must be the super-user, or the real or
>>   saved user ID of the receiving process must match the real or
>>   effective user ID of the sending process.
> 
> The text of both the FreeBSD and Linux man pages looks to be copied
> verbatim from [1].
> 
> [1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/kill.html
> 
>> Also kill(-1,) does not signal the sender.
> 
> Linux is the same.
> 
>> My analysis:
>>
>>                                           euid   ruid   suid
>>
>>   compared for receiving process                 ====   ====
>>   compared for sending process            ====   ====
>>
>>   possible rogue processes                qid    qid    qid
>>
>>   unrelated rootish processes             0      any    any
>>      or                                   any    0      any
>>      or                                   any    any    0
>>
>>   killer (our pet issuing kill)
>>      so rogues can't kill killer                 !=qid  !=qid
>>      so it doesn't kill randomly          !=0    !=0
>>      therefore:                           qid    pet    0
>>
>> We will have to reserve one uid `pet' specially for this nonsense.  We
>> call setresuid(2) to switch uids, and then kill(-1,9) and _exit(0).
>> The kill() call will kill other processes with uid `pet'.  So we take
>> a global lock while we do this.
>>
>> `pet' could be a uid associated with a reserved domid, eg dom0.

The alternate would be to have yet another UID range, to that we could
have a "target ID" (i.e., QEMU) and a "reaper ID" for each domain.  I
think that should mean any races should be benign.

 -George

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2018-03-27 14:26 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-22 18:24 [PATCH] docs/qemu-deprivilege: Revise and update with status and future plans George Dunlap
2018-03-23  9:41 ` Ross Lagerwall
2018-03-23 10:01   ` Roger Pau Monné
2018-03-23 10:53   ` George Dunlap
2018-03-23 11:33     ` Ross Lagerwall
2018-03-23 12:13 ` Anthony PERARD
2018-03-26 16:43 ` Ian Jackson
2018-03-27 10:20   ` George Dunlap
2018-03-27 11:24     ` George Dunlap
2018-03-27 13:33     ` Ian Jackson
2018-03-27 14:15       ` George Dunlap
2018-03-27 14:24         ` George Dunlap [this message]
2018-03-27 14:37           ` Ian Jackson
2018-03-27 14:45             ` George Dunlap
2018-03-27 14:36         ` Ian Jackson
2018-03-27 15:52           ` George Dunlap
2018-03-28 12:47       ` Ross Lagerwall
2018-03-28 13:44         ` George Dunlap
2018-03-27 10:21   ` George Dunlap
2018-03-28 12:28     ` Ross Lagerwall
2018-03-28 13:26       ` George Dunlap

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=df2b93b0-eae0-88f0-a13e-90f4b7600271@citrix.com \
    --to=george.dunlap@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=anthony.perard@citrix.com \
    --cc=ian.jackson@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien.grall@arm.com \
    --cc=ross.lagerwall@citrix.com \
    --cc=sstabellini@kernel.org \
    --cc=tim@xen.org \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.