Message ID | 20230214-kobj_type-bcache-v1-1-cf00ead7bee7@weissschuh.net |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2730980wrn; Mon, 13 Feb 2023 19:17:07 -0800 (PST) X-Google-Smtp-Source: AK7set9rm5SNGk8XyXx/YmITNb4mC9azYeO5Hbc6CfOLmOLMG7DTenFOrF3bZx2Cq7qaElK7BoNo X-Received: by 2002:a17:906:839a:b0:860:5723:a5e5 with SMTP id p26-20020a170906839a00b008605723a5e5mr1225436ejx.69.1676344627048; Mon, 13 Feb 2023 19:17:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676344627; cv=none; d=google.com; s=arc-20160816; b=UzkEGSFomN7A2FNieqq/4Q9qGhRXhvX4dx8X8iRN39sXScV5EqauZCnmLzrX/h4eJk Qeh3AKVWqE8CMDkr1WMU8N43m5JA39VJD0YDM3t6M5a8vcehWesodj/uc2GMH5Rui1Dn 4UrqoB/Z4LhHoVdirH5bHM3AFDn4XHjV5b/jf8g0jJkx2Yo5hNDm8AEA5fUUADmwXGvi Dwop6Khirzp55jsXpuD7/xYlWCBpK9Tf87VqXhRoynWMKCPe2H3q4hCkxuhVX9DBGtLw VvO552CfFDINRaecdZd5LaFKb9salZsq09Kjnd753gVESCWmP2ydxzDXEYl9k5uxItBF P4Sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:dkim-signature:from; bh=K00E+suf6cpB9NrrLD1tV7jRYs3IGTvxsLrpdlJVmWs=; b=oDDSTp+Dv4/oxOQ8ICipyZF5tGtV+7wbdryYsuxGIa/uRM0P5BDheR+PwuTnl31Rjx xDxpHtrxLrUjWjvEgMlrXe84TfKMpVc/B+F2XBRW2fWSuOxY89D+UZaFDBBM7qvmT5yv 908ISJ7+cdK+DSr9iP2D6Na8Sony++iS5CLFOY6hPeSFFBY7m8ef7iAwNIM9WY406hn3 9NjU/1TGTC8ac77M05q+ZFLr+vFFovFflZiE+tb0Q7miXlCCtH2lq2Lc4NuwiDX+evfs hm+AY1ADFB5SaS43P7cREPsZAs52uitSSj64zrN0GP66Qln8vSTwD/k2gb4+y3BLv8Vc 7Qtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@weissschuh.net header.s=mail header.b=fHiwu9Nk; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fb10-20020a1709073a0a00b008777140c600si14770424ejc.906.2023.02.13.19.16.42; Mon, 13 Feb 2023 19:17:07 -0800 (PST) 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=fail header.i=@weissschuh.net header.s=mail header.b=fHiwu9Nk; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230517AbjBNDOm (ORCPT <rfc822;tebrre53rla2o@gmail.com> + 99 others); Mon, 13 Feb 2023 22:14:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230446AbjBNDOl (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 13 Feb 2023 22:14:41 -0500 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E3501C582; Mon, 13 Feb 2023 19:14:11 -0800 (PST) From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= <linux@weissschuh.net> DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=weissschuh.net; s=mail; t=1676344425; bh=lUBQv/gxbu9SY9YrTLi2niEa4rAG6aaQal1onFRL2K0=; h=From:Date:Subject:To:Cc:From; b=fHiwu9Nkh1OA406ptS5CCA4B5NxL5QMbqTHkDFViGUH9shajemAjgLr5I8pvuwXdi oEKuRcCGxH/wfzhrU0xg2Ph9BL7jZUGnrdnUU6q4m3rT3KGtqd2n7udJOQYCH4b+OG /lC6duSKqXg8SU9J1+bEuMqon4XRUBgFCIjDoIbc= Date: Tue, 14 Feb 2023 03:13:39 +0000 Subject: [PATCH] bcache: make kobj_type structures constant MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20230214-kobj_type-bcache-v1-1-cf00ead7bee7@weissschuh.net> X-B4-Tracking: v=1; b=H4sIAGL86mMC/x2N0QrCMAxFf2Xk2UIbh6C/IiJJm9no6EY7xTH27 wYfz7kc7gZNqkqDS7dBlY82nYpBOHQQM5WHOE3GgB6PHkPvXhM/78s6i+NIMYs7JeQU8Mx+ILC MqdlWqcRsYXmPo8m5yqDf/8/1tu8/HKS1BXcAAAA= To: Coly Li <colyli@suse.de>, Kent Overstreet <kent.overstreet@gmail.com> Cc: linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Th?= =?utf-8?q?omas_Wei=C3=9Fschuh?= <linux@weissschuh.net> X-Mailer: b4 0.12.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1676344423; l=2027; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=lUBQv/gxbu9SY9YrTLi2niEa4rAG6aaQal1onFRL2K0=; b=TlvCX16r4S6MNFq0EVBI7VxgI64XDdViGztU1MHvVmy1roWeuLrCuLGERPS8MaF51wIKVWMIq 5OeMD9RebRSCWX575Rs360ss1izfQdHDKDQ84ZnJSJPB3jv3i0pXxtf X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757774743681021633?= X-GMAIL-MSGID: =?utf-8?q?1757774743681021633?= |
Series |
bcache: make kobj_type structures constant
|
|
Commit Message
Thomas Weißschuh
Feb. 14, 2023, 3:13 a.m. UTC
Since commit ee6d3dd4ed48 ("driver core: make kobj_type constant.")
the driver core allows the usage of const struct kobj_type.
Take advantage of this to constify the structure definitions to prevent
modification at runtime.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
drivers/md/bcache/bcache.h | 10 +++++-----
drivers/md/bcache/sysfs.h | 2 +-
2 files changed, 6 insertions(+), 6 deletions(-)
---
base-commit: f6feea56f66d34259c4222fa02e8171c4f2673d1
change-id: 20230214-kobj_type-bcache-6d2bd129b0fa
Best regards,
Comments
> 2023年2月14日 11:13,Thomas Weißschuh <linux@weissschuh.net> 写道: > > Since commit ee6d3dd4ed48 ("driver core: make kobj_type constant.") > the driver core allows the usage of const struct kobj_type. > > Take advantage of this to constify the structure definitions to prevent > modification at runtime. > How the const structure definition can prevent modification at run time? Thanks. Coly Li > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> > --- > drivers/md/bcache/bcache.h | 10 +++++----- > drivers/md/bcache/sysfs.h | 2 +- > 2 files changed, 6 insertions(+), 6 deletions(-) > > diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h > index aebb7ef10e63..a522f4f1f992 100644 > --- a/drivers/md/bcache/bcache.h > +++ b/drivers/md/bcache/bcache.h > @@ -1004,11 +1004,11 @@ extern struct workqueue_struct *bch_flush_wq; > extern struct mutex bch_register_lock; > extern struct list_head bch_cache_sets; > > -extern struct kobj_type bch_cached_dev_ktype; > -extern struct kobj_type bch_flash_dev_ktype; > -extern struct kobj_type bch_cache_set_ktype; > -extern struct kobj_type bch_cache_set_internal_ktype; > -extern struct kobj_type bch_cache_ktype; > +extern const struct kobj_type bch_cached_dev_ktype; > +extern const struct kobj_type bch_flash_dev_ktype; > +extern const struct kobj_type bch_cache_set_ktype; > +extern const struct kobj_type bch_cache_set_internal_ktype; > +extern const struct kobj_type bch_cache_ktype; > > void bch_cached_dev_release(struct kobject *kobj); > void bch_flash_dev_release(struct kobject *kobj); > diff --git a/drivers/md/bcache/sysfs.h b/drivers/md/bcache/sysfs.h > index a2ff6447b699..65b8bd975ab1 100644 > --- a/drivers/md/bcache/sysfs.h > +++ b/drivers/md/bcache/sysfs.h > @@ -3,7 +3,7 @@ > #define _BCACHE_SYSFS_H_ > > #define KTYPE(type) \ > -struct kobj_type type ## _ktype = { \ > +const struct kobj_type type ## _ktype = { \ > .release = type ## _release, \ > .sysfs_ops = &((const struct sysfs_ops) { \ > .show = type ## _show, \ > > --- > base-commit: f6feea56f66d34259c4222fa02e8171c4f2673d1 > change-id: 20230214-kobj_type-bcache-6d2bd129b0fa > > Best regards, > -- > Thomas Weißschuh <linux@weissschuh.net> >
On Tue, Feb 14, 2023 at 05:51:09PM +0800, Coly Li wrote: > > > > 2023年2月14日 11:13,Thomas Weißschuh <linux@weissschuh.net> 写道: > > > > Since commit ee6d3dd4ed48 ("driver core: make kobj_type constant.") > > the driver core allows the usage of const struct kobj_type. > > > > Take advantage of this to constify the structure definitions to prevent > > modification at runtime. > > > > How the const structure definition can prevent modification at run time? It will be put into .rodata instead of .data by the compiler. The .rodata section is mapped as read-only via the pagetable. See Documentation/security/self-protection.rst "Function pointers and sensitive variables must not be writable". Thomas > Thanks. > > Coly Li > > > > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> > > --- > > drivers/md/bcache/bcache.h | 10 +++++----- > > drivers/md/bcache/sysfs.h | 2 +- > > 2 files changed, 6 insertions(+), 6 deletions(-) > > > > diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h > > index aebb7ef10e63..a522f4f1f992 100644 > > --- a/drivers/md/bcache/bcache.h > > +++ b/drivers/md/bcache/bcache.h > > @@ -1004,11 +1004,11 @@ extern struct workqueue_struct *bch_flush_wq; > > extern struct mutex bch_register_lock; > > extern struct list_head bch_cache_sets; > > > > -extern struct kobj_type bch_cached_dev_ktype; > > -extern struct kobj_type bch_flash_dev_ktype; > > -extern struct kobj_type bch_cache_set_ktype; > > -extern struct kobj_type bch_cache_set_internal_ktype; > > -extern struct kobj_type bch_cache_ktype; > > +extern const struct kobj_type bch_cached_dev_ktype; > > +extern const struct kobj_type bch_flash_dev_ktype; > > +extern const struct kobj_type bch_cache_set_ktype; > > +extern const struct kobj_type bch_cache_set_internal_ktype; > > +extern const struct kobj_type bch_cache_ktype; > > > > void bch_cached_dev_release(struct kobject *kobj); > > void bch_flash_dev_release(struct kobject *kobj); > > diff --git a/drivers/md/bcache/sysfs.h b/drivers/md/bcache/sysfs.h > > index a2ff6447b699..65b8bd975ab1 100644 > > --- a/drivers/md/bcache/sysfs.h > > +++ b/drivers/md/bcache/sysfs.h > > @@ -3,7 +3,7 @@ > > #define _BCACHE_SYSFS_H_ > > > > #define KTYPE(type) \ > > -struct kobj_type type ## _ktype = { \ > > +const struct kobj_type type ## _ktype = { \ > > .release = type ## _release, \ > > .sysfs_ops = &((const struct sysfs_ops) { \ > > .show = type ## _show, \ > > > > --- > > base-commit: f6feea56f66d34259c4222fa02e8171c4f2673d1 > > change-id: 20230214-kobj_type-bcache-6d2bd129b0fa > > > > Best regards, > > -- > > Thomas Weißschuh <linux@weissschuh.net> > > >
> 2023年2月14日 23:21,Thomas Weißschuh <linux@weissschuh.net> 写道: > > On Tue, Feb 14, 2023 at 05:51:09PM +0800, Coly Li wrote: >> >> >>> 2023年2月14日 11:13,Thomas Weißschuh <linux@weissschuh.net> 写道: >>> >>> Since commit ee6d3dd4ed48 ("driver core: make kobj_type constant.") >>> the driver core allows the usage of const struct kobj_type. >>> >>> Take advantage of this to constify the structure definitions to prevent >>> modification at runtime. >>> >> >> How the const structure definition can prevent modification at run time? > > It will be put into .rodata instead of .data by the compiler. > The .rodata section is mapped as read-only via the pagetable. > > See Documentation/security/self-protection.rst > "Function pointers and sensitive variables must not be writable". I see. Thanks for the information. This patch will be added into my testing queue, and submitted later. Coly Li
Hi Coly, On 2023-02-15 00:16:03+0800, Coly Li wrote: > > 2023年2月14日 23:21,Thomas Weißschuh <linux@weissschuh.net> 写道: > > > > On Tue, Feb 14, 2023 at 05:51:09PM +0800, Coly Li wrote: > >> > >> > >>> 2023年2月14日 11:13,Thomas Weißschuh <linux@weissschuh.net> 写道: > >>> > >>> Since commit ee6d3dd4ed48 ("driver core: make kobj_type constant.") > >>> the driver core allows the usage of const struct kobj_type. > >>> > >>> Take advantage of this to constify the structure definitions to prevent > >>> modification at runtime. > >>> > >> > >> How the const structure definition can prevent modification at run time? > > > > It will be put into .rodata instead of .data by the compiler. > > The .rodata section is mapped as read-only via the pagetable. > > > > See Documentation/security/self-protection.rst > > "Function pointers and sensitive variables must not be writable". > > I see. Thanks for the information. > > This patch will be added into my testing queue, and submitted later. It seems this was not submitted. Or did I miss it? Thanks, Thomas
> 2023年4月5日 01:38,Thomas Weißschuh <linux@weissschuh.net> 写道: > > Hi Coly, > > On 2023-02-15 00:16:03+0800, Coly Li wrote: >>> 2023年2月14日 23:21,Thomas Weißschuh <linux@weissschuh.net> 写道: >>> >>> On Tue, Feb 14, 2023 at 05:51:09PM +0800, Coly Li wrote: >>>> >>>> >>>>> 2023年2月14日 11:13,Thomas Weißschuh <linux@weissschuh.net> 写道: >>>>> >>>>> Since commit ee6d3dd4ed48 ("driver core: make kobj_type constant.") >>>>> the driver core allows the usage of const struct kobj_type. >>>>> >>>>> Take advantage of this to constify the structure definitions to prevent >>>>> modification at runtime. >>>>> >>>> >>>> How the const structure definition can prevent modification at run time? >>> >>> It will be put into .rodata instead of .data by the compiler. >>> The .rodata section is mapped as read-only via the pagetable. >>> >>> See Documentation/security/self-protection.rst >>> "Function pointers and sensitive variables must not be writable". >> >> I see. Thanks for the information. >> >> This patch will be added into my testing queue, and submitted later. > > It seems this was not submitted. > Or did I miss it? No I don’t submit it yet. It is not emergent fix, and stay with other testing patches together. Do you want it to go now? Coly Li
Hi Coly, On 2023-04-05 21:38:01+0800, Coly Li wrote: > > 2023年4月5日 01:38,Thomas Weißschuh <linux@weissschuh.net> 写道: > > > > Hi Coly, > > > > On 2023-02-15 00:16:03+0800, Coly Li wrote: > >>> 2023年2月14日 23:21,Thomas Weißschuh <linux@weissschuh.net> 写道: > >>> > >>> On Tue, Feb 14, 2023 at 05:51:09PM +0800, Coly Li wrote: > >>>> > >>>> > >>>>> 2023年2月14日 11:13,Thomas Weißschuh <linux@weissschuh.net> 写道: > >>>>> > >>>>> Since commit ee6d3dd4ed48 ("driver core: make kobj_type constant.") > >>>>> the driver core allows the usage of const struct kobj_type. > >>>>> > >>>>> Take advantage of this to constify the structure definitions to prevent > >>>>> modification at runtime. > >>>>> > >>>> > >>>> How the const structure definition can prevent modification at run time? > >>> > >>> It will be put into .rodata instead of .data by the compiler. > >>> The .rodata section is mapped as read-only via the pagetable. > >>> > >>> See Documentation/security/self-protection.rst > >>> "Function pointers and sensitive variables must not be writable". > >> > >> I see. Thanks for the information. > >> > >> This patch will be added into my testing queue, and submitted later. > > > > It seems this was not submitted. > > Or did I miss it? > > No I don’t submit it yet. It is not emergent fix, and stay with other testing patches together. > > Do you want it to go now? No, it's not urgent. I just assumed it should have been in next by now and thought it got lost along the way. Let's keep it with the other testing patches. Thanks and sorry for bothering you, Thomas
> 2023年4月15日 02:38,Thomas Weißschuh <linux@weissschuh.net> 写道: > > Hi Coly, > > On 2023-04-05 21:38:01+0800, Coly Li wrote: >>> 2023年4月5日 01:38,Thomas Weißschuh <linux@weissschuh.net> 写道: >>> >>> Hi Coly, >>> >>> On 2023-02-15 00:16:03+0800, Coly Li wrote: >>>>> 2023年2月14日 23:21,Thomas Weißschuh <linux@weissschuh.net> 写道: >>>>> >>>>> On Tue, Feb 14, 2023 at 05:51:09PM +0800, Coly Li wrote: >>>>>> >>>>>> >>>>>>> 2023年2月14日 11:13,Thomas Weißschuh <linux@weissschuh.net> 写道: >>>>>>> >>>>>>> Since commit ee6d3dd4ed48 ("driver core: make kobj_type constant.") >>>>>>> the driver core allows the usage of const struct kobj_type. >>>>>>> >>>>>>> Take advantage of this to constify the structure definitions to prevent >>>>>>> modification at runtime. >>>>>>> >>>>>> >>>>>> How the const structure definition can prevent modification at run time? >>>>> >>>>> It will be put into .rodata instead of .data by the compiler. >>>>> The .rodata section is mapped as read-only via the pagetable. >>>>> >>>>> See Documentation/security/self-protection.rst >>>>> "Function pointers and sensitive variables must not be writable". >>>> >>>> I see. Thanks for the information. >>>> >>>> This patch will be added into my testing queue, and submitted later. >>> >>> It seems this was not submitted. >>> Or did I miss it? >> >> No I don’t submit it yet. It is not emergent fix, and stay with other testing patches together. >> >> Do you want it to go now? > > No, it's not urgent. > > I just assumed it should have been in next by now and thought it got > lost along the way. > Let's keep it with the other testing patches. Some patches from Zheming are not simple, and I need to find time to go through them carefully. If I am not able to handle them in time, I will submit the simple ones to Jens some time later. Thanks. Coly Li
diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h index aebb7ef10e63..a522f4f1f992 100644 --- a/drivers/md/bcache/bcache.h +++ b/drivers/md/bcache/bcache.h @@ -1004,11 +1004,11 @@ extern struct workqueue_struct *bch_flush_wq; extern struct mutex bch_register_lock; extern struct list_head bch_cache_sets; -extern struct kobj_type bch_cached_dev_ktype; -extern struct kobj_type bch_flash_dev_ktype; -extern struct kobj_type bch_cache_set_ktype; -extern struct kobj_type bch_cache_set_internal_ktype; -extern struct kobj_type bch_cache_ktype; +extern const struct kobj_type bch_cached_dev_ktype; +extern const struct kobj_type bch_flash_dev_ktype; +extern const struct kobj_type bch_cache_set_ktype; +extern const struct kobj_type bch_cache_set_internal_ktype; +extern const struct kobj_type bch_cache_ktype; void bch_cached_dev_release(struct kobject *kobj); void bch_flash_dev_release(struct kobject *kobj); diff --git a/drivers/md/bcache/sysfs.h b/drivers/md/bcache/sysfs.h index a2ff6447b699..65b8bd975ab1 100644 --- a/drivers/md/bcache/sysfs.h +++ b/drivers/md/bcache/sysfs.h @@ -3,7 +3,7 @@ #define _BCACHE_SYSFS_H_ #define KTYPE(type) \ -struct kobj_type type ## _ktype = { \ +const struct kobj_type type ## _ktype = { \ .release = type ## _release, \ .sysfs_ops = &((const struct sysfs_ops) { \ .show = type ## _show, \