Re: mlock and jail

2017-02-02 Thread Xin LI
On Thu, Feb 2, 2017 at 1:28 PM, Bruno Lauzé <brunola...@msn.com> wrote:
>
>
> But a simple user with no rights can mlock (64kb by default) why a jail would 
> not be able?
>

No, I'm not, by any means, arguing against having jailed processes
being able to mlock(), I'm just saying that we should have more fine
grained control over it (a knob to allow system administrators to
tweak it would be a good start).

Cheers,

>
> From: Xin LI<mailto:delp...@gmail.com>
> Sent: Thursday, February 2, 2017 1:13 PM
> To: Pavel Timofeev<mailto:tim...@gmail.com>
> Cc: Bruno Lauzé<mailto:brunola...@msn.com>; 
> freebsd-current<mailto:freebsd-current@freebsd.org>
> Subject: Re: mlock and jail
>
>
>
> On Thu, Feb 2, 2017 at 7:54 AM, Pavel Timofeev <tim...@gmail.com> wrote:
>> 2017-02-02 4:31 GMT+03:00 Xin LI <delp...@gmail.com>:
>>> I like this idea.
>>>
>>> Note that potentially your patch would make it possible for a jailed
>>> root to DoS the whole system by locking too much of pages in memory.
>>> I think it would be sensible to provide a per-jail flag to enable
>>> doing it, or better, have some finer grained control (e.g. per jail
>>> quota of permitted locked pages).
>>>
>>> Why did the application want to lock pages in main memory, though?
>>
>> For example, this secret management tool
>> https://www.vaultproject.io/docs/config/ wants to lock memory for
>> security (surprise) reason.
>> It's available as security/vault in our ports tree.
>
> No it's not surprise but overkill IMHO.  Here is why:
>
> Locking memory does prevent swapping, but in a typical multi-user
> system, if an attacker is already able to read swap (keep in mind that
> disks are by default owned by root and can not be read in a typical
> setup), then the administrator already have much bigger problem to
> worry about, and the attacker would have much more powerful tools to
> steal the secrets.
>
> Additionally, if one really cares about safety of swap, they should
> have used encrypted swap in the first place.  On FreeBSD, appending
> '.eli' to the swap device in fstab (e.g. /dev/ada0p3 ->
> /dev/ada0p3.eli) would automatically do one-time keyed swapping.
>
> Moreover, I don't think it's a good idea to use an application that
> advocates locking all memory that it owns for "security" reasons: if
> the application writer does not know which memory pages would contain
> sensitive information, good chances that the application writer have
> no idea what is privilege separation and the design they have created
> could be fundamentally flawed.
>
> Cheers,
> ___
> freebsd-current@freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-current
> To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"
___
freebsd-current@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"

RE: mlock and jail

2017-02-02 Thread Bruno Lauzé


But a simple user with no rights can mlock (64kb by default) why a jail would 
not be able?



From: Xin LI<mailto:delp...@gmail.com>
Sent: Thursday, February 2, 2017 1:13 PM
To: Pavel Timofeev<mailto:tim...@gmail.com>
Cc: Bruno Lauzé<mailto:brunola...@msn.com>; 
freebsd-current<mailto:freebsd-current@freebsd.org>
Subject: Re: mlock and jail



On Thu, Feb 2, 2017 at 7:54 AM, Pavel Timofeev <tim...@gmail.com> wrote:
> 2017-02-02 4:31 GMT+03:00 Xin LI <delp...@gmail.com>:
>> I like this idea.
>>
>> Note that potentially your patch would make it possible for a jailed
>> root to DoS the whole system by locking too much of pages in memory.
>> I think it would be sensible to provide a per-jail flag to enable
>> doing it, or better, have some finer grained control (e.g. per jail
>> quota of permitted locked pages).
>>
>> Why did the application want to lock pages in main memory, though?
>
> For example, this secret management tool
> https://www.vaultproject.io/docs/config/ wants to lock memory for
> security (surprise) reason.
> It's available as security/vault in our ports tree.

No it's not surprise but overkill IMHO.  Here is why:

Locking memory does prevent swapping, but in a typical multi-user
system, if an attacker is already able to read swap (keep in mind that
disks are by default owned by root and can not be read in a typical
setup), then the administrator already have much bigger problem to
worry about, and the attacker would have much more powerful tools to
steal the secrets.

Additionally, if one really cares about safety of swap, they should
have used encrypted swap in the first place.  On FreeBSD, appending
'.eli' to the swap device in fstab (e.g. /dev/ada0p3 ->
/dev/ada0p3.eli) would automatically do one-time keyed swapping.

