diff options
| author | Johannes Thumshirn <jthumshirn@suse.de> | 2018-03-29 18:05:07 -0400 |
|---|---|---|
| committer | Jens Axboe <axboe@kernel.dk> | 2018-03-29 19:29:09 -0400 |
| commit | 40f962d78a969e3b476451ebc82deffdee4309c2 (patch) | |
| tree | 15a5c44e22829a2d4f298c22a8772c20a6f430a4 /drivers | |
| parent | a38c78d82dd38ce178c994a777751fae61ae31c8 (diff) | |
lightnvm: centralize permission check for lightnvm ioctl
Currently all functions for handling the lightnvm core ioctl commands
do a check for CAP_SYS_ADMIN.
Change this to fail early in nvm_ctl_ioctl(), so we don't have to
duplicate the permission checks all over.
Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: Matias Bjørling <mb@lightnvm.io>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/lightnvm/core.c | 21 |
1 files changed, 3 insertions, 18 deletions
diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index 3eec948d1b7e..5b197d6bb6d9 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c | |||
| @@ -1019,9 +1019,6 @@ static long nvm_ioctl_info(struct file *file, void __user *arg) | |||
| 1019 | struct nvm_tgt_type *tt; | 1019 | struct nvm_tgt_type *tt; |
| 1020 | int tgt_iter = 0; | 1020 | int tgt_iter = 0; |
| 1021 | 1021 | ||
| 1022 | if (!capable(CAP_SYS_ADMIN)) | ||
| 1023 | return -EPERM; | ||
| 1024 | |||
| 1025 | info = memdup_user(arg, sizeof(struct nvm_ioctl_info)); | 1022 | info = memdup_user(arg, sizeof(struct nvm_ioctl_info)); |
| 1026 | if (IS_ERR(info)) | 1023 | if (IS_ERR(info)) |
| 1027 | return -EFAULT; | 1024 | return -EFAULT; |
| @@ -1060,9 +1057,6 @@ static long nvm_ioctl_get_devices(struct file *file, void __user *arg) | |||
| 1060 | struct nvm_dev *dev; | 1057 | struct nvm_dev *dev; |
| 1061 | int i = 0; | 1058 | int i = 0; |
| 1062 | 1059 | ||
| 1063 | if (!capable(CAP_SYS_ADMIN)) | ||
| 1064 | return -EPERM; | ||
| 1065 | |||
| 1066 | devices = kzalloc(sizeof(struct nvm_ioctl_get_devices), GFP_KERNEL); | 1060 | devices = kzalloc(sizeof(struct nvm_ioctl_get_devices), GFP_KERNEL); |
| 1067 | if (!devices) | 1061 | if (!devices) |
| 1068 | return -ENOMEM; | 1062 | return -ENOMEM; |
| @@ -1103,9 +1097,6 @@ static long nvm_ioctl_dev_create(struct file *file, void __user *arg) | |||
| 1103 | { | 1097 | { |
| 1104 | struct nvm_ioctl_create create; | 1098 | struct nvm_ioctl_create create; |
| 1105 | 1099 | ||
| 1106 | if (!capable(CAP_SYS_ADMIN)) | ||
| 1107 | return -EPERM; | ||
| 1108 | |||
| 1109 | if (copy_from_user(&create, arg, sizeof(struct nvm_ioctl_create))) | 1100 | if (copy_from_user(&create, arg, sizeof(struct nvm_ioctl_create))) |
| 1110 | return -EFAULT; | 1101 | return -EFAULT; |
| 1111 | 1102 | ||
| @@ -1141,9 +1132,6 @@ static long nvm_ioctl_dev_remove(struct file *file, void __user *arg) | |||
| 1141 | struct nvm_dev *dev; | 1132 | struct nvm_dev *dev; |
| 1142 | int ret = 0; | 1133 | int ret = 0; |
| 1143 | 1134 | ||
| 1144 | if (!capable(CAP_SYS_ADMIN)) | ||
| 1145 | return -EPERM; | ||
| 1146 | |||
| 1147 | if (copy_from_user(&remove, arg, sizeof(struct nvm_ioctl_remove))) | 1135 | if (copy_from_user(&remove, arg, sizeof(struct nvm_ioctl_remove))) |
| 1148 | return -EFAULT; | 1136 | return -EFAULT; |
| 1149 | 1137 | ||
| @@ -1168,9 +1156,6 @@ static long nvm_ioctl_dev_init(struct file *file, void __user *arg) | |||
| 1168 | { | 1156 | { |
| 1169 | struct nvm_ioctl_dev_init init; | 1157 | struct nvm_ioctl_dev_init init; |
| 1170 | 1158 | ||
| 1171 | if (!capable(CAP_SYS_ADMIN)) | ||
| 1172 | return -EPERM; | ||
| 1173 | |||
| 1174 | if (copy_from_user(&init, arg, sizeof(struct nvm_ioctl_dev_init))) | 1159 | if (copy_from_user(&init, arg, sizeof(struct nvm_ioctl_dev_init))) |
| 1175 | return -EFAULT; | 1160 | return -EFAULT; |
| 1176 | 1161 | ||
| @@ -1187,9 +1172,6 @@ static long nvm_ioctl_dev_factory(struct file *file, void __user *arg) | |||
| 1187 | { | 1172 | { |
| 1188 | struct nvm_ioctl_dev_factory fact; | 1173 | struct nvm_ioctl_dev_factory fact; |
| 1189 | 1174 | ||
| 1190 | if (!capable(CAP_SYS_ADMIN)) | ||
| 1191 | return -EPERM; | ||
| 1192 | |||
| 1193 | if (copy_from_user(&fact, arg, sizeof(struct nvm_ioctl_dev_factory))) | 1175 | if (copy_from_user(&fact, arg, sizeof(struct nvm_ioctl_dev_factory))) |
| 1194 | return -EFAULT; | 1176 | return -EFAULT; |
| 1195 | 1177 | ||
| @@ -1205,6 +1187,9 @@ static long nvm_ctl_ioctl(struct file *file, uint cmd, unsigned long arg) | |||
| 1205 | { | 1187 | { |
| 1206 | void __user *argp = (void __user *)arg; | 1188 | void __user *argp = (void __user *)arg; |
| 1207 | 1189 | ||
| 1190 | if (!capable(CAP_SYS_ADMIN)) | ||
| 1191 | return -EPERM; | ||
| 1192 | |||
| 1208 | switch (cmd) { | 1193 | switch (cmd) { |
| 1209 | case NVM_INFO: | 1194 | case NVM_INFO: |
| 1210 | return nvm_ioctl_info(file, argp); | 1195 | return nvm_ioctl_info(file, argp); |
