drivers/iommu/iommufd/main.c:259 iommufd_get_hw_info() warn: maybe return -EFAULT instead of the bytes remaining?
PATCH 3/95 drivers/iommu/iommufd/main.c:259 iommufd_get_hw_info() warn: maybe return -EFAULT instead of the bytes remaining?
tree: https://github.com/yiliu1765/iommufd.git wip/iommufd_pasid-0825 head: 98c119bc01ddf99ad4ac7c3e93980e3d835c0901 commit: 69055cc0284095e68fd61f1705ef518ad731d120 [3/95] iommufd: Add IOMMU_GET_HW_INFO config: x86_64-randconfig-161-20230826 (https://download.01.org/0day-ci/archive/20230827/[email protected]/config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 reproduce: (https://download.01.org/0day-ci/archive/20230827/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]> | Reported-by: Dan Carpenter <[email protected]> | Closes: https://lore.kernel.org/r/[email protected]/
smatch warnings:drivers/iommu/iommufd/main.c:259 iommufd_get_hw_info() warn: maybe return -EFAULT instead of the bytes remaining?
vim +259 drivers/iommu/iommufd/main.c
69055cc0284095e Yi Liu 2023-01-12 220 static int iommufd_get_hw_info(struct iommufd_ucmd *ucmd)
69055cc0284095e Yi Liu 2023-01-12 221 {
69055cc0284095e Yi Liu 2023-01-12 222 struct iommu_hw_info *cmd = ucmd->cmd;
69055cc0284095e Yi Liu 2023-01-12 223 unsigned int length = cmd->data_len;
69055cc0284095e Yi Liu 2023-01-12 224 struct iommufd_device *idev;
69055cc0284095e Yi Liu 2023-01-12 225 void __user *user_ptr;
69055cc0284095e Yi Liu 2023-01-12 226 u32 hw_info_type;
69055cc0284095e Yi Liu 2023-01-12 227 int rc = 0;
69055cc0284095e Yi Liu 2023-01-12 228
69055cc0284095e Yi Liu 2023-01-12 229 if (cmd->flags || cmd->__reserved || !cmd->data_len)
69055cc0284095e Yi Liu 2023-01-12 230 return -EOPNOTSUPP;
69055cc0284095e Yi Liu 2023-01-12 231
69055cc0284095e Yi Liu 2023-01-12 232 idev = iommufd_get_device(ucmd, cmd->dev_id);
69055cc0284095e Yi Liu 2023-01-12 233 if (IS_ERR(idev))
69055cc0284095e Yi Liu 2023-01-12 234 return PTR_ERR(idev);
69055cc0284095e Yi Liu 2023-01-12 235
69055cc0284095e Yi Liu 2023-01-12 236 user_ptr = u64_to_user_ptr(cmd->data_ptr);
69055cc0284095e Yi Liu 2023-01-12 237
69055cc0284095e Yi Liu 2023-01-12 238 rc = iommufd_fill_hw_info(idev->dev, user_ptr,
69055cc0284095e Yi Liu 2023-01-12 239 &length, &hw_info_type);
69055cc0284095e Yi Liu 2023-01-12 240 if (rc)
69055cc0284095e Yi Liu 2023-01-12 241 goto err_put;
69055cc0284095e Yi Liu 2023-01-12 242
69055cc0284095e Yi Liu 2023-01-12 243 /*
69055cc0284095e Yi Liu 2023-01-12 244 * Zero the trailing bytes if the user buffer is bigger than the
69055cc0284095e Yi Liu 2023-01-12 245 * data size kernel actually has.
69055cc0284095e Yi Liu 2023-01-12 246 */
69055cc0284095e Yi Liu 2023-01-12 247 if (length < cmd->data_len) {
69055cc0284095e Yi Liu 2023-01-12 248 rc = clear_user(user_ptr + length, cmd->data_len - length);clear_user() has the same return values as copy_to/from_user(). This should be:
if (clear_user(user_ptr + length, cmd->data_len - length)) {
rc = -EFAULT;
goto err_put;
}69055cc0284095e Yi Liu 2023-01-12 249 if (rc) 69055cc0284095e Yi Liu 2023-01-12 250 goto err_put; 69055cc0284095e Yi Liu 2023-01-12 251 } 69055cc0284095e Yi Liu 2023-01-12 252 69055cc0284095e Yi Liu 2023-01-12 253 cmd->data_len = length; 69055cc0284095e Yi Liu 2023-01-12 254 cmd->out_data_type = hw_info_type; 69055cc0284095e Yi Liu 2023-01-12 255 rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd)); 69055cc0284095e Yi Liu 2023-01-12 256 69055cc0284095e Yi Liu 2023-01-12 257 err_put: 69055cc0284095e Yi Liu 2023-01-12 258 iommufd_put_object(&idev->obj);
69055cc0284095e Yi Liu 2023-01-12 @259 return rc;69055cc0284095e Yi Liu 2023-01-12 260 }
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki