mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] rnull: serialize configfs updates with power changes
@ 2026-10-19  9:58 ` Jiale Yao
  2026-10-20 15:03   ` Andreas Hindborg
  0 siblings, 1 reply; 2+ messages in thread
From: Jiale Yao @ 2026-10-19  9:58 UTC (permalink / raw)
  To: Andreas Hindborg, Boqun Feng, Jens Axboe, Daniel Almeida,
	Alice Ryhl, linux-block, rust-for-linux, linux-kernel
  Cc: Jiale Yao, Jiale Yao

From: Jiale Yao <jiale.yao@example.com>

The configuration stores check whether the device is powered before
parsing the new value, then take the mutex again to update the field.
A concurrent power-on can complete between these lock acquisitions,
allowing a live device configuration to be changed.

Parse the input before taking the mutex, then check powered and update
the configuration while holding the same lock.

Fixes: d969d504bc13 ("rnull: enable configuration via `configfs`")
Signed-off-by: Jiale Yao <yaojiale02@163.com>
---
 drivers/block/rnull/configfs.rs | 42 ++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 17 deletions(-)

diff --git a/drivers/block/rnull/configfs.rs b/drivers/block/rnull/configfs.rs
index 32c10c3f4d0f..1808fcacfd55 100644
--- a/drivers/block/rnull/configfs.rs
+++ b/drivers/block/rnull/configfs.rs
@@ -174,15 +174,17 @@ impl configfs::AttributeOperations<1> for DeviceConfig {
     }
 
     fn store(this: &DeviceConfig, page: &[u8]) -> Result {
-        if this.data.lock().powered {
-            return Err(EBUSY);
-        }
-
         let text = core::str::from_utf8(page)?.trim();
         let value = text.parse::<u32>().map_err(|_| EINVAL)?;
 
         GenDiskBuilder::validate_block_size(value)?;
-        this.data.lock().block_size = value;
+        let mut guard = this.data.lock();
+
+        if guard.powered {
+            return Err(EBUSY);
+        }
+
+        guard.block_size = value;
         Ok(())
     }
 }
@@ -204,11 +206,14 @@ impl configfs::AttributeOperations<2> for DeviceConfig {
     }
 
     fn store(this: &DeviceConfig, page: &[u8]) -> Result {
-        if this.data.lock().powered {
+        let value = kstrtobool_bytes(page)?;
+        let mut guard = this.data.lock();
+
+        if guard.powered {
             return Err(EBUSY);
         }
 
-        this.data.lock().rotational = kstrtobool_bytes(page)?;
+        guard.rotational = value;
 
         Ok(())
     }
@@ -225,14 +230,15 @@ impl configfs::AttributeOperations<3> for DeviceConfig {
     }
 
     fn store(this: &DeviceConfig, page: &[u8]) -> Result {
-        if this.data.lock().powered {
-            return Err(EBUSY);
-        }
-
         let text = core::str::from_utf8(page)?.trim();
         let value = text.parse::<u64>().map_err(|_| EINVAL)?;
+        let mut guard = this.data.lock();
 
-        this.data.lock().capacity_mib = value;
+        if guard.powered {
+            return Err(EBUSY);
+        }
+
+        guard.capacity_mib = value;
         Ok(())
     }
 }
@@ -248,14 +254,16 @@ impl configfs::AttributeOperations<4> for DeviceConfig {
     }
 
     fn store(this: &DeviceConfig, page: &[u8]) -> Result {
-        if this.data.lock().powered {
-            return Err(EBUSY);
-        }
-
         let text = core::str::from_utf8(page)?.trim();
         let value = text.parse::<u8>().map_err(|_| EINVAL)?;
+        let value = IRQMode::try_from(value)?;
+        let mut guard = this.data.lock();
+
+        if guard.powered {
+            return Err(EBUSY);
+        }
 
-        this.data.lock().irq_mode = IRQMode::try_from(value)?;
+        guard.irq_mode = value;
         Ok(())
     }
 }
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] rnull: serialize configfs updates with power changes
  2026-10-19  9:58 ` [PATCH] rnull: serialize configfs updates with power changes Jiale Yao
@ 2026-10-20 15:03   ` Andreas Hindborg
  0 siblings, 0 replies; 2+ messages in thread
From: Andreas Hindborg @ 2026-10-20 15:03 UTC (permalink / raw)
  To: Jiale Yao, Boqun Feng, Jens Axboe, Daniel Almeida, Alice Ryhl,
	linux-block, rust-for-linux, linux-kernel
  Cc: Jiale Yao, Jiale Yao

"Jiale Yao" <yaojiale02@163.com> writes:

> From: Jiale Yao <jiale.yao@example.com>
>
> The configuration stores check whether the device is powered before
> parsing the new value, then take the mutex again to update the field.
> A concurrent power-on can complete between these lock acquisitions,
> allowing a live device configuration to be changed.
>
> Parse the input before taking the mutex, then check powered and update
> the configuration while holding the same lock.
>
> Fixes: d969d504bc13 ("rnull: enable configuration via `configfs`")
> Signed-off-by: Jiale Yao <yaojiale02@163.com>

I think all of these were fixed last cycle [1].

Best regards,
Andreas Hindborg


[1] https://lore.kernel.org/all/20260908200845.405112-1-qingxiao@tamu.edu/



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-20 15:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <uGK5kP3Fr_s7fJcoFfMqR0HjR2qR0Eb1RCi3tOPqNOsRa1xuQPbjmLt2WXfcTWXV9pO0_tKKFz8ciXC_W8ObyQ==@protonmail.internalid>
2026-10-19  9:58 ` [PATCH] rnull: serialize configfs updates with power changes Jiale Yao
2026-10-20 15:03   ` Andreas Hindborg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®