Moreover, I don't think it's a good idea to use an application that
advocates locking all memory that it owns for "security" reasons: if
the application writer does not know which memory pages would contain
sensitive information, good chances that the application writer have
no idea what is privilege separation and the design they have created
could be fundamentally flawed.

Cheers,
___
freebsd-current@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"


Re: mlock and jail

2017-02-02 Thread Xin LI
On Thu, Feb 2, 2017 at 7:54 AM, Pavel Timofeev  wrote:
> 2017-02-02 4:31 GMT+03:00 Xin LI :
>> I like this idea.
>>
>> Note that potentially your patch would make it possible for a jailed
>> root to DoS the whole system by locking too much of pages in memory.
>> I think it would be sensible to provide a per-jail flag to enable
>> doing it, or better, have some finer grained control (e.g. per jail
>> quota of permitted locked pages).
>>
>> Why did the application want to lock pages in main memory, though?
>
> For example, this secret management tool
> https://www.vaultproject.io/docs/config/ wants to lock memory for
> security (surprise) reason.
> It's available as security/vault in our ports tree.

No it's not surprise but overkill IMHO.  Here is why:

Locking memory does prevent swapping, but in a typical multi-user
system, if an attacker is already able to read swap (keep in mind that
disks are by default owned by root and can not be read in a typical
setup), then the administrator already have much bigger problem to
worry about, and the attacker would have much more powerful tools to
steal the secrets.

Additionally, if one really cares about safety of swap, they should
have used encrypted swap in the first place.  On FreeBSD, appending
'.eli' to the swap device in fstab (e.g. /dev/ada0p3 ->
/dev/ada0p3.eli) would automatically do one-time keyed swapping.

Moreover, I don't think it's a good idea to use an application that
advocates locking all memory that it owns for "security" reasons: if
the application writer does not know which memory pages would contain
sensitive information, good chances that the application writer have
no idea what is privilege separation and the design they have created
could be fundamentally flawed.

Cheers,
___
freebsd-current@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"


Re: mlock and jail

2017-02-02 Thread Pavel Timofeev
2017-02-02 4:31 GMT+03:00 Xin LI :
> I like this idea.
>
> Note that potentially your patch would make it possible for a jailed
> root to DoS the whole system by locking too much of pages in memory.
> I think it would be sensible to provide a per-jail flag to enable
> doing it, or better, have some finer grained control (e.g. per jail
> quota of permitted locked pages).
>
> Why did the application want to lock pages in main memory, though?

For example, this secret management tool
https://www.vaultproject.io/docs/config/ wants to lock memory for
security (surprise) reason.
It's available as security/vault in our ports tree.

>
> On Wed, Feb 1, 2017 at 3:52 PM, Bruno Lauzé  wrote:
>>
>> I would like to ask if there is a reason I would have to applythe  patch 
>> below to make an application work in a jail.
>> And who's bad? the app too intrusive or the bsd not flexible enough 
>> (allow.mlock?)
>>
>>
>> Index: sys/kern/kern_jail.c
>> ===
>> --- sys/kern/kern_jail.c(revision 313033)
>> +++ sys/kern/kern_jail.c(working copy)
>> @@ -3340,6 +3340,11 @@
>> case PRIV_PROC_SETLOGINCLASS:
>> return (0);
>>
>>
>> +case PRIV_VM_MADV_PROTECT:
>> +case PRIV_VM_MLOCK:
>> +case PRIV_VM_MUNLOCK:
>> +return (0);
>> +
>> default:
>>
>>
>> ___
___
freebsd-current@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"

Re: mlock and jail (Elasticsearch/Java use case)

2017-02-02 Thread GomoR

Hello,

Giving mlock support to jails would also allow Elasticsearch 
(Java-based) to run as a jailed process.
In fact, Java can use a memory optimization trick for better 
performances by locking a specified amount of memory.


Thus, Elasticsearch has the need for such a setting to let it run at its 
full power.


Without this tunable, one cannot take advantage of this and 
Elasticsearch cannot run jailed to its full performance.
Furthermore, putting it outside of a jail is less confortable regarding 
overall system security.


Best regards,


On 2017-02-02 02:31, Xin LI wrote:

I like this idea.

Note that potentially your patch would make it possible for a jailed
root to DoS the whole system by locking too much of pages in memory.
I think it would be sensible to provide a per-jail flag to enable
doing it, or better, have some finer grained control (e.g. per jail
quota of permitted locked pages).

Why did the application want to lock pages in main memory, though?

On Wed, Feb 1, 2017 at 3:52 PM, Bruno Lauzé  wrote:


I would like to ask if there is a reason I would have to applythe  
patch below to make an application work in a jail.
And who's bad? the app too intrusive or the bsd not flexible enough 
(allow.mlock?)



