hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * ioctl32.c: Conversion between 32bit and 64bit native ioctls.
34 * Separated from fs stuff by Arnd Bergmann <arnd@arndb.de>
....@@ -158,7 +159,7 @@
158159 compat_caddr_t p;
159160 u32 clipcount;
160161
161
- if (!access_ok(VERIFY_READ, p32, sizeof(*p32)) ||
162
+ if (!access_ok(p32, sizeof(*p32)) ||
162163 copy_in_user(&p64->w, &p32->w, sizeof(p32->w)) ||
163164 assign_in_user(&p64->field, &p32->field) ||
164165 assign_in_user(&p64->chromakey, &p32->chromakey) ||
....@@ -244,6 +245,7 @@
244245 * return: number of created buffers
245246 * @memory: buffer memory type
246247 * @format: frame format, for which buffers are requested
248
+ * @capabilities: capabilities of this buffer type.
247249 * @reserved: future extensions
248250 */
249251 struct v4l2_create_buffers32 {
....@@ -251,7 +253,8 @@
251253 __u32 count;
252254 __u32 memory; /* enum v4l2_memory */
253255 struct v4l2_format32 format;
254
- __u32 reserved[8];
256
+ __u32 capabilities;
257
+ __u32 reserved[7];
255258 };
256259
257260 static int __bufsize_v4l2_format(struct v4l2_format32 __user *p32, u32 *size)
....@@ -281,7 +284,7 @@
281284
282285 static int bufsize_v4l2_format(struct v4l2_format32 __user *p32, u32 *size)
283286 {
284
- if (!access_ok(VERIFY_READ, p32, sizeof(*p32)))
287
+ if (!access_ok(p32, sizeof(*p32)))
285288 return -EFAULT;
286289 return __bufsize_v4l2_format(p32, size);
287290 }
....@@ -333,7 +336,7 @@
333336 struct v4l2_format32 __user *p32,
334337 void __user *aux_buf, u32 aux_space)
335338 {
336
- if (!access_ok(VERIFY_READ, p32, sizeof(*p32)))
339
+ if (!access_ok(p32, sizeof(*p32)))
337340 return -EFAULT;
338341 return __get_v4l2_format32(p64, p32, aux_buf, aux_space);
339342 }
....@@ -341,7 +344,7 @@
341344 static int bufsize_v4l2_create(struct v4l2_create_buffers32 __user *p32,
342345 u32 *size)
343346 {
344
- if (!access_ok(VERIFY_READ, p32, sizeof(*p32)))
347
+ if (!access_ok(p32, sizeof(*p32)))
345348 return -EFAULT;
346349 return __bufsize_v4l2_format(&p32->format, size);
347350 }
....@@ -350,7 +353,7 @@
350353 struct v4l2_create_buffers32 __user *p32,
351354 void __user *aux_buf, u32 aux_space)
352355 {
353
- if (!access_ok(VERIFY_READ, p32, sizeof(*p32)) ||
356
+ if (!access_ok(p32, sizeof(*p32)) ||
354357 copy_in_user(p64, p32,
355358 offsetof(struct v4l2_create_buffers32, format)))
356359 return -EFAULT;
....@@ -402,7 +405,7 @@
402405 static int put_v4l2_format32(struct v4l2_format __user *p64,
403406 struct v4l2_format32 __user *p32)
404407 {
405
- if (!access_ok(VERIFY_WRITE, p32, sizeof(*p32)))
408
+ if (!access_ok(p32, sizeof(*p32)))
406409 return -EFAULT;
407410 return __put_v4l2_format32(p64, p32);
408411 }
....@@ -410,9 +413,10 @@
410413 static int put_v4l2_create32(struct v4l2_create_buffers __user *p64,
411414 struct v4l2_create_buffers32 __user *p32)
412415 {
413
- if (!access_ok(VERIFY_WRITE, p32, sizeof(*p32)) ||
416
+ if (!access_ok(p32, sizeof(*p32)) ||
414417 copy_in_user(p32, p64,
415418 offsetof(struct v4l2_create_buffers32, format)) ||
419
+ assign_in_user(&p32->capabilities, &p64->capabilities) ||
416420 copy_in_user(p32->reserved, p64->reserved, sizeof(p64->reserved)))
417421 return -EFAULT;
418422 return __put_v4l2_format32(&p64->format, &p32->format);
....@@ -431,7 +435,7 @@
431435 struct v4l2_standard32 __user *p32)
432436 {
433437 /* other fields are not set by the user, nor used by the driver */
434
- if (!access_ok(VERIFY_READ, p32, sizeof(*p32)) ||
438
+ if (!access_ok(p32, sizeof(*p32)) ||
435439 assign_in_user(&p64->index, &p32->index))
436440 return -EFAULT;
437441 return 0;
....@@ -440,7 +444,7 @@
440444 static int put_v4l2_standard32(struct v4l2_standard __user *p64,
441445 struct v4l2_standard32 __user *p32)
442446 {
443
- if (!access_ok(VERIFY_WRITE, p32, sizeof(*p32)) ||
447
+ if (!access_ok(p32, sizeof(*p32)) ||
444448 assign_in_user(&p32->index, &p64->index) ||
445449 assign_in_user(&p32->id, &p64->id) ||
446450 copy_in_user(p32->name, p64->name, sizeof(p32->name)) ||
....@@ -461,16 +465,28 @@
461465 __s32 fd;
462466 } m;
463467 __u32 data_offset;
468
+ /*
469
+ * few userspace clients and drivers use reserved fields
470
+ * and it is up to them how these fields are used. v4l2
471
+ * simply copy reserved fields between them.
472
+ */
464473 __u32 reserved[11];
465474 };
466475
476
+/*
477
+ * This is correct for all architectures including i386, but not x32,
478
+ * which has different alignment requirements for timestamp
479
+ */
467480 struct v4l2_buffer32 {
468481 __u32 index;
469482 __u32 type; /* enum v4l2_buf_type */
470483 __u32 bytesused;
471484 __u32 flags;
472485 __u32 field; /* enum v4l2_field */
473
- struct compat_timeval timestamp;
486
+ struct {
487
+ compat_s64 tv_sec;
488
+ compat_s64 tv_usec;
489
+ } timestamp;
474490 struct v4l2_timecode timecode;
475491 __u32 sequence;
476492
....@@ -484,7 +500,30 @@
484500 } m;
485501 __u32 length;
486502 __u32 reserved2;
487
- __u32 reserved;
503
+ __s32 request_fd;
504
+};
505
+
506
+struct v4l2_buffer32_time32 {
507
+ __u32 index;
508
+ __u32 type; /* enum v4l2_buf_type */
509
+ __u32 bytesused;
510
+ __u32 flags;
511
+ __u32 field; /* enum v4l2_field */
512
+ struct old_timeval32 timestamp;
513
+ struct v4l2_timecode timecode;
514
+ __u32 sequence;
515
+
516
+ /* memory location */
517
+ __u32 memory; /* enum v4l2_memory */
518
+ union {
519
+ __u32 offset;
520
+ compat_long_t userptr;
521
+ compat_caddr_t planes;
522
+ __s32 fd;
523
+ } m;
524
+ __u32 length;
525
+ __u32 reserved2;
526
+ __s32 request_fd;
488527 };
489528
490529 static int get_v4l2_plane32(struct v4l2_plane __user *p64,
....@@ -495,7 +534,9 @@
495534
496535 if (copy_in_user(p64, p32, 2 * sizeof(__u32)) ||
497536 copy_in_user(&p64->data_offset, &p32->data_offset,
498
- sizeof(p64->data_offset)))
537
+ sizeof(p64->data_offset)) ||
538
+ copy_in_user(p64->reserved, p32->reserved,
539
+ sizeof(p64->reserved)))
499540 return -EFAULT;
500541
501542 switch (memory) {
....@@ -527,7 +568,9 @@
527568
528569 if (copy_in_user(p32, p64, 2 * sizeof(__u32)) ||
529570 copy_in_user(&p32->data_offset, &p64->data_offset,
530
- sizeof(p64->data_offset)))
571
+ sizeof(p64->data_offset)) ||
572
+ copy_in_user(p32->reserved, p64->reserved,
573
+ sizeof(p32->reserved)))
531574 return -EFAULT;
532575
533576 switch (memory) {
....@@ -557,7 +600,32 @@
557600 u32 type;
558601 u32 length;
559602
560
- if (!access_ok(VERIFY_READ, p32, sizeof(*p32)) ||
603
+ if (!access_ok(p32, sizeof(*p32)) ||
604
+ get_user(type, &p32->type) ||
605
+ get_user(length, &p32->length))
606
+ return -EFAULT;
607
+
608
+ if (V4L2_TYPE_IS_MULTIPLANAR(type)) {
609
+ if (length > VIDEO_MAX_PLANES)
610
+ return -EINVAL;
611
+
612
+ /*
613
+ * We don't really care if userspace decides to kill itself
614
+ * by passing a very big length value
615
+ */
616
+ *size = length * sizeof(struct v4l2_plane);
617
+ } else {
618
+ *size = 0;
619
+ }
620
+ return 0;
621
+}
622
+
623
+static int bufsize_v4l2_buffer_time32(struct v4l2_buffer32_time32 __user *p32, u32 *size)
624
+{
625
+ u32 type;
626
+ u32 length;
627
+
628
+ if (!access_ok(p32, sizeof(*p32)) ||
561629 get_user(type, &p32->type) ||
562630 get_user(length, &p32->length))
563631 return -EFAULT;
....@@ -583,13 +651,14 @@
583651 {
584652 u32 type;
585653 u32 length;
654
+ s32 request_fd;
586655 enum v4l2_memory memory;
587656 struct v4l2_plane32 __user *uplane32;
588657 struct v4l2_plane __user *uplane;
589658 compat_caddr_t p;
590659 int ret;
591660
592
- if (!access_ok(VERIFY_READ, p32, sizeof(*p32)) ||
661
+ if (!access_ok(p32, sizeof(*p32)) ||
593662 assign_in_user(&p64->index, &p32->index) ||
594663 get_user(type, &p32->type) ||
595664 put_user(type, &p64->type) ||
....@@ -597,7 +666,9 @@
597666 get_user(memory, &p32->memory) ||
598667 put_user(memory, &p64->memory) ||
599668 get_user(length, &p32->length) ||
600
- put_user(length, &p64->length))
669
+ put_user(length, &p64->length) ||
670
+ get_user(request_fd, &p32->request_fd) ||
671
+ put_user(request_fd, &p64->request_fd))
601672 return -EFAULT;
602673
603674 if (V4L2_TYPE_IS_OUTPUT(type))
....@@ -626,7 +697,107 @@
626697 return -EFAULT;
627698
628699 uplane32 = compat_ptr(p);
629
- if (!access_ok(VERIFY_READ, uplane32,
700
+ if (!access_ok(uplane32,
701
+ num_planes * sizeof(*uplane32)))
702
+ return -EFAULT;
703
+
704
+ /*
705
+ * We don't really care if userspace decides to kill itself
706
+ * by passing a very big num_planes value
707
+ */
708
+ if (aux_space < num_planes * sizeof(*uplane))
709
+ return -EFAULT;
710
+
711
+ uplane = aux_buf;
712
+ if (put_user_force(uplane, &p64->m.planes))
713
+ return -EFAULT;
714
+
715
+ while (num_planes--) {
716
+ ret = get_v4l2_plane32(uplane, uplane32, memory);
717
+ if (ret)
718
+ return ret;
719
+ uplane++;
720
+ uplane32++;
721
+ }
722
+ } else {
723
+ switch (memory) {
724
+ case V4L2_MEMORY_MMAP:
725
+ case V4L2_MEMORY_OVERLAY:
726
+ if (assign_in_user(&p64->m.offset, &p32->m.offset))
727
+ return -EFAULT;
728
+ break;
729
+ case V4L2_MEMORY_USERPTR: {
730
+ compat_ulong_t userptr;
731
+
732
+ if (get_user(userptr, &p32->m.userptr) ||
733
+ put_user((unsigned long)compat_ptr(userptr),
734
+ &p64->m.userptr))
735
+ return -EFAULT;
736
+ break;
737
+ }
738
+ case V4L2_MEMORY_DMABUF:
739
+ if (assign_in_user(&p64->m.fd, &p32->m.fd))
740
+ return -EFAULT;
741
+ break;
742
+ }
743
+ }
744
+
745
+ return 0;
746
+}
747
+
748
+static int get_v4l2_buffer32_time32(struct v4l2_buffer_time32 __user *p64,
749
+ struct v4l2_buffer32_time32 __user *p32,
750
+ void __user *aux_buf, u32 aux_space)
751
+{
752
+ u32 type;
753
+ u32 length;
754
+ s32 request_fd;
755
+ enum v4l2_memory memory;
756
+ struct v4l2_plane32 __user *uplane32;
757
+ struct v4l2_plane __user *uplane;
758
+ compat_caddr_t p;
759
+ int ret;
760
+
761
+ if (!access_ok(p32, sizeof(*p32)) ||
762
+ assign_in_user(&p64->index, &p32->index) ||
763
+ get_user(type, &p32->type) ||
764
+ put_user(type, &p64->type) ||
765
+ assign_in_user(&p64->flags, &p32->flags) ||
766
+ get_user(memory, &p32->memory) ||
767
+ put_user(memory, &p64->memory) ||
768
+ get_user(length, &p32->length) ||
769
+ put_user(length, &p64->length) ||
770
+ get_user(request_fd, &p32->request_fd) ||
771
+ put_user(request_fd, &p64->request_fd))
772
+ return -EFAULT;
773
+
774
+ if (V4L2_TYPE_IS_OUTPUT(type))
775
+ if (assign_in_user(&p64->bytesused, &p32->bytesused) ||
776
+ assign_in_user(&p64->field, &p32->field) ||
777
+ assign_in_user(&p64->timestamp.tv_sec,
778
+ &p32->timestamp.tv_sec) ||
779
+ assign_in_user(&p64->timestamp.tv_usec,
780
+ &p32->timestamp.tv_usec))
781
+ return -EFAULT;
782
+
783
+ if (V4L2_TYPE_IS_MULTIPLANAR(type)) {
784
+ u32 num_planes = length;
785
+
786
+ if (num_planes == 0) {
787
+ /*
788
+ * num_planes == 0 is legal, e.g. when userspace doesn't
789
+ * need planes array on DQBUF
790
+ */
791
+ return put_user(NULL, &p64->m.planes);
792
+ }
793
+ if (num_planes > VIDEO_MAX_PLANES)
794
+ return -EINVAL;
795
+
796
+ if (get_user(p, &p32->m.planes))
797
+ return -EFAULT;
798
+
799
+ uplane32 = compat_ptr(p);
800
+ if (!access_ok(uplane32,
630801 num_planes * sizeof(*uplane32)))
631802 return -EFAULT;
632803
....@@ -685,7 +856,7 @@
685856 compat_caddr_t p;
686857 int ret;
687858
688
- if (!access_ok(VERIFY_WRITE, p32, sizeof(*p32)) ||
859
+ if (!access_ok(p32, sizeof(*p32)) ||
689860 assign_in_user(&p32->index, &p64->index) ||
690861 get_user(type, &p64->type) ||
691862 put_user(type, &p32->type) ||
....@@ -701,7 +872,87 @@
701872 copy_in_user(&p32->timecode, &p64->timecode, sizeof(p64->timecode)) ||
702873 assign_in_user(&p32->sequence, &p64->sequence) ||
703874 assign_in_user(&p32->reserved2, &p64->reserved2) ||
704
- assign_in_user(&p32->reserved, &p64->reserved) ||
875
+ assign_in_user(&p32->request_fd, &p64->request_fd) ||
876
+ get_user(length, &p64->length) ||
877
+ put_user(length, &p32->length))
878
+ return -EFAULT;
879
+
880
+ if (V4L2_TYPE_IS_MULTIPLANAR(type)) {
881
+ u32 num_planes = length;
882
+
883
+ if (num_planes == 0)
884
+ return 0;
885
+ /* We need to define uplane without __user, even though
886
+ * it does point to data in userspace here. The reason is
887
+ * that v4l2-ioctl.c copies it from userspace to kernelspace,
888
+ * so its definition in videodev2.h doesn't have a
889
+ * __user markup. Defining uplane with __user causes
890
+ * smatch warnings, so instead declare it without __user
891
+ * and cast it as a userspace pointer to put_v4l2_plane32().
892
+ */
893
+ if (get_user(uplane, &p64->m.planes))
894
+ return -EFAULT;
895
+ if (get_user(p, &p32->m.planes))
896
+ return -EFAULT;
897
+ uplane32 = compat_ptr(p);
898
+
899
+ while (num_planes--) {
900
+ ret = put_v4l2_plane32((void __user *)uplane,
901
+ uplane32, memory);
902
+ if (ret)
903
+ return ret;
904
+ ++uplane;
905
+ ++uplane32;
906
+ }
907
+ } else {
908
+ switch (memory) {
909
+ case V4L2_MEMORY_MMAP:
910
+ case V4L2_MEMORY_OVERLAY:
911
+ if (assign_in_user(&p32->m.offset, &p64->m.offset))
912
+ return -EFAULT;
913
+ break;
914
+ case V4L2_MEMORY_USERPTR:
915
+ if (assign_in_user(&p32->m.userptr, &p64->m.userptr))
916
+ return -EFAULT;
917
+ break;
918
+ case V4L2_MEMORY_DMABUF:
919
+ if (assign_in_user(&p32->m.fd, &p64->m.fd))
920
+ return -EFAULT;
921
+ break;
922
+ }
923
+ }
924
+
925
+ return 0;
926
+}
927
+
928
+static int put_v4l2_buffer32_time32(struct v4l2_buffer_time32 __user *p64,
929
+ struct v4l2_buffer32_time32 __user *p32)
930
+{
931
+ u32 type;
932
+ u32 length;
933
+ enum v4l2_memory memory;
934
+ struct v4l2_plane32 __user *uplane32;
935
+ struct v4l2_plane *uplane;
936
+ compat_caddr_t p;
937
+ int ret;
938
+
939
+ if (!access_ok(p32, sizeof(*p32)) ||
940
+ assign_in_user(&p32->index, &p64->index) ||
941
+ get_user(type, &p64->type) ||
942
+ put_user(type, &p32->type) ||
943
+ assign_in_user(&p32->flags, &p64->flags) ||
944
+ get_user(memory, &p64->memory) ||
945
+ put_user(memory, &p32->memory))
946
+ return -EFAULT;
947
+
948
+ if (assign_in_user(&p32->bytesused, &p64->bytesused) ||
949
+ assign_in_user(&p32->field, &p64->field) ||
950
+ assign_in_user(&p32->timestamp.tv_sec, &p64->timestamp.tv_sec) ||
951
+ assign_in_user(&p32->timestamp.tv_usec, &p64->timestamp.tv_usec) ||
952
+ copy_in_user(&p32->timecode, &p64->timecode, sizeof(p64->timecode)) ||
953
+ assign_in_user(&p32->sequence, &p64->sequence) ||
954
+ assign_in_user(&p32->reserved2, &p64->reserved2) ||
955
+ assign_in_user(&p32->request_fd, &p64->request_fd) ||
705956 get_user(length, &p64->length) ||
706957 put_user(length, &p32->length))
707958 return -EFAULT;
....@@ -775,7 +1026,7 @@
7751026 {
7761027 compat_caddr_t tmp;
7771028
778
- if (!access_ok(VERIFY_READ, p32, sizeof(*p32)) ||
1029
+ if (!access_ok(p32, sizeof(*p32)) ||
7791030 get_user(tmp, &p32->base) ||
7801031 put_user_force(compat_ptr(tmp), &p64->base) ||
7811032 assign_in_user(&p64->capability, &p32->capability) ||
....@@ -790,7 +1041,7 @@
7901041 {
7911042 void *base;
7921043
793
- if (!access_ok(VERIFY_WRITE, p32, sizeof(*p32)) ||
1044
+ if (!access_ok(p32, sizeof(*p32)) ||
7941045 get_user(base, &p64->base) ||
7951046 put_user(ptr_to_compat((void __user *)base), &p32->base) ||
7961047 assign_in_user(&p32->capability, &p64->capability) ||
....@@ -836,7 +1087,8 @@
8361087 __u32 which;
8371088 __u32 count;
8381089 __u32 error_idx;
839
- __u32 reserved[2];
1090
+ __s32 request_fd;
1091
+ __u32 reserved[1];
8401092 compat_caddr_t controls; /* actually struct v4l2_ext_control32 * */
8411093 };
8421094
....@@ -886,7 +1138,7 @@
8861138 {
8871139 u32 count;
8881140
889
- if (!access_ok(VERIFY_READ, p32, sizeof(*p32)) ||
1141
+ if (!access_ok(p32, sizeof(*p32)) ||
8901142 get_user(count, &p32->count))
8911143 return -EFAULT;
8921144 if (count > V4L2_CID_MAX_CTRLS)
....@@ -906,11 +1158,12 @@
9061158 u32 n;
9071159 compat_caddr_t p;
9081160
909
- if (!access_ok(VERIFY_READ, p32, sizeof(*p32)) ||
1161
+ if (!access_ok(p32, sizeof(*p32)) ||
9101162 assign_in_user(&p64->which, &p32->which) ||
9111163 get_user(count, &p32->count) ||
9121164 put_user(count, &p64->count) ||
9131165 assign_in_user(&p64->error_idx, &p32->error_idx) ||
1166
+ assign_in_user(&p64->request_fd, &p32->request_fd) ||
9141167 copy_in_user(p64->reserved, p32->reserved, sizeof(p64->reserved)))
9151168 return -EFAULT;
9161169
....@@ -921,7 +1174,7 @@
9211174 if (get_user(p, &p32->controls))
9221175 return -EFAULT;
9231176 ucontrols = compat_ptr(p);
924
- if (!access_ok(VERIFY_READ, ucontrols, count * sizeof(*ucontrols)))
1177
+ if (!access_ok(ucontrols, count * sizeof(*ucontrols)))
9251178 return -EFAULT;
9261179 if (aux_space < count * sizeof(*kcontrols))
9271180 return -EFAULT;
....@@ -971,11 +1224,12 @@
9711224 * with __user causes smatch warnings, so instead declare it
9721225 * without __user and cast it as a userspace pointer where needed.
9731226 */
974
- if (!access_ok(VERIFY_WRITE, p32, sizeof(*p32)) ||
1227
+ if (!access_ok(p32, sizeof(*p32)) ||
9751228 assign_in_user(&p32->which, &p64->which) ||
9761229 get_user(count, &p64->count) ||
9771230 put_user(count, &p32->count) ||
9781231 assign_in_user(&p32->error_idx, &p64->error_idx) ||
1232
+ assign_in_user(&p32->request_fd, &p64->request_fd) ||
9791233 copy_in_user(p32->reserved, p64->reserved, sizeof(p32->reserved)) ||
9801234 get_user(kcontrols, &p64->controls))
9811235 return -EFAULT;
....@@ -985,7 +1239,7 @@
9851239 if (get_user(p, &p32->controls))
9861240 return -EFAULT;
9871241 ucontrols = compat_ptr(p);
988
- if (!access_ok(VERIFY_WRITE, ucontrols, count * sizeof(*ucontrols)))
1242
+ if (!access_ok(ucontrols, count * sizeof(*ucontrols)))
9891243 return -EFAULT;
9901244
9911245 for (n = 0; n < count; n++) {
....@@ -1018,6 +1272,15 @@
10181272 return 0;
10191273 }
10201274
1275
+#ifdef CONFIG_X86_64
1276
+/*
1277
+ * x86 is the only compat architecture with different struct alignment
1278
+ * between 32-bit and 64-bit tasks.
1279
+ *
1280
+ * On all other architectures, v4l2_event32 and v4l2_event32_time32 are
1281
+ * the same as v4l2_event and v4l2_event_time32, so we can use the native
1282
+ * handlers, converting v4l2_event to v4l2_event_time32 if necessary.
1283
+ */
10211284 struct v4l2_event32 {
10221285 __u32 type;
10231286 union {
....@@ -1026,7 +1289,23 @@
10261289 } u;
10271290 __u32 pending;
10281291 __u32 sequence;
1029
- struct compat_timespec timestamp;
1292
+ struct {
1293
+ compat_s64 tv_sec;
1294
+ compat_s64 tv_nsec;
1295
+ } timestamp;
1296
+ __u32 id;
1297
+ __u32 reserved[8];
1298
+};
1299
+
1300
+struct v4l2_event32_time32 {
1301
+ __u32 type;
1302
+ union {
1303
+ compat_s64 value64;
1304
+ __u8 data[64];
1305
+ } u;
1306
+ __u32 pending;
1307
+ __u32 sequence;
1308
+ struct old_timespec32 timestamp;
10301309 __u32 id;
10311310 __u32 reserved[8];
10321311 };
....@@ -1034,7 +1313,7 @@
10341313 static int put_v4l2_event32(struct v4l2_event __user *p64,
10351314 struct v4l2_event32 __user *p32)
10361315 {
1037
- if (!access_ok(VERIFY_WRITE, p32, sizeof(*p32)) ||
1316
+ if (!access_ok(p32, sizeof(*p32)) ||
10381317 assign_in_user(&p32->type, &p64->type) ||
10391318 copy_in_user(&p32->u, &p64->u, sizeof(p64->u)) ||
10401319 assign_in_user(&p32->pending, &p64->pending) ||
....@@ -1046,6 +1325,23 @@
10461325 return -EFAULT;
10471326 return 0;
10481327 }
1328
+
1329
+static int put_v4l2_event32_time32(struct v4l2_event_time32 __user *p64,
1330
+ struct v4l2_event32_time32 __user *p32)
1331
+{
1332
+ if (!access_ok(p32, sizeof(*p32)) ||
1333
+ assign_in_user(&p32->type, &p64->type) ||
1334
+ copy_in_user(&p32->u, &p64->u, sizeof(p64->u)) ||
1335
+ assign_in_user(&p32->pending, &p64->pending) ||
1336
+ assign_in_user(&p32->sequence, &p64->sequence) ||
1337
+ assign_in_user(&p32->timestamp.tv_sec, &p64->timestamp.tv_sec) ||
1338
+ assign_in_user(&p32->timestamp.tv_nsec, &p64->timestamp.tv_nsec) ||
1339
+ assign_in_user(&p32->id, &p64->id) ||
1340
+ copy_in_user(p32->reserved, p64->reserved, sizeof(p32->reserved)))
1341
+ return -EFAULT;
1342
+ return 0;
1343
+}
1344
+#endif
10491345
10501346 struct v4l2_edid32 {
10511347 __u32 pad;
....@@ -1060,7 +1356,7 @@
10601356 {
10611357 compat_uptr_t tmp;
10621358
1063
- if (!access_ok(VERIFY_READ, p32, sizeof(*p32)) ||
1359
+ if (!access_ok(p32, sizeof(*p32)) ||
10641360 assign_in_user(&p64->pad, &p32->pad) ||
10651361 assign_in_user(&p64->start_block, &p32->start_block) ||
10661362 assign_in_user_cast(&p64->blocks, &p32->blocks) ||
....@@ -1076,7 +1372,7 @@
10761372 {
10771373 void *edid;
10781374
1079
- if (!access_ok(VERIFY_WRITE, p32, sizeof(*p32)) ||
1375
+ if (!access_ok(p32, sizeof(*p32)) ||
10801376 assign_in_user(&p32->pad, &p64->pad) ||
10811377 assign_in_user(&p32->start_block, &p64->start_block) ||
10821378 assign_in_user(&p32->blocks, &p64->blocks) ||
....@@ -1098,10 +1394,13 @@
10981394 #define VIDIOC_G_FMT32 _IOWR('V', 4, struct v4l2_format32)
10991395 #define VIDIOC_S_FMT32 _IOWR('V', 5, struct v4l2_format32)
11001396 #define VIDIOC_QUERYBUF32 _IOWR('V', 9, struct v4l2_buffer32)
1397
+#define VIDIOC_QUERYBUF32_TIME32 _IOWR('V', 9, struct v4l2_buffer32_time32)
11011398 #define VIDIOC_G_FBUF32 _IOR ('V', 10, struct v4l2_framebuffer32)
11021399 #define VIDIOC_S_FBUF32 _IOW ('V', 11, struct v4l2_framebuffer32)
11031400 #define VIDIOC_QBUF32 _IOWR('V', 15, struct v4l2_buffer32)
1401
+#define VIDIOC_QBUF32_TIME32 _IOWR('V', 15, struct v4l2_buffer32_time32)
11041402 #define VIDIOC_DQBUF32 _IOWR('V', 17, struct v4l2_buffer32)
1403
+#define VIDIOC_DQBUF32_TIME32 _IOWR('V', 17, struct v4l2_buffer32_time32)
11051404 #define VIDIOC_ENUMSTD32 _IOWR('V', 25, struct v4l2_standard32)
11061405 #define VIDIOC_ENUMINPUT32 _IOWR('V', 26, struct v4l2_input32)
11071406 #define VIDIOC_G_EDID32 _IOWR('V', 40, struct v4l2_edid32)
....@@ -1111,8 +1410,10 @@
11111410 #define VIDIOC_S_EXT_CTRLS32 _IOWR('V', 72, struct v4l2_ext_controls32)
11121411 #define VIDIOC_TRY_EXT_CTRLS32 _IOWR('V', 73, struct v4l2_ext_controls32)
11131412 #define VIDIOC_DQEVENT32 _IOR ('V', 89, struct v4l2_event32)
1413
+#define VIDIOC_DQEVENT32_TIME32 _IOR ('V', 89, struct v4l2_event32_time32)
11141414 #define VIDIOC_CREATE_BUFS32 _IOWR('V', 92, struct v4l2_create_buffers32)
11151415 #define VIDIOC_PREPARE_BUF32 _IOWR('V', 93, struct v4l2_buffer32)
1416
+#define VIDIOC_PREPARE_BUF32_TIME32 _IOWR('V', 93, struct v4l2_buffer32_time32)
11161417
11171418 #define VIDIOC_OVERLAY32 _IOW ('V', 14, s32)
11181419 #define VIDIOC_STREAMON32 _IOW ('V', 18, s32)
....@@ -1182,17 +1483,23 @@
11821483 case VIDIOC_G_FMT32: ncmd = VIDIOC_G_FMT; break;
11831484 case VIDIOC_S_FMT32: ncmd = VIDIOC_S_FMT; break;
11841485 case VIDIOC_QUERYBUF32: ncmd = VIDIOC_QUERYBUF; break;
1486
+ case VIDIOC_QUERYBUF32_TIME32: ncmd = VIDIOC_QUERYBUF_TIME32; break;
11851487 case VIDIOC_G_FBUF32: ncmd = VIDIOC_G_FBUF; break;
11861488 case VIDIOC_S_FBUF32: ncmd = VIDIOC_S_FBUF; break;
11871489 case VIDIOC_QBUF32: ncmd = VIDIOC_QBUF; break;
1490
+ case VIDIOC_QBUF32_TIME32: ncmd = VIDIOC_QBUF_TIME32; break;
11881491 case VIDIOC_DQBUF32: ncmd = VIDIOC_DQBUF; break;
1492
+ case VIDIOC_DQBUF32_TIME32: ncmd = VIDIOC_DQBUF_TIME32; break;
11891493 case VIDIOC_ENUMSTD32: ncmd = VIDIOC_ENUMSTD; break;
11901494 case VIDIOC_ENUMINPUT32: ncmd = VIDIOC_ENUMINPUT; break;
11911495 case VIDIOC_TRY_FMT32: ncmd = VIDIOC_TRY_FMT; break;
11921496 case VIDIOC_G_EXT_CTRLS32: ncmd = VIDIOC_G_EXT_CTRLS; break;
11931497 case VIDIOC_S_EXT_CTRLS32: ncmd = VIDIOC_S_EXT_CTRLS; break;
11941498 case VIDIOC_TRY_EXT_CTRLS32: ncmd = VIDIOC_TRY_EXT_CTRLS; break;
1499
+#ifdef CONFIG_X86_64
11951500 case VIDIOC_DQEVENT32: ncmd = VIDIOC_DQEVENT; break;
1501
+ case VIDIOC_DQEVENT32_TIME32: ncmd = VIDIOC_DQEVENT_TIME32; break;
1502
+#endif
11961503 case VIDIOC_OVERLAY32: ncmd = VIDIOC_OVERLAY; break;
11971504 case VIDIOC_STREAMON32: ncmd = VIDIOC_STREAMON; break;
11981505 case VIDIOC_STREAMOFF32: ncmd = VIDIOC_STREAMOFF; break;
....@@ -1202,6 +1509,7 @@
12021509 case VIDIOC_S_OUTPUT32: ncmd = VIDIOC_S_OUTPUT; break;
12031510 case VIDIOC_CREATE_BUFS32: ncmd = VIDIOC_CREATE_BUFS; break;
12041511 case VIDIOC_PREPARE_BUF32: ncmd = VIDIOC_PREPARE_BUF; break;
1512
+ case VIDIOC_PREPARE_BUF32_TIME32: ncmd = VIDIOC_PREPARE_BUF_TIME32; break;
12051513 case VIDIOC_G_EDID32: ncmd = VIDIOC_G_EDID; break;
12061514 case VIDIOC_S_EDID32: ncmd = VIDIOC_S_EDID; break;
12071515 default: ncmd = cmd; break;
....@@ -1283,6 +1591,22 @@
12831591 compatible_arg = 0;
12841592 break;
12851593
1594
+ case VIDIOC_PREPARE_BUF32_TIME32:
1595
+ case VIDIOC_QUERYBUF32_TIME32:
1596
+ case VIDIOC_QBUF32_TIME32:
1597
+ case VIDIOC_DQBUF32_TIME32:
1598
+ err = bufsize_v4l2_buffer_time32(p32, &aux_space);
1599
+ if (!err)
1600
+ err = alloc_userspace(sizeof(struct v4l2_buffer),
1601
+ aux_space, &new_p64);
1602
+ if (!err) {
1603
+ aux_buf = new_p64 + sizeof(struct v4l2_buffer);
1604
+ err = get_v4l2_buffer32_time32(new_p64, p32,
1605
+ aux_buf, aux_space);
1606
+ }
1607
+ compatible_arg = 0;
1608
+ break;
1609
+
12861610 case VIDIOC_S_FBUF32:
12871611 err = alloc_userspace(sizeof(struct v4l2_framebuffer), 0,
12881612 &new_p64);
....@@ -1326,10 +1650,16 @@
13261650 }
13271651 compatible_arg = 0;
13281652 break;
1653
+#ifdef CONFIG_X86_64
13291654 case VIDIOC_DQEVENT32:
13301655 err = alloc_userspace(sizeof(struct v4l2_event), 0, &new_p64);
13311656 compatible_arg = 0;
13321657 break;
1658
+ case VIDIOC_DQEVENT32_TIME32:
1659
+ err = alloc_userspace(sizeof(struct v4l2_event_time32), 0, &new_p64);
1660
+ compatible_arg = 0;
1661
+ break;
1662
+#endif
13331663 }
13341664 if (err)
13351665 return err;
....@@ -1394,9 +1724,15 @@
13941724 err = put_v4l2_framebuffer32(new_p64, p32);
13951725 break;
13961726
1727
+#ifdef CONFIG_X86_64
13971728 case VIDIOC_DQEVENT32:
13981729 err = put_v4l2_event32(new_p64, p32);
13991730 break;
1731
+
1732
+ case VIDIOC_DQEVENT32_TIME32:
1733
+ err = put_v4l2_event32_time32(new_p64, p32);
1734
+ break;
1735
+#endif
14001736
14011737 case VIDIOC_G_EDID32:
14021738 err = put_v4l2_edid32(new_p64, p32);
....@@ -1419,6 +1755,13 @@
14191755 err = put_v4l2_buffer32(new_p64, p32);
14201756 break;
14211757
1758
+ case VIDIOC_PREPARE_BUF32_TIME32:
1759
+ case VIDIOC_QUERYBUF32_TIME32:
1760
+ case VIDIOC_QBUF32_TIME32:
1761
+ case VIDIOC_DQBUF32_TIME32:
1762
+ err = put_v4l2_buffer32_time32(new_p64, p32);
1763
+ break;
1764
+
14221765 case VIDIOC_ENUMSTD32:
14231766 err = put_v4l2_standard32(new_p64, p32);
14241767 break;