nvme: make sending wall-clock time to NVMe opt-in
PATCH 1/1 nvme: make sending wall-clock time to NVMe opt-in
Some NVMe devices maintain a persistent log, the PEL, of events like power-on and thermal excursions. The NVMe Set Features (Timestamp) command allows an operating system to inform the NVMe of the current wall-clock time. Wall-clock timestamp updates are logged to the PEL alongside other events. By correlating PEL records, an attacker can infer a user's usage patterns and even guess at time zone changes.
This change adds a per-controller NVMe flag accessible via sysfs that controls whether we send the device the time. The flag is always present and does nothing if the Timestamp feature is not supported. We update the NVMe device's wall-clock time during controller initialization (if the flag is enabled) and whenever the flag transitions from 0 to 1 on a live controller. The flag latches the requested value. Sending the timestamp to the device is best-effort and warns on every failure.
The nvme_core.timestamps_enabled_default module parameter supplies the default value of the per-controller flag. Default it to false as the privacy-preserving choice. Users who want to provide controllers with real-world time can set the module parameter to true or enable the per-controller sysfs flag, perhaps via udev.
As an alternative, we could also get the timestamp updates out of the kernel entirely and have interested users run nvme(1) to update timestamps.
--- Documentation/ABI/testing/sysfs-nvme | 21 ++++++++++++++++++ MAINTAINERS | 2 +- drivers/nvme/host/core.c | 22 +++++++++++-------- drivers/nvme/host/nvme.h | 2 ++ drivers/nvme/host/sysfs.c | 32 ++++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-nvme
Documentation/ABI/testing/sysfs-nvme new file +21 -0
@@ -0,0 +1,21 @@ +What: /sys/class/nvme/nvmeX/timestamps_enabled +Date: July 2026 +KernelVersion: 7.3 +Contact: Linux NVMe mailing list <[email protected]> +Description: + Shows or sets whether the kernel sends wall-clock time to the + controller using the NVMe Timestamp feature. Reading returns 1 + (enabled) or 0 (disabled). Writing accepts a boolean value. The + attribute is present for every controller. On controllers that + do not support the Timestamp feature, the setting has no effect. + + The per-controller value is initialized from + nvme_core.timestamps_enabled_default, which defaults to false. When + enabled, the kernel sends a timestamp whenever the controller + starts, including on controller resets and resume from suspend. + Changing the value from 0 to 1 on a live controller + sends a timestamp immediately. Disabling does not affect a + timestamp already sent. + + Writes latch the requested value. Sending timestamps to the + controller is best-effort; every failure generates a warning.
MAINTAINERS +1 -1
@@ -19207,7 +19207,7 @@ L: [email protected] S: Supported W: http://git.infradead.org/nvme.git T: git git://git.infradead.org/nvme.git -F: Documentation/ABI/stable/sysfs-nvme +F: Documentation/ABI/*/sysfs-nvme F: Documentation/admin-guide/nvme-multipath.rst F: Documentation/fault-injection/nvme-fault-injection.rst F: Documentation/nvme/
drivers/nvme/host/core.c +13 -9
@@ -71,6 +71,11 @@ module_param(default_ps_max_latency_us, ulong, 0644);MODULE_PARM_DESC (default_ps_max_latency_us,"max power saving latency for new devices; use PM QOS to change per device" ); +static bool timestamps_enabled_default; +module_param (timestamps_enabled_default, bool,0644 ); +MODULE_PARM_DESC (timestamps_enabled_default, +"default value of the per-controller timestamps_enabled sysfs attribute" ); +static bool force_apst;module_param (force_apst, bool,0644 );MODULE_PARM_DESC (force_apst,"allow APST for newly enumerated devices even if quirked off" );
@@ -2824,21 +2829,21 @@ int nvme_enable_ctrl(struct nvme_ctrl *ctrl) }EXPORT_SYMBOL_GPL (nvme_enable_ctrl); -static int nvme_configure_timestamp (struct nvme_ctrl *ctrl) +void nvme_configure_timestamp (struct nvme_ctrl *ctrl) {__le64 ts;int ret; -if (!(ctrl->oncs &NVME_CTRL_ONCS_TIMESTAMP )) -return 0 ; +if (!READ_ONCE (ctrl->timestamps_enabled) || + !(ctrl->oncs &NVME_CTRL_ONCS_TIMESTAMP )) +return ; ts =cpu_to_le64 (ktime_to_ms (ktime_get_real ())); ret =nvme_set_features (ctrl,NVME_FEAT_TIMESTAMP ,0 , &ts,sizeof (ts),NULL );if (ret) -dev_warn_once (ctrl->device, -"could not set timestamp (%d)\n" , ret); -return ret; +dev_warn (ctrl->device, +"could not set timestamp (%d)\n" , ret); }static int nvme_configure_host_options (struct nvme_ctrl *ctrl)
@@ -3771,9 +3776,7 @@ int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl, bool was_suspended)if (ret <0 )return ret; - ret =nvme_configure_timestamp (ctrl); -if (ret <0 ) -return ret; +nvme_configure_timestamp (ctrl); ret =nvme_configure_host_options (ctrl);if (ret <0 )
@@ -5168,6 +5171,7 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,WRITE_ONCE (ctrl->state,NVME_CTRL_NEW ); ctrl->passthru_err_log_enabled = false; + ctrl->timestamps_enabled =READ_ONCE (timestamps_enabled_default);clear_bit (NVME_CTRL_FAILFAST_EXPIRED , &ctrl->flags);spin_lock_init (&ctrl->lock);mutex_init (&ctrl->namespaces_lock);
drivers/nvme/host/nvme.h +2 -0
@@ -335,6 +335,7 @@ struct nvme_ctrl {bool comp_seen;bool identified;bool passthru_err_log_enabled; +bool timestamps_enabled;enum nvme_ctrl_state state;spinlock_t lock;struct mutex scan_lock;
@@ -891,6 +892,7 @@ void nvme_uninit_ctrl(struct nvme_ctrl *ctrl);void nvme_start_ctrl (struct nvme_ctrl *ctrl);void nvme_stop_ctrl (struct nvme_ctrl *ctrl);int nvme_init_ctrl_finish (struct nvme_ctrl *ctrl,bool was_suspended); +void nvme_configure_timestamp (struct nvme_ctrl *ctrl);int nvme_alloc_admin_tag_set (struct nvme_ctrl *ctrl,struct blk_mq_tag_set *set,const struct blk_mq_ops *ops,unsigned int cmd_size);void nvme_remove_admin_tag_set (struct nvme_ctrl *ctrl);
drivers/nvme/host/sysfs.c +32 -0
@@ -36,6 +36,37 @@ static ssize_t nvme_sysfs_rescan(struct device *dev, } static DEVICE_ATTR(rescan_controller, S_IWUSR, NULL, nvme_sysfs_rescan); +static ssize_t timestamps_enabled_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct nvme_ctrl *ctrl =dev_get_drvdata (dev); + +return sysfs_emit (buf,"%d\n" ,READ_ONCE (ctrl->timestamps_enabled)); +} + +static ssize_t timestamps_enabled_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct nvme_ctrl *ctrl =dev_get_drvdata (dev); +bool enabled, was_enabled; +int ret; + + ret =kstrtobool (buf, &enabled); +if (ret) +return ret; + + was_enabled =READ_ONCE (ctrl->timestamps_enabled); +WRITE_ONCE (ctrl->timestamps_enabled, enabled); + +if (enabled && !was_enabled && +nvme_ctrl_state (ctrl) ==NVME_CTRL_LIVE ) +nvme_configure_timestamp (ctrl); + +return count; +} +static DEVICE_ATTR_RW (timestamps_enabled); +static ssize_t nvme_adm_passthru_err_log_enabled_show (struct device *dev,struct device_attribute *attr,char *buf) {
@@ -929,6 +960,7 @@ static DEVICE_ATTR(dhchap_ctrl_secret, S_IRUGO | S_IWUSR,static struct attribute *nvme_dev_attrs[] = { &dev_attr_reset_controller.attr, &dev_attr_rescan_controller.attr, + &dev_attr_timestamps_enabled.attr, &dev_attr_model.attr, &dev_attr_serial.attr, &dev_attr_firmware_rev.attr,
base-commit: cdf9a65e80ec874b630502946d269fac38dc5de8
Signature · 1 line
2.53.0
Keith Busch
maintainerQuoted 6 lines · Daniel Colascione
Some NVMe devices maintain a persistent log, the PEL, of events like power-on and thermal excursions. The NVMe Set Features (Timestamp) command allows an operating system to inform the NVMe of the current wall-clock time. Wall-clock timestamp updates are logged to the PEL alongside other events. By correlating PEL records, an attacker can infer a user's usage patterns and even guess at time zone changes.
How does an attacker come to acquire PEL records if the system isn't already compromised?
Quoted 9 lines
The nvme_core.timestamps_enabled_default module parameter supplies the default value of the per-controller flag. Default it to false as the privacy-preserving choice. Users who want to provide controllers with real-world time can set the module parameter to true or enable the per-controller sysfs flag, perhaps via udev.
As an alternative, we could also get the timestamp updates out of the kernel entirely and have interested users run nvme(1) to update timestamps.
The use cases for the timestamp feature are outside the specification. But I know of at least one implementation that uses it to determine how long it has been powered off so it can better apply correction to media drift. Yeah yeah, depending on the host for something so critical is pretty fragile, but it apparently worked out well enough. This proposal would break them.
Quoted 10 lines · Keith Busch
Quoted 6 lines · Daniel Colascione
Some NVMe devices maintain a persistent log, the PEL, of events like power-on and thermal excursions. The NVMe Set Features (Timestamp) command allows an operating system to inform the NVMe of the current wall-clock time. Wall-clock timestamp updates are logged to the PEL alongside other events. By correlating PEL records, an attacker can infer a user's usage patterns and even guess at time zone changes.
How does an attacker come to acquire PEL records if the system isn't already compromised?
The PEL can be read without any authentication whatsoever, so even an otherwise completely measured secure-boot system with FDE could leak the log to an evil maid. A sophisticated evil maid could execute some kind of adaptive attack, but the PEL is right there and easy to read even for an unsophisticated one-shot adversary.
Another thing to emphasize is that the log persists *through* cryptographic sanitize, so you can "wipe" a drive using the strongest available NVMe command, hand it to someone else, and still unwittingly leak real-world usage patterns. It's a side channel I'd rather not have, especially if I'm not getting any value from the timestamp.
Quoted 10 lines
Quoted 9 lines
The nvme_core.timestamps_enabled_default module parameter supplies the default value of the per-controller flag. Default it to false as the privacy-preserving choice. Users who want to provide controllers with real-world time can set the module parameter to true or enable the per-controller sysfs flag, perhaps via udev.
As an alternative, we could also get the timestamp updates out of the kernel entirely and have interested users run nvme(1) to update timestamps.
Quoted 6 lines
The use cases for the timestamp feature are outside the specification. But I know of at least one implementation that uses it to determine how long it has been powered off so it can better apply correction to media drift. Yeah yeah, depending on the host for something so critical is pretty fragile, but it apparently worked out well enough. This proposal would break them.
We could make the timestamp-updating opt-out instead of opt-in or require users of this hardware to change the module parameter. Also, IIUC, nothing in the spec requires a host to use this command.
I mostly care about having *some* knob to turn this off. Right now, it's unconditional. I'm happy with either opt-in or opt-out, although I have a weak preference for the former.
Quoted 3 lines · Daniel Colascione
I mostly care about having *some* knob to turn this off. Right now, it's unconditional. I'm happy with either opt-in or opt-out, although I have a weak preference for the former.
Ping. Is there anything I should be addressing in the patch? Thanks
Keith Busch
maintainerQuoted 6 lines · Daniel Colascione
Quoted 3 lines · Daniel Colascione
I mostly care about having *some* knob to turn this off. Right now, it's unconditional. I'm happy with either opt-in or opt-out, although I have a weak preference for the former.
Ping. Is there anything I should be addressing in the patch? Thanks
The historic behavior is that the timestamp feature happens. Making an option to change behavior usually leaves the historic behavior the default so that anything using it isn't suddenly having to scramble to restore what they had before.
Quoted 6 lines · Keith Busch
Quoted 5 lines · Daniel Colascione
Quoted 3 lines · Daniel Colascione
I mostly care about having *some* knob to turn this off. Right now, it's unconditional. I'm happy with either opt-in or opt-out, although I have a weak preference for the former.
Quoted 6 lines
Quoted 1 line
Ping. Is there anything I should be addressing in the patch? Thanks
The historic behavior is that the timestamp feature happens. Making an option to change behavior usually leaves the historic behavior the default so that anything using it isn't suddenly having to scramble to restore what they had before.
Will do. Thanks!