Index: sys/kern/kern_jail.c
===
--- sys/kern/kern_jail.c(revision 313033)
+++ sys/kern/kern_jail.c(working copy)
@@ -3340,6 +3340,11 @@
case PRIV_PROC_SETLOGINCLASS:
return (0);


+case PRIV_VM_MADV_PROTECT:
+case PRIV_VM_MLOCK:
+case PRIV_VM_MUNLOCK:
+return (0);
+
default:


___
freebsd-current@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to 
"freebsd-current-unsubscr...@freebsd.org"

___
freebsd-current@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to 
"freebsd-current-unsubscr...@freebsd.org"


___
freebsd-current@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"

Re: mlock and jail

2017-02-01 Thread Bruno Lauzé
Thanks you.

The app in fact is dotnet https://github.com/dotnet/coreclr

And since it's already possible to cap overall memory with rctl ( -- 
jail:httpd:memoryuse:deny=2G/jail -- or -- jail:httpd:memorylocked:deny=1G/jail 
 -- ) it seems correct to say the lock weight could only be within those limits?


But right now memorylocked rctl does apply since prison is denied mlock. I 
might be missing something. Thanks for your help.


By the way, FreeBSD would gain a lot pushing for dotnet support as it did with 
Java in the days.


From: Xin LI <delp...@gmail.com>
Sent: February 1, 2017 8:31:35 PM
To: Bruno Lauzé
Cc: freebsd-current
Subject: Re: mlock and jail

I like this idea.

Note that potentially your patch would make it possible for a jailed
root to DoS the whole system by locking too much of pages in memory.
I think it would be sensible to provide a per-jail flag to enable
doing it, or better, have some finer grained control (e.g. per jail
quota of permitted locked pages).

Why did the application want to lock pages in main memory, though?

On Wed, Feb 1, 2017 at 3:52 PM, Bruno Lauzé <brunola...@msn.com> wrote:
>
> I would like to ask if there is a reason I would have to applythe  patch 
> below to make an application work in a jail.
> And who's bad? the app too intrusive or the bsd not flexible enough 
> (allow.mlock?)
>
>
> Index: sys/kern/kern_jail.c
> ===
> --- sys/kern/kern_jail.c(revision 313033)
> +++ sys/kern/kern_jail.c(working copy)
> @@ -3340,6 +3340,11 @@
> case PRIV_PROC_SETLOGINCLASS:
> return (0);
>
>
> +case PRIV_VM_MADV_PROTECT:
> +case PRIV_VM_MLOCK:
> +case PRIV_VM_MUNLOCK:
> +return (0);
> +
> default:
>
>
> ___
> freebsd-current@freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-current
> To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"
___
freebsd-current@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"


Re: mlock and jail

2017-02-01 Thread Xin LI
I like this idea.

Note that potentially your patch would make it possible for a jailed
root to DoS the whole system by locking too much of pages in memory.
I think it would be sensible to provide a per-jail flag to enable
doing it, or better, have some finer grained control (e.g. per jail
quota of permitted locked pages).

Why did the application want to lock pages in main memory, though?

On Wed, Feb 1, 2017 at 3:52 PM, Bruno Lauzé  wrote:
>
> I would like to ask if there is a reason I would have to applythe  patch 
> below to make an application work in a jail.
> And who's bad? the app too intrusive or the bsd not flexible enough 
> (allow.mlock?)
>
>
> Index: sys/kern/kern_jail.c
> ===
> --- sys/kern/kern_jail.c(revision 313033)
> +++ sys/kern/kern_jail.c(working copy)
> @@ -3340,6 +3340,11 @@
> case PRIV_PROC_SETLOGINCLASS:
> return (0);
>
>
> +case PRIV_VM_MADV_PROTECT:
> +case PRIV_VM_MLOCK:
> +case PRIV_VM_MUNLOCK:
> +return (0);
> +
> default:
>
>
> ___
> freebsd-current@freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-current
> To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"
___
freebsd-current@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"

mlock and jail

2017-02-01 Thread Bruno Lauzé

I would like to ask if there is a reason I would have to applythe  patch below 
to make an application work in a jail.
And who's bad? the app too intrusive or the bsd not flexible enough 
(allow.mlock?)


Index: sys/kern/kern_jail.c
===
--- sys/kern/kern_jail.c        (revision 313033)
+++ sys/kern/kern_jail.c        (working copy)
@@ -3340,6 +3340,11 @@
        case PRIV_PROC_SETLOGINCLASS:
                return (0);


+        case PRIV_VM_MADV_PROTECT:
+        case PRIV_VM_MLOCK:
+        case PRIV_VM_MUNLOCK:
+                return (0);
+
        default:


___
freebsd-current@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"