Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp501660imn; Wed, 27 Jul 2022 12:00:28 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vmGVgk8oga9GSHFjcpbT7Bq0wLFbXNFZ69F7B/dHDzm89T8xfeYTuBWC5hYYHSuJaAgOil X-Received: by 2002:a17:907:2d86:b0:72b:4aee:7729 with SMTP id gt6-20020a1709072d8600b0072b4aee7729mr18514310ejc.143.1658948428382; Wed, 27 Jul 2022 12:00:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658948428; cv=none; d=google.com; s=arc-20160816; b=qNTLRvMoS1BF0IQ0zd23yRH2uDTwbqubvWiQf8LUUpLsOr4fnjH5IHZ4ao9EdzM/km 5McV99qzb8iPu7nNpQdjHGCo8yNIyehwe4cpyKAxQpVR9Cx2eCXBzQ5858x03lW3FvQJ lfZmS90cd55z4rZGuZSE4NiIneopJqyy2K7HViVyKERazMCtxFCALZGQ1H7XjSi6Qxce RwIRLWffMUN+nn/DUEMCP8cRUjcmr+xPRhrPutE1zZSAxM3rqj0Zx4lsZM8D0/yzmnE/ Lqrf9KvzT4ec0L6vFCdGLY0YHzPTmgN1Lqgml436G25IB4CIAUvCulH9hONcqxcOUa8F 9NnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=H/YoNoMBJ5KLzizvRdlp2kaTQKAcETzt8x9wjboShNc=; b=t1951PAKc68sjCb8qhtlWX3jmboJgr9jMbFfKB0B7lSefOTJMnC+DQu4abjmcP5y6J kwOQ3I2S7OB36GecfwyHAKDc0fJ0nQjY+MQTzmUO5LVbzekBB9eiK6quUcx7is+Zyi+V aYr4ZtzQJnDw+IDFwF2Gp+QQLEI3h41BJhdz/TjaN5zk9eBGcMxlHkzksZG+bJJN6RrV g7zI53iWvyQyxSAnKkVyejZdHfvxAy9gRBQ1K0mDvf5m2RPM+FMigL0Hg8ArS0S8MSxY wo1QiV2Yril1RwhJZJNfextv4Nh4OBoE0GxIJXrbcw/ZT6iqqIYxtZvmazbPYL7oOULm /DLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=f294ewGx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cs19-20020a170906dc9300b0072eec79ad38si20604136ejc.807.2022.07.27.12.00.02; Wed, 27 Jul 2022 12:00:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=f294ewGx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241576AbiG0SIH (ORCPT + 99 others); Wed, 27 Jul 2022 14:08:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238974AbiG0SHr (ORCPT ); Wed, 27 Jul 2022 14:07:47 -0400 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C0B8C7AC1 for ; Wed, 27 Jul 2022 10:11:22 -0700 (PDT) Received: from mail-oi1-f198.google.com (mail-oi1-f198.google.com [209.85.167.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id C426B3F0DA for ; Wed, 27 Jul 2022 17:11:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1658941880; bh=H/YoNoMBJ5KLzizvRdlp2kaTQKAcETzt8x9wjboShNc=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=f294ewGx3RuSG3n7RyP908ORZRmbHecmM5VYwd9wR8OGMeSoiOgbk6YtQXC4VTZ4S nKiy1hi/htLv4QHn5YuzkepU7QVIlFfJ4QCG8YdE9W9gBEUt7ItVPTCTz9DOo0+/DD BQwninWot1opMfUg0re/qunCpuYKxCaszaIG3xjFyYZc6Wod8iHbkWNKE7h7ZZP6jA XhHJZzBPJFPUBl51Q/NDQ6YQ539fmzKBUt8/qxMW/iOn9M0iaUFZVU3odIIVGJ6/QG 8hbcvadoNLdlvWmsS+3tSBr/d9pqrMcigh2ja8ucrKwR5MmrKFMlFwd8SQfCpyBvYD K6YrN8vrcL/uw== Received: by mail-oi1-f198.google.com with SMTP id bo42-20020a05680822aa00b0033ac79f2523so5158258oib.22 for ; Wed, 27 Jul 2022 10:11:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=H/YoNoMBJ5KLzizvRdlp2kaTQKAcETzt8x9wjboShNc=; b=k36tzOxRHAHTOvJYOmG+aPk4WEbM7dUgdu7Ok69NbWzkXsrNmB50m01WhUW901FswH BQz3nA/+KZ6vZmzFHhGnUycVg1cRssM2LhG73Nz2+Iy6r6Iy4wU78gvI4njOTJ45vjXD liRR7cGrMnoV2kPLcReepONTqWicRBhmu1oZ9oNr3B+cR1mnHDh96nf2EkYpM7vhIHLK r9K5t+Cc3zi3DbooHLiYUteSbCRe/FzwSEzKv3YPmrn2x3qtz1ZW7onDwEuKFF2Mvof0 pRM7d7ypxgkce58nvk3d1i974BDi5TahXs4xiAEV33K49MLwbwFK/EZLdyXpnGdqpgLg 8HyQ== X-Gm-Message-State: AJIora9W6It9/TrVMcA055I6NvMjP87unG31blLRdmNfEmOfBZ+uDUoa IADCdL910xo7JZW4aQ+GRm7+6WcRpUqP6XbIhyJW7XSCj5ETdot1bYfMhSYqakizYn84dUNDZb9 beOpjPD4ovGzHszpSA4Wejf05QY9vLAa6xOj71XRaxxNDsWDQvJF1qivjNA== X-Received: by 2002:a9d:2602:0:b0:61c:30c1:fa03 with SMTP id a2-20020a9d2602000000b0061c30c1fa03mr9316714otb.86.1658941879704; Wed, 27 Jul 2022 10:11:19 -0700 (PDT) X-Received: by 2002:a9d:2602:0:b0:61c:30c1:fa03 with SMTP id a2-20020a9d2602000000b0061c30c1fa03mr9316702otb.86.1658941879435; Wed, 27 Jul 2022 10:11:19 -0700 (PDT) MIME-Version: 1.0 References: <20220722022416.137548-1-mfo@canonical.com> <20220722022416.137548-7-mfo@canonical.com> In-Reply-To: From: Mauricio Faria de Oliveira Date: Wed, 27 Jul 2022 14:11:08 -0300 Message-ID: Subject: Re: [RFC PATCH 6/6] sysctl: introduce /proc/sys/kernel/modprobe_sysctl_alias To: Masahiro Yamada Cc: Linux Kernel Mailing List , linux-modules , Linux Kbuild mailing list , Linux FS-devel Mailing List , Michal Marek , Nick Desaulniers , Luis Chamberlain , Kees Cook , Iurii Zaikin Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 26, 2022 at 6:24 AM Masahiro Yamada wrote: > > On Fri, Jul 22, 2022 at 11:24 AM Mauricio Faria de Oliveira > wrote: > > > > The goal of the earlier patches is to let sysctl userspace tools > > load the kernel module with a sysctl entry that is not available > > yet in /proc/sys/ when the tool runs (so it can become available). > > > > Let's expose this file for userspace for two reasons: > > > > 1) Allow such tools to identify that the running kernel has the > > code which produces sysctl module aliases, so they could run > > 'modprobe sysctl:' only when it may actually help. > > > > 2) Allow an administrator to hint such tools not to do that, if > > that is desired for some reason (e.g., rather have the tools > > fail if something is misconfigured in a critical deployment). > > This flag is just a hint. > User-space tools are still able to ignore it. > > Perhaps, such administrator's choice might be specified in > tools' configuration file. > > For example, > > /etc/modprobe.d/forbid-sysctl-alias.conf > > may specify > > blacklist: sysctl:* > > if they want to forbid sysctl aliasing. > (but I do not know if this works or not). Yes, it's just a hint. I considered this isn't strong enough, but didn't think more into it. Now, your idea with modprobe.d is strong enough. We have to change it a bit, as only 'alias' supports wildcards per modprobe.d(5), then add 'install' to make sure. # cat /etc/modprobe.d/disable-sysctl-alias.conf alias sysctl:* sysctl_alias_off install sysctl_alias_off /bin/false # or /bin/true, per the sysadmin. # modprobe sysctl:nf_conntrack_max modprobe: ERROR: ../libkmod/libkmod-module.c:990 command_do() Error running install command '/bin/false' for module sysctl_alias_off: retcode 1 modprobe: ERROR: could not insert 'sysctl_alias_off': Invalid argument I'll document this in the commit message for now. P.S.: Since the flag is a hint to userspace tools in sense 1) as well (so they know not to run modprobe if sysctl aliases aren't expected), the idea or the file itself seems worth keeping -- but maybe differently. Thanks, > > > > > > > > > > > > > > > > Also add a module parameter for that (proc.modprobe_sysctl_alias), > > for another method that doesn't depend on sysctl tools to be set > > (that wouldn't fail them to try and set it if it's not there yet). > > > > Signed-off-by: Mauricio Faria de Oliveira > > --- > > fs/proc/proc_sysctl.c | 8 ++++++++ > > include/linux/module.h | 1 + > > kernel/sysctl.c | 9 +++++++++ > > 3 files changed, 18 insertions(+) > > > > diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c > > index ebbf8702387e..1e63819fcda8 100644 > > --- a/fs/proc/proc_sysctl.c > > +++ b/fs/proc/proc_sysctl.c > > @@ -33,6 +33,14 @@ static void check_struct_sysctl_device_id(void) > > BUILD_BUG_ON(offsetof(struct sysctl_device_id, procname) > > != offsetof(struct ctl_table, procname)); > > } > > + > > +/* > > + * Hint sysctl userspace tools whether or not to run modprobe with sysctl alias > > + * ('modprobe sysctl:entry') if they cannot find the file '/proc/sys/.../entry' > > + */ > > +int modprobe_sysctl_alias = 1; > > +module_param(modprobe_sysctl_alias, int, 0644); > > + > > #else > > static void check_struct_sysctl_device_id(void) {} > > #endif > > diff --git a/include/linux/module.h b/include/linux/module.h > > index 3010f687df19..5f565491c596 100644 > > --- a/include/linux/module.h > > +++ b/include/linux/module.h > > @@ -304,6 +304,7 @@ struct notifier_block; > > #ifdef CONFIG_MODULES > > > > extern int modules_disabled; /* for sysctl */ > > +extern int modprobe_sysctl_alias; /* for proc sysctl */ > > /* Get/put a kernel symbol (calls must be symmetric) */ > > void *__symbol_get(const char *symbol); > > void *__symbol_get_gpl(const char *symbol); > > diff --git a/kernel/sysctl.c b/kernel/sysctl.c > > index 15073621cfa8..b396cfcb55fc 100644 > > --- a/kernel/sysctl.c > > +++ b/kernel/sysctl.c > > @@ -1763,6 +1763,15 @@ static struct ctl_table kern_table[] = { > > .mode = 0644, > > .proc_handler = proc_dostring, > > }, > > +#ifdef CONFIG_PROC_SYSCTL > > + { > > + .procname = "modprobe_sysctl_alias", > > + .data = &modprobe_sysctl_alias, > > + .maxlen = sizeof(modprobe_sysctl_alias), > > + .mode = 0644, > > + .proc_handler = proc_dointvec, > > + }, > > +#endif > > { > > .procname = "modules_disabled", > > .data = &modules_disabled, > > -- > > 2.25.1 > > > > > -- > Best Regards > Masahiro Yamada -- Mauricio Faria de Oliveira