libnvdimm/security: 'security' attr never show 'overwrite' state
PATCH 1/2 libnvdimm/security: 'security' attr never show 'overwrite' state
Since
commit d78c620a2e82 ("libnvdimm/security: Introduce a 'frozen' attribute"), when issue
# ndctl sanitize-dimm nmem0 --overwrite then immediately check the 'security' attribute, # cat /sys/devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/nmem0/security unlocked Actually the attribute stays 'unlocked' through out the entire overwrite operation, never changed. That's because 'nvdimm->sec.flags' is a bitmap that has both bits set indicating 'overwrite' and 'unlocked'. But security_show() checks the mutually exclusive bits before it checks the 'overwrite' bit at last. The order should be reversed.
The commit also has a typo: in one occasion, 'nvdimm->sec.ext_state' assignment is replaced with 'nvdimm->sec.flags' assignment for the NVDIMM_MASTER type.
--- drivers/nvdimm/dimm_devs.c | 4 ++-- drivers/nvdimm/security.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/nvdimm/dimm_devs.c +2 -2
@@ -363,14 +363,14 @@ __weak ssize_t security_show(struct device *dev, {struct nvdimm *nvdimm =to_nvdimm (dev); +if (test_bit (NVDIMM_SECURITY_OVERWRITE , &nvdimm->sec.flags)) +return sprintf (buf,"overwrite\n" );if (test_bit (NVDIMM_SECURITY_DISABLED , &nvdimm->sec.flags))return sprintf (buf,"disabled\n" );if (test_bit (NVDIMM_SECURITY_UNLOCKED , &nvdimm->sec.flags))return sprintf (buf,"unlocked\n" );if (test_bit (NVDIMM_SECURITY_LOCKED , &nvdimm->sec.flags))return sprintf (buf,"locked\n" ); -if (test_bit (NVDIMM_SECURITY_OVERWRITE , &nvdimm->sec.flags)) -return sprintf (buf,"overwrite\n" );return -ENOTTY ; }
drivers/nvdimm/security.c +1 -1
@@ -457,7 +457,7 @@ void __nvdimm_security_overwrite_query(struct nvdimm *nvdimm)clear_bit (NDD_WORK_PENDING , &nvdimm->flags);put_device (&nvdimm->dev); nvdimm->sec.flags =nvdimm_security_flags (nvdimm,NVDIMM_USER ); - nvdimm->sec.flags =nvdimm_security_flags (nvdimm,NVDIMM_MASTER ); + nvdimm->sec.ext_flags =nvdimm_security_flags (nvdimm,NVDIMM_MASTER ); }void nvdimm_security_overwrite_query (struct work_struct *work)
Signature · 4 lines
1.8.3.1 _______________________________________________ Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
PATCH 2/2 libnvdimm/security: ensure sysfs poll thread woke up and fetch updated attr
commit 7d988097c546 ("acpi/nfit, libnvdimm/security: Add security DSM overwrite support") adds a sysfs_notify_dirent() to wake up userspace poll thread when the "overwrite" operation has completed. But the notification is issued before the internal dimm security state and flags have been updated, so the userspace poll thread wakes up and fetches the not-yet-updated attr and falls back to sleep, forever. But if user from another terminal issue "ndctl wait-overwrite nmemX" again, the command returns instantly.
--- drivers/nvdimm/security.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/nvdimm/security.c +8 -3
@@ -450,14 +450,19 @@ void __nvdimm_security_overwrite_query(struct nvdimm *nvdimm)else dev_dbg (&nvdimm->dev,"overwrite completed\n" ); -if (nvdimm->sec.overwrite_state) -sysfs_notify_dirent (nvdimm->sec.overwrite_state); +/* +* Mark the overwrite work done and update dimm security flags, +* then send a sysfs event notification to wake up userspace +* poll threads to picked up the changed state. +*/ nvdimm->sec.overwrite_tmo =0 ;clear_bit (NDD_SECURITY_OVERWRITE , &nvdimm->flags);clear_bit (NDD_WORK_PENDING , &nvdimm->flags); -put_device (&nvdimm->dev); nvdimm->sec.flags =nvdimm_security_flags (nvdimm,NVDIMM_USER ); nvdimm->sec.ext_flags =nvdimm_security_flags (nvdimm,NVDIMM_MASTER ); +if (nvdimm->sec.overwrite_state) +sysfs_notify_dirent (nvdimm->sec.overwrite_state); +put_device (&nvdimm->dev); }void nvdimm_security_overwrite_query (struct work_struct *work)
Signature · 4 lines
1.8.3.1 _______________________________________________ Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Re: [PATCH 2/2] libnvdimm/security: ensure sysfs poll thread woke up and fetch updated attr
Quoted 8 lines · Jane Chu
commit
7d988097c546("acpi/nfit, libnvdimm/security: Add security DSM overwrite support") adds asysfs_notify_dirent()to wake up userspace poll thread when the "overwrite" operation has completed. But the notification is issued before the internal dimm security state and flags have been updated, so the userspace poll thread wakes up and fetches the not-yet-updated attr and falls back to sleep, forever. But if user from another terminal issue "ndctl wait-overwrite nmemX" again, the command returns instantly.
Quoted 4 lines
Cc Dave Jiang <[email protected]>Cc Dan Williams <[email protected]>Fixes 7d988097c546 ("acpi/nfit, libnvdimm/security: Add security DSM overwrite support")Signed-off-by Jane Chu <[email protected]>
Quoted 22 lines
--- drivers/nvdimm/security.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)drivers/nvdimm/security.c +5
-2@@ -450,14 +450,19 @@ void __nvdimm_security_overwrite_query(struct nvdimm *nvdimm)else dev_dbg (&nvdimm->dev,"overwrite completed\n" ); -if (nvdimm->sec.overwrite_state) -sysfs_notify_dirent (nvdimm->sec.overwrite_state); +/* +* Mark the overwrite work done and update dimm security flags, +* then send a sysfs event notification to wake up userspace +* poll threads to picked up the changed state. +*/ nvdimm->sec.overwrite_tmo =0 ;clear_bit (NDD_SECURITY_OVERWRITE , &nvdimm->flags);
drivers/nvdimm/security.c void __nvdimm_security_overwrite_query(struct nvdimm *nvdimm) · line 468
Quoted 10 lines
drivers/nvdimm/security.c +3
-1clear_bit (NDD_WORK_PENDING , &nvdimm->flags); -put_device (&nvdimm->dev); nvdimm->sec.flags =nvdimm_security_flags (nvdimm,NVDIMM_USER ); nvdimm->sec.ext_flags =nvdimm_security_flags (nvdimm,NVDIMM_MASTER ); +if (nvdimm->sec.overwrite_state) +sysfs_notify_dirent (nvdimm->sec.overwrite_state); +put_device (&nvdimm->dev); }void nvdimm_security_overwrite_query (struct work_struct *work)
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Hi,
Any taker on this and next patch
[PATCH 2/2] libnvdimm/security: ensure sysfs poll thread woke up and
fetch updated attr
?
According to our test, they're bugs, and folks are waiting to get the issues fixed.
Thanks!
-jane
Quoted 52 lines · Jane Chu
Since
commitd78c620a2e82("libnvdimm/security: Introduce a 'frozen' attribute"), when issue# ndctl sanitize-dimm nmem0 --overwrite then immediately check the 'security' attribute, # cat /sys/devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/nmem0/security unlocked Actually the attribute stays 'unlocked' through out the entire overwrite operation, never changed. That's because 'nvdimm->sec.flags' is a bitmap that has both bits set indicating 'overwrite' and 'unlocked'. But security_show() checks the mutually exclusive bits before it checks the 'overwrite' bit at last. The order should be reversed.The commit also has a typo: in one occasion, '
nvdimm->sec.ext_state' assignment is replaced with 'nvdimm->sec.flags' assignment for theNVDIMM_MASTERtype.Cc Dan Williams <[email protected]>Fixes d78c620a2e82 ("libnvdimm/security: Introduce a 'frozen' attribute")Signed-off-by Jane Chu <[email protected]>--- drivers/nvdimm/dimm_devs.c | 4 ++-- drivers/nvdimm/security.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)drivers/nvdimm/dimm_devs.c +2
-2@@ -363,14 +363,14 @@ __weak ssize_t security_show(struct device *dev, {struct nvdimm *nvdimm =to_nvdimm (dev); +if (test_bit (NVDIMM_SECURITY_OVERWRITE , &nvdimm->sec.flags)) +return sprintf (buf,"overwrite\n" );if (test_bit (NVDIMM_SECURITY_DISABLED , &nvdimm->sec.flags))return sprintf (buf,"disabled\n" );if (test_bit (NVDIMM_SECURITY_UNLOCKED , &nvdimm->sec.flags))return sprintf (buf,"unlocked\n" );if (test_bit (NVDIMM_SECURITY_LOCKED , &nvdimm->sec.flags))return sprintf (buf,"locked\n" ); -if (test_bit (NVDIMM_SECURITY_OVERWRITE , &nvdimm->sec.flags)) -return sprintf (buf,"overwrite\n" );return -ENOTTY ; }drivers/nvdimm/security.c +0
-0
drivers/nvdimm/security.c void __nvdimm_security_overwrite_query(struct nvdimm *nvdimm) · line 463
Quoted 8 lines
drivers/nvdimm/security.c +1
-1@@ -457,7 +457,7 @@ void __nvdimm_security_overwrite_query(struct nvdimm *nvdimm)clear_bit (NDD_WORK_PENDING , &nvdimm->flags);put_device (&nvdimm->dev); nvdimm->sec.flags =nvdimm_security_flags (nvdimm,NVDIMM_USER ); - nvdimm->sec.flags =nvdimm_security_flags (nvdimm,NVDIMM_MASTER ); + nvdimm->sec.ext_flags =nvdimm_security_flags (nvdimm,NVDIMM_MASTER ); }void nvdimm_security_overwrite_query (struct work_struct *work)
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Dave Jiang
maintainerQuoted 13 lines · Jane Chu
Since
commitd78c620a2e82("libnvdimm/security: Introduce a 'frozen' attribute"), when issue# ndctl sanitize-dimm nmem0 --overwrite then immediately check the 'security' attribute, # cat /sys/devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/nmem0/security unlocked Actually the attribute stays 'unlocked' through out the entire overwrite operation, never changed. That's because 'nvdimm->sec.flags' is a bitmap that has both bits set indicating 'overwrite' and 'unlocked'. But security_show() checks the mutually exclusive bits before it checks the 'overwrite' bit at last. The order should be reversed.
Quoted 3 lines
The commit also has a typo: in one occasion, '
nvdimm->sec.ext_state' assignment is replaced with 'nvdimm->sec.flags' assignment for theNVDIMM_MASTERtype.
May be best to split this fix to a different patch? Just thinking git bisect later on to track issues. Otherwise Reviewed-by: Dave Jiang <[email protected]>
Quoted 36 lines
Cc Dan Williams <[email protected]>Fixes d78c620a2e82 ("libnvdimm/security: Introduce a 'frozen' attribute")Signed-off-by Jane Chu <[email protected]>--- drivers/nvdimm/dimm_devs.c | 4 ++-- drivers/nvdimm/security.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)drivers/nvdimm/dimm_devs.c +2
-2@@ -363,14 +363,14 @@ __weak ssize_t security_show(struct device *dev, {struct nvdimm *nvdimm =to_nvdimm (dev); +if (test_bit (NVDIMM_SECURITY_OVERWRITE , &nvdimm->sec.flags)) +return sprintf (buf,"overwrite\n" );if (test_bit (NVDIMM_SECURITY_DISABLED , &nvdimm->sec.flags))return sprintf (buf,"disabled\n" );if (test_bit (NVDIMM_SECURITY_UNLOCKED , &nvdimm->sec.flags))return sprintf (buf,"unlocked\n" );if (test_bit (NVDIMM_SECURITY_LOCKED , &nvdimm->sec.flags))return sprintf (buf,"locked\n" ); -if (test_bit (NVDIMM_SECURITY_OVERWRITE , &nvdimm->sec.flags)) -return sprintf (buf,"overwrite\n" );return -ENOTTY ; }drivers/nvdimm/security.c +0
-0
drivers/nvdimm/security.c void __nvdimm_security_overwrite_query(struct nvdimm *nvdimm) · line 463
Quoted 8 lines
drivers/nvdimm/security.c +1
-1@@ -457,7 +457,7 @@ void __nvdimm_security_overwrite_query(struct nvdimm *nvdimm)clear_bit (NDD_WORK_PENDING , &nvdimm->flags);put_device (&nvdimm->dev); nvdimm->sec.flags =nvdimm_security_flags (nvdimm,NVDIMM_USER ); - nvdimm->sec.flags =nvdimm_security_flags (nvdimm,NVDIMM_MASTER ); + nvdimm->sec.ext_flags =nvdimm_security_flags (nvdimm,NVDIMM_MASTER ); }void nvdimm_security_overwrite_query (struct work_struct *work)
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Hi, Dave,
Quoted 14 lines · Dave Jiang
Quoted 13 lines · Jane Chu
Since
commitd78c620a2e82("libnvdimm/security: Introduce a 'frozen' attribute"), when issue# ndctl sanitize-dimm nmem0 --overwrite then immediately check the 'security' attribute, # cat /sys/devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/nmem0/security unlocked Actually the attribute stays 'unlocked' through out the entire overwrite operation, never changed. That's because 'nvdimm->sec.flags' is a bitmap that has both bits set indicating 'overwrite' and 'unlocked'. But security_show() checks the mutually exclusive bits before it checks the 'overwrite' bit at last. The order should be reversed.
Quoted 5 lines
Quoted 3 lines
The commit also has a typo: in one occasion, '
nvdimm->sec.ext_state' assignment is replaced with 'nvdimm->sec.flags' assignment for theNVDIMM_MASTERtype.May be best to split this fix to a different patch? Just thinking git bisect later on to track issues. Otherwise Reviewed-by: Dave Jiang <[email protected]>
Sure. I take it you meant to separate the typo fix from the change that tests the OVERWRITE bit first?
Regards,
-jane
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Dave Jiang
maintainerQuoted 17 lines · Jane Chu
Hi, Dave,
Quoted 14 lines · Dave Jiang
Quoted 13 lines · Jane Chu
Since
commitd78c620a2e82("libnvdimm/security: Introduce a 'frozen' attribute"), when issue# ndctl sanitize-dimm nmem0 --overwrite then immediately check the 'security' attribute, # cat /sys/devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/nmem0/security unlocked Actually the attribute stays 'unlocked' through out the entire overwrite operation, never changed. That's because 'nvdimm->sec.flags' is a bitmap that has both bits set indicating 'overwrite' and 'unlocked'. But security_show() checks the mutually exclusive bits before it checks the 'overwrite' bit at last. The order should be reversed.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
The commit also has a typo: in one occasion, '
nvdimm->sec.ext_state' assignment is replaced with 'nvdimm->sec.flags' assignment for theNVDIMM_MASTERtype.May be best to split this fix to a different patch? Just thinking git bisect later on to track issues. Otherwise Reviewed-by: Dave Jiang <[email protected]>
Sure. I take it you meant to separate the typo fix from the change that tests the OVERWRITE bit first?
Yep!
Quoted 3 lines
Regards,
-jane
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]