Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp499009imn; Wed, 27 Jul 2022 11:56:02 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vsIIlJDQbptUSc+K+KedEqAdiO2qh9x1/TVYIIpEEZlbq6H1v9uXwMJVDTRySHxR1Dfusu X-Received: by 2002:a05:6402:28c3:b0:43a:6d78:1b64 with SMTP id ef3-20020a05640228c300b0043a6d781b64mr24594123edb.93.1658948162545; Wed, 27 Jul 2022 11:56:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658948162; cv=none; d=google.com; s=arc-20160816; b=RuIF+3JSd4hc6YWg+6ofNaHm4zKBNwCeXxR7hIUPBaebg1oX8sE3JPnWXF1aYud9Y9 4Q/lTJssCkmP7lR9r5FR3fXAsjmDhyQfNI1Xf4BhegmrvbYdtXsZopS+gHqZ8vG9toz4 x/nkeouV7zf127JK/ff1eLCm5rgVOimCrrWshdQ+DkQgCvT1fJBfEUSd8ONFSph5Jgyp KcyKBGUDAkDxo865RnNOnQ3IJamJfDqh9pKlzVosisi+WbhGkKTnaG4C5yFr4jl+4pUZ JN9wq/I9T045l1ctBKw5uljHbRZ0Rds4xxJJBGUTgCBijjy5Lpn0OqrxKLv/7wKNJOwX vqGw== 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=p8BxUinmu0In37tgfklk8SPEbUyiUeXieDC0F6YQ4cE=; b=Z1XycyqQpcBpKeJ2gWA2yR2ojlZF5e3PSw4BcqFn9grfdT4/Ab/idkw+ro89X+vOuZ Szqv3DsCtrmsPkp4MRa0/IRMnwNrpKNjrjknCcfwsMO4X6u2o4PzjMgv1ySSUrWnlm5G DN42e1N5mQJTma0HX0rcAUCzjsQ441dBcWELFwvRJRLDP663MwWmwoXsu2beXI7resAS TGJVpIyAhzuC/8zjXXc4pTQwE7JI3LX6Tzl/9/uarikWtd7F48J9uXnMCTbBOjw4sEYY kBCA9woS7U+qYW/XkUpYOnQukZ7WC/T/2kKBItVprYKc5PMBEsRq6aRcG+DrXwggYNRW s22Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=oCIGhuE+; 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 sc40-20020a1709078a2800b0072efd2ebeecsi22826916ejc.785.2022.07.27.11.55.37; Wed, 27 Jul 2022 11:56:02 -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=oCIGhuE+; 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 S232465AbiG0SIr (ORCPT + 99 others); Wed, 27 Jul 2022 14:08:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232276AbiG0SIb (ORCPT ); Wed, 27 Jul 2022 14:08:31 -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 98A5DCB74F for ; Wed, 27 Jul 2022 10:11:55 -0700 (PDT) Received: from mail-oa1-f71.google.com (mail-oa1-f71.google.com [209.85.160.71]) (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 8EB713F130 for ; Wed, 27 Jul 2022 17:11:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1658941912; bh=p8BxUinmu0In37tgfklk8SPEbUyiUeXieDC0F6YQ4cE=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=oCIGhuE+BbtgzTjbzXY+o5mSVkNAXeBXBu16cmUG8GF/VYDhZJeXAH9lhtV13o08w B6WXRFbTxNAyjFEunOqRx83DS3zet66aRFc2kYGwBEZzOlmo/+TC4mygD3XBtqWDJG AN4oiC2fQ/hZCh5ta1DTZkpbaUyl8Oa410mruViOBvW48M3y9+EywQWJuxtBhUapmh Zz8H1fWGSoVYIaP1Pr5oxXyUBsomojrJ4gyZbcC8JoK/7pEB37cJFIGJqtyZB4VqPl ELiW9nBppKf/VkrSnTRN5RZKZP+oekH4qVB9h7LlFNKy9kM4hwg89e63VqDA5zW1aq aAybR6puiyKmg== Received: by mail-oa1-f71.google.com with SMTP id 586e51a60fabf-10d6ce04410so9480195fac.23 for ; Wed, 27 Jul 2022 10:11:52 -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=p8BxUinmu0In37tgfklk8SPEbUyiUeXieDC0F6YQ4cE=; b=ZDCeacaovvnNh16tmjGQBZuB2XtRVOPIQ6QINoFU2SR+oqMyWN7jPL7Vq4J8S9UGkg aukJOkcZxhfQwya2hc7YJRkoYLeo4otzBaV03AgAhmOrniHZ6dGo5AohSlnGOso4D+As YUFd1usxqrswbctOsG6Gof7JNpAkD0wojMeQGjXX8U2Ssw1o9a0JyVjrzD8+IRiHGQvu EUwHjytD2xygh6rPKEAU4mPGqzkXm1WYQQMgUmwoAj6/ocsAeTwZdM8RNUSUTaky5LbS nzRYL7dzCcJk7H/50q6DCxOvMk+aqMHE5K+yqBt61hWKmenVyvXuG0DPk7koCSg39+Bp Ttcg== X-Gm-Message-State: AJIora/xGdjxwwAEGTHqKigL7jx/X5LGBC4SQNeMZxUSGUcURmnToXKM O5Alri1IpH8cNiL4wOk6zfNKAV547vgV8JAUYh01EcbwqTB/1nQAh76j8rIrCOup9er2xodE4lV 51orVj5dAbx9KkRG6ABkuVh1y9YijGdy9Gjuq15N2RMCdKArZArfLktAFng== X-Received: by 2002:a54:4789:0:b0:33a:5a42:71c with SMTP id o9-20020a544789000000b0033a5a42071cmr2428439oic.239.1658941911503; Wed, 27 Jul 2022 10:11:51 -0700 (PDT) X-Received: by 2002:a54:4789:0:b0:33a:5a42:71c with SMTP id o9-20020a544789000000b0033a5a42071cmr2428429oic.239.1658941911233; Wed, 27 Jul 2022 10:11:51 -0700 (PDT) MIME-Version: 1.0 References: <20220722022416.137548-1-mfo@canonical.com> <20220722022416.137548-4-mfo@canonical.com> In-Reply-To: From: Mauricio Faria de Oliveira Date: Wed, 27 Jul 2022 14:11:39 -0300 Message-ID: Subject: Re: [RFC PATCH 3/6] sysctl, mod_devicetable: shadow struct ctl_table.procname for file2alias 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=ham 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:27 AM Masahiro Yamada wrote: > > On Fri, Jul 22, 2022 at 11:24 AM Mauricio Faria de Oliveira > wrote: > > > > In order to expose a sysctl entry to modpost (file2alias.c, precisely) > > we have to shadow 'struct ctl_table' in mod_devicetable.h, as scripts > > should not access kernel headers or its types (see file2alias.c). > > > > The required field is '.procname' (basename of '/proc/sys/.../entry'). > > > > Since 'struct ctl_table' is annotated for structure randomization and > > we need a known offset for '.procname' (remember, no kernel headers), > > take it out of the randomized portion (as in, eg, 'struct task_struct'). > > > > Of course, add build-time checks for struct size and .procname offset > > between both structs. (This has to be done on kernel side; for headers.) > > > > With that in place, use the regular macros in devicetable-offsets.c to > > define SIZE_... and OFF_... macros for the shadow struct and the field > > of interest. > > > > Signed-off-by: Mauricio Faria de Oliveira > > --- > > fs/proc/proc_sysctl.c | 19 +++++++++++++++++++ > > include/linux/mod_devicetable.h | 25 +++++++++++++++++++++++++ > > include/linux/sysctl.h | 11 ++++++++++- > > kernel/sysctl.c | 1 + > > scripts/mod/devicetable-offsets.c | 3 +++ > > 5 files changed, 58 insertions(+), 1 deletion(-) > > > > diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c > > index 021e83fe831f..ebbf8702387e 100644 > > --- a/fs/proc/proc_sysctl.c > > +++ b/fs/proc/proc_sysctl.c > > @@ -19,6 +19,24 @@ > > #include > > #include "internal.h" > > > > +#ifdef CONFIG_MODULES > > +#include > > + > > +static void check_struct_sysctl_device_id(void) > > +{ > > + /* > > + * The shadow struct sysctl_device_id for file2alias.c needs > > + * the same size of struct ctl_table and offset for procname. > > + */ > > + BUILD_BUG_ON(sizeof(struct sysctl_device_id) > > + != sizeof(struct ctl_table)); > > + BUILD_BUG_ON(offsetof(struct sysctl_device_id, procname) > > + != offsetof(struct ctl_table, procname)); > > > Nit: > > If you use static_assert(), you can remove > check_struct_sysctl_device_id(). > > > You can write static_assert() out of a function. That's a nice cleanup; thanks! > > > > > diff --git a/kernel/sysctl.c b/kernel/sysctl.c > > index 223376959d29..15073621cfa8 100644 > > --- a/kernel/sysctl.c > > +++ b/kernel/sysctl.c > > @@ -2487,6 +2487,7 @@ int __init sysctl_init_bases(void) > > > > return 0; > > } > > + > > > Noise. Fixed. > > > > > > #endif /* CONFIG_SYSCTL */ > > /* > > * No sense putting this after each symbol definition, twice, > > diff --git a/scripts/mod/devicetable-offsets.c b/scripts/mod/devicetable-offsets.c > > index c0d3bcb99138..43b2549940d2 100644 > > --- a/scripts/mod/devicetable-offsets.c > > +++ b/scripts/mod/devicetable-offsets.c > > @@ -262,5 +262,8 @@ int main(void) > > DEVID(ishtp_device_id); > > DEVID_FIELD(ishtp_device_id, guid); > > > > + DEVID(sysctl_device_id); > > + DEVID_FIELD(sysctl_device_id, procname); > > + > > return 0; > > } > > -- > > 2.25.1 > > > > > -- > Best Regards > Masahiro Yamada -- Mauricio Faria de Oliveira