habanalabs: check pad and reserved fields in ioctls
authorfarah kassabri <fkassabri@habana.ai>
Tue, 3 Jan 2023 12:23:55 +0000 (14:23 +0200)
committerOded Gabbay <ogabbay@kernel.org>
Thu, 26 Jan 2023 09:52:12 +0000 (11:52 +0200)
Make sure all reserved/pad fields in uapi input structures
are set to 0.

Signed-off-by: farah kassabri <fkassabri@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
drivers/accel/habanalabs/common/command_submission.c
drivers/accel/habanalabs/common/habanalabs_ioctl.c

index bb9584d72c322b4ba4cc4e33872f362d24461ef8..c54f504383ace0848eb33277f4815d613b157f1a 100644 (file)
@@ -1310,6 +1310,13 @@ static int hl_cs_sanity_checks(struct hl_fpriv *hpriv, union hl_cs_args *args)
        enum hl_device_status status;
        enum hl_cs_type cs_type;
        bool is_sync_stream;
+       int i;
+
+       for (i = 0 ; i < sizeof(args->in.pad) ; i++)
+               if (args->in.pad[i]) {
+                       dev_dbg(hdev->dev, "Padding bytes must be 0\n");
+                       return -EINVAL;
+               }
 
        if (!hl_device_operational(hdev, &status)) {
                return -EBUSY;
@@ -2918,7 +2925,13 @@ static int hl_multi_cs_wait_ioctl(struct hl_fpriv *hpriv, void *data)
        u32 size_to_copy;
        u64 *cs_seq_arr;
        u8 seq_arr_len;
-       int rc;
+       int rc, i;
+
+       for (i = 0 ; i < sizeof(args->in.pad) ; i++)
+               if (args->in.pad[i]) {
+                       dev_dbg(hdev->dev, "Padding bytes must be 0\n");
+                       return -EINVAL;
+               }
 
        if (!hdev->supports_wait_for_multi_cs) {
                dev_err(hdev->dev, "Wait for multi CS is not supported\n");
index 72493bf94ba317f5a6e61398a8d3923b53836390..5005e6fca691234ded305a45c2255e4d3a465dd7 100644 (file)
@@ -884,9 +884,13 @@ static int _hl_info_ioctl(struct hl_fpriv *hpriv, void *data,
        enum hl_device_status status;
        struct hl_info_args *args = data;
        struct hl_device *hdev = hpriv->hdev;
-
        int rc;
 
+       if (args->pad) {
+               dev_dbg(hdev->dev, "Padding bytes must be 0\n");
+               return -EINVAL;
+       }
+
        /*
         * Information is returned for the following opcodes even if the device
         * is disabled or in reset.