FAILED: patch "[PATCH] nilfs2: protect references to superblock parameters exposed" failed to apply to 5.10-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x 683408258917541bdb294cd717c210a04381931e
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2024090805-deck-despise-e91c@gregkh' --subject-prefix 'PATCH 5.10.y' HEAD^..
Possible dependencies:
683408258917 ("nilfs2: protect references to superblock parameters exposed in sysfs") 3bcd6c5bd483 ("nilfs2: replace snprintf in show functions with sysfs_emit")
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 683408258917541bdb294cd717c210a04381931e Mon Sep 17 00:00:00 2001
From: Ryusuke Konishi <[email protected]>
Date: Sun, 11 Aug 2024 19:03:20 +0900
Subject: [PATCH] nilfs2: protect references to superblock parameters exposed
in sysfs
The superblock buffers of nilfs2 can not only be overwritten at runtime for modifications/repairs, but they are also regularly swapped, replaced during resizing, and even abandoned when degrading to one side due to backing device issues. So, accessing them requires mutual exclusion using the reader/writer semaphore "nilfs->ns_sem".
Some sysfs attribute show methods read this superblock buffer without the necessary mutual exclusion, which can cause problems with pointer dereferencing and memory access, so fix it.
fs/nilfs2/sysfs.c +33 -10
@@ -836,9 +836,15 @@ ssize_t nilfs_dev_revision_show(struct nilfs_dev_attr *attr,struct the_nilfs *nilfs, char *buf) { - struct nilfs_super_block **sbp = nilfs->ns_sbp; -u32 major =le32_to_cpu (sbp[0 ]->s_rev_level); -u16 minor =le16_to_cpu (sbp[0 ]->s_minor_rev_level); + struct nilfs_super_block *raw_sb; +u32 major; +u16 minor; + +down_read (&nilfs->ns_sem); + raw_sb = nilfs->ns_sbp[0 ]; + major =le32_to_cpu (raw_sb->s_rev_level); + minor =le16_to_cpu (raw_sb->s_minor_rev_level); +up_read (&nilfs->ns_sem);return sysfs_emit (buf,"%d.%d\n" , major, minor); }
@@ -856,8 +862,13 @@ ssize_t nilfs_dev_device_size_show(struct nilfs_dev_attr *attr,struct the_nilfs *nilfs, char *buf) { - struct nilfs_super_block **sbp = nilfs->ns_sbp; -u64 dev_size =le64_to_cpu (sbp[0 ]->s_dev_size); + struct nilfs_super_block *raw_sb; +u64 dev_size; + +down_read (&nilfs->ns_sem); + raw_sb = nilfs->ns_sbp[0 ]; + dev_size =le64_to_cpu (raw_sb->s_dev_size); +up_read (&nilfs->ns_sem);return sysfs_emit (buf,"%llu\n" , dev_size); }
@@ -879,9 +890,15 @@ ssize_t nilfs_dev_uuid_show(struct nilfs_dev_attr *attr,struct the_nilfs *nilfs, char *buf) { - struct nilfs_super_block **sbp = nilfs->ns_sbp; + struct nilfs_super_block *raw_sb; +ssize_t len; -return sysfs_emit (buf,"%pUb\n" , sbp[0 ]->s_uuid); +down_read (&nilfs->ns_sem); + raw_sb = nilfs->ns_sbp[0 ]; + len =sysfs_emit (buf,"%pUb\n" , raw_sb->s_uuid); +up_read (&nilfs->ns_sem); + +return len; } static
@@ -889,10 +906,16 @@ ssize_t nilfs_dev_volume_name_show(struct nilfs_dev_attr *attr,struct the_nilfs *nilfs, char *buf) { - struct nilfs_super_block **sbp = nilfs->ns_sbp; + struct nilfs_super_block *raw_sb; +ssize_t len; -return scnprintf (buf,sizeof (sbp[0 ]->s_volume_name),"%s\n" , - sbp[0 ]->s_volume_name); +down_read (&nilfs->ns_sem); + raw_sb = nilfs->ns_sbp[0 ]; + len =scnprintf (buf,sizeof (raw_sb->s_volume_name),"%s\n" , + raw_sb->s_volume_name); +up_read (&nilfs->ns_sem); + +return len; } static const char dev_readme_str[] =