Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp532678imn; Tue, 26 Jul 2022 02:39:13 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tWUIo8uDxRs6N2gP9FrQ9k/jQIDUn7Ep0OA31ZEKJKBBfGTu5vys0lqncRYFXgJDpuA0yu X-Received: by 2002:a17:907:2854:b0:72b:7daf:cc0d with SMTP id el20-20020a170907285400b0072b7dafcc0dmr13282598ejc.524.1658828353216; Tue, 26 Jul 2022 02:39:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658828353; cv=none; d=google.com; s=arc-20160816; b=MSdOHwomEt7a5n7Wxd7uX6xy2XMPeaT3oeXp5HE+52U2rhIJuxOUXQ4doyPTEJCB06 o8DtPO+YlLGBme7MUG8AqmRJCPaXgv4xxqsWn9jT5yOCSVZml0fkkdhhAW3sSkFwohIp 6GyiUHZqpDC9IJWa3CuOcb1ep0NItcngIPP/0lB03jS7d9K4PFbnT49FEHN/+fQKfms+ /9n7xxsa4fxFmQrS7oU+SyLmb7JW5RiyK71TbF0sPON0TJMDYENzjLNuTxYkvXPbFaUs rddmJD3tziQDA/jCNbllfqHF1o4nmU8qs2ILClCa2clslq34Xo9Sg5aUHKgqe8K964pD 3zXA== 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:dkim-filter; bh=d6NNJ+nW6fZ2WWBYBA5DCiVLw0ZFlnZQJAM4KipXE4A=; b=AXPbfcF026woM9NHeBdzCOl/nS0xT7wB2epfdmu33kU2jXQ2xITqZvWnWT0iohuZ7d 4W7Q8QSL6+fzYxYAreN0W5KI1Zyi3H0ykyXGux0Y9pKOdvkXMcxjmIsU107DQLcMzprU KUzMKcBROIGm3qfGURLQ/iT1Ah/I4vuui9V7JMisWdkjxkiKK6RQq1oXiottoudmNyAX FQVva8mD5VkwZJJBOmqE2vQsUYRYcLWgf8JHQHfj6pSalIIKCwCJMe13i1kuCyBHtIxl JGKQtX67ChEVQhG3FECrBdB1n05Lro5VviQUoNhmWzpx7uA0cVTbBbsi+JT2Z74H6dIG dUvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=jPARB7HA; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qb27-20020a1709077e9b00b0072f9b440ffbsi16445062ejc.225.2022.07.26.02.38.48; Tue, 26 Jul 2022 02:39:13 -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=@nifty.com header.s=dec2015msa header.b=jPARB7HA; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237886AbiGZJ1V (ORCPT + 99 others); Tue, 26 Jul 2022 05:27:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229749AbiGZJ1U (ORCPT ); Tue, 26 Jul 2022 05:27:20 -0400 Received: from conssluserg-02.nifty.com (conssluserg-02.nifty.com [210.131.2.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 117D02E9F6; Tue, 26 Jul 2022 02:27:18 -0700 (PDT) Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (authenticated) by conssluserg-02.nifty.com with ESMTP id 26Q9QrdN024374; Tue, 26 Jul 2022 18:26:53 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-02.nifty.com 26Q9QrdN024374 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1658827614; bh=d6NNJ+nW6fZ2WWBYBA5DCiVLw0ZFlnZQJAM4KipXE4A=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=jPARB7HAapfEkUCDpves2bids8NaztvHxYcrpmaz30aXBKKCq5Fls6fPm6JMl4NEB A+CXQn86ICJNahuYe+wJUVp4X42qyknJGMTFem8Fg39gyqprHgP6bGqygnGJySLLpY Fi0TJ4n8AGHy1QHghgmYAb6tG67BBglbtafIao4SUkicjwCuxWlMCf234yupSWwONe QXTA/NB4xuFdazVACjtFGA/3J6GXfrlFE7KiQy3L10fGJswdIINwUuYL80GwdwbA/X 1oaSD81CRh1UXkmTAspo/hdqn56A4uPd0xGP0lEi/wZspTN5MpNFXg4n7sMAhQFY4U xr5ezJ4ImSfvQ== X-Nifty-SrcIP: [209.85.128.41] Received: by mail-wm1-f41.google.com with SMTP id w8-20020a05600c014800b003a32e89bc4eso7783829wmm.5; Tue, 26 Jul 2022 02:26:53 -0700 (PDT) X-Gm-Message-State: AJIora/2pKak2LpGwKZTl3vd0m6XP8zASBoBMlLp0+mjXsh8PgPb+uHl x6DEomJxckWccPXLwh36ZnUSnHhXNk2KwJ6TOHg= X-Received: by 2002:a05:600c:35ce:b0:3a3:1b7f:bbd8 with SMTP id r14-20020a05600c35ce00b003a31b7fbbd8mr11063089wmq.22.1658827612274; Tue, 26 Jul 2022 02:26:52 -0700 (PDT) MIME-Version: 1.0 References: <20220722022416.137548-1-mfo@canonical.com> <20220722022416.137548-4-mfo@canonical.com> In-Reply-To: <20220722022416.137548-4-mfo@canonical.com> From: Masahiro Yamada Date: Tue, 26 Jul 2022 18:25:51 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH 3/6] sysctl, mod_devicetable: shadow struct ctl_table.procname for file2alias To: Mauricio Faria de Oliveira 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=-1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no 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 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. > 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. > #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