Sed-opal Fixes
Subsystems (3)
changes from v3->v4:
Changed manual kzalloc + copy from user to memdup_user.
This small series fixes a small ABI issue when using the _IOC_SIZE with the Activate Locking SP ioctl. I had put the wrong structure in the IOW macro in the uapi header which caused issues when trying to copy in the contents for the command.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH v4 1/2 uapi: sed-opal fix IOW for activate lsp to use correct struct
the IOW for the IOC_OPAL_ACTIVATE_LSP took the wrong strcure which would give us the wrong size when using _IOC_SIZE, switch it to the right structure.
--- include/uapi/linux/sed-opal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/uapi/linux/sed-opal.h +1 -1
@@ -106,7 +106,7 @@ struct opal_mbr_data {#define IOC_OPAL_SAVE _IOW('p', 220, struct opal_lock_unlock)#define IOC_OPAL_LOCK_UNLOCK _IOW('p', 221, struct opal_lock_unlock)#define IOC_OPAL_TAKE_OWNERSHIP _IOW('p', 222, struct opal_key) -#define IOC_OPAL_ACTIVATE_LSP _IOW('p', 223, struct opal_key) +#define IOC_OPAL_ACTIVATE_LSP _IOW('p', 223, struct opal_lr_act)#define IOC_OPAL_SET_PW _IOW('p', 224, struct opal_new_pw)#define IOC_OPAL_ACTIVATE_USR _IOW('p', 225, struct opal_session_info)#define IOC_OPAL_REVERT_TPR _IOW('p', 226, struct opal_key)
Signature · 7 lines
2.7.4 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH V4 1/2] uapi: sed-opal fix IOW for activate lsp to use correct struct
Looks fine,
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH v4 2/2 Move stack parameters for sed_ioctl to prevent oversized stack with CONFIG_KASAN
In reply to Scott BauerWhen CONFIG_KASAN is enabled, compilation fails:
block/sed-opal.c: In function 'sed_ioctl':block/sed-opal.c:2447:1: error: the frame size of 2256 bytes is larger than 2048 bytes [-Werror=frame-larger-than=]
Moved all the ioctl structures off the stack and dynamically activate using _IOC_SIZE()
--- block/sed-opal.c | 132 ++++++++++++++++++++----------------------------------- 1 file changed, 48 insertions(+), 84 deletions(-)
block/sed-opal.c +48 -84
@@ -2346,7 +2346,10 @@ EXPORT_SYMBOL(opal_unlock_from_suspend);int sed_ioctl (struct opal_dev *dev,unsigned int cmd,unsigned long ptr) { +void *ioctl_ptr; +int ret = -ENOTTY ;void __user *arg = (void __user *)ptr; +unsigned int cmd_size =_IOC_SIZE (cmd);if (!capable (CAP_SYS_ADMIN ))return -EACCES ;
@@ -2355,94 +2358,55 @@ int sed_ioctl(struct opal_dev *dev, unsigned int cmd, unsigned long ptr)return -ENOTSUPP ; } -switch (cmd) { -case IOC_OPAL_SAVE : { -struct opal_lock_unlock lk_unlk; - -if (copy_from_user (&lk_unlk, arg,sizeof (lk_unlk))) -return -EFAULT ; -return opal_save (dev, &lk_unlk); - } -case IOC_OPAL_LOCK_UNLOCK : { -struct opal_lock_unlock lk_unlk; - -if (copy_from_user (&lk_unlk, arg,sizeof (lk_unlk))) -return -EFAULT ; -return opal_lock_unlock (dev, &lk_unlk); - } -case IOC_OPAL_TAKE_OWNERSHIP : { -struct opal_key opal_key; - -if (copy_from_user (&opal_key, arg,sizeof (opal_key))) -return -EFAULT ; -return opal_take_ownership (dev, &opal_key); - } -case IOC_OPAL_ACTIVATE_LSP : { -struct opal_lr_act opal_lr_act; - -if (copy_from_user (&opal_lr_act, arg,sizeof (opal_lr_act))) -return -EFAULT ; -return opal_activate_lsp (dev, &opal_lr_act); - } -case IOC_OPAL_SET_PW : { -struct opal_new_pw opal_pw; - -if (copy_from_user (&opal_pw, arg,sizeof (opal_pw))) -return -EFAULT ; -return opal_set_new_pw (dev, &opal_pw); - } -case IOC_OPAL_ACTIVATE_USR : { -struct opal_session_info session; - -if (copy_from_user (&session, arg,sizeof (session))) -return -EFAULT ; -return opal_activate_user (dev, &session); - } -case IOC_OPAL_REVERT_TPR : { -struct opal_key opal_key; - -if (copy_from_user (&opal_key, arg,sizeof (opal_key))) -return -EFAULT ; -return opal_reverttper (dev, &opal_key); - } -case IOC_OPAL_LR_SETUP : { -struct opal_user_lr_setup lrs; - -if (copy_from_user (&lrs, arg,sizeof (lrs))) -return -EFAULT ; -return opal_setup_locking_range (dev, &lrs); - } -case IOC_OPAL_ADD_USR_TO_LR : { -struct opal_lock_unlock lk_unlk; - -if (copy_from_user (&lk_unlk, arg,sizeof (lk_unlk))) -return -EFAULT ; -return opal_add_user_to_lr (dev, &lk_unlk); - } -case IOC_OPAL_ENABLE_DISABLE_MBR : { -struct opal_mbr_data mbr; - -if (copy_from_user (&mbr, arg,sizeof (mbr))) -return -EFAULT ; -return opal_enable_disable_shadow_mbr (dev, &mbr); - } -case IOC_OPAL_ERASE_LR : { -struct opal_session_info session; - -if (copy_from_user (&session, arg,sizeof (session))) -return -EFAULT ; -return opal_erase_locking_range (dev, &session); + ioctl_ptr =memdup_user (arg, cmd_size); +if (IS_ERR_OR_NULL (ioctl_ptr)) { + ret =PTR_ERR (ioctl_ptr); + goto out; } -case IOC_OPAL_SECURE_ERASE_LR : { -struct opal_session_info session; -if (copy_from_user (&session, arg,sizeof (session))) -return -EFAULT ; -return opal_secure_erase_locking_range (dev, &session); - } +switch (cmd) { +case IOC_OPAL_SAVE : + ret =opal_save (dev, ioctl_ptr); +break ; +case IOC_OPAL_LOCK_UNLOCK : + ret =opal_lock_unlock (dev, ioctl_ptr); +break ; +case IOC_OPAL_TAKE_OWNERSHIP : + ret =opal_take_ownership (dev, ioctl_ptr); +break ; +case IOC_OPAL_ACTIVATE_LSP : + ret =opal_activate_lsp (dev, ioctl_ptr); +break ; +case IOC_OPAL_SET_PW : + ret =opal_set_new_pw (dev, ioctl_ptr); +break ; +case IOC_OPAL_ACTIVATE_USR : + ret =opal_activate_user (dev, ioctl_ptr); +break ; +case IOC_OPAL_REVERT_TPR : + ret =opal_reverttper (dev, ioctl_ptr); +break ; +case IOC_OPAL_LR_SETUP : + ret =opal_setup_locking_range (dev, ioctl_ptr); +break ; +case IOC_OPAL_ADD_USR_TO_LR : + ret =opal_add_user_to_lr (dev, ioctl_ptr); +break ; +case IOC_OPAL_ENABLE_DISABLE_MBR : + ret =opal_enable_disable_shadow_mbr (dev, ioctl_ptr); +break ; +case IOC_OPAL_ERASE_LR : + ret =opal_erase_locking_range (dev, ioctl_ptr); +break ; +case IOC_OPAL_SECURE_ERASE_LR : + ret =opal_secure_erase_locking_range (dev, ioctl_ptr); +break ;default :pr_warn ("No such Opal Ioctl %u\n" , cmd); } -return -ENOTTY ; + + out: +kfree (ioctl_ptr); +return ret; }EXPORT_SYMBOL_GPL (sed_ioctl);
Signature · 7 lines
2.7.4 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH V4 2/2] Move stack parameters for sed_ioctl to prevent oversized stack with CONFIG_KASAN
block/sed-opal.c EXPORT_SYMBOL(opal_unlock_from_suspend); · line 2351
Quoted 5 lines
int
sed_ioctl(struct opal_dev *dev, unsigned int cmd, unsigned long ptr){block/sed-opal.c +2
-0+void *ioctl_ptr; +int ret = -ENOTTY ;void __user *arg = (void __user *)ptr;
Can we use this opportunity to clean up the usual ioctl argument mess. Id say pass the "void __user *argp" argument already (nvme_ioctl should have a local variable for it anyway), and then just rename ioctl_ptr variable to the usual short p.
block/sed-opal.c EXPORT_SYMBOL(opal_unlock_from_suspend);
Quoted 4 lines
block/sed-opal.c +2
-0+unsigned int cmd_size =_IOC_SIZE (cmd); + ioctl_ptr =memdup_user (arg, cmd_size);
cmd_size is only used once, so why not opencode the expression in the argument to memdup_user.