linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: "André Almeida" <andrealmeid@igalia.com>
Cc: Hugh Dickins <hughd@google.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
	krisman@kernel.org, Stephen Rothwell <sfr@canb.auug.org.au>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, kernel-dev@igalia.com,
	Theodore Ts'o <tytso@mit.edu>
Subject: Re: [PATCH 2/3] tmpfs: Fix type for sysfs' casefold attribute
Date: Fri, 1 Nov 2024 00:12:08 -0700	[thread overview]
Message-ID: <20241101071208.GA2962282@thelio-3990X> (raw)
In-Reply-To: <20241101013741.295792-3-andrealmeid@igalia.com>

On Thu, Oct 31, 2024 at 10:37:40PM -0300, André Almeida wrote:
> DEVICE_STRING_ATTR_RO should be only used by device drivers since it
> relies on `struct device` to use device_show_string() function. Using
> this with non device code led to a kCFI violation:
> 
> > cat /sys/fs/tmpfs/features/casefold
> [   70.558496] CFI failure at kobj_attr_show+0x2c/0x4c (target: device_show_string+0x0/0x38; expected type: 0xc527b809)
> 
> Like the other filesystems, fix this by manually declaring the attribute
> using kobj_attribute() and writing a proper show() function.
> 
> Also, leave macros for anyone that need to expand tmpfs sysfs' with
> more attributes (as seen in fs/btrfs/sysfs.c).
> 
> Fixes: 5132f08bd332 ("tmpfs: Expose filesystem features via sysfs")
> Reported-by: Nathan Chancellor <nathan@kernel.org>
> Closes: https://lore.kernel.org/lkml/20241031051822.GA2947788@thelio-3990X/
> Signed-off-by: André Almeida <andrealmeid@igalia.com>

Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>

> ---
>  mm/shmem.c | 29 +++++++++++++++++++++++++++--
>  1 file changed, 27 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/shmem.c b/mm/shmem.c
> index b86f526a1cb1..6038e1d11987 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -5548,13 +5548,38 @@ struct page *shmem_read_mapping_page_gfp(struct address_space *mapping,
>  EXPORT_SYMBOL_GPL(shmem_read_mapping_page_gfp);
>  
>  #if defined(CONFIG_SYSFS) && defined(CONFIG_TMPFS)
> +
> +#define __INIT_KOBJ_ATTR(_name, _mode, _show, _store)			\
> +{									\
> +	.attr	= { .name = __stringify(_name), .mode = _mode },	\
> +	.show	= _show,						\
> +	.store	= _store,						\
> +}
> +
> +#define TMPFS_ATTR_W(_name, _store)				\
> +	static struct kobj_attribute tmpfs_attr_##_name =	\
> +			__INIT_KOBJ_ATTR(_name, 0200, NULL, _store)
> +
> +#define TMPFS_ATTR_RW(_name, _show, _store)			\
> +	static struct kobj_attribute tmpfs_attr_##_name =	\
> +			__INIT_KOBJ_ATTR(_name, 0644, _show, _store)
> +
> +#define TMPFS_ATTR_RO(_name, _show)				\
> +	static struct kobj_attribute tmpfs_attr_##_name =	\
> +			__INIT_KOBJ_ATTR(_name, 0444, _show, NULL)
> +
>  #if IS_ENABLED(CONFIG_UNICODE)
> -static DEVICE_STRING_ATTR_RO(casefold, 0444, "supported");
> +static ssize_t casefold_show(struct kobject *kobj, struct kobj_attribute *a,
> +			char *buf)
> +{
> +		return sysfs_emit(buf, "supported\n");

Small nit, I think this might be overindented?

> +}
> +TMPFS_ATTR_RO(casefold, casefold_show);
>  #endif
>  
>  static struct attribute *tmpfs_attributes[] = {
>  #if IS_ENABLED(CONFIG_UNICODE)
> -	&dev_attr_casefold.attr.attr,
> +	&tmpfs_attr_casefold.attr,
>  #endif
>  	NULL
>  };
> -- 
> 2.47.0
> 


  reply	other threads:[~2024-11-01  7:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-01  1:37 [PATCH 0/3] tmpfs: Casefold fixes André Almeida
2024-11-01  1:37 ` [PATCH 1/3] libfs: Fix kernel-doc warning in generic_ci_validate_strict_name André Almeida
2024-11-01  1:37 ` [PATCH 2/3] tmpfs: Fix type for sysfs' casefold attribute André Almeida
2024-11-01  7:12   ` Nathan Chancellor [this message]
2024-11-01  1:37 ` [PATCH 3/3] tmpfs: Initialize sysfs during tmpfs init André Almeida
2024-11-01  7:19   ` Nathan Chancellor
2024-11-01 16:23     ` André Almeida

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=20241101071208.GA2962282@thelio-3990X \
    --to=nathan@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=andrealmeid@igalia.com \
    --cc=brauner@kernel.org \
    --cc=hughd@google.com \
    --cc=jack@suse.cz \
    --cc=kernel-dev@igalia.com \
    --cc=krisman@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=sfr@canb.auug.org.au \
    --cc=tytso@mit.edu \
    --cc=viro@zeniv.linux.org.uk \
    /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