lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <26fb047f-9164-96ae-a6cd-7a7efa41d43b@virtuozzo.com>
Date:   Tue, 11 Dec 2018 15:22:42 +0300
From:   Kirill Tkhai <ktkhai@...tuozzo.com>
To:     Cyrill Gorcunov <gorcunov@...il.com>
Cc:     akpm@...ux-foundation.org, mhocko@...e.com, linux-mm@...ck.org,
        linux-kernel@...r.kernel.org, gorcunov@...tuozzo.com
Subject: Re: [PATCH v2] ksm: React on changing "sleep_millisecs" parameter
 faster

On 11.12.2018 14:13, Cyrill Gorcunov wrote:
> On Tue, Dec 11, 2018 at 01:26:59PM +0300, Kirill Tkhai wrote:
>> ksm thread unconditionally sleeps in ksm_scan_thread()
>> after each iteration:
>>
>> 	schedule_timeout_interruptible(
>> 		msecs_to_jiffies(ksm_thread_sleep_millisecs))
>>
>> The timeout is configured in /sys/kernel/mm/ksm/sleep_millisecs.
>>
>> In case of user writes a big value by a mistake, and the thread
>> enters into schedule_timeout_interruptible(), it's not possible
>> to cancel the sleep by writing a new smaler value; the thread
>> is just sleeping till timeout expires.
>>
>> The patch fixes the problem by waking the thread each time
>> after the value is updated.
>>
>> This also may be useful for debug purposes; and also for userspace
>> daemons, which change sleep_millisecs value in dependence of
>> system load.
>>
>> Signed-off-by: Kirill Tkhai <ktkhai@...tuozzo.com>
>>
>> v2: Use wait_event_interruptible_timeout() instead of unconditional
>>     schedule_timeout().
> ...
>> @@ -2844,7 +2849,10 @@ static ssize_t sleep_millisecs_store(struct kobject *kobj,
>>  	if (err || msecs > UINT_MAX)
>>  		return -EINVAL;
>>  
>> +	mutex_lock(&ksm_thread_mutex);
>>  	ksm_thread_sleep_millisecs = msecs;
>> +	mutex_unlock(&ksm_thread_mutex);
>> +	wake_up_interruptible(&ksm_iter_wait);
> 
> Btw, just thought -- if we start using this mutex here don't we
> open a window for force attack on the thread self execution,
> iow if there gonna be a million of writers do we have a guarantee
> thread ksm_scan_thread will grab the mutex earlier than writers
> (or somewhere inbetween)?

This file is permitted for global root only. I don't think there is
a problem.

If someone wants to make ksm helpless, a person may just write a big
"sleep_millisecs" value. KSM thread won't be executed almost all the time
in this case.

Kirill

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