linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vlastimil Babka <vbabka@suse.cz>
To: Kees Cook <keescook@chromium.org>
Cc: Luis Chamberlain <mcgrof@kernel.org>,
	Iurii Zaikin <yzaikin@google.com>,
	linux-kernel@vger.kernel.org, linux-api@vger.kernel.org,
	linux-mm@kvack.org, Ivan Teterevkov <ivan.teterevkov@nutanix.com>,
	Michal Hocko <mhocko@kernel.org>,
	David Rientjes <rientjes@google.com>,
	Matthew Wilcox <willy@infradead.org>,
	"Eric W . Biederman" <ebiederm@xmission.com>
Subject: Re: [RFC] kernel/sysctl: support setting sysctl parameters from kernel command line
Date: Tue, 24 Mar 2020 17:50:49 +0100	[thread overview]
Message-ID: <bc721358-6202-bdc5-0398-29921b3f9855@suse.cz> (raw)
In-Reply-To: <202003171421.5DCADF51@keescook>

On 3/17/20 10:29 PM, Kees Cook wrote:
> On Tue, Mar 17, 2020 at 02:21:05PM +0100, Vlastimil Babka wrote:
>> A recently proposed patch to add vm_swappiness command line parameter in
>> addition to existing sysctl [1] made me wonder why we don't have a general
>> support for passing sysctl parameters via command line. Googling found only
>> somebody else wondering the same [2], but I haven't found any prior discussion
>> with reasons why not to do this.
> 
> I'd like to see stuff like this (as you say, you've found some
> redundancies here which could be cleaned up a bit). I think the reason
> it hasn't happened before is that the answers have mostly revolved
> around "just set it in your initramfs". :P
> 
>> [...]
>> Hence, this patch adds a new parse_args() pass that looks for parameters
>> prefixed by 'sysctl.' and searches for them in the sysctl ctl_tables. When
>> found, the respective proc handler is invoked. The search is just a naive
>> linear one, to avoid using the whole procfs layer. It should be acceptable,
>> as the cost depends on number of sysctl. parameters passed.
> 
> I think this needs reconsidering: this RFC only searches 1 level deep,
> but sysctls are a tree. For example:

Yes, that was an oversight, easily fixed.

> kernel.yama.ptrace_scope
> mm.transparent_hugepage.enabled

Hm, transparent_hugepage is in sysfs (/sys/kernel/mm), but not sysctl, at least
in my case the sysctl tool doesn't list it. Yours does? Yay for consistency.

> net.ipv4.conf.default.rp_filter
> ...etc
> 
> If this goes in, it'll need to do full traversal.

Right.

>> The main limitation of avoiding the procfs layer is however that sysctls
>> dynamically registered by register_sysctl_table() or register_sysctl_paths()
>> cannot be set by this method.
> 
> Correct. And I like what you've done in the code: announce any unhandled
> sysctls.
> 
>> The processing is hooked right before the init process is loaded, as some
>> handlers might be more complicated than simple setters and might need some
>> subsystems to be initialized. At the moment the init process can be started and
>> eventually execute a process writing to /proc/sys/ then it should be also fine
>> to do that from the kernel.
> 
> I agree about placement.
> 
>> 
>> [1] https://lore.kernel.org/linux-doc/BL0PR02MB560167492CA4094C91589930E9FC0@BL0PR02MB5601.namprd02.prod.outlook.com/
>> [2] https://unix.stackexchange.com/questions/558802/how-to-set-sysctl-using-kernel-command-line-parameter
>> 
>> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
>> ---
>> Hi,
>> 
>> this is an early RFC so I can get feedback whether to pursue this idea further,
>> before trying the more complicated stuff with dynamically registered sysctls.
>> For those I have some unanswered questions:
>> - Support them at all?
> 
> Maybe? It seems excessive for the initial version.

OK

>> - Do so by an internal procfs mount again, that was removed by 61a47c1ad3a4 ?
>>   Or try to keep it simple.
> 
> I think you can walk the registered sysctl structures themselves, yes?

I should be able to, yeah.

>> - If sysctls are dynamically registered at module load, process the command
>>   line sysctl arguments again? - this would be rather complicated I guess.
> 
> If it does get supported, perhaps saving them somewhere for
> register_sysctl_table() to walk when it gets called?
> 
> I like the idea if just for having to build less boiler plate for
> supporting things that I've had to plumb to both boot_params and sysctl.
> :)

Thanks, I will pursue the idea further then :)

Vlastimil

  reply	other threads:[~2020-03-24 16:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-17 13:21 [RFC] kernel/sysctl: support setting sysctl parameters from kernel command line Vlastimil Babka
2020-03-17 21:29 ` Kees Cook
2020-03-24 16:50   ` Vlastimil Babka [this message]
2020-03-24 18:24     ` Kees Cook

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=bc721358-6202-bdc5-0398-29921b3f9855@suse.cz \
    --to=vbabka@suse.cz \
    --cc=ebiederm@xmission.com \
    --cc=ivan.teterevkov@nutanix.com \
    --cc=keescook@chromium.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mcgrof@kernel.org \
    --cc=mhocko@kernel.org \
    --cc=rientjes@google.com \
    --cc=willy@infradead.org \
    --cc=yzaikin@google.com \
    /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 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 NNTP newsgroup(s).