@@ -302,6 +302,9 @@ static int set_powered(struct sock *sk, u16 index, unsigned char *data, u16 len)
302302
303303 BT_DBG ("request for hci%u" , index );
304304
305+ if (len != sizeof (* cp ))
306+ return cmd_status (sk , index , MGMT_OP_SET_POWERED , EINVAL );
307+
305308 hdev = hci_dev_get (index );
306309 if (!hdev )
307310 return cmd_status (sk , index , MGMT_OP_SET_POWERED , ENODEV );
@@ -351,6 +354,9 @@ static int set_discoverable(struct sock *sk, u16 index, unsigned char *data,
351354
352355 BT_DBG ("request for hci%u" , index );
353356
357+ if (len != sizeof (* cp ))
358+ return cmd_status (sk , index , MGMT_OP_SET_DISCOVERABLE , EINVAL );
359+
354360 hdev = hci_dev_get (index );
355361 if (!hdev )
356362 return cmd_status (sk , index , MGMT_OP_SET_DISCOVERABLE , ENODEV );
@@ -409,6 +415,9 @@ static int set_connectable(struct sock *sk, u16 index, unsigned char *data,
409415
410416 BT_DBG ("request for hci%u" , index );
411417
418+ if (len != sizeof (* cp ))
419+ return cmd_status (sk , index , MGMT_OP_SET_CONNECTABLE , EINVAL );
420+
412421 hdev = hci_dev_get (index );
413422 if (!hdev )
414423 return cmd_status (sk , index , MGMT_OP_SET_CONNECTABLE , ENODEV );
@@ -499,6 +508,9 @@ static int set_pairable(struct sock *sk, u16 index, unsigned char *data,
499508
500509 BT_DBG ("request for hci%u" , index );
501510
511+ if (len != sizeof (* cp ))
512+ return cmd_status (sk , index , MGMT_OP_SET_PAIRABLE , EINVAL );
513+
502514 hdev = hci_dev_get (index );
503515 if (!hdev )
504516 return cmd_status (sk , index , MGMT_OP_SET_PAIRABLE , ENODEV );
@@ -569,6 +581,9 @@ static int add_uuid(struct sock *sk, u16 index, unsigned char *data, u16 len)
569581
570582 BT_DBG ("request for hci%u" , index );
571583
584+ if (len != sizeof (* cp ))
585+ return cmd_status (sk , index , MGMT_OP_ADD_UUID , EINVAL );
586+
572587 hdev = hci_dev_get (index );
573588 if (!hdev )
574589 return cmd_status (sk , index , MGMT_OP_ADD_UUID , ENODEV );
@@ -611,6 +626,9 @@ static int remove_uuid(struct sock *sk, u16 index, unsigned char *data, u16 len)
611626
612627 BT_DBG ("request for hci%u" , index );
613628
629+ if (len != sizeof (* cp ))
630+ return cmd_status (sk , index , MGMT_OP_REMOVE_UUID , EINVAL );
631+
614632 hdev = hci_dev_get (index );
615633 if (!hdev )
616634 return cmd_status (sk , index , MGMT_OP_REMOVE_UUID , ENODEV );
@@ -663,6 +681,9 @@ static int set_dev_class(struct sock *sk, u16 index, unsigned char *data,
663681
664682 BT_DBG ("request for hci%u" , index );
665683
684+ if (len != sizeof (* cp ))
685+ return cmd_status (sk , index , MGMT_OP_SET_DEV_CLASS , EINVAL );
686+
666687 hdev = hci_dev_get (index );
667688 if (!hdev )
668689 return cmd_status (sk , index , MGMT_OP_SET_DEV_CLASS , ENODEV );
@@ -692,6 +713,10 @@ static int set_service_cache(struct sock *sk, u16 index, unsigned char *data,
692713
693714 cp = (void * ) data ;
694715
716+ if (len != sizeof (* cp ))
717+ return cmd_status (sk , index , MGMT_OP_SET_SERVICE_CACHE ,
718+ EINVAL );
719+
695720 hdev = hci_dev_get (index );
696721 if (!hdev )
697722 return cmd_status (sk , index , MGMT_OP_SET_SERVICE_CACHE , ENODEV );
@@ -726,6 +751,10 @@ static int load_keys(struct sock *sk, u16 index, unsigned char *data, u16 len)
726751 int i ;
727752
728753 cp = (void * ) data ;
754+
755+ if (len < sizeof (* cp ))
756+ return - EINVAL ;
757+
729758 key_count = get_unaligned_le16 (& cp -> key_count );
730759
731760 expected_len = sizeof (* cp ) + key_count * sizeof (struct mgmt_key_info );
@@ -775,6 +804,9 @@ static int remove_key(struct sock *sk, u16 index, unsigned char *data, u16 len)
775804
776805 cp = (void * ) data ;
777806
807+ if (len != sizeof (* cp ))
808+ return cmd_status (sk , index , MGMT_OP_REMOVE_KEY , EINVAL );
809+
778810 hdev = hci_dev_get (index );
779811 if (!hdev )
780812 return cmd_status (sk , index , MGMT_OP_REMOVE_KEY , ENODEV );
@@ -821,6 +853,9 @@ static int disconnect(struct sock *sk, u16 index, unsigned char *data, u16 len)
821853
822854 cp = (void * ) data ;
823855
856+ if (len != sizeof (* cp ))
857+ return cmd_status (sk , index , MGMT_OP_DISCONNECT , EINVAL );
858+
824859 hdev = hci_dev_get (index );
825860 if (!hdev )
826861 return cmd_status (sk , index , MGMT_OP_DISCONNECT , ENODEV );
@@ -931,6 +966,9 @@ static int pin_code_reply(struct sock *sk, u16 index, unsigned char *data,
931966
932967 cp = (void * ) data ;
933968
969+ if (len != sizeof (* cp ))
970+ return cmd_status (sk , index , MGMT_OP_PIN_CODE_REPLY , EINVAL );
971+
934972 hdev = hci_dev_get (index );
935973 if (!hdev )
936974 return cmd_status (sk , index , MGMT_OP_PIN_CODE_REPLY , ENODEV );
@@ -975,6 +1013,10 @@ static int pin_code_neg_reply(struct sock *sk, u16 index, unsigned char *data,
9751013
9761014 cp = (void * ) data ;
9771015
1016+ if (len != sizeof (* cp ))
1017+ return cmd_status (sk , index , MGMT_OP_PIN_CODE_NEG_REPLY ,
1018+ EINVAL );
1019+
9781020 hdev = hci_dev_get (index );
9791021 if (!hdev )
9801022 return cmd_status (sk , index , MGMT_OP_PIN_CODE_NEG_REPLY ,
@@ -1017,6 +1059,10 @@ static int set_io_capability(struct sock *sk, u16 index, unsigned char *data,
10171059
10181060 cp = (void * ) data ;
10191061
1062+ if (len != sizeof (* cp ))
1063+ return cmd_status (sk , index , MGMT_OP_SET_IO_CAPABILITY ,
1064+ EINVAL );
1065+
10201066 hdev = hci_dev_get (index );
10211067 if (!hdev )
10221068 return cmd_status (sk , index , MGMT_OP_SET_IO_CAPABILITY , ENODEV );
@@ -1107,6 +1153,9 @@ static int pair_device(struct sock *sk, u16 index, unsigned char *data, u16 len)
11071153
11081154 cp = (void * ) data ;
11091155
1156+ if (len != sizeof (* cp ))
1157+ return cmd_status (sk , index , MGMT_OP_PAIR_DEVICE , EINVAL );
1158+
11101159 hdev = hci_dev_get (index );
11111160 if (!hdev )
11121161 return cmd_status (sk , index , MGMT_OP_PAIR_DEVICE , ENODEV );
@@ -1178,6 +1227,9 @@ static int user_confirm_reply(struct sock *sk, u16 index, unsigned char *data,
11781227 hci_op = HCI_OP_USER_CONFIRM_NEG_REPLY ;
11791228 }
11801229
1230+ if (len != sizeof (* cp ))
1231+ return cmd_status (sk , index , mgmt_op , EINVAL );
1232+
11811233 hdev = hci_dev_get (index );
11821234 if (!hdev )
11831235 return cmd_status (sk , index , mgmt_op , ENODEV );
0 commit comments