4.14.20-stable review
Subsystems (3)
Greg Kroah-Hartman
maintainerPATCH 124/195 media: v4l2-compat-ioctl32.c: move helper functions to __get/put_v4l2_format32
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans Verkuil <[email protected]>
commit 486c521510c44a04cd756a9267e7d1e271c8a4ba upstream.
These helper functions do not really help. Move the code to the __get/put_v4l2_format32 functions.
--- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 124 +++++--------------------- 1 file changed, 24 insertions(+), 100 deletions(-)
drivers/media/v4l2-core/v4l2-compat-ioctl32.c +24 -100
@@ -92,92 +92,6 @@ static int put_v4l2_window32(struct v4l2return 0 ; } -static inline int get_v4l2_pix_format (struct v4l2_pix_format *kp,struct v4l2_pix_format __user *up) -{ -if (copy_from_user (kp, up,sizeof (struct v4l2_pix_format ))) -return -EFAULT ; -return 0 ; -} - -static inline int get_v4l2_pix_format_mplane (struct v4l2_pix_format_mplane *kp, -struct v4l2_pix_format_mplane __user *up) -{ -if (copy_from_user (kp, up,sizeof (struct v4l2_pix_format_mplane ))) -return -EFAULT ; -return 0 ; -} - -static inline int put_v4l2_pix_format (struct v4l2_pix_format *kp,struct v4l2_pix_format __user *up) -{ -if (copy_to_user (up, kp,sizeof (struct v4l2_pix_format ))) -return -EFAULT ; -return 0 ; -} - -static inline int put_v4l2_pix_format_mplane (struct v4l2_pix_format_mplane *kp, -struct v4l2_pix_format_mplane __user *up) -{ -if (copy_to_user (up, kp,sizeof (struct v4l2_pix_format_mplane ))) -return -EFAULT ; -return 0 ; -} - -static inline int get_v4l2_vbi_format (struct v4l2_vbi_format *kp,struct v4l2_vbi_format __user *up) -{ -if (copy_from_user (kp, up,sizeof (struct v4l2_vbi_format ))) -return -EFAULT ; -return 0 ; -} - -static inline int put_v4l2_vbi_format (struct v4l2_vbi_format *kp,struct v4l2_vbi_format __user *up) -{ -if (copy_to_user (up, kp,sizeof (struct v4l2_vbi_format ))) -return -EFAULT ; -return 0 ; -} - -static inline int get_v4l2_sliced_vbi_format (struct v4l2_sliced_vbi_format *kp,struct v4l2_sliced_vbi_format __user *up) -{ -if (copy_from_user (kp, up,sizeof (struct v4l2_sliced_vbi_format ))) -return -EFAULT ; -return 0 ; -} - -static inline int put_v4l2_sliced_vbi_format (struct v4l2_sliced_vbi_format *kp,struct v4l2_sliced_vbi_format __user *up) -{ -if (copy_to_user (up, kp,sizeof (struct v4l2_sliced_vbi_format ))) -return -EFAULT ; -return 0 ; -} - -static inline int get_v4l2_sdr_format (struct v4l2_sdr_format *kp,struct v4l2_sdr_format __user *up) -{ -if (copy_from_user (kp, up,sizeof (struct v4l2_sdr_format ))) -return -EFAULT ; -return 0 ; -} - -static inline int put_v4l2_sdr_format (struct v4l2_sdr_format *kp,struct v4l2_sdr_format __user *up) -{ -if (copy_to_user (up, kp,sizeof (struct v4l2_sdr_format ))) -return -EFAULT ; -return 0 ; -} - -static inline int get_v4l2_meta_format (struct v4l2_meta_format *kp,struct v4l2_meta_format __user *up) -{ -if (copy_from_user (kp, up,sizeof (struct v4l2_meta_format ))) -return -EFAULT ; -return 0 ; -} - -static inline int put_v4l2_meta_format (struct v4l2_meta_format *kp,struct v4l2_meta_format __user *up) -{ -if (copy_to_user (up, kp,sizeof (struct v4l2_meta_format ))) -return -EFAULT ; -return 0 ; -} -struct v4l2_format32 {__u32 type;/* enum v4l2_buf_type */ union {
@@ -217,25 +131,30 @@ static int __get_v4l2_format32(struct v4switch (kp->type) {case V4L2_BUF_TYPE_VIDEO_CAPTURE :case V4L2_BUF_TYPE_VIDEO_OUTPUT : -return get_v4l2_pix_format (&kp->fmt.pix, &up->fmt.pix); +return copy_from_user (&kp->fmt.pix, &up->fmt.pix, +sizeof (kp->fmt.pix)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE :case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE : -return get_v4l2_pix_format_mplane (&kp->fmt.pix_mp, - &up->fmt.pix_mp); +return copy_from_user (&kp->fmt.pix_mp, &up->fmt.pix_mp, +sizeof (kp->fmt.pix_mp)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_VIDEO_OVERLAY :case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY :return get_v4l2_window32 (&kp->fmt.win, &up->fmt.win);case V4L2_BUF_TYPE_VBI_CAPTURE :case V4L2_BUF_TYPE_VBI_OUTPUT : -return get_v4l2_vbi_format (&kp->fmt.vbi, &up->fmt.vbi); +return copy_from_user (&kp->fmt.vbi, &up->fmt.vbi, +sizeof (kp->fmt.vbi)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE :case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT : -return get_v4l2_sliced_vbi_format (&kp->fmt.sliced, &up->fmt.sliced); +return copy_from_user (&kp->fmt.sliced, &up->fmt.sliced, +sizeof (kp->fmt.sliced)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_SDR_CAPTURE :case V4L2_BUF_TYPE_SDR_OUTPUT : -return get_v4l2_sdr_format (&kp->fmt.sdr, &up->fmt.sdr); +return copy_from_user (&kp->fmt.sdr, &up->fmt.sdr, +sizeof (kp->fmt.sdr)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_META_CAPTURE : -return get_v4l2_meta_format (&kp->fmt.meta, &up->fmt.meta); +return copy_from_user (&kp->fmt.meta, &up->fmt.meta, +sizeof (kp->fmt.meta)) ? -EFAULT :0 ;default :pr_info ("compat_ioctl32: unexpected VIDIOC_FMT type %d\n" , kp->type);
@@ -266,25 +185,30 @@ static int __put_v4l2_format32(struct v4switch (kp->type) {case V4L2_BUF_TYPE_VIDEO_CAPTURE :case V4L2_BUF_TYPE_VIDEO_OUTPUT : -return put_v4l2_pix_format (&kp->fmt.pix, &up->fmt.pix); +return copy_to_user (&up->fmt.pix, &kp->fmt.pix, +sizeof (kp->fmt.pix)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE :case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE : -return put_v4l2_pix_format_mplane (&kp->fmt.pix_mp, - &up->fmt.pix_mp); +return copy_to_user (&up->fmt.pix_mp, &kp->fmt.pix_mp, +sizeof (kp->fmt.pix_mp)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_VIDEO_OVERLAY :case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY :return put_v4l2_window32 (&kp->fmt.win, &up->fmt.win);case V4L2_BUF_TYPE_VBI_CAPTURE :case V4L2_BUF_TYPE_VBI_OUTPUT : -return put_v4l2_vbi_format (&kp->fmt.vbi, &up->fmt.vbi); +return copy_to_user (&up->fmt.vbi, &kp->fmt.vbi, +sizeof (kp->fmt.vbi)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE :case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT : -return put_v4l2_sliced_vbi_format (&kp->fmt.sliced, &up->fmt.sliced); +return copy_to_user (&up->fmt.sliced, &kp->fmt.sliced, +sizeof (kp->fmt.sliced)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_SDR_CAPTURE :case V4L2_BUF_TYPE_SDR_OUTPUT : -return put_v4l2_sdr_format (&kp->fmt.sdr, &up->fmt.sdr); +return copy_to_user (&up->fmt.sdr, &kp->fmt.sdr, +sizeof (kp->fmt.sdr)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_META_CAPTURE : -return put_v4l2_meta_format (&kp->fmt.meta, &up->fmt.meta); +return copy_to_user (&up->fmt.meta, &kp->fmt.meta, +sizeof (kp->fmt.meta)) ? -EFAULT :0 ;default :pr_info ("compat_ioctl32: unexpected VIDIOC_FMT type %d\n" , kp->type);
Greg Kroah-Hartman
maintainerPATCH 125/195 media: v4l2-compat-ioctl32.c: avoid sizeof(type)
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans Verkuil <[email protected]>
commit 333b1e9f96ce05f7498b581509bb30cde03018bf upstream.
Instead of doing sizeof(struct foo) use sizeof(*up). There even were cases where 4 * sizeof(__u32) was used instead of sizeof(kp->reserved), which is very dangerous when the size of the reserved array changes.
--- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 79 +++++++++++--------------- 1 file changed, 36 insertions(+), 43 deletions(-)
drivers/media/v4l2-core/v4l2-compat-ioctl32.c +36 -43
@@ -48,7 +48,7 @@ struct v4l2_window32 {static int get_v4l2_window32 (struct v4l2_window *kp,struct v4l2_window32 __user *up) { - if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_window32)) || + if (!access_ok(VERIFY_READ, up, sizeof(*up)) || copy_from_user(&kp->w, &up->w, sizeof(up->w)) || get_user(kp->field, &up->field) || get_user(kp->chromakey, &up->chromakey) ||
@@ -66,7 +66,7 @@ static int get_v4l2_window32(struct v4l2if (get_user (p, &up->clips))return -EFAULT ; uclips =compat_ptr (p); - kclips =compat_alloc_user_space (n *sizeof (struct v4l2_clip )); + kclips =compat_alloc_user_space (n *sizeof (*kclips)); kp->clips = kclips;while (--n >=0 ) {if (copy_in_user (&kclips->c, &uclips->c,sizeof (uclips->c)))
@@ -164,14 +164,14 @@ static int __get_v4l2_format32(struct v4static int get_v4l2_format32 (struct v4l2_format *kp,struct v4l2_format32 __user *up) { -if (!access_ok (VERIFY_READ , up,sizeof (struct v4l2_format32 ))) +if (!access_ok (VERIFY_READ , up,sizeof (*up)))return -EFAULT ;return __get_v4l2_format32 (kp, up); }static int get_v4l2_create32 (struct v4l2_create_buffers *kp,struct v4l2_create_buffers32 __user *up) { -if (!access_ok (VERIFY_READ , up,sizeof (struct v4l2_create_buffers32 )) || +if (!access_ok (VERIFY_READ , up,sizeof (*up)) ||copy_from_user (kp, up, offsetof(struct v4l2_create_buffers32 , format)))return -EFAULT ;return __get_v4l2_format32 (&kp->format, &up->format);
@@ -218,14 +218,14 @@ static int __put_v4l2_format32(struct v4static int put_v4l2_format32 (struct v4l2_format *kp,struct v4l2_format32 __user *up) { -if (!access_ok (VERIFY_WRITE , up,sizeof (struct v4l2_format32 ))) +if (!access_ok (VERIFY_WRITE , up,sizeof (*up)))return -EFAULT ;return __put_v4l2_format32 (kp, up); }static int put_v4l2_create32 (struct v4l2_create_buffers *kp,struct v4l2_create_buffers32 __user *up) { -if (!access_ok (VERIFY_WRITE , up,sizeof (struct v4l2_create_buffers32 )) || +if (!access_ok (VERIFY_WRITE , up,sizeof (*up)) ||copy_to_user (up, kp, offsetof(struct v4l2_create_buffers32 , format)) ||copy_to_user (up->reserved, kp->reserved,sizeof (kp->reserved)))return -EFAULT ;
@@ -244,7 +244,7 @@ struct v4l2_standard32 {static int get_v4l2_standard32 (struct v4l2_standard *kp,struct v4l2_standard32 __user *up) {/* other fields are not set by the user, nor used by the driver */ -if (!access_ok (VERIFY_READ , up,sizeof (struct v4l2_standard32 )) || +if (!access_ok (VERIFY_READ , up,sizeof (*up)) ||get_user (kp->index, &up->index))return -EFAULT ;return 0 ;
@@ -252,14 +252,14 @@ static int get_v4l2_standard32(struct v4static int put_v4l2_standard32 (struct v4l2_standard *kp,struct v4l2_standard32 __user *up) { -if (!access_ok (VERIFY_WRITE , up,sizeof (struct v4l2_standard32 )) || +if (!access_ok (VERIFY_WRITE , up,sizeof (*up)) ||put_user (kp->index, &up->index) ||put_user (kp->id, &up->id) || -copy_to_user (up->name, kp->name,24 ) || +copy_to_user (up->name, kp->name,sizeof (up->name)) ||copy_to_user (&up->frameperiod, &kp->frameperiod,sizeof (kp->frameperiod)) ||put_user (kp->framelines, &up->framelines) || -copy_to_user (up->reserved, kp->reserved,4 *sizeof (__u32))) +copy_to_user (up->reserved, kp->reserved,sizeof (kp->reserved)))return -EFAULT ;return 0 ; }
@@ -307,7 +307,7 @@ static int get_v4l2_plane32(struct v4l2_if (copy_in_user (up, up32,2 *sizeof (__u32)) ||copy_in_user (&up->data_offset, &up32->data_offset, -sizeof (__u32))) +sizeof (up->data_offset)))return -EFAULT ;if (memory ==V4L2_MEMORY_USERPTR ) {
@@ -317,11 +317,11 @@ static int get_v4l2_plane32(struct v4l2_if (put_user ((unsigned long )up_pln, &up->m.userptr))return -EFAULT ; }else if (memory ==V4L2_MEMORY_DMABUF ) { -if (copy_in_user (&up->m.fd, &up32->m.fd,sizeof (int ))) +if (copy_in_user (&up->m.fd, &up32->m.fd,sizeof (up32->m.fd)))return -EFAULT ; }else {if (copy_in_user (&up->m.mem_offset, &up32->m.mem_offset, -sizeof (__u32))) +sizeof (up32->m.mem_offset)))return -EFAULT ; }
@@ -333,19 +333,19 @@ static int put_v4l2_plane32(struct v4l2_ {if (copy_in_user (up32, up,2 *sizeof (__u32)) ||copy_in_user (&up32->data_offset, &up->data_offset, -sizeof (__u32))) +sizeof (up->data_offset)))return -EFAULT ;/* For MMAP, driver might've set up the offset, so copy it back. * USERPTR stays the same (was userspace-provided), so no copying. */ if (memory ==V4L2_MEMORY_MMAP )if (copy_in_user (&up32->m.mem_offset, &up->m.mem_offset, -sizeof (__u32))) +sizeof (up->m.mem_offset)))return -EFAULT ;/* For DMABUF, driver might've set up the fd, so copy it back. */ if (memory ==V4L2_MEMORY_DMABUF )if (copy_in_user (&up32->m.fd, &up->m.fd, -sizeof (int ))) +sizeof (up->m.fd)))return -EFAULT ;return 0 ;
@@ -358,7 +358,7 @@ static int get_v4l2_buffer32(struct v4l2compat_caddr_t p;int ret; - if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_buffer32)) || + if (!access_ok(VERIFY_READ, up, sizeof(*up)) || get_user(kp->index, &up->index) || get_user(kp->type, &up->type) || get_user(kp->flags, &up->flags) ||
@@ -370,8 +370,7 @@ static int get_v4l2_buffer32(struct v4l2if (get_user (kp->bytesused, &up->bytesused) ||get_user (kp->field, &up->field) ||get_user (kp->timestamp.tv_sec, &up->timestamp.tv_sec) || -get_user (kp->timestamp.tv_usec, - &up->timestamp.tv_usec)) +get_user (kp->timestamp.tv_usec, &up->timestamp.tv_usec))return -EFAULT ;if (V4L2_TYPE_IS_MULTIPLANAR (kp->type)) {
@@ -391,13 +390,12 @@ static int get_v4l2_buffer32(struct v4l2 uplane32 =compat_ptr (p);if (!access_ok (VERIFY_READ , uplane32, - kp->length *sizeof (struct v4l2_plane32 ))) + kp->length *sizeof (*uplane32)))return -EFAULT ;/* We don't really care if userspace decides to kill itself * by passing a very big num_planes value */ - uplane =compat_alloc_user_space (kp->length * -sizeof (struct v4l2_plane )); + uplane =compat_alloc_user_space (kp->length *sizeof (*uplane)); kp->m.planes = (__force struct v4l2_plane *)uplane;for (num_planes =0 ; num_planes < kp->length; num_planes++) {
@@ -445,7 +443,7 @@ static int put_v4l2_buffer32(struct v4l2int num_planes;int ret; - if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_buffer32)) || + if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || put_user(kp->index, &up->index) || put_user(kp->type, &up->type) || put_user(kp->flags, &up->flags) ||
@@ -456,8 +454,7 @@ static int put_v4l2_buffer32(struct v4l2put_user (kp->field, &up->field) ||put_user (kp->timestamp.tv_sec, &up->timestamp.tv_sec) ||put_user (kp->timestamp.tv_usec, &up->timestamp.tv_usec) || -copy_to_user (&up->timecode, &kp->timecode, -sizeof (struct v4l2_timecode )) || +copy_to_user (&up->timecode, &kp->timecode,sizeof (kp->timecode)) ||put_user (kp->sequence, &up->sequence) ||put_user (kp->reserved2, &up->reserved2) || put_user(kp->reserved, &up->reserved) ||
@@ -525,7 +522,7 @@ static int get_v4l2_framebuffer32(struct {u32 tmp; - if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_framebuffer32)) || + if (!access_ok(VERIFY_READ, up, sizeof(*up)) || get_user(tmp, &up->base) || get_user(kp->capability, &up->capability) || get_user(kp->flags, &up->flags) ||
@@ -539,7 +536,7 @@ static int put_v4l2_framebuffer32(struct {u32 tmp = (u32)((unsigned long )kp->base); - if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_framebuffer32)) || + if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || put_user(tmp, &up->base) || put_user(kp->capability, &up->capability) || put_user(kp->flags, &up->flags) ||
@@ -564,14 +561,14 @@ struct v4l2_input32 {Otherwise it is identical to the 32-bit version. */ static inline int get_v4l2_input32 (struct v4l2_input *kp,struct v4l2_input32 __user *up) { -if (copy_from_user (kp, up,sizeof (struct v4l2_input32 ))) +if (copy_from_user (kp, up,sizeof (*up)))return -EFAULT ;return 0 ; }static inline int put_v4l2_input32 (struct v4l2_input *kp,struct v4l2_input32 __user *up) { -if (copy_to_user (up, kp,sizeof (struct v4l2_input32 ))) +if (copy_to_user (up, kp,sizeof (*up)))return -EFAULT ;return 0 ; }
@@ -619,12 +616,11 @@ static int get_v4l2_ext_controls32(strucunsigned int n;compat_caddr_t p; -if (!access_ok (VERIFY_READ , up,sizeof (struct v4l2_ext_controls32 )) || +if (!access_ok (VERIFY_READ , up,sizeof (*up)) ||get_user (kp->which, &up->which) ||get_user (kp->count, &up->count) ||get_user (kp->error_idx, &up->error_idx) || -copy_from_user (kp->reserved, up->reserved, -sizeof (kp->reserved))) +copy_from_user (kp->reserved, up->reserved,sizeof (kp->reserved)))return -EFAULT ;if (kp->count ==0 ) { kp->controls =NULL ;
@@ -635,11 +631,9 @@ static int get_v4l2_ext_controls32(strucif (get_user (p, &up->controls))return -EFAULT ; ucontrols =compat_ptr (p); -if (!access_ok (VERIFY_READ , ucontrols, - kp->count *sizeof (struct v4l2_ext_control32 ))) +if (!access_ok (VERIFY_READ , ucontrols, kp->count *sizeof (*ucontrols)))return -EFAULT ; - kcontrols =compat_alloc_user_space (kp->count * -sizeof (struct v4l2_ext_control )); + kcontrols =compat_alloc_user_space (kp->count *sizeof (*kcontrols)); kp->controls = (__force struct v4l2_ext_control *)kcontrols;for (n =0 ; n < kp->count; n++) {u32 id;
@@ -671,7 +665,7 @@ static int put_v4l2_ext_controls32(strucint n = kp->count;compat_caddr_t p; - if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_ext_controls32)) || + if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || put_user(kp->which, &up->which) || put_user(kp->count, &up->count) || put_user(kp->error_idx, &up->error_idx) ||
@@ -683,8 +677,7 @@ static int put_v4l2_ext_controls32(strucif (get_user (p, &up->controls))return -EFAULT ; ucontrols =compat_ptr (p); -if (!access_ok (VERIFY_WRITE , ucontrols, - n *sizeof (struct v4l2_ext_control32 ))) +if (!access_ok (VERIFY_WRITE , ucontrols, n *sizeof (*ucontrols)))return -EFAULT ;while (--n >=0 ) {
@@ -721,7 +714,7 @@ struct v4l2_event32 {static int put_v4l2_event32 (struct v4l2_event *kp,struct v4l2_event32 __user *up) { - if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_event32)) || + if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || put_user(kp->type, &up->type) || copy_to_user(&up->u, &kp->u, sizeof(kp->u)) || put_user(kp->pending, &up->pending) ||
@@ -729,7 +722,7 @@ static int put_v4l2_event32(struct v4l2_put_user (kp->timestamp.tv_sec, &up->timestamp.tv_sec) ||put_user (kp->timestamp.tv_nsec, &up->timestamp.tv_nsec) ||put_user (kp->id, &up->id) || - copy_to_user(up->reserved, kp->reserved, 8 * sizeof(__u32))) + copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved))) return -EFAULT;return 0 ; }
@@ -746,7 +739,7 @@ static int get_v4l2_edid32(struct v4l2_e {u32 tmp; - if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_edid32)) || + if (!access_ok(VERIFY_READ, up, sizeof(*up)) || get_user(kp->pad, &up->pad) || get_user(kp->start_block, &up->start_block) || get_user(kp->blocks, &up->blocks) ||
@@ -761,7 +754,7 @@ static int put_v4l2_edid32(struct v4l2_e {u32 tmp = (u32)((unsigned long )kp->edid); - if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_edid32)) || + if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) || put_user(kp->pad, &up->pad) || put_user(kp->start_block, &up->start_block) || put_user(kp->blocks, &up->blocks) ||
Greg Kroah-Hartman
maintainerPATCH 126/195 media: v4l2-compat-ioctl32.c: copy m.userptr in put_v4l2_plane32
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans Verkuil <[email protected]>
commit 8ed5a59dcb47a6f76034ee760b36e089f3e82529 upstream.
The struct v4l2_plane32 should set m.userptr as well. The same happens in v4l2_buffer32 and v4l2-compliance tests for this.
--- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 47 +++++++++++++++----------- 1 file changed, 28 insertions(+), 19 deletions(-)
drivers/media/v4l2-core/v4l2-compat-ioctl32.c +28 -19
@@ -310,19 +310,24 @@ static int get_v4l2_plane32(struct v4l2_ sizeof(up->data_offset)))return -EFAULT ; -if (memory ==V4L2_MEMORY_USERPTR ) { +switch (memory) { +case V4L2_MEMORY_MMAP : +case V4L2_MEMORY_OVERLAY : +if (copy_in_user (&up->m.mem_offset, &up32->m.mem_offset, +sizeof (up32->m.mem_offset))) +return -EFAULT ; +break ; +case V4L2_MEMORY_USERPTR :if (get_user (p, &up32->m.userptr))return -EFAULT ; up_pln =compat_ptr (p);if (put_user ((unsigned long )up_pln, &up->m.userptr))return -EFAULT ; - }else if (memory ==V4L2_MEMORY_DMABUF ) { +break ; +case V4L2_MEMORY_DMABUF :if (copy_in_user (&up->m.fd, &up32->m.fd,sizeof (up32->m.fd)))return -EFAULT ; - }else { -if (copy_in_user (&up->m.mem_offset, &up32->m.mem_offset, -sizeof (up32->m.mem_offset))) -return -EFAULT ; +break ; }return 0 ;
@@ -331,22 +336,32 @@ static int get_v4l2_plane32(struct v4l2_static int put_v4l2_plane32 (struct v4l2_plane __user *up,struct v4l2_plane32 __user *up32,enum v4l2_memory memory) { +unsigned long p; +if (copy_in_user (up32, up,2 *sizeof (__u32)) ||copy_in_user (&up32->data_offset, &up->data_offset,sizeof (up->data_offset)))return -EFAULT ; -/* For MMAP, driver might've set up the offset, so copy it back. -* USERPTR stays the same (was userspace-provided), so no copying. */ -if (memory ==V4L2_MEMORY_MMAP ) +switch (memory) { +case V4L2_MEMORY_MMAP : +case V4L2_MEMORY_OVERLAY :if (copy_in_user (&up32->m.mem_offset, &up->m.mem_offset,sizeof (up->m.mem_offset)))return -EFAULT ; -/* For DMABUF, driver might've set up the fd, so copy it back. */ -if (memory ==V4L2_MEMORY_DMABUF ) +break ; +case V4L2_MEMORY_USERPTR : +if (get_user (p, &up->m.userptr) || +put_user ((compat_ulong_t )ptr_to_compat ((__force void *)p), + &up32->m.userptr)) +return -EFAULT ; +break ; +case V4L2_MEMORY_DMABUF :if (copy_in_user (&up32->m.fd, &up->m.fd,sizeof (up->m.fd)))return -EFAULT ; +break ; + }return 0 ; }
@@ -408,6 +423,7 @@ static int get_v4l2_buffer32(struct v4l2 }else {switch (kp->memory) {case V4L2_MEMORY_MMAP : +case V4L2_MEMORY_OVERLAY :if (get_user (kp->m.offset, &up->m.offset))return -EFAULT ;break ;
@@ -421,10 +437,6 @@ static int get_v4l2_buffer32(struct v4l2 kp->m.userptr = (unsigned long )compat_ptr (tmp); }break ; -case V4L2_MEMORY_OVERLAY : -if (get_user (kp->m.offset, &up->m.offset)) -return -EFAULT ; -break ;case V4L2_MEMORY_DMABUF :if (get_user (kp->m.fd, &up->m.fd))return -EFAULT ;
@@ -481,6 +493,7 @@ static int put_v4l2_buffer32(struct v4l2 }else {switch (kp->memory) {case V4L2_MEMORY_MMAP : +case V4L2_MEMORY_OVERLAY :if (put_user (kp->m.offset, &up->m.offset))return -EFAULT ;break ;
@@ -488,10 +501,6 @@ static int put_v4l2_buffer32(struct v4l2if (put_user (kp->m.userptr, &up->m.userptr))return -EFAULT ;break ; -case V4L2_MEMORY_OVERLAY : -if (put_user (kp->m.offset, &up->m.offset)) -return -EFAULT ; -break ;case V4L2_MEMORY_DMABUF :if (put_user (kp->m.fd, &up->m.fd))return -EFAULT ;
Greg Kroah-Hartman
maintainerPATCH 127/195 media: v4l2-compat-ioctl32.c: fix ctrl_is_pointer
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans Verkuil <[email protected]>
commit b8c601e8af2d08f733d74defa8465303391bb930 upstream.
ctrl_is_pointer just hardcoded two known string controls, but that caused problems when using e.g. custom controls that use a pointer for the payload.
Reimplement this function: it now finds the v4l2_ctrl (if the driver uses the control framework) or it calls vidioc_query_ext_ctrl (if the driver implements that directly).
In both cases it can now check if the control is a pointer control or not.
--- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 59 +++++++++++++++++--------- 1 file changed, 39 insertions(+), 20 deletions(-)
drivers/media/v4l2-core/v4l2-compat-ioctl32.c +39 -20
@@ -18,6 +18,8 @@#include <linux/videodev2.h> #include <linux/v4l2-subdev.h> #include <media/v4l2-dev.h> +#include <media/v4l2-fh.h> +#include <media/v4l2-ctrls.h> #include <media/v4l2-ioctl.h> static long native_ioctl (struct file *file,unsigned int cmd,unsigned long arg)
@@ -601,24 +603,39 @@ struct v4l2_ext_control32 { }; } __attribute__ ((packed)); -/* The following function really belong in v4l2-common, but that causes -a circular dependency between modules. We need to think about this, but -for now this will do. */ - -/* Return non-zero if this control is a pointer type. Currently only -type STRING is a pointer type. */ -static inline int ctrl_is_pointer (u32 id) -{ -switch (id) { -case V4L2_CID_RDS_TX_PS_NAME : -case V4L2_CID_RDS_TX_RADIO_TEXT : -return 1 ; -default : -return 0 ; +/* Return true if this control is a pointer type. */ +static inline bool ctrl_is_pointer (struct file *file,u32 id) +{ +struct video_device *vdev =video_devdata (file); +struct v4l2_fh *fh =NULL ; +struct v4l2_ctrl_handler *hdl =NULL ; +struct v4l2_query_ext_ctrl qec = { id }; +const struct v4l2_ioctl_ops *ops = vdev->ioctl_ops; + +if (test_bit (V4L2_FL_USES_V4L2_FH , &vdev->flags)) + fh = file->private_data; + +if (fh && fh->ctrl_handler) + hdl = fh->ctrl_handler; +else if (vdev->ctrl_handler) + hdl = vdev->ctrl_handler; + +if (hdl) { +struct v4l2_ctrl *ctrl =v4l2_ctrl_find (hdl, id); + +return ctrl && ctrl->is_ptr; } + +if (!ops->vidioc_query_ext_ctrl) +return false; + +return !ops->vidioc_query_ext_ctrl (file, fh, &qec) && + (qec.flags &V4L2_CTRL_FLAG_HAS_PAYLOAD ); } -static int get_v4l2_ext_controls32 (struct v4l2_ext_controls *kp,struct v4l2_ext_controls32 __user *up) +static int get_v4l2_ext_controls32 (struct file *file, +struct v4l2_ext_controls *kp, +struct v4l2_ext_controls32 __user *up) {struct v4l2_ext_control32 __user *ucontrols;struct v4l2_ext_control __user *kcontrols;
@@ -651,7 +668,7 @@ static int get_v4l2_ext_controls32(strucreturn -EFAULT ;if (get_user (id, &kcontrols->id))return -EFAULT ; -if (ctrl_is_pointer (id)) { +if (ctrl_is_pointer (file, id)) {void __user *s;if (get_user (p, &ucontrols->string))
@@ -666,7 +683,9 @@ static int get_v4l2_ext_controls32(strucreturn 0 ; } -static int put_v4l2_ext_controls32 (struct v4l2_ext_controls *kp,struct v4l2_ext_controls32 __user *up) +static int put_v4l2_ext_controls32 (struct file *file, +struct v4l2_ext_controls *kp, +struct v4l2_ext_controls32 __user *up) {struct v4l2_ext_control32 __user *ucontrols; struct v4l2_ext_control __user *kcontrols =
@@ -698,7 +717,7 @@ static int put_v4l2_ext_controls32(struc/* Do not modify the pointer when copying a pointer control. The contents of the pointer was changed, not the pointer itself. */ -if (ctrl_is_pointer (id)) +if (ctrl_is_pointer (file, id)) size -=sizeof (ucontrols->value64);if (copy_in_user (ucontrols, kcontrols, size))return -EFAULT ;
@@ -912,7 +931,7 @@ static long do_video_ioctl(struct file *case VIDIOC_G_EXT_CTRLS :case VIDIOC_S_EXT_CTRLS :case VIDIOC_TRY_EXT_CTRLS : - err =get_v4l2_ext_controls32 (&karg.v2ecs, up); + err =get_v4l2_ext_controls32 (file, &karg.v2ecs, up); compatible_arg =0 ;break ;case VIDIOC_DQEVENT :
@@ -939,7 +958,7 @@ static long do_video_ioctl(struct file *case VIDIOC_G_EXT_CTRLS :case VIDIOC_S_EXT_CTRLS :case VIDIOC_TRY_EXT_CTRLS : -if (put_v4l2_ext_controls32 (&karg.v2ecs, up)) +if (put_v4l2_ext_controls32 (file, &karg.v2ecs, up)) err = -EFAULT ;break ;case VIDIOC_S_EDID :
Greg Kroah-Hartman
maintainerPATCH 128/195 media: v4l2-compat-ioctl32.c: copy clip list in put_v4l2_window32
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans Verkuil <[email protected]>
commit a751be5b142ef6bcbbb96d9899516f4d9c8d0ef4 upstream.
put_v4l2_window32() didn't copy back the clip list to userspace. Drivers can update the clip rectangles, so this should be done.
--- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 59 +++++++++++++++++--------- 1 file changed, 40 insertions(+), 19 deletions(-)
drivers/media/v4l2-core/v4l2-compat-ioctl32.c +40 -19
@@ -50,6 +50,11 @@ struct v4l2_window32 {static int get_v4l2_window32 (struct v4l2_window *kp,struct v4l2_window32 __user *up) { +struct v4l2_clip32 __user *uclips; +struct v4l2_clip __user *kclips; +compat_caddr_t p; +u32 n; + if (!access_ok(VERIFY_READ, up, sizeof(*up)) || copy_from_user(&kp->w, &up->w, sizeof(up->w)) || get_user(kp->field, &up->field) ||
@@ -59,38 +64,54 @@ static int get_v4l2_window32(struct v4l2return -EFAULT ;if (kp->clipcount >2048 )return -EINVAL ; -if (kp->clipcount) { -struct v4l2_clip32 __user *uclips; -struct v4l2_clip __user *kclips; -int n = kp->clipcount; -compat_caddr_t p; +if (!kp->clipcount) { + kp->clips =NULL ; +return 0 ; + } -if (get_user (p, &up->clips)) + n = kp->clipcount; +if (get_user (p, &up->clips)) +return -EFAULT ; + uclips =compat_ptr (p); + kclips =compat_alloc_user_space (n *sizeof (*kclips)); + kp->clips = kclips; +while (n--) { +if (copy_in_user (&kclips->c, &uclips->c,sizeof (uclips->c)))return -EFAULT ; - uclips =compat_ptr (p); - kclips =compat_alloc_user_space (n *sizeof (*kclips)); - kp->clips = kclips; -while (--n >=0 ) { -if (copy_in_user (&kclips->c, &uclips->c,sizeof (uclips->c))) -return -EFAULT ; -if (put_user (n ? kclips +1 :NULL , &kclips->next)) -return -EFAULT ; - uclips +=1 ; - kclips +=1 ; - } - }else - kp->clips =NULL ; +if (put_user (n ? kclips +1 :NULL , &kclips->next)) +return -EFAULT ; + uclips++; + kclips++; + }return 0 ; }static int put_v4l2_window32 (struct v4l2_window *kp,struct v4l2_window32 __user *up) { +struct v4l2_clip __user *kclips = kp->clips; +struct v4l2_clip32 __user *uclips; +u32 n = kp->clipcount; +compat_caddr_t p; +if (copy_to_user (&up->w, &kp->w,sizeof (kp->w)) ||put_user (kp->field, &up->field) ||put_user (kp->chromakey, &up->chromakey) ||put_user (kp->clipcount, &up->clipcount) ||put_user (kp->global_alpha, &up->global_alpha))return -EFAULT ; + +if (!kp->clipcount) +return 0 ; + +if (get_user (p, &up->clips)) +return -EFAULT ; + uclips =compat_ptr (p); +while (n--) { +if (copy_in_user (&uclips->c, &kclips->c,sizeof (uclips->c))) +return -EFAULT ; + uclips++; + kclips++; + }return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 129/195 media: v4l2-compat-ioctl32.c: drop pr_info for unknown buffer type
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans Verkuil <[email protected]>
commit 169f24ca68bf0f247d111aef07af00dd3a02ae88 upstream.
There is nothing wrong with using an unknown buffer type. So stop spamming the kernel log whenever this happens. The kernel will just return -EINVAL to signal this.
--- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/media/v4l2-core/v4l2-compat-ioctl32.c +0 -4
@@ -179,8 +179,6 @@ static int __get_v4l2_format32(struct v4return copy_from_user (&kp->fmt.meta, &up->fmt.meta,sizeof (kp->fmt.meta)) ? -EFAULT :0 ;default : -pr_info ("compat_ioctl32: unexpected VIDIOC_FMT type %d\n" , - kp->type);return -EINVAL ; } }
@@ -233,8 +231,6 @@ static int __put_v4l2_format32(struct v4return copy_to_user (&up->fmt.meta, &kp->fmt.meta,sizeof (kp->fmt.meta)) ? -EFAULT :0 ;default : -pr_info ("compat_ioctl32: unexpected VIDIOC_FMT type %d\n" , - kp->type);return -EINVAL ; } }
Greg Kroah-Hartman
maintainerPATCH 130/195 media: v4l2-compat-ioctl32.c: dont copy back the result for certain errors
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans Verkuil <[email protected]>
commit d83a8243aaefe62ace433e4384a4f077bed86acb upstream.
Some ioctls need to copy back the result even if the ioctl returned an error. However, don't do this for the error code -ENOTTY. It makes no sense in that cases.
--- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/media/v4l2-core/v4l2-compat-ioctl32.c +3 -0
@@ -968,6 +968,9 @@ static long do_video_ioctl(struct file *set_fs (old_fs); } +if (err == -ENOTTY ) +return err; +/* Special case: even after an error we need to put the results back for these ioctls since the error_idx will contain information on which control failed. */
Greg Kroah-Hartman
maintainerPATCH 131/195 media: v4l2-compat-ioctl32.c: refactor compat ioctl32 logic
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Mentz <[email protected]>
commit a1dfb4c48cc1e64eeb7800a27c66a6f7e88d075a upstream.
The 32-bit compat v4l2 ioctl handling is implemented based on its 64-bit equivalent. It converts 32-bit data structures into its 64-bit equivalents and needs to provide the data to the 64-bit ioctl in user space memory which is commonly allocated using compat_alloc_user_space().
However, due to how that function is implemented, it can only be called a single time for every syscall invocation.
Supposedly to avoid this limitation, the existing code uses a mix of memory from the kernel stack and memory allocated through compat_alloc_user_space().
Under normal circumstances, this would not work, because the 64-bit ioctl expects all pointers to point to user space memory. As a workaround, set_fs(KERNEL_DS) is called to temporarily disable this extra safety check and allow kernel pointers. However, this might introduce a security vulnerability: The result of the 32-bit to 64-bit conversion is writeable by user space because the output buffer has been allocated via compat_alloc_user_space(). A malicious user space process could then manipulate pointers inside this output buffer, and due to the previous set_fs(KERNEL_DS) call, functions like get_user() or put_user() no longer prevent kernel memory access.
The new approach is to pre-calculate the total amount of user space memory that is needed, allocate it using compat_alloc_user_space() and then divide up the allocated memory to accommodate all data structures that need to be converted.
An alternative approach would have been to retain the union type karg that they allocated on the kernel stack in do_video_ioctl(), copy all data from user space into karg and then back to user space. However, we decided against this approach because it does not align with other compat syscall implementations. Instead, we tried to replicate the get_user/put_user pairs as found in other places in the kernel:
if (get_user(clipcount, &up->clipcount) ||
put_user(clipcount, &kp->clipcount)) return -EFAULT;Notes from [email protected]:
This patch was taken from:
https://github.com/LineageOS/android_kernel_samsung_apq8084/commit/97b733953c06e4f0398ade18850f0817778255f7
Clearly nobody could be bothered to upstream this patch or at minimum tell us :-( We only heard about this a week ago.
This patch was rebased and cleaned up. Compared to the original I also swapped the order of the convert_in_user arguments so that they matched copy_in_user. It was hard to review otherwise. I also replaced the ALLOC_USER_SPACE/ALLOC_AND_GET by a normal function.
--- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 752 ++++++++++++++++---------- 1 file changed, 483 insertions(+), 269 deletions(-)
drivers/media/v4l2-core/v4l2-compat-ioctl32.c +483 -269
@@ -22,6 +22,14 @@#include <media/v4l2-ctrls.h> #include <media/v4l2-ioctl.h> +/* Use the same argument order as copy_in_user */ +#define assign_in_user (to, from) \ +({ \ + typeof(*from) __assign_tmp; \ + \ + get_user(__assign_tmp, from) || put_user(__assign_tmp, to); \ +}) +static long native_ioctl (struct file *file,unsigned int cmd,unsigned long arg) {long ret = -ENOIOCTLCMD ;
@@ -48,37 +56,41 @@ struct v4l2_window32 {__u8 global_alpha; }; -static int get_v4l2_window32 (struct v4l2_window *kp,struct v4l2_window32 __user *up) +static int get_v4l2_window32 (struct v4l2_window __user *kp, +struct v4l2_window32 __user *up, +void __user *aux_buf,u32 aux_space) {struct v4l2_clip32 __user *uclips;struct v4l2_clip __user *kclips;compat_caddr_t p; -u32 n; +u32 clipcount;if (!access_ok (VERIFY_READ , up,sizeof (*up)) || -copy_from_user (&kp->w, &up->w,sizeof (up->w)) || -get_user (kp->field, &up->field) || -get_user (kp->chromakey, &up->chromakey) || -get_user (kp->clipcount, &up->clipcount) || -get_user (kp->global_alpha, &up->global_alpha)) +copy_in_user (&kp->w, &up->w,sizeof (up->w)) || +assign_in_user (&kp->field, &up->field) || +assign_in_user (&kp->chromakey, &up->chromakey) || +assign_in_user (&kp->global_alpha, &up->global_alpha) || +get_user (clipcount, &up->clipcount) || +put_user (clipcount, &kp->clipcount))return -EFAULT ; -if (kp->clipcount >2048 ) +if (clipcount >2048 )return -EINVAL ; -if (!kp->clipcount) { - kp->clips =NULL ; -return 0 ; - } +if (!clipcount) +return put_user (NULL , &kp->clips); - n = kp->clipcount;if (get_user (p, &up->clips))return -EFAULT ; uclips =compat_ptr (p); - kclips =compat_alloc_user_space (n *sizeof (*kclips)); - kp->clips = kclips; -while (n--) { +if (aux_space < clipcount *sizeof (*kclips)) +return -EFAULT ; + kclips = aux_buf; +if (put_user (kclips, &kp->clips)) +return -EFAULT ; + +while (clipcount--) {if (copy_in_user (&kclips->c, &uclips->c,sizeof (uclips->c)))return -EFAULT ; -if (put_user (n ? kclips +1 :NULL , &kclips->next)) +if (put_user (clipcount ? kclips +1 :NULL , &kclips->next))return -EFAULT ; uclips++; kclips++;
@@ -86,27 +98,28 @@ static int get_v4l2_window32(struct v4l2return 0 ; } -static int put_v4l2_window32 (struct v4l2_window *kp,struct v4l2_window32 __user *up) +static int put_v4l2_window32 (struct v4l2_window __user *kp, +struct v4l2_window32 __user *up) {struct v4l2_clip __user *kclips = kp->clips;struct v4l2_clip32 __user *uclips; -u32 n = kp->clipcount;compat_caddr_t p; +u32 clipcount; -if (copy_to_user (&up->w, &kp->w,sizeof (kp->w)) || -put_user (kp->field, &up->field) || -put_user (kp->chromakey, &up->chromakey) || -put_user (kp->clipcount, &up->clipcount) || -put_user (kp->global_alpha, &up->global_alpha)) +if (copy_in_user (&up->w, &kp->w,sizeof (kp->w)) || +assign_in_user (&up->field, &kp->field) || +assign_in_user (&up->chromakey, &kp->chromakey) || +assign_in_user (&up->global_alpha, &kp->global_alpha) || +get_user (clipcount, &kp->clipcount) || +put_user (clipcount, &up->clipcount))return -EFAULT ; - -if (!kp->clipcount) +if (!clipcount)return 0 ;if (get_user (p, &up->clips))return -EFAULT ; uclips =compat_ptr (p); -while (n--) { +while (clipcount--) {if (copy_in_user (&uclips->c, &kclips->c,sizeof (uclips->c)))return -EFAULT ; uclips++;
@@ -146,107 +159,164 @@ struct v4l2_create_buffers32 {__u32 reserved[8 ]; }; -static int __get_v4l2_format32 (struct v4l2_format *kp,struct v4l2_format32 __user *up) +static int __bufsize_v4l2_format (struct v4l2_format32 __user *up,u32 *size) +{ +u32 type; + +if (get_user (type, &up->type)) +return -EFAULT ; + +switch (type) { +case V4L2_BUF_TYPE_VIDEO_OVERLAY : +case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY : { +u32 clipcount; + +if (get_user (clipcount, &up->fmt.win.clipcount)) +return -EFAULT ; +if (clipcount >2048 ) +return -EINVAL ; + *size = clipcount *sizeof (struct v4l2_clip ); +return 0 ; + } +default : + *size =0 ; +return 0 ; + } +} + +static int bufsize_v4l2_format (struct v4l2_format32 __user *up,u32 *size) +{ +if (!access_ok (VERIFY_READ , up,sizeof (*up))) +return -EFAULT ; +return __bufsize_v4l2_format (up, size); +} + +static int __get_v4l2_format32 (struct v4l2_format __user *kp, +struct v4l2_format32 __user *up, +void __user *aux_buf,u32 aux_space) { -if (get_user (kp->type, &up->type)) +u32 type; + +if (get_user (type, &up->type) ||put_user (type, &kp->type))return -EFAULT ; -switch (kp->type) { +switch (type) {case V4L2_BUF_TYPE_VIDEO_CAPTURE :case V4L2_BUF_TYPE_VIDEO_OUTPUT : -return copy_from_user (&kp->fmt.pix, &up->fmt.pix, -sizeof (kp->fmt.pix)) ? -EFAULT :0 ; +return copy_in_user (&kp->fmt.pix, &up->fmt.pix, +sizeof (kp->fmt.pix)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE :case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE : -return copy_from_user (&kp->fmt.pix_mp, &up->fmt.pix_mp, -sizeof (kp->fmt.pix_mp)) ? -EFAULT :0 ; +return copy_in_user (&kp->fmt.pix_mp, &up->fmt.pix_mp, +sizeof (kp->fmt.pix_mp)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_VIDEO_OVERLAY :case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY : -return get_v4l2_window32 (&kp->fmt.win, &up->fmt.win); +return get_v4l2_window32 (&kp->fmt.win, &up->fmt.win, + aux_buf, aux_space);case V4L2_BUF_TYPE_VBI_CAPTURE :case V4L2_BUF_TYPE_VBI_OUTPUT : -return copy_from_user (&kp->fmt.vbi, &up->fmt.vbi, -sizeof (kp->fmt.vbi)) ? -EFAULT :0 ; +return copy_in_user (&kp->fmt.vbi, &up->fmt.vbi, +sizeof (kp->fmt.vbi)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE :case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT : -return copy_from_user (&kp->fmt.sliced, &up->fmt.sliced, -sizeof (kp->fmt.sliced)) ? -EFAULT :0 ; +return copy_in_user (&kp->fmt.sliced, &up->fmt.sliced, +sizeof (kp->fmt.sliced)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_SDR_CAPTURE :case V4L2_BUF_TYPE_SDR_OUTPUT : -return copy_from_user (&kp->fmt.sdr, &up->fmt.sdr, -sizeof (kp->fmt.sdr)) ? -EFAULT :0 ; +return copy_in_user (&kp->fmt.sdr, &up->fmt.sdr, +sizeof (kp->fmt.sdr)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_META_CAPTURE : -return copy_from_user (&kp->fmt.meta, &up->fmt.meta, -sizeof (kp->fmt.meta)) ? -EFAULT :0 ; +return copy_in_user (&kp->fmt.meta, &up->fmt.meta, +sizeof (kp->fmt.meta)) ? -EFAULT :0 ;default :return -EINVAL ; } } -static int get_v4l2_format32 (struct v4l2_format *kp,struct v4l2_format32 __user *up) +static int get_v4l2_format32 (struct v4l2_format __user *kp, +struct v4l2_format32 __user *up, +void __user *aux_buf,u32 aux_space) {if (!access_ok (VERIFY_READ , up,sizeof (*up)))return -EFAULT ; -return __get_v4l2_format32 (kp, up); +return __get_v4l2_format32 (kp, up, aux_buf, aux_space); } -static int get_v4l2_create32 (struct v4l2_create_buffers *kp,struct v4l2_create_buffers32 __user *up) +static int bufsize_v4l2_create (struct v4l2_create_buffers32 __user *up, +u32 *size) +{ +if (!access_ok (VERIFY_READ , up,sizeof (*up))) +return -EFAULT ; +return __bufsize_v4l2_format (&up->format, size); +} + +static int get_v4l2_create32 (struct v4l2_create_buffers __user *kp, +struct v4l2_create_buffers32 __user *up, +void __user *aux_buf,u32 aux_space) {if (!access_ok (VERIFY_READ , up,sizeof (*up)) || -copy_from_user (kp, up, offsetof(struct v4l2_create_buffers32 , format))) +copy_in_user (kp, up, + offsetof(struct v4l2_create_buffers32 , format)))return -EFAULT ; -return __get_v4l2_format32 (&kp->format, &up->format); +return __get_v4l2_format32 (&kp->format, &up->format, + aux_buf, aux_space); } -static int __put_v4l2_format32 (struct v4l2_format *kp,struct v4l2_format32 __user *up) +static int __put_v4l2_format32 (struct v4l2_format __user *kp, +struct v4l2_format32 __user *up) { -if (put_user (kp->type, &up->type)) +u32 type; + +if (get_user (type, &kp->type))return -EFAULT ; -switch (kp->type) { +switch (type) {case V4L2_BUF_TYPE_VIDEO_CAPTURE :case V4L2_BUF_TYPE_VIDEO_OUTPUT : -return copy_to_user (&up->fmt.pix, &kp->fmt.pix, +return copy_in_user (&up->fmt.pix, &kp->fmt.pix,sizeof (kp->fmt.pix)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE :case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE : -return copy_to_user (&up->fmt.pix_mp, &kp->fmt.pix_mp, +return copy_in_user (&up->fmt.pix_mp, &kp->fmt.pix_mp,sizeof (kp->fmt.pix_mp)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_VIDEO_OVERLAY :case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY :return put_v4l2_window32 (&kp->fmt.win, &up->fmt.win);case V4L2_BUF_TYPE_VBI_CAPTURE :case V4L2_BUF_TYPE_VBI_OUTPUT : -return copy_to_user (&up->fmt.vbi, &kp->fmt.vbi, +return copy_in_user (&up->fmt.vbi, &kp->fmt.vbi,sizeof (kp->fmt.vbi)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE :case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT : -return copy_to_user (&up->fmt.sliced, &kp->fmt.sliced, +return copy_in_user (&up->fmt.sliced, &kp->fmt.sliced,sizeof (kp->fmt.sliced)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_SDR_CAPTURE :case V4L2_BUF_TYPE_SDR_OUTPUT : -return copy_to_user (&up->fmt.sdr, &kp->fmt.sdr, +return copy_in_user (&up->fmt.sdr, &kp->fmt.sdr,sizeof (kp->fmt.sdr)) ? -EFAULT :0 ;case V4L2_BUF_TYPE_META_CAPTURE : -return copy_to_user (&up->fmt.meta, &kp->fmt.meta, +return copy_in_user (&up->fmt.meta, &kp->fmt.meta,sizeof (kp->fmt.meta)) ? -EFAULT :0 ;default :return -EINVAL ; } } -static int put_v4l2_format32 (struct v4l2_format *kp,struct v4l2_format32 __user *up) +static int put_v4l2_format32 (struct v4l2_format __user *kp, +struct v4l2_format32 __user *up) {if (!access_ok (VERIFY_WRITE , up,sizeof (*up)))return -EFAULT ;return __put_v4l2_format32 (kp, up); } -static int put_v4l2_create32 (struct v4l2_create_buffers *kp,struct v4l2_create_buffers32 __user *up) +static int put_v4l2_create32 (struct v4l2_create_buffers __user *kp, +struct v4l2_create_buffers32 __user *up) {if (!access_ok (VERIFY_WRITE , up,sizeof (*up)) || -copy_to_user (up, kp, offsetof(struct v4l2_create_buffers32 , format)) || -copy_to_user (up->reserved, kp->reserved,sizeof (kp->reserved))) +copy_in_user (up, kp, + offsetof(struct v4l2_create_buffers32 , format)) || +copy_in_user (up->reserved, kp->reserved,sizeof (kp->reserved)))return -EFAULT ;return __put_v4l2_format32 (&kp->format, &up->format); }
@@ -260,25 +330,27 @@ struct v4l2_standard32 {__u32 reserved[4 ]; }; -static int get_v4l2_standard32 (struct v4l2_standard *kp,struct v4l2_standard32 __user *up) +static int get_v4l2_standard32 (struct v4l2_standard __user *kp, +struct v4l2_standard32 __user *up) {/* other fields are not set by the user, nor used by the driver */ if (!access_ok (VERIFY_READ , up,sizeof (*up)) || -get_user (kp->index, &up->index)) +assign_in_user (&kp->index, &up->index))return -EFAULT ;return 0 ; } -static int put_v4l2_standard32 (struct v4l2_standard *kp,struct v4l2_standard32 __user *up) +static int put_v4l2_standard32 (struct v4l2_standard __user *kp, +struct v4l2_standard32 __user *up) {if (!access_ok (VERIFY_WRITE , up,sizeof (*up)) || -put_user (kp->index, &up->index) || -put_user (kp->id, &up->id) || -copy_to_user (up->name, kp->name,sizeof (up->name)) || -copy_to_user (&up->frameperiod, &kp->frameperiod, -sizeof (kp->frameperiod)) || -put_user (kp->framelines, &up->framelines) || -copy_to_user (up->reserved, kp->reserved,sizeof (kp->reserved))) +assign_in_user (&up->index, &kp->index) || +assign_in_user (&up->id, &kp->id) || +copy_in_user (up->name, kp->name,sizeof (up->name)) || +copy_in_user (&up->frameperiod, &kp->frameperiod, +sizeof (up->frameperiod)) || +assign_in_user (&up->framelines, &kp->framelines) || +copy_in_user (up->reserved, kp->reserved,sizeof (up->reserved)))return -EFAULT ;return 0 ; }
@@ -318,11 +390,11 @@ struct v4l2_buffer32 {__u32 reserved; }; -static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32, +static int get_v4l2_plane32(struct v4l2_plane __user *up, + struct v4l2_plane32 __user *up32, enum v4l2_memory memory) { - void __user *up_pln; - compat_long_t p; + compat_ulong_t p; if (copy_in_user(up, up32, 2 * sizeof(__u32)) || copy_in_user(&up->data_offset, &up32->data_offset,
@@ -337,10 +409,8 @@ static int get_v4l2_plane32(struct v4l2_return -EFAULT ;break ;case V4L2_MEMORY_USERPTR : -if (get_user (p, &up32->m.userptr)) -return -EFAULT ; - up_pln =compat_ptr (p); -if (put_user ((unsigned long )up_pln, &up->m.userptr)) +if (get_user (p, &up32->m.userptr) || +put_user ((unsigned long )compat_ptr (p), &up->m.userptr))return -EFAULT ;break ;case V4L2_MEMORY_DMABUF :
@@ -352,7 +422,8 @@ static int get_v4l2_plane32(struct v4l2_return 0 ; } -static int put_v4l2_plane32 (struct v4l2_plane __user *up,struct v4l2_plane32 __user *up32, +static int put_v4l2_plane32 (struct v4l2_plane __user *up, +struct v4l2_plane32 __user *up32,enum v4l2_memory memory) {unsigned long p;
@@ -376,8 +447,7 @@ static int put_v4l2_plane32(struct v4l2_return -EFAULT ;break ;case V4L2_MEMORY_DMABUF : -if (copy_in_user (&up32->m.fd, &up->m.fd, -sizeof (up->m.fd))) +if (copy_in_user (&up32->m.fd, &up->m.fd,sizeof (up->m.fd)))return -EFAULT ;break ; }
@@ -385,79 +455,121 @@ static int put_v4l2_plane32(struct v4l2_return 0 ; } -static int get_v4l2_buffer32 (struct v4l2_buffer *kp,struct v4l2_buffer32 __user *up) +static int bufsize_v4l2_buffer (struct v4l2_buffer32 __user *up,u32 *size) { +u32 type; +u32 length; + +if (!access_ok (VERIFY_READ , up,sizeof (*up)) || +get_user (type, &up->type) || +get_user (length, &up->length)) +return -EFAULT ; + +if (V4L2_TYPE_IS_MULTIPLANAR (type)) { +if (length >VIDEO_MAX_PLANES ) +return -EINVAL ; + +/* +* We don't really care if userspace decides to kill itself +* by passing a very big length value +*/ + *size = length *sizeof (struct v4l2_plane ); + }else { + *size =0 ; + } +return 0 ; +} + +static int get_v4l2_buffer32 (struct v4l2_buffer __user *kp, +struct v4l2_buffer32 __user *up, +void __user *aux_buf,u32 aux_space) +{ +u32 type; +u32 length; +enum v4l2_memory memory;struct v4l2_plane32 __user *uplane32;struct v4l2_plane __user *uplane;compat_caddr_t p;int ret;if (!access_ok (VERIFY_READ , up,sizeof (*up)) || -get_user (kp->index, &up->index) || -get_user (kp->type, &up->type) || -get_user (kp->flags, &up->flags) || -get_user (kp->memory, &up->memory) || -get_user (kp->length, &up->length)) -return -EFAULT ; - -if (V4L2_TYPE_IS_OUTPUT (kp->type)) -if (get_user (kp->bytesused, &up->bytesused) || -get_user (kp->field, &up->field) || -get_user (kp->timestamp.tv_sec, &up->timestamp.tv_sec) || -get_user (kp->timestamp.tv_usec, &up->timestamp.tv_usec)) -return -EFAULT ; - -if (V4L2_TYPE_IS_MULTIPLANAR (kp->type)) { -unsigned int num_planes; - -if (kp->length ==0 ) { - kp->m.planes =NULL ; -/* num_planes == 0 is legal, e.g. when userspace doesn't -* need planes array on DQBUF*/ -return 0 ; - }else if (kp->length >VIDEO_MAX_PLANES ) { -return -EINVAL ; +assign_in_user (&kp->index, &up->index) || +get_user (type, &up->type) || +put_user (type, &kp->type) || +assign_in_user (&kp->flags, &up->flags) || +get_user (memory, &up->memory) || +put_user (memory, &kp->memory) || +get_user (length, &up->length) || +put_user (length, &kp->length)) +return -EFAULT ; + +if (V4L2_TYPE_IS_OUTPUT (type)) +if (assign_in_user (&kp->bytesused, &up->bytesused) || +assign_in_user (&kp->field, &up->field) || +assign_in_user (&kp->timestamp.tv_sec, + &up->timestamp.tv_sec) || +assign_in_user (&kp->timestamp.tv_usec, + &up->timestamp.tv_usec)) +return -EFAULT ; + +if (V4L2_TYPE_IS_MULTIPLANAR (type)) { +u32 num_planes = length; + +if (num_planes ==0 ) { +/* +* num_planes == 0 is legal, e.g. when userspace doesn't +* need planes array on DQBUF +*/ +return put_user (NULL , &kp->m.planes); } +if (num_planes >VIDEO_MAX_PLANES ) +return -EINVAL ;if (get_user (p, &up->m.planes))return -EFAULT ; uplane32 =compat_ptr (p);if (!access_ok (VERIFY_READ , uplane32, - kp->length *sizeof (*uplane32))) + num_planes *sizeof (*uplane32)))return -EFAULT ; -/* We don't really care if userspace decides to kill itself -* by passing a very big num_planes value */ - uplane =compat_alloc_user_space (kp->length *sizeof (*uplane)); - kp->m.planes = (__force struct v4l2_plane *)uplane; +/* +* We don't really care if userspace decides to kill itself +* by passing a very big num_planes value +*/ +if (aux_space < num_planes *sizeof (*uplane)) +return -EFAULT ; -for (num_planes =0 ; num_planes < kp->length; num_planes++) { - ret =get_v4l2_plane32 (uplane, uplane32, kp->memory); + uplane = aux_buf; +if (put_user ((__force struct v4l2_plane *)uplane, + &kp->m.planes)) +return -EFAULT ; + +while (num_planes--) { + ret =get_v4l2_plane32 (uplane, uplane32, memory);if (ret)return ret; - ++uplane; - ++uplane32; + uplane++; + uplane32++; } }else { -switch (kp->memory) { +switch (memory) {case V4L2_MEMORY_MMAP :case V4L2_MEMORY_OVERLAY : -if (get_user (kp->m.offset, &up->m.offset)) +if (assign_in_user (&kp->m.offset, &up->m.offset))return -EFAULT ;break ; -case V4L2_MEMORY_USERPTR : - { -compat_long_t tmp; +case V4L2_MEMORY_USERPTR : { +compat_ulong_t userptr; -if (get_user (tmp, &up->m.userptr)) -return -EFAULT ; - - kp->m.userptr = (unsigned long )compat_ptr (tmp); - } +if (get_user (userptr, &up->m.userptr) || +put_user ((unsigned long )compat_ptr (userptr), + &kp->m.userptr)) +return -EFAULT ;break ; + }case V4L2_MEMORY_DMABUF : -if (get_user (kp->m.fd, &up->m.fd)) +if (assign_in_user (&kp->m.fd, &up->m.fd))return -EFAULT ;break ; }
@@ -466,62 +578,70 @@ static int get_v4l2_buffer32(struct v4l2return 0 ; } -static int put_v4l2_buffer32 (struct v4l2_buffer *kp,struct v4l2_buffer32 __user *up) +static int put_v4l2_buffer32 (struct v4l2_buffer __user *kp, +struct v4l2_buffer32 __user *up) { +u32 type; +u32 length; +enum v4l2_memory memory;struct v4l2_plane32 __user *uplane32;struct v4l2_plane __user *uplane;compat_caddr_t p; -int num_planes;int ret;if (!access_ok (VERIFY_WRITE , up,sizeof (*up)) || -put_user (kp->index, &up->index) || -put_user (kp->type, &up->type) || -put_user (kp->flags, &up->flags) || -put_user (kp->memory, &up->memory)) -return -EFAULT ; - -if (put_user (kp->bytesused, &up->bytesused) || -put_user (kp->field, &up->field) || -put_user (kp->timestamp.tv_sec, &up->timestamp.tv_sec) || -put_user (kp->timestamp.tv_usec, &up->timestamp.tv_usec) || -copy_to_user (&up->timecode, &kp->timecode,sizeof (kp->timecode)) || -put_user (kp->sequence, &up->sequence) || -put_user (kp->reserved2, &up->reserved2) || -put_user (kp->reserved, &up->reserved) || -put_user (kp->length, &up->length)) +assign_in_user (&up->index, &kp->index) || +get_user (type, &kp->type) || +put_user (type, &up->type) || +assign_in_user (&up->flags, &kp->flags) || +get_user (memory, &kp->memory) || +put_user (memory, &up->memory)) +return -EFAULT ; + +if (assign_in_user (&up->bytesused, &kp->bytesused) || +assign_in_user (&up->field, &kp->field) || +assign_in_user (&up->timestamp.tv_sec, &kp->timestamp.tv_sec) || +assign_in_user (&up->timestamp.tv_usec, &kp->timestamp.tv_usec) || +copy_in_user (&up->timecode, &kp->timecode,sizeof (kp->timecode)) || +assign_in_user (&up->sequence, &kp->sequence) || +assign_in_user (&up->reserved2, &kp->reserved2) || +assign_in_user (&up->reserved, &kp->reserved) || +get_user (length, &kp->length) || +put_user (length, &up->length))return -EFAULT ; -if (V4L2_TYPE_IS_MULTIPLANAR (kp->type)) { - num_planes = kp->length; +if (V4L2_TYPE_IS_MULTIPLANAR (type)) { +u32 num_planes = length; +if (num_planes ==0 )return 0 ; - uplane = (__force struct v4l2_plane __user *)kp->m.planes; +if (get_user (uplane, ((__force struct v4l2_plane __user **)&kp->m.planes))) +return -EFAULT ;if (get_user (p, &up->m.planes))return -EFAULT ; uplane32 =compat_ptr (p); -while (--num_planes >=0 ) { - ret =put_v4l2_plane32 (uplane, uplane32, kp->memory); +while (num_planes--) { + ret =put_v4l2_plane32 (uplane, uplane32, memory);if (ret)return ret; ++uplane; ++uplane32; } }else { -switch (kp->memory) { +switch (memory) {case V4L2_MEMORY_MMAP :case V4L2_MEMORY_OVERLAY : -if (put_user (kp->m.offset, &up->m.offset)) +if (assign_in_user (&up->m.offset, &kp->m.offset))return -EFAULT ;break ;case V4L2_MEMORY_USERPTR : -if (put_user (kp->m.userptr, &up->m.userptr)) +if (assign_in_user (&up->m.userptr, &kp->m.userptr))return -EFAULT ;break ;case V4L2_MEMORY_DMABUF : -if (put_user (kp->m.fd, &up->m.fd)) +if (assign_in_user (&up->m.fd, &kp->m.fd))return -EFAULT ;break ; }
@@ -546,29 +666,32 @@ struct v4l2_framebuffer32 { } fmt; }; -static int get_v4l2_framebuffer32 (struct v4l2_framebuffer *kp,struct v4l2_framebuffer32 __user *up) +static int get_v4l2_framebuffer32 (struct v4l2_framebuffer __user *kp, +struct v4l2_framebuffer32 __user *up) { -u32 tmp; +compat_caddr_t tmp;if (!access_ok (VERIFY_READ , up,sizeof (*up)) ||get_user (tmp, &up->base) || -get_user (kp->capability, &up->capability) || -get_user (kp->flags, &up->flags) || -copy_from_user (&kp->fmt, &up->fmt,sizeof (up->fmt))) +put_user ((__force void *)compat_ptr (tmp), &kp->base) || +assign_in_user (&kp->capability, &up->capability) || +assign_in_user (&kp->flags, &up->flags) || +copy_in_user (&kp->fmt, &up->fmt,sizeof (kp->fmt)))return -EFAULT ; - kp->base = (__force void *)compat_ptr (tmp);return 0 ; } -static int put_v4l2_framebuffer32 (struct v4l2_framebuffer *kp,struct v4l2_framebuffer32 __user *up) +static int put_v4l2_framebuffer32 (struct v4l2_framebuffer __user *kp, +struct v4l2_framebuffer32 __user *up) { -u32 tmp = (u32)((unsigned long )kp->base); +void *base;if (!access_ok (VERIFY_WRITE , up,sizeof (*up)) || -put_user (tmp, &up->base) || -put_user (kp->capability, &up->capability) || -put_user (kp->flags, &up->flags) || -copy_to_user (&up->fmt, &kp->fmt,sizeof (up->fmt))) +get_user (base, &kp->base) || +put_user (ptr_to_compat (base), &up->base) || +assign_in_user (&up->capability, &kp->capability) || +assign_in_user (&up->flags, &kp->flags) || +copy_in_user (&up->fmt, &kp->fmt,sizeof (kp->fmt)))return -EFAULT ;return 0 ; }
@@ -585,18 +708,22 @@ struct v4l2_input32 {__u32 reserved[3 ]; }; -/* The 64-bit v4l2_input struct has extra padding at the end of the struct. -Otherwise it is identical to the 32-bit version. */ -static inline int get_v4l2_input32 (struct v4l2_input *kp,struct v4l2_input32 __user *up) +/* +* The 64-bit v4l2_input struct has extra padding at the end of the struct. +* Otherwise it is identical to the 32-bit version. +*/ +static inline int get_v4l2_input32 (struct v4l2_input __user *kp, +struct v4l2_input32 __user *up) { -if (copy_from_user (kp, up,sizeof (*up))) +if (copy_in_user (kp, up,sizeof (*up)))return -EFAULT ;return 0 ; } -static inline int put_v4l2_input32 (struct v4l2_input *kp,struct v4l2_input32 __user *up) +static inline int put_v4l2_input32 (struct v4l2_input __user *kp, +struct v4l2_input32 __user *up) { -if (copy_to_user (up, kp,sizeof (*up))) +if (copy_in_user (up, kp,sizeof (*up)))return -EFAULT ;return 0 ; }
@@ -650,41 +777,64 @@ static inline bool ctrl_is_pointer(struc (qec.flags &V4L2_CTRL_FLAG_HAS_PAYLOAD ); } +static int bufsize_v4l2_ext_controls (struct v4l2_ext_controls32 __user *up, +u32 *size) +{ +u32 count; + +if (!access_ok (VERIFY_READ , up,sizeof (*up)) || +get_user (count, &up->count)) +return -EFAULT ; +if (count >V4L2_CID_MAX_CTRLS ) +return -EINVAL ; + *size = count *sizeof (struct v4l2_ext_control ); +return 0 ; +} +static int get_v4l2_ext_controls32 (struct file *file, -struct v4l2_ext_controls *kp, -struct v4l2_ext_controls32 __user *up) +struct v4l2_ext_controls __user *kp, +struct v4l2_ext_controls32 __user *up, +void __user *aux_buf,u32 aux_space) {struct v4l2_ext_control32 __user *ucontrols;struct v4l2_ext_control __user *kcontrols; -unsigned int n; +u32 count; +u32 n;compat_caddr_t p;if (!access_ok (VERIFY_READ , up,sizeof (*up)) || -get_user (kp->which, &up->which) || -get_user (kp->count, &up->count) || -get_user (kp->error_idx, &up->error_idx) || -copy_from_user (kp->reserved, up->reserved,sizeof (kp->reserved))) +assign_in_user (&kp->which, &up->which) || +get_user (count, &up->count) || +put_user (count, &kp->count) || +assign_in_user (&kp->error_idx, &up->error_idx) || +copy_in_user (kp->reserved, up->reserved,sizeof (kp->reserved)))return -EFAULT ; -if (kp->count ==0 ) { - kp->controls =NULL ; -return 0 ; - }else if (kp->count >V4L2_CID_MAX_CTRLS ) { + +if (count ==0 ) +return put_user (NULL , &kp->controls); +if (count >V4L2_CID_MAX_CTRLS )return -EINVAL ; - }if (get_user (p, &up->controls))return -EFAULT ; ucontrols =compat_ptr (p); -if (!access_ok (VERIFY_READ , ucontrols, kp->count *sizeof (*ucontrols))) +if (!access_ok (VERIFY_READ , ucontrols, count *sizeof (*ucontrols)))return -EFAULT ; - kcontrols =compat_alloc_user_space (kp->count *sizeof (*kcontrols)); - kp->controls = (__force struct v4l2_ext_control *)kcontrols; -for (n =0 ; n < kp->count; n++) { +if (aux_space < count *sizeof (*kcontrols)) +return -EFAULT ; + kcontrols = aux_buf; +if (put_user ((__force struct v4l2_ext_control *)kcontrols, + &kp->controls)) +return -EFAULT ; + +for (n =0 ; n < count; n++) {u32 id;if (copy_in_user (kcontrols, ucontrols,sizeof (*ucontrols)))return -EFAULT ; +if (get_user (id, &kcontrols->id))return -EFAULT ; +if (ctrl_is_pointer (file, id)) {void __user *s;
@@ -701,43 +851,54 @@ static int get_v4l2_ext_controls32(struc }static int put_v4l2_ext_controls32 (struct file *file, -struct v4l2_ext_controls *kp, +struct v4l2_ext_controls __user *kp,struct v4l2_ext_controls32 __user *up) {struct v4l2_ext_control32 __user *ucontrols; -struct v4l2_ext_control __user *kcontrols = - (__force struct v4l2_ext_control __user *)kp->controls; -int n = kp->count; +struct v4l2_ext_control __user *kcontrols; +u32 count; +u32 n;compat_caddr_t p;if (!access_ok (VERIFY_WRITE , up,sizeof (*up)) || -put_user (kp->which, &up->which) || -put_user (kp->count, &up->count) || -put_user (kp->error_idx, &up->error_idx) || -copy_to_user (up->reserved, kp->reserved,sizeof (up->reserved))) +assign_in_user (&up->which, &kp->which) || +get_user (count, &kp->count) || +put_user (count, &up->count) || +assign_in_user (&up->error_idx, &kp->error_idx) || +copy_in_user (up->reserved, kp->reserved,sizeof (up->reserved)) || +get_user (kcontrols, &kp->controls))return -EFAULT ; -if (!kp->count) -return 0 ; +if (!count) +return 0 ;if (get_user (p, &up->controls))return -EFAULT ; ucontrols =compat_ptr (p); -if (!access_ok (VERIFY_WRITE , ucontrols, n *sizeof (*ucontrols))) +if (!access_ok (VERIFY_WRITE , ucontrols, count *sizeof (*ucontrols)))return -EFAULT ; -while (--n >=0 ) { -unsigned size =sizeof (*ucontrols); +for (n =0 ; n < count; n++) { +unsigned int size =sizeof (*ucontrols);u32 id; -if (get_user (id, &kcontrols->id)) +if (get_user (id, &kcontrols->id) || +put_user (id, &ucontrols->id) || +assign_in_user (&ucontrols->size, &kcontrols->size) || +copy_in_user (&ucontrols->reserved2, &kcontrols->reserved2, +sizeof (ucontrols->reserved2)))return -EFAULT ; -/* Do not modify the pointer when copying a pointer control. -The contents of the pointer was changed, not the pointer -itself. */ + +/* +* Do not modify the pointer when copying a pointer control. +* The contents of the pointer was changed, not the pointer +* itself. +*/ if (ctrl_is_pointer (file, id)) size -=sizeof (ucontrols->value64); +if (copy_in_user (ucontrols, kcontrols, size))return -EFAULT ; + ucontrols++; kcontrols++; }
@@ -757,17 +918,18 @@ struct v4l2_event32 {__u32 reserved[8 ]; }; -static int put_v4l2_event32 (struct v4l2_event *kp,struct v4l2_event32 __user *up) +static int put_v4l2_event32 (struct v4l2_event __user *kp, +struct v4l2_event32 __user *up) {if (!access_ok (VERIFY_WRITE , up,sizeof (*up)) || -put_user (kp->type, &up->type) || -copy_to_user (&up->u, &kp->u,sizeof (kp->u)) || -put_user (kp->pending, &up->pending) || -put_user (kp->sequence, &up->sequence) || -put_user (kp->timestamp.tv_sec, &up->timestamp.tv_sec) || -put_user (kp->timestamp.tv_nsec, &up->timestamp.tv_nsec) || -put_user (kp->id, &up->id) || -copy_to_user (up->reserved, kp->reserved,sizeof (kp->reserved))) +assign_in_user (&up->type, &kp->type) || +copy_in_user (&up->u, &kp->u,sizeof (kp->u)) || +assign_in_user (&up->pending, &kp->pending) || +assign_in_user (&up->sequence, &kp->sequence) || +assign_in_user (&up->timestamp.tv_sec, &kp->timestamp.tv_sec) || +assign_in_user (&up->timestamp.tv_nsec, &kp->timestamp.tv_nsec) || +assign_in_user (&up->id, &kp->id) || +copy_in_user (up->reserved, kp->reserved,sizeof (up->reserved)))return -EFAULT ;return 0 ; }
@@ -780,31 +942,34 @@ struct v4l2_edid32 {compat_caddr_t edid; }; -static int get_v4l2_edid32 (struct v4l2_edid *kp,struct v4l2_edid32 __user *up) +static int get_v4l2_edid32 (struct v4l2_edid __user *kp, +struct v4l2_edid32 __user *up) { -u32 tmp; +compat_uptr_t tmp;if (!access_ok (VERIFY_READ , up,sizeof (*up)) || -get_user (kp->pad, &up->pad) || -get_user (kp->start_block, &up->start_block) || -get_user (kp->blocks, &up->blocks) || +assign_in_user (&kp->pad, &up->pad) || +assign_in_user (&kp->start_block, &up->start_block) || +assign_in_user (&kp->blocks, &up->blocks) ||get_user (tmp, &up->edid) || -copy_from_user (kp->reserved, up->reserved,sizeof (kp->reserved))) +put_user (compat_ptr (tmp), &kp->edid) || +copy_in_user (kp->reserved, up->reserved,sizeof (kp->reserved)))return -EFAULT ; - kp->edid = (__force u8 *)compat_ptr (tmp);return 0 ; } -static int put_v4l2_edid32 (struct v4l2_edid *kp,struct v4l2_edid32 __user *up) +static int put_v4l2_edid32 (struct v4l2_edid __user *kp, +struct v4l2_edid32 __user *up) { -u32 tmp = (u32)((unsigned long )kp->edid); +void *edid;if (!access_ok (VERIFY_WRITE , up,sizeof (*up)) || -put_user (kp->pad, &up->pad) || -put_user (kp->start_block, &up->start_block) || -put_user (kp->blocks, &up->blocks) || -put_user (tmp, &up->edid) || -copy_to_user (up->reserved, kp->reserved,sizeof (up->reserved))) +assign_in_user (&up->pad, &kp->pad) || +assign_in_user (&up->start_block, &kp->start_block) || +assign_in_user (&up->blocks, &kp->blocks) || +get_user (edid, &kp->edid) || +put_user (ptr_to_compat (edid), &up->edid) || +copy_in_user (up->reserved, kp->reserved,sizeof (up->reserved)))return -EFAULT ;return 0 ; }
@@ -837,22 +1002,23 @@ static int put_v4l2_edid32(struct v4l2_e#define VIDIOC_G_OUTPUT32 _IOR ('V', 46, s32)#define VIDIOC_S_OUTPUT32 _IOWR('V', 47, s32) +static int alloc_userspace (unsigned int size,u32 aux_space, +void __user **up_native) +{ + *up_native =compat_alloc_user_space (size + aux_space); +if (!*up_native) +return -ENOMEM ; +if (clear_user (*up_native, size)) +return -EFAULT ; +return 0 ; +} +static long do_video_ioctl (struct file *file,unsigned int cmd,unsigned long arg) { -union { -struct v4l2_format v2f; -struct v4l2_buffer v2b; -struct v4l2_framebuffer v2fb; -struct v4l2_input v2i; -struct v4l2_standard v2s; -struct v4l2_ext_controls v2ecs; -struct v4l2_event v2ev; -struct v4l2_create_buffers v2crt; -struct v4l2_edid v2edid; -unsigned long vx; -int vi; - } karg;void __user *up =compat_ptr (arg); +void __user *up_native =NULL ; +void __user *aux_buf; +u32 aux_space;int compatible_arg =1 ;long err =0 ;
@@ -891,30 +1057,52 @@ static long do_video_ioctl(struct file *case VIDIOC_STREAMOFF :case VIDIOC_S_INPUT :case VIDIOC_S_OUTPUT : - err =get_user (karg.vi, (s32 __user *)up); + err =alloc_userspace (sizeof (unsigned int ),0 , &up_native); +if (!err &&assign_in_user ((unsigned int __user *)up_native, + (compat_uint_t __user *)up)) + err = -EFAULT ; compatible_arg =0 ;break ;case VIDIOC_G_INPUT :case VIDIOC_G_OUTPUT : + err =alloc_userspace (sizeof (unsigned int ),0 , &up_native); compatible_arg =0 ;break ;case VIDIOC_G_EDID :case VIDIOC_S_EDID : - err =get_v4l2_edid32 (&karg.v2edid, up); + err =alloc_userspace (sizeof (struct v4l2_edid ),0 , &up_native); +if (!err) + err =get_v4l2_edid32 (up_native, up); compatible_arg =0 ;break ;case VIDIOC_G_FMT :case VIDIOC_S_FMT :case VIDIOC_TRY_FMT : - err =get_v4l2_format32 (&karg.v2f, up); + err =bufsize_v4l2_format (up, &aux_space); +if (!err) + err =alloc_userspace (sizeof (struct v4l2_format ), + aux_space, &up_native); +if (!err) { + aux_buf = up_native +sizeof (struct v4l2_format ); + err =get_v4l2_format32 (up_native, up, + aux_buf, aux_space); + } compatible_arg =0 ;break ;case VIDIOC_CREATE_BUFS : - err =get_v4l2_create32 (&karg.v2crt, up); + err =bufsize_v4l2_create (up, &aux_space); +if (!err) + err =alloc_userspace (sizeof (struct v4l2_create_buffers ), + aux_space, &up_native); +if (!err) { + aux_buf = up_native +sizeof (struct v4l2_create_buffers ); + err =get_v4l2_create32 (up_native, up, + aux_buf, aux_space); + } compatible_arg =0 ;break ;
@@ -922,36 +1110,63 @@ static long do_video_ioctl(struct file *case VIDIOC_QUERYBUF :case VIDIOC_QBUF :case VIDIOC_DQBUF : - err =get_v4l2_buffer32 (&karg.v2b, up); + err =bufsize_v4l2_buffer (up, &aux_space); +if (!err) + err =alloc_userspace (sizeof (struct v4l2_buffer ), + aux_space, &up_native); +if (!err) { + aux_buf = up_native +sizeof (struct v4l2_buffer ); + err =get_v4l2_buffer32 (up_native, up, + aux_buf, aux_space); + } compatible_arg =0 ;break ;case VIDIOC_S_FBUF : - err =get_v4l2_framebuffer32 (&karg.v2fb, up); + err =alloc_userspace (sizeof (struct v4l2_framebuffer ),0 , + &up_native); +if (!err) + err =get_v4l2_framebuffer32 (up_native, up); compatible_arg =0 ;break ;case VIDIOC_G_FBUF : + err =alloc_userspace (sizeof (struct v4l2_framebuffer ),0 , + &up_native); compatible_arg =0 ;break ;case VIDIOC_ENUMSTD : - err =get_v4l2_standard32 (&karg.v2s, up); + err =alloc_userspace (sizeof (struct v4l2_standard ),0 , + &up_native); +if (!err) + err =get_v4l2_standard32 (up_native, up); compatible_arg =0 ;break ;case VIDIOC_ENUMINPUT : - err =get_v4l2_input32 (&karg.v2i, up); + err =alloc_userspace (sizeof (struct v4l2_input ),0 , &up_native); +if (!err) + err =get_v4l2_input32 (up_native, up); compatible_arg =0 ;break ;case VIDIOC_G_EXT_CTRLS :case VIDIOC_S_EXT_CTRLS :case VIDIOC_TRY_EXT_CTRLS : - err =get_v4l2_ext_controls32 (file, &karg.v2ecs, up); + err =bufsize_v4l2_ext_controls (up, &aux_space); +if (!err) + err =alloc_userspace (sizeof (struct v4l2_ext_controls ), + aux_space, &up_native); +if (!err) { + aux_buf = up_native +sizeof (struct v4l2_ext_controls ); + err =get_v4l2_ext_controls32 (file, up_native, up, + aux_buf, aux_space); + } compatible_arg =0 ;break ;case VIDIOC_DQEVENT : + err =alloc_userspace (sizeof (struct v4l2_event ),0 , &up_native); compatible_arg =0 ;break ; }
@@ -960,29 +1175,26 @@ static long do_video_ioctl(struct file *if (compatible_arg) err =native_ioctl (file, cmd, (unsigned long )up); -else { -mm_segment_t old_fs =get_fs (); - -set_fs (KERNEL_DS ); - err =native_ioctl (file, cmd, (unsigned long )&karg); -set_fs (old_fs); - } +else + err =native_ioctl (file, cmd, (unsigned long )up_native);if (err == -ENOTTY )return err; -/* Special case: even after an error we need to put the -results back for these ioctls since the error_idx will -contain information on which control failed. */ +/* +* Special case: even after an error we need to put the +* results back for these ioctls since the error_idx will +* contain information on which control failed. +*/ switch (cmd) {case VIDIOC_G_EXT_CTRLS :case VIDIOC_S_EXT_CTRLS :case VIDIOC_TRY_EXT_CTRLS : -if (put_v4l2_ext_controls32 (file, &karg.v2ecs, up)) +if (put_v4l2_ext_controls32 (file, up_native, up)) err = -EFAULT ;break ;case VIDIOC_S_EDID : -if (put_v4l2_edid32 (&karg.v2edid, up)) +if (put_v4l2_edid32 (up_native, up)) err = -EFAULT ;break ; }
@@ -994,44 +1206,46 @@ static long do_video_ioctl(struct file *case VIDIOC_S_OUTPUT :case VIDIOC_G_INPUT :case VIDIOC_G_OUTPUT : - err =put_user (((s32 )karg.vi), (s32 __user *)up); +if (assign_in_user ((compat_uint_t __user *)up, + ((unsigned int __user *)up_native))) + err = -EFAULT ;break ;case VIDIOC_G_FBUF : - err =put_v4l2_framebuffer32 (&karg.v2fb, up); + err =put_v4l2_framebuffer32 (up_native, up);break ;case VIDIOC_DQEVENT : - err =put_v4l2_event32 (&karg.v2ev, up); + err =put_v4l2_event32 (up_native, up);break ;case VIDIOC_G_EDID : - err =put_v4l2_edid32 (&karg.v2edid, up); + err =put_v4l2_edid32 (up_native, up);break ;case VIDIOC_G_FMT :case VIDIOC_S_FMT :case VIDIOC_TRY_FMT : - err =put_v4l2_format32 (&karg.v2f, up); + err =put_v4l2_format32 (up_native, up);break ;case VIDIOC_CREATE_BUFS : - err =put_v4l2_create32 (&karg.v2crt, up); + err =put_v4l2_create32 (up_native, up);break ;case VIDIOC_PREPARE_BUF :case VIDIOC_QUERYBUF :case VIDIOC_QBUF :case VIDIOC_DQBUF : - err =put_v4l2_buffer32 (&karg.v2b, up); + err =put_v4l2_buffer32 (up_native, up);break ;case VIDIOC_ENUMSTD : - err =put_v4l2_standard32 (&karg.v2s, up); + err =put_v4l2_standard32 (up_native, up);break ;case VIDIOC_ENUMINPUT : - err =put_v4l2_input32 (&karg.v2i, up); + err =put_v4l2_input32 (up_native, up);break ; }return err;
Greg Kroah-Hartman
maintainerPATCH 132/195 media: v4l2-compat-ioctl32.c: make ctrl_is_pointer work for subdevs
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans Verkuil <[email protected]>
commit 273caa260035c03d89ad63d72d8cd3d9e5c5e3f1 upstream.
If the device is of type VFL_TYPE_SUBDEV then vdev->ioctl_ops is NULL so the 'if (!ops->vidioc_query_ext_ctrl)' check would crash. Add a test for !ops to the condition.
All sub-devices that have controls will use the control framework, so they do not have an equivalent to ops->vidioc_query_ext_ctrl. Returning false if ops is NULL is the correct thing to do here.
--- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/v4l2-core/v4l2-compat-ioctl32.c +1 -1
@@ -770,7 +770,7 @@ static inline bool ctrl_is_pointer(strucreturn ctrl && ctrl->is_ptr; } -if (!ops->vidioc_query_ext_ctrl) +if (!ops || !ops->vidioc_query_ext_ctrl)return false; return !ops->vidioc_query_ext_ctrl(file, fh, &qec) &&
Greg Kroah-Hartman
maintainerPATCH 133/195 crypto: caam - fix endless loop when DECO acquire fails
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Horia Geantă <[email protected]>
commit 225ece3e7dad4cfc44cca38ce7a3a80f255ea8f1 upstream.
In case DECO0 cannot be acquired - i.e. run_descriptor_deco0() fails with -ENODEV, caam_probe() enters an endless loop:
run_descriptor_deco0
ret -ENODEV -> instantiate_rng -ENODEV, overwritten by -EAGAIN ret -EAGAIN -> caam_probe -EAGAIN results in endless loop
It turns out the error path in instantiate_rng() is incorrect, the checks are done in the wrong order.
--- drivers/crypto/caam/ctrl.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/crypto/caam/ctrl.c +6 -2
@@ -228,12 +228,16 @@ static int instantiate_rng(struct device* without any error (HW optimizations for later * CAAM eras), then try again. */ +if (ret) +break ; + rdsta_val =rd_reg32 (&ctrl->r4tst[0 ].rdsta) &RDSTA_IFMASK ;if ((status && status !=JRSTA_SSRC_JUMP_HALT_CC ) || - !(rdsta_val & (1 << sh_idx))) + !(rdsta_val & (1 << sh_idx))) { ret = -EAGAIN ; -if (ret)break ; + } +dev_info (ctrldev,"Instantiated RNG4 SH%d\n" , sh_idx);/* Clear the contents before recreating the descriptor */ memset (desc,0x00 ,CAAM_CMD_SZ *7 );
Greg Kroah-Hartman
maintainerPATCH 134/195 crypto: sha512-mb - initialize pending lengths correctly
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit eff84b379089cd8b4e83599639c1f5f6e34ef7bf upstream.
The SHA-512 multibuffer code keeps track of the number of blocks pending in each lane. The minimum of these values is used to identify the next lane that will be completed. Unused lanes are set to a large number (0xFFFFFFFF) so that they don't affect this calculation.
However, it was forgotten to set the lengths to this value in the initial state, where all lanes are unused. As a result it was possible for sha512_mb_mgr_get_comp_job_avx2() to select an unused lane, causing a NULL pointer dereference. Specifically this could happen in the case where ->update() was passed fewer than SHA512_BLOCK_SIZE bytes of data, so it then called sha_complete_job() without having actually submitted any blocks to the multi-buffer code. This hit a NULL pointer dereference if another task happened to have submitted blocks concurrently to the same CPU and the flush timer had not yet expired.
Fix this by initializing sha512_mb_mgr->lens correctly.
As usual, this bug was found by syzkaller.
--- arch/x86/crypto/sha512-mb/sha512_mb_mgr_init_avx2.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
arch/x86/crypto/sha512-mb/sha512_mb_mgr_init_avx2.c +6 -4
@@ -57,10 +57,12 @@ void sha512_mb_mgr_init_avx2(struct sha5 {unsigned int j; - state->lens[0 ] =0 ; - state->lens[1 ] =1 ; - state->lens[2 ] =2 ; - state->lens[3 ] =3 ; +/* initially all lanes are unused */ + state->lens[0 ] =0xFFFFFFFF00000000 ; + state->lens[1 ] =0xFFFFFFFF00000001 ; + state->lens[2 ] =0xFFFFFFFF00000002 ; + state->lens[3 ] =0xFFFFFFFF00000003 ; + state->unused_lanes =0xFF03020100 ;for (j =0 ; j <4 ; j++) state->ldata[j].job_in_lane =NULL ;
Greg Kroah-Hartman
maintainerPATCH 135/195 crypto: talitos - fix Kernel Oops on hashing an empty file
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: LEROY Christophe <[email protected]>
commit 87a81dce53b1ea61acaeefa5191a0376a2d1d721 upstream.
Performing the hash of an empty file leads to a kernel Oops
[ 44.504600] Unable to handle kernel paging request for data at address 0x0000000c [ 44.512819] Faulting instruction address: 0xc02d2be8 [ 44.524088] Oops: Kernel access of bad area, sig: 11 [#1] [ 44.529171] BE PREEMPT CMPC885 [ 44.532232] CPU: 0 PID: 491 Comm: md5sum Not tainted 4.15.0-rc8-00211-g3a968610b6ea #81 [ 44.540814] NIP: c02d2be8 LR: c02d2984 CTR: 00000000 [ 44.545812] REGS: c6813c90 TRAP: 0300 Not tainted (4.15.0-rc8-00211-g3a968610b6ea) [ 44.554223] MSR: 00009032 <EE,ME,IR,DR,RI> CR: 48222822 XER: 20000000 [ 44.560855] DAR: 0000000c DSISR: c0000000 [ 44.560855] GPR00: c02d28fc c6813d40 c6828000 c646fa40 00000001 00000001 00000001 00000000 [ 44.560855] GPR08: 0000004c 00000000 c000bfcc 00000000 28222822 100280d4 00000000 10020008 [ 44.560855] GPR16: 00000000 00000020 00000000 00000000 10024008 00000000 c646f9f0 c6179a10 [ 44.560855] GPR24: 00000000 00000001 c62f0018 c6179a10 00000000 c6367a30 c62f0000 c646f9c0 [ 44.598542] NIP [c02d2be8] ahash_process_req+0x448/0x700 [ 44.603751] LR [c02d2984] ahash_process_req+0x1e4/0x700 [ 44.608868] Call Trace: [ 44.611329] [c6813d40] [c02d28fc] ahash_process_req+0x15c/0x700 (unreliable) [ 44.618302] [c6813d90] [c02060c4] hash_recvmsg+0x11c/0x210 [ 44.623716] [c6813db0] [c0331354] ___sys_recvmsg+0x98/0x138 [ 44.629226] [c6813eb0] [c03332c0] __sys_recvmsg+0x40/0x84 [ 44.634562] [c6813f10] [c03336c0] SyS_socketcall+0xb8/0x1d4 [ 44.640073] [c6813f40] [c000d1ac] ret_from_syscall+0x0/0x38 [ 44.645530] Instruction dump: [ 44.648465] 38c00001 7f63db78 4e800421 7c791b78 54690ffe 0f090000 80ff0190 2f870000 [ 44.656122] 40befe50 2f990001 409e0210 813f01bc <8129000c> b39e003a 7d29c214 913e003c
This patch fixes that Oops by checking if src is NULL.
--- drivers/crypto/talitos.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/crypto/talitos.c +4 -0
@@ -1127,6 +1127,10 @@ int talitos_sg_map(struct device *dev, sto_talitos_ptr_len (ptr, len, is_sec1);to_talitos_ptr_ext_set (ptr,0 , is_sec1); +if (!src) { +to_talitos_ptr (ptr,0 ,0 , is_sec1); +return 1 ; + }if (sg_count ==1 ) {to_talitos_ptr (ptr,sg_dma_address (src) + offset, is_sec1);return sg_count;
Greg Kroah-Hartman
maintainerPATCH 136/195 arm: KVM: Fix SMCCC handling of unimplemented SMC/HVC calls
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
commit 20e8175d246e9f9deb377f2784b3e7dfb2ad3e86 upstream.
KVM doesn't follow the SMCCC when it comes to unimplemented calls, and inject an UNDEF instead of returning an error. Since firmware calls are now used for security mitigation, they are becoming more common, and the undef is counter productive.
Instead, let's follow the SMCCC which states that -1 must be returned to the caller when getting an unknown function number.
--- arch/arm/kvm/handle_exit.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
arch/arm/kvm/handle_exit.c +11 -2
@@ -38,7 +38,7 @@ static int handle_hvc(struct kvm_vcpu *v ret =kvm_hvc_call_handler (vcpu);if (ret <0 ) { -kvm_inject_undefined (vcpu); +vcpu_set_reg (vcpu,0 , ~0UL );return 1 ; }
@@ -47,7 +47,16 @@ static int handle_hvc(struct kvm_vcpu *vstatic int handle_smc (struct kvm_vcpu *vcpu,struct kvm_run *run) { -kvm_inject_undefined (vcpu); +/* +* "If an SMC instruction executed at Non-secure EL1 is +* trapped to EL2 because HCR_EL2.TSC is 1, the exception is a +* Trap exception, not a Secure Monitor Call exception [...]" +* +* We need to advance the PC after the trap, as it would +* otherwise return to the same address... +*/ +vcpu_set_reg (vcpu,0 , ~0UL ); +kvm_skip_instr (vcpu,kvm_vcpu_trap_il_is32bit (vcpu));return 1 ; }
Greg Kroah-Hartman
maintainerPATCH 137/195 KVM: nVMX: Fix races when sending nested PI while dest enters/leaves L2
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Liran Alon <[email protected]>
commit 6b6977117f50d60455ace86b2d256f6fb4f3de05 upstream.
Consider the following scenario:
1. CPU A calls vmx_deliver_nested_posted_interrupt() to send an IPI to CPU B via virtual posted-interrupt mechanism.
2. CPU B is currently executing L2 guest.
3. vmx_deliver_nested_posted_interrupt() calls kvm_vcpu_trigger_posted_interrupt() which will note that vcpu->mode == IN_GUEST_MODE.
4. Assume that before CPU A sends the physical POSTED_INTR_NESTED_VECTOR IPI, CPU B exits from L2 to L0 during event-delivery
(valid IDT-vectoring-info).
5. CPU A now sends the physical IPI. The IPI is received in host and it's handler (smp_kvm_posted_intr_nested_ipi()) does nothing.
6. Assume that before CPU A sets pi_pending=true and KVM_REQ_EVENT, CPU B continues to run in L0 and reach vcpu_enter_guest(). As KVM_REQ_EVENT is not set yet, vcpu_enter_guest() will continue and resume L2 guest.
7. At this point, CPU A sets pi_pending=true and KVM_REQ_EVENT but it's too late! CPU B already entered L2 and KVM_REQ_EVENT will only be consumed at next L2 entry!
Another scenario to consider:
1. CPU A calls vmx_deliver_nested_posted_interrupt() to send an IPI to CPU B via virtual posted-interrupt mechanism.
2. Assume that before CPU A calls kvm_vcpu_trigger_posted_interrupt(), CPU B is at L0 and is about to resume into L2. Further assume that it is in vcpu_enter_guest() after check for KVM_REQ_EVENT.
3. At this point, CPU A calls kvm_vcpu_trigger_posted_interrupt() which will note that vcpu->mode != IN_GUEST_MODE. Therefore, do nothing and return false. Then, will set pi_pending=true and KVM_REQ_EVENT.
4. Now CPU B continue and resumes into L2 guest without processing the posted-interrupt until next L2 entry!
To fix both issues, we just need to change vmx_deliver_nested_posted_interrupt() to set pi_pending=true and KVM_REQ_EVENT before calling kvm_vcpu_trigger_posted_interrupt().
It will fix the first scenario by chaging step (6) to note that KVM_REQ_EVENT and pi_pending=true and therefore process nested posted-interrupt.
It will fix the second scenario by two possible ways:
1. If kvm_vcpu_trigger_posted_interrupt() is called while CPU B has changed vcpu->mode to IN_GUEST_MODE, physical IPI will be sent and will be received when CPU resumes into L2.
2. If kvm_vcpu_trigger_posted_interrupt() is called while CPU B hasn't yet changed vcpu->mode to IN_GUEST_MODE, then after CPU B will change vcpu->mode it will call kvm_request_pending() which will return true and therefore force another round of vcpu_enter_guest() which will note that KVM_REQ_EVENT and pi_pending=true and therefore process nested posted-interrupt.
[Add kvm_vcpu_kick to also handle the case where L1 doesn't intercept L2 HLT
and L2 executes HLT instruction. - Paolo]
--- arch/x86/kvm/vmx.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/kvm/vmx.c +3 -2
@@ -5322,14 +5322,15 @@ static int vmx_deliver_nested_posted_intif (is_guest_mode (vcpu) && vector == vmx->nested.posted_intr_nv) { -/* the PIR and ON have been set by L1. */ -kvm_vcpu_trigger_posted_interrupt (vcpu, true);/* * If a posted intr is not recognized by hardware, * we will accomplish it in the next vmentry. */ vmx->nested.pi_pending = true;kvm_make_request (KVM_REQ_EVENT , vcpu); +/* the PIR and ON have been set by L1. */ +if (!kvm_vcpu_trigger_posted_interrupt (vcpu, true)) +kvm_vcpu_kick (vcpu);return 0 ; }return -1 ;
Greg Kroah-Hartman
maintainerPATCH 138/195 KVM: nVMX: Fix bug of injecting L2 exception into L1
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Liran Alon <[email protected]>
commit 5c7d4f9ad39d980728b39752304ce10bb2960cbf upstream.
kvm_clear_exception_queue() should clear pending exception. This also includes exceptions which were only marked pending but not yet injected. This is because exception.pending is used for both L1 and L2 to determine if an exception should be raised to guest. Note that an exception which is pending but not yet injected will be raised again once the guest will be resumed.
Consider the following scenario:
1) L0 KVM with ignore_msrs=false.
2) L1 prepare vmcs12 with the following:
a) No intercepts on MSR (MSR_BITMAP exist and is filled with 0).
b) No intercept for #GP.
c) vmx-preemption-timer is configured.
3) L1 enters into L2.
4) L2 reads an unhandled MSR that exists in MSR_BITMAP (such as 0x1fff).
L2 RDMSR could be handled as described below:
1) L2 exits to L0 on RDMSR and calls handle_rdmsr().
2) handle_rdmsr() calls kvm_inject_gp() which sets KVM_REQ_EVENT, exception.pending=true and exception.injected=false.
3) vcpu_enter_guest() consumes KVM_REQ_EVENT and calls inject_pending_event() which calls vmx_check_nested_events() which sees that exception.pending=true but nested_vmx_check_exception() returns 0 and therefore does nothing at this point. However let's assume it later sees vmx-preemption-timer expired and therefore exits from L2 to L1 by calling nested_vmx_vmexit().
4) nested_vmx_vmexit() calls prepare_vmcs12()
which calls vmcs12_save_pending_event() but it does nothing as exception.injected is false. Also prepare_vmcs12() calls kvm_clear_exception_queue() which does nothing as exception.injected is already false.
5) We now return from vmx_check_nested_events() with 0 while still having exception.pending=true!
6) Therefore inject_pending_event() continues
and we inject L2 exception to L1!...
This commit will fix above issue by changing step (4) to clear exception.pending in kvm_clear_exception_queue().
--- arch/x86/kvm/vmx.c | 1 - arch/x86/kvm/x86.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/vmx.c +0 -1
@@ -11246,7 +11246,6 @@ static int vmx_check_nested_events(strucif (block_nested_events)return -EBUSY ;nested_vmx_inject_exception_vmexit (vcpu, exit_qual); - vcpu->arch.exception.pending = false;return 0 ; }
arch/x86/kvm/x86.h +1 -0
@@ -12,6 +12,7 @@static inline void kvm_clear_exception_queue (struct kvm_vcpu *vcpu) { + vcpu->arch.exception.pending = false; vcpu->arch.exception.injected = false; }
Greg Kroah-Hartman
maintainerPATCH 139/195 KVM: PPC: Book3S HV: Make sure we dont re-enter guest without XIVE loaded
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paul Mackerras <[email protected]>
commit 43ff3f65234061e08d234bdef5a9aadc19832b74 upstream.
This fixes a bug where it is possible to enter a guest on a POWER9 system without having the XIVE (interrupt controller) context loaded. This can happen because we unload the XIVE context from the CPU before doing the real-mode handling for machine checks. After the real-mode handler runs, it is possible that we re-enter the guest via a fast path which does not load the XIVE context.
To fix this, we move the unloading of the XIVE context to come after the real-mode machine check handler is called.
--- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 40 ++++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-)
arch/powerpc/kvm/book3s_hv_rmhandlers.S +20 -20
@@ -1387,6 +1387,26 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300) blt deliver_guest_interrupt guest_exit_cont: /* r9 = vcpu, r12 = trap, r13 = paca */ + /* Save more register state */ + mfdar r6 + mfdsisr r7 + std r6, VCPU_DAR(r9) + stw r7, VCPU_DSISR(r9) + /* don't overwrite fault_dar/fault_dsisr if HDSI */ + cmpwi r12,BOOK3S_INTERRUPT_H_DATA_STORAGE + beq mc_cont + std r6, VCPU_FAULT_DAR(r9) + stw r7, VCPU_FAULT_DSISR(r9) + + /* See if it is a machine check */ + cmpwi r12, BOOK3S_INTERRUPT_MACHINE_CHECK + beq machine_check_realmode +mc_cont: +#ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING + addi r3, r9, VCPU_TB_RMEXIT + mr r4, r9 + bl kvmhv_accumulate_time +#endif #ifdef CONFIG_KVM_XICS /* We are exiting, pull the VP from the XIVE */ lwz r0, VCPU_XIVE_PUSHED(r9)
@@ -1424,26 +1444,6 @@ guest_exit_cont: /* r9 = vcpu, r12 = tr eieio 1: #endif /* CONFIG_KVM_XICS */ - /* Save more register state */ - mfdar r6 - mfdsisr r7 - std r6, VCPU_DAR(r9) - stw r7, VCPU_DSISR(r9) - /* don't overwrite fault_dar/fault_dsisr if HDSI */ - cmpwi r12,BOOK3S_INTERRUPT_H_DATA_STORAGE - beq mc_cont - std r6, VCPU_FAULT_DAR(r9) - stw r7, VCPU_FAULT_DSISR(r9) - - /* See if it is a machine check */ - cmpwi r12, BOOK3S_INTERRUPT_MACHINE_CHECK - beq machine_check_realmode -mc_cont: -#ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING - addi r3, r9, VCPU_TB_RMEXIT - mr r4, r9 - bl kvmhv_accumulate_time -#endif mr r3, r12 /* Increment exit count, poke other threads to exit */
Greg Kroah-Hartman
maintainerPATCH 140/195 KVM: PPC: Book3S HV: Drop locks before reading guest memory
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paul Mackerras <[email protected]>
commit 36ee41d161c67a6fcf696d4817a0da31f778938c upstream.
Running with CONFIG_DEBUG_ATOMIC_SLEEP reveals that HV KVM tries to read guest memory, in order to emulate guest instructions, while preempt is disabled and a vcore lock is held. This occurs in kvmppc_handle_exit_hv(), called from post_guest_process(), when emulating guest doorbell instructions on POWER9 systems, and also when checking whether we have hit a hypervisor breakpoint. Reading guest memory can cause a page fault and thus cause the task to sleep, so we need to avoid reading guest memory while holding a spinlock or when preempt is disabled.
To fix this, we move the preempt_enable() in kvmppc_run_core() to before the loop that calls post_guest_process() for each vcore that has just run, and we drop and re-take the vcore lock around the calls to kvmppc_emulate_debug_inst() and kvmppc_emulate_doorbell_instr().
Dropping the lock is safe with respect to the iteration over the runnable vcpus in post_guest_process(); for_each_runnable_thread is actually safe to use locklessly. It is possible for a vcpu to become runnable and add itself to the runnable_threads array (code near the beginning of kvmppc_run_vcpu()) and then get included in the iteration in post_guest_process despite the fact that it has not just run. This is benign because vcpu->arch.trap and vcpu->arch.ceded will be zero.
--- arch/powerpc/kvm/book3s_hv.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
arch/powerpc/kvm/book3s_hv.c +12 -4
@@ -999,8 +999,6 @@ static int kvmppc_emulate_doorbell_instrstruct kvm *kvm = vcpu->kvm;struct kvm_vcpu *tvcpu; -if (!cpu_has_feature (CPU_FTR_ARCH_300 )) -return EMULATE_FAIL ;if (kvmppc_get_last_inst (vcpu,INST_GENERIC , &inst) !=EMULATE_DONE )return RESUME_GUEST ;if (get_op (inst) !=31 )
@@ -1050,6 +1048,7 @@ static int kvmppc_emulate_doorbell_instrreturn RESUME_GUEST ; } +/* Called with vcpu->arch.vcore->lock held */ static int kvmppc_handle_exit_hv (struct kvm_run *run,struct kvm_vcpu *vcpu,struct task_struct *tsk) {
@@ -1169,7 +1168,10 @@ static int kvmppc_handle_exit_hv(struct swab32(vcpu->arch.emul_inst) : vcpu->arch.emul_inst;if (vcpu->guest_debug &KVM_GUESTDBG_USE_SW_BP ) { +/* Need vcore unlocked to call kvmppc_get_last_inst */ +spin_unlock (&vcpu->arch.vcore->lock); r =kvmppc_emulate_debug_inst (run, vcpu); +spin_lock (&vcpu->arch.vcore->lock); }else {kvmppc_core_queue_program (vcpu,SRR1_PROGILL ); r =RESUME_GUEST ;
@@ -1184,8 +1186,13 @@ static int kvmppc_handle_exit_hv(struct*/ case BOOK3S_INTERRUPT_H_FAC_UNAVAIL : r =EMULATE_FAIL ; -if ((vcpu->arch.hfscr >>56 ) ==FSCR_MSGP_LG ) +if (((vcpu->arch.hfscr >>56 ) ==FSCR_MSGP_LG ) && +cpu_has_feature (CPU_FTR_ARCH_300 )) { +/* Need vcore unlocked to call kvmppc_get_last_inst */ +spin_unlock (&vcpu->arch.vcore->lock); r =kvmppc_emulate_doorbell_instr (vcpu); +spin_lock (&vcpu->arch.vcore->lock); + }if (r ==EMULATE_FAIL ) {kvmppc_core_queue_program (vcpu,SRR1_PROGILL ); r =RESUME_GUEST ;
@@ -2889,13 +2896,14 @@ static noinline void kvmppc_run_core(str/* make sure updates to secondary vcpu structs are visible now */ smp_mb (); +preempt_enable (); +for (sub =0 ; sub < core_info.n_subcores; ++sub) { pvc = core_info.vc[sub];post_guest_process (pvc, pvc == vc); }spin_lock (&vc->lock); -preempt_enable (); out: vc->vcore_state =VCORE_INACTIVE ;
Greg Kroah-Hartman
maintainerPATCH 141/195 KVM: arm/arm64: Handle CPU_PM_ENTER_FAILED
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Morse <[email protected]>
commit 58d6b15e9da5042a99c9c30ad725792e4569150e upstream.
cpu_pm_enter() calls the pm notifier chain with CPU_PM_ENTER, then if there is a failure: CPU_PM_ENTER_FAILED.
When KVM receives CPU_PM_ENTER it calls cpu_hyp_reset() which will return us to the hyp-stub. If we subsequently get a CPU_PM_ENTER_FAILED, KVM does nothing, leaving the CPU running with the hyp-stub, at odds with kvm_arm_hardware_enabled.
Add CPU_PM_ENTER_FAILED as a fallthrough for CPU_PM_EXIT, this reloads KVM based on kvm_arm_hardware_enabled. This is safe even if CPU_PM_ENTER never gets as far as KVM, as cpu_hyp_reinit() calls cpu_hyp_reset() to make sure the hyp-stub is loaded before reloading KVM.
--- virt/kvm/arm/arm.c | 1 + 1 file changed, 1 insertion(+)
virt/kvm/arm/arm.c +1 -0
@@ -1220,6 +1220,7 @@ static int hyp_init_cpu_pm_notifier(strucpu_hyp_reset ();return NOTIFY_OK ; +case CPU_PM_ENTER_FAILED :case CPU_PM_EXIT :if (__this_cpu_read (kvm_arm_hardware_enabled))/* The hardware was enabled before suspend. */
Greg Kroah-Hartman
maintainerPATCH 142/195 KVM: PPC: Book3S PR: Fix broken select due to misspelling
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ulf Magnusson <[email protected]>
commit 57ea5f161a7de5b1913c212d04f57a175b159fdf upstream.
Commit 76d837a4c0f9 ("KVM: PPC: Book3S PR: Don't include SPAPR TCE code on non-pseries platforms") added a reference to the globally undefined symbol PPC_SERIES. Looking at the rest of the commit, PPC_PSERIES was probably intended.
Change PPC_SERIES to PPC_PSERIES.
Discovered with the
https://github.com/ulfalizer/Kconfiglib/blob/master/examples/list_undefined.py
script.
--- arch/powerpc/kvm/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kvm/Kconfig +1 -1
@@ -68,7 +68,7 @@ config KVM_BOOK3S_64 select KVM_BOOK3S_64_HANDLER select KVM select KVM_BOOK3S_PR_POSSIBLE if !KVM_BOOK3S_HV_POSSIBLE - select SPAPR_TCE_IOMMU if IOMMU_SUPPORT && (PPC_SERIES || PPC_POWERNV) + select SPAPR_TCE_IOMMU if IOMMU_SUPPORT && (PPC_PSERIES || PPC_POWERNV) ---help--- Support running unmodified book3s_64 and book3s_32 guest kernels in virtual machines on book3s_64 host processors.
Greg Kroah-Hartman
maintainerPATCH 143/195 ASoC: rockchip: i2s: fix playback after runtime resume
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Keeping <[email protected]>
commit c66234cfedfc3e6e3b62563a5f2c1562be09a35d upstream.
When restoring registers during runtime resume, we must not write to I2S_TXDR which is the transmit FIFO as this queues up a sample to be output and pushes all of the output channels down by one.
This can be demonstrated with the speaker-test utility:
for i in a b c; do speaker-test -c 2 -s 1; done
which should play a test through the left speaker three times but if the I2S hardware starts runtime suspended the first sample will be played through the right speaker.
Fix this by marking I2S_TXDR as volatile (which also requires marking it as readble, even though it technically isn't). This seems to be the most robust fix, the alternative of giving I2S_TXDR a default value is more fragile since it does not prevent regcache writing to the register in all circumstances.
While here, also fix the configuration of I2S_RXDR and I2S_FIFOLR; these are not writable so they do not suffer from the same problem as I2S_TXDR but reading from I2S_RXDR does suffer from a similar problem.
--- sound/soc/rockchip/rockchip_i2s.c | 6 ++++++ 1 file changed, 6 insertions(+)
sound/soc/rockchip/rockchip_i2s.c +6 -0
@@ -504,6 +504,7 @@ static bool rockchip_i2s_rd_reg(struct dcase I2S_INTCR :case I2S_XFER :case I2S_CLR : +case I2S_TXDR :case I2S_RXDR :case I2S_FIFOLR :case I2S_INTSR :
@@ -518,6 +519,9 @@ static bool rockchip_i2s_volatile_reg(stswitch (reg) {case I2S_INTSR :case I2S_CLR : +case I2S_FIFOLR : +case I2S_TXDR : +case I2S_RXDR :return true;default :return false;
@@ -527,6 +531,8 @@ static bool rockchip_i2s_volatile_reg(ststatic bool rockchip_i2s_precious_reg (struct device *dev,unsigned int reg) {switch (reg) { +case I2S_RXDR : +return true;default :return false; }
Greg Kroah-Hartman
maintainerPATCH 144/195 ASoC: skl: Fix kernel warning due to zero NHTL entry
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit 20a1ea2222e7cbf96e9bf8579362e971491e6aea upstream.
I got the following kernel warning when loading snd-soc-skl module on Dell Latitude 7270 laptop:
memremap attempted on mixed range 0x0000000000000000 size: 0x0
WARNING: CPU: 0 PID: 484 at kernel/memremap.c:98 memremap+0x8a/0x180 Call Trace: skl_nhlt_init+0x82/0xf0 [snd_soc_skl] skl_probe+0x2ee/0x7c0 [snd_soc_skl] ....
It seems that the machine doesn't support the SKL DSP gives the empty NHLT entry, and it triggers the warning. For avoiding it, let do the zero check before calling memremap().
--- sound/soc/intel/skylake/skl-nhlt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
sound/soc/intel/skylake/skl-nhlt.c +2 -1
@@ -41,7 +41,8 @@ struct nhlt_acpi_table *skl_nhlt_init(st obj =acpi_evaluate_dsm (handle, &osc_guid,1 ,1 ,NULL );if (obj && obj->type ==ACPI_TYPE_BUFFER ) { nhlt_ptr = (struct nhlt_resource_desc *)obj->buffer.pointer; - nhlt_table = (struct nhlt_acpi_table *) +if (nhlt_ptr->length) + nhlt_table = (struct nhlt_acpi_table *)memremap (nhlt_ptr->min_addr, nhlt_ptr->length,MEMREMAP_WB );ACPI_FREE (obj);
Greg Kroah-Hartman
maintainerPATCH 145/195 watchdog: imx2_wdt: restore previous timeout after suspend+resume
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Martin Kaiser <[email protected]>
commit 0be267255cef64e1c58475baa7b25568355a3816 upstream.
When the watchdog device is suspended, its timeout is set to the maximum value. During resume, the previously set timeout should be restored. This does not work at the moment.
The suspend function calls
imx2_wdt_set_timeout(wdog, IMX2_WDT_MAX_TIME);
and resume reverts this by calling
imx2_wdt_set_timeout(wdog, wdog->timeout);
However, imx2_wdt_set_timeout() updates wdog->timeout. Therefore, wdog->timeout is set to IMX2_WDT_MAX_TIME when we enter the resume function.
Fix this by adding a new function __imx2_wdt_set_timeout() which only updates the hardware settings. imx2_wdt_set_timeout() now calls __imx2_wdt_set_timeout() and then saves the new timeout to wdog->timeout.
During suspend, we call __imx2_wdt_set_timeout() directly so that wdog->timeout won't be updated and we can restore the previous value during resume. This approach makes wdog->timeout different from the actual setting in the hardware which is usually not a good thing. However, the two differ only while we're suspended and no kernel code is running, so it should be ok in this case.
--- drivers/watchdog/imx2_wdt.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
drivers/watchdog/imx2_wdt.c +15 -5
@@ -169,15 +169,21 @@ static int imx2_wdt_ping(struct watchdogreturn 0 ; } -static int imx2_wdt_set_timeout (struct watchdog_device *wdog, -unsigned int new_timeout) +static void __imx2_wdt_set_timeout (struct watchdog_device *wdog, +unsigned int new_timeout) {struct imx2_wdt_device *wdev =watchdog_get_drvdata (wdog); - wdog->timeout = new_timeout; -regmap_update_bits (wdev->regmap,IMX2_WDT_WCR ,IMX2_WDT_WCR_WT ,WDOG_SEC_TO_COUNT (new_timeout)); +} + +static int imx2_wdt_set_timeout (struct watchdog_device *wdog, +unsigned int new_timeout) +{ +__imx2_wdt_set_timeout (wdog, new_timeout); + + wdog->timeout = new_timeout;return 0 ; }
@@ -371,7 +377,11 @@ static int imx2_wdt_suspend(struct devic/* The watchdog IP block is running */ if (imx2_wdt_is_running (wdev)) { -imx2_wdt_set_timeout (wdog,IMX2_WDT_MAX_TIME ); +/* +* Don't update wdog->timeout, we'll restore the current value +* during resume. +*/ +__imx2_wdt_set_timeout (wdog,IMX2_WDT_MAX_TIME );imx2_wdt_ping (wdog); }
Greg Kroah-Hartman
maintainerPATCH 146/195 Btrfs: raid56: iterate raid56 internal bio with bio_for_each_segment_all
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Liu Bo <[email protected]>
commit 0198e5b707cfeb5defbd1b71b1ec6e71580d7db9 upstream.
Bio iterated by set_bio_pages_uptodate() is raid56 internal one, so it will never be a BIO_CLONED bio, and since this is called by end_io functions, bio->bi_iter.bi_size is zero, we mustn't use bio_for_each_segment() as that is a no-op if bi_size is zero.
--- fs/btrfs/raid56.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
fs/btrfs/raid56.c +5 -6
@@ -1432,14 +1432,13 @@ static int fail_bio_stripe(struct btrfs_*/ static void set_bio_pages_uptodate (struct bio *bio) { -struct bio_vec bvec; -struct bvec_iter iter; +struct bio_vec *bvec; +int i; -if (bio_flagged (bio,BIO_CLONED )) - bio->bi_iter =btrfs_io_bio (bio)->iter; +ASSERT (!bio_flagged (bio,BIO_CLONED )); -bio_for_each_segment (bvec, bio, iter) -SetPageUptodate (bvec.bv_page); +bio_for_each_segment_all (bvec, bio, i) +SetPageUptodate (bvec->bv_page); }/*
Greg Kroah-Hartman
maintainerPATCH 147/195 kasan: dont emit builtin calls when sanitization is off
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrey Konovalov <[email protected]>
commit 0e410e158e5baa1300bdf678cea4f4e0cf9d8b94 upstream.
With KASAN enabled the kernel has two different memset() functions, one with KASAN checks (memset) and one without (__memset). KASAN uses some macro tricks to use the proper version where required. For example memset() calls in mm/slub.c are without KASAN checks, since they operate on poisoned slab object metadata.
The issue is that clang emits memset() calls even when there is no memset() in the source code. They get linked with improper memset() implementation and the kernel fails to boot due to a huge amount of KASAN reports during early boot stages.
The solution is to add -fno-builtin flag for files with KASAN_SANITIZE := n marker.
--- Makefile | 3 ++- scripts/Makefile.kasan | 3 +++ scripts/Makefile.lib | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-)
Makefile +2 -1
@@ -416,7 +416,8 @@ export MAKE AWK GENKSYMS INSTALLKERNEL P export HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS -export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE CFLAGS_KASAN CFLAGS_UBSAN +export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE +export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE CFLAGS_UBSAN export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL
scripts/Makefile.kasan +3 -0
@@ -31,4 +31,7 @@ else endif CFLAGS_KASAN += $(call cc-option, -fsanitize-address-use-after-scope) + +CFLAGS_KASAN_NOSANITIZE := -fno-builtin + endif
scripts/Makefile.lib +1 -1
@@ -128,7 +128,7 @@ endif ifeq ($(CONFIG_KASAN),y) _c_flags += $(if $(patsubst n%,, \ $(KASAN_SANITIZE_$(basetarget).o)$(KASAN_SANITIZE)y), \ - $(CFLAGS_KASAN)) + $(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE)) endif ifeq ($(CONFIG_UBSAN),y)
Greg Kroah-Hartman
maintainerPATCH 148/195 kasan: rework Kconfig settings
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnd Bergmann <[email protected]>
commit e7c52b84fb18f08ce49b6067ae6285aca79084a8 upstream.
We get a lot of very large stack frames using gcc-7.0.1 with the default -fsanitize-address-use-after-scope --param asan-stack=1 options, which can easily cause an overflow of the kernel stack, e.g.
drivers/gpu/drm/i915/gvt/handlers.c:2434:1: warning: the frame size of 46176 bytes is larger than 3072 bytes drivers/net/wireless/ralink/rt2x00/rt2800lib.c:5650:1: warning: the frame size of 23632 bytes is larger than 3072 bytes lib/atomic64_test.c:250:1: warning: the frame size of 11200 bytes is larger than 3072 bytes drivers/gpu/drm/i915/gvt/handlers.c:2621:1: warning: the frame size of 9208 bytes is larger than 3072 bytes drivers/media/dvb-frontends/stv090x.c:3431:1: warning: the frame size of 6816 bytes is larger than 3072 bytes fs/fscache/stats.c:287:1: warning: the frame size of 6536 bytes is larger than 3072 bytes
To reduce this risk, -fsanitize-address-use-after-scope is now split out into a separate CONFIG_KASAN_EXTRA Kconfig option, leading to stack frames that are smaller than 2 kilobytes most of the time on x86_64. An earlier version of this patch also prevented combining KASAN_EXTRA with KASAN_INLINE, but that is no longer necessary with gcc-7.0.1.
All patches to get the frame size below 2048 bytes with CONFIG_KASAN=y and CONFIG_KASAN_EXTRA=n have been merged by maintainers now, so we can bring back that default now. KASAN_EXTRA=y still causes lots of warnings but now defaults to !COMPILE_TEST to disable it in allmodconfig, and it remains disabled in all other defconfigs since it is a new option. I arbitrarily raise the warning limit for KASAN_EXTRA to 3072 to reduce the noise, but an allmodconfig kernel still has around 50 warnings on gcc-7.
I experimented a bit more with smaller stack frames and have another follow-up series that reduces the warning limit for 64-bit architectures to 1280 bytes (without CONFIG_KASAN).
With earlier versions of this patch series, I also had patches to address the warnings we get with KASAN and/or KASAN_EXTRA, using a "noinline_if_stackbloat" annotation.
That annotation now got replaced with a gcc-8 bugfix (see
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81715) and a workaround for older compilers, which means that KASAN_EXTRA is now just as bad as before and will lead to an instant stack overflow in a few extreme cases.
This reverts parts of commit 3f181b4d8652 ("lib/Kconfig.debug: disable -Wframe-larger-than warnings with KASAN=y"). Two patches in linux-next should be merged first to avoid introducing warnings in an allmodconfig build:
3cd890dbe2a4 ("media: dvb-frontends: fix i2c access helpers for KASAN") 16c3ada89cff ("media: r820t: fix r820t_write_reg for KASAN")
Do we really need to backport this?
I think we do: without this patch, enabling KASAN will lead to unavoidable kernel stack overflow in certain device drivers when built with gcc-7 or higher on linux-4.10+ or any version that contains a backport of commit c5caf21ab0cf8. Most people are probably still on older compilers, but it will get worse over time as they upgrade their distros.
The warnings we get on kernels older than this should all be for code that uses dangerously large stack frames, though most of them do not cause an actual stack overflow by themselves.The asan-stack option was added in linux-4.0, and commit 3f181b4d8652 ("lib/Kconfig.debug:
disable -Wframe-larger-than warnings with KASAN=y") effectively turned off the warning for allmodconfig kernels, so I would like to see this fix backported to any kernels later than 4.0.
I have done dozens of fixes for individual functions with stack frames larger than 2048 bytes with asan-stack, and I plan to make sure that all those fixes make it into the stable kernels as well (most are already there).
Part of the complication here is that asan-stack (from 4.0) was originally assumed to always require much larger stacks, but that turned out to be a combination of multiple gcc bugs that we have now worked around and fixed, but sanitize-address-use-after-scope (from v4.10) has a much higher inherent stack usage and also suffers from at least three other problems that we have analyzed but not yet fixed upstream, each of them makes the stack usage more severe than it should be.
--- lib/Kconfig.debug | 2 +- lib/Kconfig.kasan | 11 +++++++++++ scripts/Makefile.kasan | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-)
lib/Kconfig.debug +1 -1
@@ -217,7 +217,7 @@ config ENABLE_MUST_CHECK config FRAME_WARN int "Warn for stack frames larger than (needs gcc 4.4)" range 0 8192 - default 0 if KASAN + default 3072 if KASAN_EXTRA default 2048 if GCC_PLUGIN_LATENT_ENTROPY default 1280 if (!64BIT && PARISC) default 1024 if (!64BIT && !PARISC)
lib/Kconfig.kasan +11 -0
@@ -20,6 +20,17 @@ config KASAN Currently CONFIG_KASAN doesn't work with CONFIG_DEBUG_SLAB (the resulting kernel does not boot). +config KASAN_EXTRA + bool "KAsan: extra checks" + depends on KASAN && DEBUG_KERNEL && !COMPILE_TEST + help + This enables further checks in the kernel address sanitizer, for now + it only includes the address-use-after-scope check that can lead + to excessive kernel stack usage, frame size warnings and longer + compile time. + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 has more + + choice prompt "Instrumentation type" depends on KASAN
scripts/Makefile.kasan +2 -0
@@ -30,7 +30,9 @@ else endif endif +ifdef CONFIG_KASAN_EXTRA CFLAGS_KASAN += $(call cc-option, -fsanitize-address-use-after-scope) +endif CFLAGS_KASAN_NOSANITIZE := -fno-builtin
Greg Kroah-Hartman
maintainerPATCH 149/195 media: dvb-frontends: fix i2c access helpers for KASAN
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnd Bergmann <[email protected]>
commit 3cd890dbe2a4f14cc44c85bb6cf37e5e22d4dd0e upstream.
A typical code fragment was copied across many dvb-frontend drivers and causes large stack frames when built with with CONFIG_KASAN on gcc-5/6/7:
drivers/media/dvb-frontends/cxd2841er.c:3225:1: error: the frame size of 3992 bytes is larger than 3072 bytes [-Werror=frame-larger-than=] drivers/media/dvb-frontends/cxd2841er.c:3404:1: error: the frame size of 3136 bytes is larger than 3072 bytes [-Werror=frame-larger-than=] drivers/media/dvb-frontends/stv0367.c:3143:1: error: the frame size of 4016 bytes is larger than 3072 bytes [-Werror=frame-larger-than=] drivers/media/dvb-frontends/stv090x.c:3430:1: error: the frame size of 5312 bytes is larger than 3072 bytes [-Werror=frame-larger-than=] drivers/media/dvb-frontends/stv090x.c:4248:1: error: the frame size of 4872 bytes is larger than 3072 bytes [-Werror=frame-larger-than=]
gcc-8 now solves this by consolidating the stack slots for the argument variables, but on older compilers we can get the same behavior by taking the pointer of a local variable rather than the inline function argument.
--- drivers/media/dvb-frontends/ascot2e.c | 4 +++- drivers/media/dvb-frontends/cxd2841er.c | 4 +++- drivers/media/dvb-frontends/helene.c | 4 +++- drivers/media/dvb-frontends/horus3a.c | 4 +++- drivers/media/dvb-frontends/itd1000.c | 5 +++-- drivers/media/dvb-frontends/mt312.c | 5 ++++- drivers/media/dvb-frontends/stb0899_drv.c | 3 ++- drivers/media/dvb-frontends/stb6100.c | 6 ++++-- drivers/media/dvb-frontends/stv0367.c | 4 +++- drivers/media/dvb-frontends/stv090x.c | 4 +++- drivers/media/dvb-frontends/stv6110x.c | 4 +++- drivers/media/dvb-frontends/zl10039.c | 4 +++- 12 files changed, 37 insertions(+), 14 deletions(-)
drivers/media/dvb-frontends/ascot2e.c +3 -1
@@ -155,7 +155,9 @@ static int ascot2e_write_regs(struct ascstatic int ascot2e_write_reg (struct ascot2e_priv *priv,u8 reg,u8 val) { -return ascot2e_write_regs (priv, reg, &val,1 ); +u8 tmp = val;/* see gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 */ + +return ascot2e_write_regs (priv, reg, &tmp,1 ); } static int ascot2e_read_regs(struct ascot2e_priv *priv,
drivers/media/dvb-frontends/cxd2841er.c +3 -1
@@ -257,7 +257,9 @@ static int cxd2841er_write_regs(struct cstatic int cxd2841er_write_reg (struct cxd2841er_priv *priv,u8 addr,u8 reg,u8 val) { -return cxd2841er_write_regs (priv, addr, reg, &val,1 ); +u8 tmp = val;/* see gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 */ + +return cxd2841er_write_regs (priv, addr, reg, &tmp,1 ); } static int cxd2841er_read_regs(struct cxd2841er_priv *priv,
drivers/media/dvb-frontends/helene.c +3 -1
@@ -331,7 +331,9 @@ static int helene_write_regs(struct helestatic int helene_write_reg (struct helene_priv *priv,u8 reg,u8 val) { -return helene_write_regs (priv, reg, &val,1 ); +u8 tmp = val;/* see gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 */ + +return helene_write_regs (priv, reg, &tmp,1 ); } static int helene_read_regs(struct helene_priv *priv,
drivers/media/dvb-frontends/horus3a.c +3 -1
@@ -89,7 +89,9 @@ static int horus3a_write_regs(struct horstatic int horus3a_write_reg (struct horus3a_priv *priv,u8 reg,u8 val) { -return horus3a_write_regs (priv, reg, &val,1 ); +u8 tmp = val;/* see gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 */ + +return horus3a_write_regs (priv, reg, &tmp,1 ); }static int horus3a_enter_power_save (struct horus3a_priv *priv)
drivers/media/dvb-frontends/itd1000.c +3 -2
@@ -95,8 +95,9 @@ static int itd1000_read_reg(struct itd10static inline int itd1000_write_reg (struct itd1000_state *state,u8 r,u8 v) { -int ret =itd1000_write_regs (state, r, &v,1 ); - state->shadow[r] = v; +u8 tmp = v;/* see gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 */ +int ret =itd1000_write_regs (state, r, &tmp,1 ); + state->shadow[r] = tmp;return ret; }
drivers/media/dvb-frontends/mt312.c +4 -1
@@ -142,7 +142,10 @@ static inline int mt312_readreg(struct mstatic inline int mt312_writereg (struct mt312_state *state,const enum mt312_reg_addr reg,const u8 val) { -return mt312_write (state, reg, &val,1 ); +u8 tmp = val;/* see gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 */ + + +return mt312_write (state, reg, &tmp,1 ); }static inline u32 mt312_div (u32 a,u32 b)
drivers/media/dvb-frontends/stb0899_drv.c +2 -1
@@ -539,7 +539,8 @@ int stb0899_write_regs(struct stb0899_stint stb0899_write_reg (struct stb0899_state *state,unsigned int reg,u8 data) { -return stb0899_write_regs (state, reg, &data,1 ); +u8 tmp = data; +return stb0899_write_regs (state, reg, &tmp,1 ); }/*
drivers/media/dvb-frontends/stb6100.c +4 -2
@@ -226,12 +226,14 @@ static int stb6100_write_reg_range(strucstatic int stb6100_write_reg (struct stb6100_state *state,u8 reg,u8 data) { +u8 tmp = data;/* see gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 */ +if (unlikely (reg >=STB6100_NUMREGS )) {dprintk (verbose,FE_ERROR ,1 ,"Invalid register offset 0x%x" , reg);return -EREMOTEIO ; } - data = (data & stb6100_template[reg].mask) | stb6100_template[reg].set; -return stb6100_write_reg_range (state, &data, reg,1 ); + tmp = (tmp & stb6100_template[reg].mask) | stb6100_template[reg].set; +return stb6100_write_reg_range (state, &tmp, reg,1 ); }
drivers/media/dvb-frontends/stv0367.c +3 -1
@@ -166,7 +166,9 @@ int stv0367_writeregs(struct stv0367_stastatic int stv0367_writereg (struct stv0367_state *state,u16 reg,u8 data) { -return stv0367_writeregs (state, reg, &data,1 ); +u8 tmp = data;/* see gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 */ + +return stv0367_writeregs (state, reg, &tmp,1 ); }static u8 stv0367_readreg (struct stv0367_state *state,u16 reg)
drivers/media/dvb-frontends/stv090x.c +3 -1
@@ -755,7 +755,9 @@ static int stv090x_write_regs(struct stvstatic int stv090x_write_reg (struct stv090x_state *state,unsigned int reg,u8 data) { -return stv090x_write_regs (state, reg, &data,1 ); +u8 tmp = data;/* see gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 */ + +return stv090x_write_regs (state, reg, &tmp,1 ); }static int stv090x_i2c_gate_ctrl (struct stv090x_state *state,int enable)
drivers/media/dvb-frontends/stv6110x.c +3 -1
@@ -97,7 +97,9 @@ static int stv6110x_write_regs(struct ststatic int stv6110x_write_reg (struct stv6110x_state *stv6110x,u8 reg,u8 data) { -return stv6110x_write_regs (stv6110x, reg, &data,1 ); +u8 tmp = data;/* see gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 */ + +return stv6110x_write_regs (stv6110x, reg, &tmp,1 ); }static int stv6110x_init (struct dvb_frontend *fe)
drivers/media/dvb-frontends/zl10039.c +3 -1
@@ -134,7 +134,9 @@ static inline int zl10039_writereg(strucconst enum zl10039_reg_addr reg, const u8 val) { - return zl10039_write(state, reg, &val, 1); + const u8 tmp = val; /* see gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 */ + +return zl10039_write (state, reg, &tmp,1 ); }static int zl10039_init (struct dvb_frontend *fe)
Greg Kroah-Hartman
maintainerPATCH 150/195 media: ts2020: avoid integer overflows on 32 bit machines
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mauro Carvalho Chehab <[email protected]>
commit 81742be14b6a90c9fd0ff6eb4218bdf696ad8e46 upstream.
Before this patch, when compiled for arm32, the signal strength were reported as:
Lock (0x1f) Signal= 4294908.66dBm C/N= 12.79dB
Because of a 32 bit integer overflow. After it, it is properly reported as:
Lock (0x1f) Signal= -58.64dBm C/N= 12.79dB
--- drivers/media/dvb-frontends/ts2020.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/dvb-frontends/ts2020.c +2 -2
@@ -368,7 +368,7 @@ static int ts2020_read_tuner_gain(struct gain2 =clamp_t (long, gain2,0 ,13 ); v_agc =clamp_t (long, v_agc,400 ,1100 ); - *_gain = -(gain1 *2330 + + *_gain = -((__s64 )gain1 *2330 + gain2 *3500 + v_agc *24 /10 *10 +10000 );
@@ -386,7 +386,7 @@ static int ts2020_read_tuner_gain(struct gain3 =clamp_t (long, gain3,0 ,6 ); v_agc =clamp_t (long, v_agc,600 ,1600 ); - *_gain = -(gain1 * 2650 + + *_gain = -((__s64)gain1 * 2650 + gain2 * 3380 + gain3 * 2850 + v_agc * 176 / 100 * 10 -
Greg Kroah-Hartman
maintainerPATCH 151/195 media: cxusb, dib0700: ignore XC2028_I2C_FLUSH
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mauro Carvalho Chehab <[email protected]>
commit 9893b905e743ded332575ca04486bd586c0772f7 upstream.
The XC2028_I2C_FLUSH only needs to be implemented on a few devices. Others can safely ignore it.
That prevents filling the dmesg with lots of messages like:
dib0700: stk7700ph_xc3028_callback: unknown command 2, arg 0
--- drivers/media/usb/dvb-usb/cxusb.c | 2 ++ drivers/media/usb/dvb-usb/dib0700_devices.c | 1 + 2 files changed, 3 insertions(+)
drivers/media/usb/dvb-usb/cxusb.c +2 -0
@@ -677,6 +677,8 @@ static int dvico_bluebird_xc2028_callbaccase XC2028_RESET_CLK :deb_info ("%s: XC2028_RESET_CLK %d\n" , __func__, arg);break ; +case XC2028_I2C_FLUSH : +break ;default :deb_info ("%s: unknown command %d, arg %d\n" , __func__, command, arg);
drivers/media/usb/dvb-usb/dib0700_devices.c +1 -0
@@ -430,6 +430,7 @@ static int stk7700ph_xc3028_callback(voi state->dib7000p_ops.set_gpio (adap->fe_adap[0 ].fe,8 ,0 ,1 );break ;case XC2028_RESET_CLK : +case XC2028_I2C_FLUSH :break ;default : err("%s: unknown command %d, arg %d\n", __func__,
Greg Kroah-Hartman
maintainerPATCH 152/195 fs/proc/kcore.c: use probe_kernel_read() instead of memcpy()
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Heiko Carstens <[email protected]>
commit d0290bc20d4739b7a900ae37eb5d4cc3be2b393f upstream.
Commit df04abfd181a ("fs/proc/kcore.c: Add bounce buffer for ktext data") added a bounce buffer to avoid hardened usercopy checks. Copying to the bounce buffer was implemented with a simple memcpy() assuming that it is always valid to read from kernel memory iff the kern_addr_valid() check passed.
A simple, but pointless, test case like "dd if=/proc/kcore of=/dev/null" now can easily crash the kernel, since the former execption handling on invalid kernel addresses now doesn't work anymore.
Also adding a kern_addr_valid() implementation wouldn't help here. Most architectures simply return 1 here, while a couple implemented a page table walk to figure out if something is mapped at the address in question.
With DEBUG_PAGEALLOC active mappings are established and removed all the time, so that relying on the result of kern_addr_valid() before executing the memcpy() also doesn't work.
Therefore simply use probe_kernel_read() to copy to the bounce buffer. This also allows to simplify read_kcore().
At least on s390 this fixes the observed crashes and doesn't introduce warnings that were removed with df04abfd181a ("fs/proc/kcore.c: Add bounce buffer for ktext data"), even though the generic probe_kernel_read() implementation uses uaccess functions.
While looking into this I'm also wondering if kern_addr_valid() could be completely removed...(?)
--- fs/proc/kcore.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)
fs/proc/kcore.c +5 -13
@@ -512,23 +512,15 @@ read_kcore(struct file *file, char __usereturn -EFAULT ; }else {if (kern_addr_valid (start)) { -unsigned long n; -/* * Using bounce buffer to bypass the * hardened user copy kernel text checks. */ -memcpy (buf, (char *) start, tsz); - n =copy_to_user (buffer, buf, tsz); -/* -* We cannot distinguish between fault on source -* and fault on destination. When this happens -* we clear too and hope it will trigger the -* EFAULT again. -*/ -if (n) { -if (clear_user (buffer + tsz - n, - n)) +if (probe_kernel_read (buf, (void *) start, tsz)) { +if (clear_user (buffer, tsz)) +return -EFAULT ; + }else { +if (copy_to_user (buffer, buf, tsz))return -EFAULT ; } }else {
Greg Kroah-Hartman
maintainerPATCH 153/195 kernel/async.c: revert "async: simplify lowest_in_progress()"
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rasmus Villemoes <[email protected]>
commit 4f7e988e63e336827f4150de48163bed05d653bd upstream.
This reverts commit 92266d6ef60c ("async: simplify lowest_in_progress()") which was simply wrong: In the case where domain is NULL, we now use the wrong offsetof() in the list_first_entry macro, so we don't actually fetch the ->cookie value, but rather the eight bytes located sizeof(struct list_head) further into the struct async_entry.
On 64 bit, that's the data member, while on 32 bit, that's a u64 built from func and data in some order.
I think the bug happens to be harmless in practice: It obviously only affects callers which pass a NULL domain, and AFAICT the only such caller is
async_synchronize_full() -> async_synchronize_full_domain(NULL) -> async_synchronize_cookie_domain(ASYNC_COOKIE_MAX, NULL)
and the ASYNC_COOKIE_MAX means that in practice we end up waiting for the async_global_pending list to be empty - but it would break if somebody happened to pass (void*)-1 as the data element to async_schedule, and of course also if somebody ever does a async_synchronize_cookie_domain(, NULL) with a "finite" cookie value.
Maybe the "harmless in practice" means this isn't -stable material. But I'm not completely confident my quick git grep'ing is enough, and there might be affected code in one of the earlier kernels that has since been removed, so I'll leave the decision to the stable guys.
--- kernel/async.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
kernel/async.c +12 -8
@@ -84,20 +84,24 @@ static atomic_t entry_count;static async_cookie_t lowest_in_progress (struct async_domain *domain) { -struct list_head *pending; +struct async_entry *first =NULL ;async_cookie_t ret =ASYNC_COOKIE_MAX ;unsigned long flags;spin_lock_irqsave (&async_lock, flags); -if (domain) - pending = &domain->pending; -else - pending = &async_global_pending; +if (domain) { +if (!list_empty (&domain->pending)) + first =list_first_entry (&domain->pending, + struct async_entry, domain_list); + }else { +if (!list_empty (&async_global_pending)) + first =list_first_entry (&async_global_pending, + struct async_entry, global_list); + } -if (!list_empty (pending)) - ret = list_first_entry(pending, struct async_entry, - domain_list)->cookie; +if (first) + ret = first->cookie;spin_unlock_irqrestore (&async_lock, flags);return ret;
Greg Kroah-Hartman
maintainerPATCH 154/195 kernel/relay.c: revert "kernel/relay.c: fix potential memory leak"
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit a1be1f3931bfe0a42b46fef77a04593c2b136e7f upstream.
This reverts commit ba62bafe942b ("kernel/relay.c: fix potential memory leak").
This commit introduced a double free bug, because 'chan' is already freed by the line:
kref_put(&chan->kref, relay_destroy_channel);
This bug was found by syzkaller, using the BLKTRACESETUP ioctl.
--- kernel/relay.c | 1 - 1 file changed, 1 deletion(-)
kernel/relay.c +0 -1
@@ -611,7 +611,6 @@ free_bufs:kref_put (&chan->kref, relay_destroy_channel);mutex_unlock (&relay_channels_mutex); -kfree (chan);return NULL ; }EXPORT_SYMBOL_GPL (relay_open);
Greg Kroah-Hartman
maintainerPATCH 155/195 pipe: actually allow root to exceed the pipe buffer limits
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 85c2dd5473b2718b4b63e74bfeb1ca876868e11f upstream.
pipe-user-pages-hard and pipe-user-pages-soft are only supposed to apply to unprivileged users, as documented in both Documentation/sysctl/fs.txt and the pipe(7) man page.
However, the capabilities are actually only checked when increasing a pipe's size using F_SETPIPE_SZ, not when creating a new pipe. Therefore, if pipe-user-pages-hard has been set, the root user can run into it and be unable to create pipes. Similarly, if pipe-user-pages-soft has been set, the root user can run into it and have their pipes limited to 1 page each.
Fix this by allowing the privileged override in both cases.
--- fs/pipe.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
fs/pipe.c +8 -3
@@ -618,6 +618,11 @@ static bool too_many_pipe_buffers_hard(ureturn pipe_user_pages_hard && user_bufs >= pipe_user_pages_hard; } +static bool is_unprivileged_user (void ) +{ +return !capable (CAP_SYS_RESOURCE ) && !capable (CAP_SYS_ADMIN ); +} +struct pipe_inode_info *alloc_pipe_info (void ) {struct pipe_inode_info *pipe;
@@ -634,12 +639,12 @@ struct pipe_inode_info *alloc_pipe_info( user_bufs =account_pipe_buffers (user,0 , pipe_bufs); -if (too_many_pipe_buffers_soft (user_bufs)) { +if (too_many_pipe_buffers_soft (user_bufs) &&is_unprivileged_user ()) { user_bufs =account_pipe_buffers (user, pipe_bufs,1 ); pipe_bufs =1 ; } -if (too_many_pipe_buffers_hard (user_bufs)) +if (too_many_pipe_buffers_hard (user_bufs) &&is_unprivileged_user ()) goto out_revert_acct; pipe->bufs = kcalloc(pipe_bufs, sizeof(struct pipe_buffer),
@@ -1069,7 +1074,7 @@ static long pipe_set_size(struct pipe_inif (nr_pages > pipe->buffers && (too_many_pipe_buffers_hard (user_bufs) ||too_many_pipe_buffers_soft (user_bufs)) && - !capable (CAP_SYS_RESOURCE ) && !capable (CAP_SYS_ADMIN )) { +is_unprivileged_user ()) { ret = -EPERM ; goto out_revert_acct; }
Greg Kroah-Hartman
maintainerPATCH 156/195 pipe: fix off-by-one error when checking buffer limits
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 9903a91c763ecdae333a04a9d89d79d2b8966503 upstream.
With pipe-user-pages-hard set to 'N', users were actually only allowed up to 'N - 1' buffers; and likewise for pipe-user-pages-soft.
Fix this to allow up to 'N' buffers, as would be expected.
--- fs/pipe.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/pipe.c +2 -2
@@ -610,12 +610,12 @@ static unsigned long account_pipe_bufferstatic bool too_many_pipe_buffers_soft (unsigned long user_bufs) { -return pipe_user_pages_soft && user_bufs >= pipe_user_pages_soft; +return pipe_user_pages_soft && user_bufs > pipe_user_pages_soft; }static bool too_many_pipe_buffers_hard (unsigned long user_bufs) { -return pipe_user_pages_hard && user_bufs >= pipe_user_pages_hard; +return pipe_user_pages_hard && user_bufs > pipe_user_pages_hard; }static bool is_unprivileged_user (void )
Greg Kroah-Hartman
maintainerPATCH 157/195 HID: quirks: Fix keyboard + touchpad on Toshiba Click Mini not working
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans de Goede <[email protected]>
commit edfc3722cfef4217c7fe92b272cbe0288ba1ff57 upstream.
The Toshiba Click Mini uses an i2c attached keyboard/touchpad combo (single i2c_hid device for both) which has a vid:pid of 04F3:0401, which is also used by a bunch of Elan touchpads which are handled by the drivers/input/mouse/elan_i2c driver, but that driver deals with pure touchpads and does not work for a combo device such as the one on the Toshiba Click Mini.
The combo on the Mini has an ACPI id of ELAN0800, which is not claimed by the elan_i2c driver, so check for that and if it is found do not ignore the device. This fixes the keyboard/touchpad combo on the Mini not working (although with the touchpad in mouse emulation mode).
--- drivers/hid/hid-core.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/hid/hid-core.c +11 -1
@@ -2638,7 +2638,6 @@ static const struct hid_device_id hid_ig { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE) }, { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20) }, { HID_I2C_DEVICE(USB_VENDOR_ID_ELAN, 0x0400) }, - { HID_I2C_DEVICE(USB_VENDOR_ID_ELAN, 0x0401) }, { HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) }, { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC5UH) }, { HID_USB_DEVICE(USB_VENDOR_ID_ETT, USB_DEVICE_ID_TC4UM) },
@@ -2908,6 +2907,17 @@ bool hid_ignore(struct hid_device *hdev) strncmp(hdev->name, "www.masterkit.ru MA901", 22) == 0)return true;break ; +case USB_VENDOR_ID_ELAN : +/* +* Many Elan devices have a product id of 0x0401 and are handled +* by the elan_i2c input driver. But the ACPI HID ELAN0800 dev +* is not (and cannot be) handled by that driver -> +* Ignore all 0x0401 devs except for the ELAN0800 dev. +*/ +if (hdev->product ==0x0401 && +strncmp (hdev->name,"ELAN0800" ,8 ) !=0 ) +return true; +break ; } if (hdev->type == HID_TYPE_USBMOUSE &&
Greg Kroah-Hartman
maintainerPATCH 158/195 Bluetooth: btsdio: Do not bind to non-removable BCM43341
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans de Goede <[email protected]>
commit b4cdaba274247c9c841c6a682c08fa91fb3aa549 upstream.
BCM43341 devices soldered onto the PCB (non-removable) always (AFAICT) use an UART connection for bluetooth. But they also advertise btsdio support on their 3th sdio function, this causes 2 problems:
1) A non functioning BT HCI getting registered
2) Since the btsdio driver does not have suspend/resume callbacks, mmc_sdio_pre_suspend will return -ENOSYS, causing mmc_pm_notify() to react as if the SDIO-card is removed and since the slot is marked as non-removable it will never get detected as inserted again. Which results in wifi no longer working after a suspend/resume.
This commit fixes both by making btsdio ignore BCM43341 devices when connected to a slot which is marked non-removable.
--- drivers/bluetooth/btsdio.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/bluetooth/btsdio.c +9 -0
@@ -31,6 +31,7 @@#include <linux/errno.h> #include <linux/skbuff.h> +#include <linux/mmc/host.h> #include <linux/mmc/sdio_ids.h> #include <linux/mmc/sdio_func.h>
@@ -292,6 +293,14 @@ static int btsdio_probe(struct sdio_func tuple = tuple->next; } +/* BCM43341 devices soldered onto the PCB (non-removable) use an +* uart connection for bluetooth, ignore the BT SDIO interface. +*/ +if (func->vendor ==SDIO_VENDOR_ID_BROADCOM && + func->device ==SDIO_DEVICE_ID_BROADCOM_43341 && + !mmc_card_is_removable (func->card->host)) +return -ENODEV ; + data =devm_kzalloc (&func->dev,sizeof (*data),GFP_KERNEL );if (!data)return -ENOMEM ;
Greg Kroah-Hartman
maintainerPATCH 159/195 Revert "Bluetooth: btusb: fix QCA Rome suspend/resume"
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kai-Heng Feng <[email protected]>
commit 7d06d5895c159f64c46560dc258e553ad8670fe0 upstream.
This reverts commit fd865802c66bc451dc515ed89360f84376ce1a56.
This commit causes a regression on some QCA ROME chips. The USB device reset happens in btusb_open(), hence firmware loading gets interrupted.
Furthermore, this commit stops working after commit ("a0085f2510e8976614ad8f766b209448b385492f Bluetooth: btusb: driver to enable the usb-wakeup feature"). Reset-resume quirk only gets enabled in btusb_suspend() when it's not a wakeup source.
If we really want to reset the USB device, we need to do it before btusb_open(). Let's handle it in drivers/usb/core/quirks.c.
--- drivers/bluetooth/btusb.c | 6 ------ 1 file changed, 6 deletions(-)
drivers/bluetooth/btusb.c +0 -6
@@ -3099,12 +3099,6 @@ static int btusb_probe(struct usb_interfif (id->driver_info &BTUSB_QCA_ROME ) { data->setup_on_usb = btusb_setup_qca; hdev->set_bdaddr = btusb_set_bdaddr_ath3012; - -/* QCA Rome devices lose their updated firmware over suspend, -* but the USB hub doesn't notice any status change. -* Explicitly request a device reset on resume. -*/ -set_bit (BTUSB_RESET_RESUME , &data->flags); }#ifdef CONFIG_BT_HCIBTUSB_RTL
Greg Kroah-Hartman
maintainerPATCH 160/195 Bluetooth: btusb: Restore QCA Rome suspend/resume fix with a "rewritten" version
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans de Goede <[email protected]>
commit 61f5acea8737d9b717fcc22bb6679924f3c82b98 upstream.
Commit 7d06d5895c15 ("Revert "Bluetooth: btusb: fix QCA...suspend/resume"") removed the setting of the BTUSB_RESET_RESUME quirk for QCA Rome devices, instead favoring adding USB_QUIRK_RESET_RESUME quirks in usb/core/quirks.c.
This was done because the DIY BTUSB_RESET_RESUME reset-resume handling has several issues (see the original commit message). An added advantage of moving over to the USB-core reset-resume handling is that it also disables autosuspend for these devices, which is similarly broken on these.
But there are 2 issues with this approach:
1) It leaves the broken DIY BTUSB_RESET_RESUME code in place for Realtek devices.
2) Sofar only 2 of the 10 QCA devices known to the btusb code have been added to usb/core/quirks.c and if we fix the Realtek case the same way we need to add an additional 14 entries. So in essence we need to duplicate a large part of the usb_device_id table in btusb.c in usb/core/quirks.c and manually keep them in sync.
This commit instead restores setting a reset-resume quirk for QCA devices in the btusb.c code, avoiding the duplicate usb_device_id table problem.
This commit avoids the problems with the original DIY BTUSB_RESET_RESUME code by simply setting the USB_QUIRK_RESET_RESUME quirk directly on the usb_device.
This commit also moves the BTUSB_REALTEK case over to directly setting the USB_QUIRK_RESET_RESUME on the usb_device and removes the now unused BTUSB_RESET_RESUME code.
--- drivers/bluetooth/btusb.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/bluetooth/btusb.c +10 -12
@@ -23,6 +23,7 @@#include <linux/module.h> #include <linux/usb.h> +#include <linux/usb/quirks.h> #include <linux/firmware.h> #include <linux/of_device.h> #include <linux/of_irq.h>
@@ -392,9 +393,8 @@ static const struct usb_device_id blackl#define BTUSB_FIRMWARE_LOADED 7#define BTUSB_FIRMWARE_FAILED 8#define BTUSB_BOOTING 9 -#define BTUSB_RESET_RESUME 10 -#define BTUSB_DIAG_RUNNING 11 -#define BTUSB_OOB_WAKE_ENABLED 12 +#define BTUSB_DIAG_RUNNING 10 +#define BTUSB_OOB_WAKE_ENABLED 11struct btusb_data {struct hci_dev *hdev;
@@ -3099,6 +3099,12 @@ static int btusb_probe(struct usb_interfif (id->driver_info &BTUSB_QCA_ROME ) { data->setup_on_usb = btusb_setup_qca; hdev->set_bdaddr = btusb_set_bdaddr_ath3012; + +/* QCA Rome devices lose their updated firmware over suspend, +* but the USB hub doesn't notice any status change. +* explicitly request a device reset on resume. +*/ +interface_to_usbdev (intf)->quirks |=USB_QUIRK_RESET_RESUME ; }#ifdef CONFIG_BT_HCIBTUSB_RTL
@@ -3109,7 +3115,7 @@ static int btusb_probe(struct usb_interf* but the USB hub doesn't notice any status change. * Explicitly request a device reset on resume. */ - set_bit(BTUSB_RESET_RESUME, &data->flags); + interface_to_usbdev(intf)->quirks |= USB_QUIRK_RESET_RESUME; }#endif
@@ -3274,14 +3280,6 @@ static int btusb_suspend(struct usb_inteenable_irq (data->oob_wake_irq); } -/* Optionally request a device reset on resume, but only when -* wakeups are disabled. If wakeups are enabled we assume the -* device will stay powered up throughout suspend. -*/ -if (test_bit (BTUSB_RESET_RESUME , &data->flags) && - !device_may_wakeup (&data->udev->dev)) - data->udev->reset_resume =1 ; -return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 161/195 ipmi: use dynamic memory for DMI driver override
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Garry <[email protected]>
commit 5516e21a1e95e9b9f39985598431a25477d91643 upstream.
Currently a crash can be seen if we reach the "err" label in dmi_add_platform_ipmi(), calling platform_device_put(), like here:
[ 7.270584] (null): ipmi:dmi: Unable to add resources: -16 [ 7.330229] ------------[ cut here ]------------ [ 7.334889] kernel BUG at mm/slub.c:3894! [ 7.338936] Internal error: Oops - BUG: 0 [#1] PREEMPT SMP [ 7.344475] Modules linked in: [ 7.347556] CPU: 1 PID: 1 Comm: swapper/0 Not tainted 4.15.0-rc2-00004-gbe9cb7b-dirty #114 [ 7.355907] Hardware name: Huawei Taishan 2280 /D05, BIOS Hisilicon D05 IT17 Nemo 2.0 RC0 11/29/2017 [ 7.365137] task: 00000000c211f6d3 task.stack: 00000000f276e9af [ 7.371116] pstate: 60000005 (nZCv daif -PAN -UAO) [ 7.375957] pc : kfree+0x194/0x1b4 [ 7.379389] lr : platform_device_release+0xcc/0xd8 [ 7.384225] sp : ffff0000092dba90 [ 7.387567] x29: ffff0000092dba90 x28: ffff000008a83000 [ 7.392933] x27: ffff0000092dbc10 x26: 00000000000000e6 [ 7.398297] x25: 0000000000000003 x24: ffff0000085b51e8 [ 7.403662] x23: 0000000000000100 x22: ffff7e0000234cc0 [ 7.409027] x21: ffff000008af3660 x20: ffff8017d21acc10 [ 7.414392] x19: ffff8017d21acc00 x18: 0000000000000002 [ 7.419757] x17: 0000000000000001 x16: 0000000000000008 [ 7.425121] x15: 0000000000000001 x14: 6666666678303d65 [ 7.430486] x13: 6469727265766f5f x12: 7265766972642e76 [ 7.435850] x11: 6564703e2d617020 x10: 6530326435373638 [ 7.441215] x9 : 3030303030303030 x8 : 3d76656420657361 [ 7.446580] x7 : ffff000008f59df8 x6 : ffff8017fbe0ea50 [ 7.451945] x5 : 0000000000000000 x4 : 0000000000000000 [ 7.457309] x3 : ffffffffffffffff x2 : 0000000000000000 [ 7.462674] x1 : 0fffc00000000800 x0 : ffff7e0000234ce0 [ 7.468039] Process swapper/0 (pid: 1, stack limit = 0x00000000f276e9af) [ 7.474809] Call trace: [ 7.477272] kfree+0x194/0x1b4 [ 7.480351] platform_device_release+0xcc/0xd8 [ 7.484837] device_release+0x34/0x90 [ 7.488531] kobject_put+0x70/0xcc [ 7.491961] put_device+0x14/0x1c [ 7.495304] platform_device_put+0x14/0x1c [ 7.499439] dmi_add_platform_ipmi+0x348/0x3ac [ 7.503923] scan_for_dmi_ipmi+0xfc/0x10c [ 7.507970] do_one_initcall+0x38/0x124 [ 7.511840] kernel_init_freeable+0x188/0x228 [ 7.516238] kernel_init+0x10/0x100 [ 7.519756] ret_from_fork+0x10/0x18 [ 7.523362] Code: f94002c0 37780080 f94012c0 37000040 (d4210000) [ 7.529552] ---[ end trace 11750e4787deef9e ]--- [ 7.534228] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b [ 7.534228]
This is because when the device is released in platform_device_release(), we try to free pdev.driver_override. This is a const string, hence the crash.
Fix by using dynamic memory for pdev->driver_override.
[Removed the free of driver_override from ipmi_si_remove_by_dev(). The
free is done in platform_device_release(), and would result in a double free, and ipmi_si_remove_by_dev() is called by non-platform devices.]
--- drivers/char/ipmi/ipmi_dmi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/char/ipmi/ipmi_dmi.c +4 -1
@@ -81,7 +81,10 @@ static void __init dmi_add_platform_ipmipr_err ("ipmi:dmi: Error allocation IPMI platform device" );return ; } - pdev->driver_override = override; + pdev->driver_override =kasprintf (GFP_KERNEL ,"%s" , + override); +if (!pdev->driver_override) + goto err;if (type ==IPMI_DMI_TYPE_SSIF ) goto add_properties;
Greg Kroah-Hartman
maintainerPATCH 162/195 signal/openrisc: Fix do_unaligned_access to send the proper signal
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric W. Biederman <[email protected]>
commit 500d58300571b6602341b041f97c082a461ef994 upstream.
While reviewing the signal sending on openrisc the do_unaligned_access function stood out because it is obviously wrong. A comment about an si_code set above when actually si_code is never set. Leading to a random si_code being sent to userspace in the event of an unaligned access.
Looking further SIGBUS BUS_ADRALN is the proper pair of signal and si_code to send for an unaligned access. That is what other architectures do and what is required by posix.
Given that do_unaligned_access is broken in a way that no one can be relying on it on openrisc fix the code to just do the right thing.
--- arch/openrisc/kernel/traps.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
arch/openrisc/kernel/traps.c +5 -5
@@ -306,12 +306,12 @@ asmlinkage void do_unaligned_access(strusiginfo_t info;if (user_mode (regs)) { -/* Send a SIGSEGV */ - info.si_signo =SIGSEGV ; +/* Send a SIGBUS */ + info.si_signo =SIGBUS ; info.si_errno =0 ; -/* info.si_code has been set above */ - info.si_addr = (void *)address; -force_sig_info (SIGSEGV , &info, current); + info.si_code =BUS_ADRALN ; + info.si_addr = (void __user *)address; +force_sig_info (SIGBUS , &info, current); }else {printk ("KERNEL: Unaligned Access 0x%.8lx\n" , address);show_registers (regs);
Greg Kroah-Hartman
maintainerPATCH 163/195 signal/sh: Ensure si_signo is initialized in do_divide_error
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric W. Biederman <[email protected]>
commit 0e88bb002a9b2ee8cc3cc9478ce2dc126f849696 upstream.
Set si_signo.
--- arch/sh/kernel/traps_32.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/sh/kernel/traps_32.c +2 -1
@@ -609,7 +609,8 @@ asmlinkage void do_divide_error(unsigned break; } -force_sig_info (SIGFPE , &info, current); + info.si_signo =SIGFPE ; +force_sig_info (info.si_signo, &info, current); }#endif
Greg Kroah-Hartman
maintainerPATCH 164/195 alpha: fix crash if pthread_create races with signal delivery
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
commit 21ffceda1c8b3807615c40d440d7815e0c85d366 upstream.
On alpha, a process will crash if it attempts to start a thread and a signal is delivered at the same time. The crash can be reproduced with this program: https://cygwin.com/ml/cygwin/2014-11/msg00473.html
The reason for the crash is this:
* we call the clone syscall
* we go to the function copy_process
* copy process calls copy_thread_tls, it is a wrapper around copy_thread
* copy_thread sets the tls pointer: childti->pcb.unique = regs->r20
* copy_thread sets regs->r20 to zero
* we go back to copy_process
* copy process checks "if (signal_pending(current))" and returns -ERESTARTNOINTR
* the clone syscall is restarted, but this time, regs->r20 is zero, so the new thread is created with zero tls pointer
* the new thread crashes in start_thread when attempting to access tls
The comment in the code says that setting the register r20 is some compatibility with OSF/1. But OSF/1 doesn't use the CLONE_SETTLS flag, so we don't have to zero r20 if CLONE_SETTLS is set. This patch fixes the bug by zeroing regs->r20 only if CLONE_SETTLS is not set.
--- arch/alpha/kernel/process.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/alpha/kernel/process.c +2 -1
@@ -269,12 +269,13 @@ copy_thread(unsigned long clone_flags, uapplication calling fork. */ if (clone_flags &CLONE_SETTLS ) childti->pcb.unique = regs->r20; +else + regs->r20 =0 ;/* OSF/1 has some strange fork() semantics. */ childti->pcb.usp = usp ?:rdusp (); *childregs = *regs; childregs->r0 =0 ; childregs->r19 =0 ; childregs->r20 =1 ;/* OSF/1 has some strange fork() semantics. */ - regs->r20 =0 ; stack = ((struct switch_stack *) regs) -1 ; *childstack = *stack; childstack->r26 = (unsigned long ) ret_from_fork;
Greg Kroah-Hartman
maintainerPATCH 165/195 alpha: osf_sys.c: fix put_tv32 regression
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnd Bergmann <[email protected]>
commit 47669fb6b5951d0e09fc99719653e0ac92b50b99 upstream.
There was a typo in the new version of put_tv32() that caused an unguarded access of a user space pointer, and failed to return the correct result in gettimeofday(), wait4(), usleep_thread() and old_adjtimex().
This fixes it to give the correct behavior again.
--- arch/alpha/kernel/osf_sys.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/alpha/kernel/osf_sys.c +2 -2
@@ -964,8 +964,8 @@ static inline long put_tv32(struct timeval32 __user *o, struct timeval *i) { return copy_to_user(o, &(struct timeval32){ - .tv_sec = o->tv_sec, - .tv_usec = o->tv_usec}, + .tv_sec = i->tv_sec, + .tv_usec = i->tv_usec}, sizeof(struct timeval32)); }
Greg Kroah-Hartman
maintainerPATCH 166/195 alpha: Fix mixed up args in EXC macro in futex operations
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Cree <[email protected]>
commit 84e455361ec97ea6037d31d42a2955628ea2094b upstream.
Fix the typo (mixed up arguments) in the EXC macro in the futex definitions introduced by commit ca282f697381 (alpha: add a helper for emitting exception table entries).
--- arch/alpha/include/asm/futex.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/alpha/include/asm/futex.h +4 -4
@@ -20,8 +20,8 @@"3: .subsection 2\n" \"4: br 1b\n" \" .previous\n" \ - EXC(1b,3b,%1,$31) \ - EXC(2b,3b,%1,$31) \ + EXC(1b,3b,$31,%1) \ + EXC(2b,3b,$31,%1) \ : "=&r" (oldval), "=&r"(ret) \: " r" (uaddr), " r"(oparg) \ : "memory")
@@ -82,8 +82,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval,"3: .subsection 2\n" "4: br 1b\n" " .previous\n" - EXC(1b,3b,%0,$31) - EXC(2b,3b,%0,$31) + EXC(1b,3b,$31,%0) + EXC(2b,3b,$31,%0) : "+r"(ret), "=&r"(prev), "=&r"(cmp) : "r"(uaddr), "r"((long)(int)oldval), "r"(newval) : "memory");
Greg Kroah-Hartman
maintainerPATCH 167/195 alpha: fix reboot on Avanti platform
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
commit 55fc633c41a08ce9244ff5f528f420b16b1e04d6 upstream.
We need to define NEED_SRM_SAVE_RESTORE on the Avanti, otherwise we get machine check exception when attempting to reboot the machine.
--- arch/alpha/kernel/pci_impl.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/alpha/kernel/pci_impl.h +2 -1
@@ -144,7 +144,8 @@ struct pci_iommu_arena };#if defined(CONFIG_ALPHA_SRM ) && \ - (defined(CONFIG_ALPHA_CIA ) || defined(CONFIG_ALPHA_LCA )) + (defined(CONFIG_ALPHA_CIA ) || defined(CONFIG_ALPHA_LCA ) || \ + defined(CONFIG_ALPHA_AVANTI ))# define NEED_SRM_SAVE_RESTORE #else # undef NEED_SRM_SAVE_RESTORE
Greg Kroah-Hartman
maintainerPATCH 168/195 alpha: fix formating of stack content
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
commit 4b01abdb32fc36abe877503bfbd33019159fad71 upstream.
Since version 4.9, the kernel automatically breaks printk calls into multiple newlines unless pr_cont is used. Fix the alpha stacktrace code, so that it prints stack trace in four columns, as it was initially intended.
--- arch/alpha/kernel/traps.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
arch/alpha/kernel/traps.c +9 -4
@@ -160,11 +160,16 @@ void show_stack(struct task_struct *taskfor (i=0 ; i < kstack_depth_to_print; i++) {if (((long ) stack & (THREAD_SIZE -1 )) ==0 )break ; -if (i && ((i %4 ) ==0 )) -printk ("\n " ); -printk ("%016lx " , *stack++); +if ((i %4 ) ==0 ) { +if (i) +pr_cont ("\n" ); +printk (" " ); + }else { +pr_cont (" " ); + } +pr_cont ("%016lx" , *stack++); } -printk ("\n" ); +pr_cont ("\n" );dik_show_trace (sp); }
Greg Kroah-Hartman
maintainerPATCH 169/195 xtensa: fix futex_atomic_cmpxchg_inatomic
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Max Filippov <[email protected]>
commit ca47480921587ae30417dd234a9f79af188e3666 upstream.
Return 0 if the operation was successful, not the userspace memory value. Check that userspace value equals passed oldval, not itself. Don't update *uval if the value wasn't read from userspace memory.
This fixes process hang due to infinite loop in futex_lock_pi. It also fixes a bunch of glibc tests nptl/tst-mutexpi*.
--- arch/xtensa/include/asm/futex.h | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-)
arch/xtensa/include/asm/futex.h +10 -13
@@ -92,7 +92,6 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 oldval, u32 newval) { int ret = 0; -u32 prev;if (!access_ok (VERIFY_WRITE , uaddr,sizeof (u32)))return -EFAULT ;
@@ -103,26 +102,24 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, __asm__ __volatile__ (" # futex_atomic_cmpxchg_inatomic\n" -"1: l32i %1, %3, 0\n" -" mov %0, %5\n" -" wsr %1, scompare1\n" -"2: s32c1i %0, %3, 0\n" -"3:\n" +" wsr %5, scompare1\n" +"1: s32c1i %1, %4, 0\n" +" s32i %1, %6, 0\n" +"2:\n" " .section .fixup,\"ax\"\n" " .align 4\n" -"4: .long 3b\n" -"5: l32r %1, 4b\n" -" movi %0, %6\n" +"3: .long 2b\n" +"4: l32r %1, 3b\n" +" movi %0, %7\n" " jx %1\n" " .previous\n" " .section __ex_table,\"a\"\n" -" .long 1b,5b,2b,5b\n" +" .long 1b,4b\n" " .previous\n" - :"+r" (ret),"=&r" (prev),"+m" (*uaddr) - :"r" (uaddr),"r" (oldval),"r" (newval),"I" (-EFAULT ) + :"+r" (ret),"+r" (newval),"+m" (*uaddr),"+m" (*uval) + :"r" (uaddr),"r" (oldval),"r" (uval),"I" (-EFAULT ) :"memory" ); - *uval = prev;return ret; }
Greg Kroah-Hartman
maintainerPATCH 170/195 EDAC, octeon: Fix an uninitialized variable warning
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Hogan <[email protected]>
commit 544e92581a2ac44607d7cc602c6b54d18656f56d upstream.
Fix an uninitialized variable warning in the Octeon EDAC driver, as seen in MIPS cavium_octeon_defconfig builds since v4.14 with Codescape GNU Tools 2016.05-03:
drivers/edac/octeon_edac-lmc.c In function ‘octeon_lmc_edac_poll_o2’:
drivers/edac/octeon_edac-lmc.c:87:24: warning: ‘((long unsigned int*)&int_reg)[1]’ may \
be used uninitialized in this function [-Wmaybe-uninitialized]
if (int_reg.s.sec_err || int_reg.s.ded_err) {
^Iinitialise the whole int_reg variable to zero before the conditional assignments in the error injection case.
--- drivers/edac/octeon_edac-lmc.c | 1 + 1 file changed, 1 insertion(+)
drivers/edac/octeon_edac-lmc.c +1 -0
@@ -78,6 +78,7 @@ static void octeon_lmc_edac_poll_o2(struif (!pvt->inject) int_reg.u64 =cvmx_read_csr (CVMX_LMCX_INT (mci->mc_idx));else { + int_reg.u64 =0 ;if (pvt->error_type ==1 ) int_reg.s.sec_err =1 ;if (pvt->error_type ==2 )
Greg Kroah-Hartman
maintainerPATCH 171/195 pinctrl: intel: Initialize GPIO properly when used through irqchip
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mika Westerberg <[email protected]>
commit f5a26acf0162477af6ee4c11b4fb9cffe5d3e257 upstream.
When a GPIO is requested using gpiod_get_* APIs the intel pinctrl driver switches the pin to GPIO mode and makes sure interrupts are routed to the GPIO hardware instead of IOAPIC. However, if the GPIO is used directly through irqchip, as is the case with many I2C-HID devices where I2C core automatically configures interrupt for the device, the pin is not initialized as GPIO. Instead we rely that the BIOS configures the pin accordingly which seems not to be the case at least in Asus X540NA SKU3 with Focaltech touchpad.
When the pin is not properly configured it might result weird behaviour like interrupts suddenly stop firing completely and the touchpad stops responding to user input.
Fix this by properly initializing the pin to GPIO mode also when it is used directly through irqchip.
--- drivers/pinctrl/intel/pinctrl-intel.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)
drivers/pinctrl/intel/pinctrl-intel.c +15 -8
@@ -427,6 +427,18 @@ static void __intel_gpio_set_direction(vwritel (value, padcfg0); } +static void intel_gpio_set_gpio_mode (void __iomem *padcfg0) +{ +u32 value; + +/* Put the pad into GPIO mode */ + value =readl (padcfg0) & ~PADCFG0_PMODE_MASK ; +/* Disable SCI/SMI/NMI generation */ + value &= ~(PADCFG0_GPIROUTIOXAPIC |PADCFG0_GPIROUTSCI ); + value &= ~(PADCFG0_GPIROUTSMI |PADCFG0_GPIROUTNMI ); +writel (value, padcfg0); +} +static int intel_gpio_request_enable (struct pinctrl_dev *pctldev,struct pinctrl_gpio_range *range,unsigned pin)
@@ -434,7 +446,6 @@ static int intel_gpio_request_enable(strstruct intel_pinctrl *pctrl =pinctrl_dev_get_drvdata (pctldev);void __iomem *padcfg0;unsigned long flags; -u32 value;raw_spin_lock_irqsave (&pctrl->lock, flags);
@@ -444,13 +455,7 @@ static int intel_gpio_request_enable(str } padcfg0 =intel_get_padcfg (pctrl, pin,PADCFG0 ); -/* Put the pad into GPIO mode */ - value =readl (padcfg0) & ~PADCFG0_PMODE_MASK ; -/* Disable SCI/SMI/NMI generation */ - value &= ~(PADCFG0_GPIROUTIOXAPIC |PADCFG0_GPIROUTSCI ); - value &= ~(PADCFG0_GPIROUTSMI |PADCFG0_GPIROUTNMI ); -writel (value, padcfg0); - +intel_gpio_set_gpio_mode (padcfg0);/* Disable TX buffer and enable RX (this will be input) */ __intel_gpio_set_direction (padcfg0, true);
@@ -935,6 +940,8 @@ static int intel_gpio_irq_type(struct irraw_spin_lock_irqsave (&pctrl->lock, flags); +intel_gpio_set_gpio_mode (reg); + value =readl (reg); value &= ~(PADCFG0_RXEVCFG_MASK |PADCFG0_RXINV );
Greg Kroah-Hartman
maintainerPATCH 172/195 pinctrl: mcp23s08: fix irq setup order
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Mastykin <[email protected]>
commit 02e389e63e3523828fc3832f27e0341885f60f6f upstream.
When using mcp23s08 module with gpio-keys, often (50% of boots) it fails to get irq numbers with message:
"gpio-keys keys: Unable to get irq number for GPIO 0, error -6". Seems that irqs must be setup before devm_gpiochip_add_data().
--- drivers/pinctrl/pinctrl-mcp23s08.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/pinctrl/pinctrl-mcp23s08.c +4 -4
@@ -891,16 +891,16 @@ static int mcp23s08_probe_one(struct mcp goto fail; } - ret =devm_gpiochip_add_data (dev, &mcp->chip, mcp); -if (ret <0 ) - goto fail; -if (mcp->irq && mcp->irq_controller) { ret =mcp23s08_irq_setup (mcp);if (ret) goto fail; } + ret =devm_gpiochip_add_data (dev, &mcp->chip, mcp); +if (ret <0 ) + goto fail; + mcp->pinctrl_desc.name ="mcp23xxx-pinctrl" ; mcp->pinctrl_desc.pctlops = &mcp_pinctrl_ops; mcp->pinctrl_desc.confops = &mcp_pinconf_ops;
Greg Kroah-Hartman
maintainerPATCH 173/195 pinctrl: sx150x: Unregister the pinctrl on release
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Rosin <[email protected]>
commit 0657cb50b5a75abd92956028727dc255d690a4a6 upstream.
There is no matching call to pinctrl_unregister, so switch to the managed devm_pinctrl_register to clean up properly when done.
--- drivers/pinctrl/pinctrl-sx150x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/pinctrl-sx150x.c +1 -1
@@ -1225,7 +1225,7 @@ static int sx150x_probe(struct i2c_clien pctl->pinctrl_desc.npins = pctl->data->npins; pctl->pinctrl_desc.owner =THIS_MODULE ; - pctl->pctldev =pinctrl_register (&pctl->pinctrl_desc, dev, pctl); + pctl->pctldev =devm_pinctrl_register (dev, &pctl->pinctrl_desc, pctl);if (IS_ERR (pctl->pctldev)) {dev_err (dev,"Failed to register pinctrl device\n" );return PTR_ERR (pctl->pctldev);
Greg Kroah-Hartman
maintainerPATCH 174/195 pinctrl: sx150x: Register pinctrl before adding the gpiochip
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Rosin <[email protected]>
commit 1a1d39e1b8dd1d0f92a79da4fcc1ab0be3ae9bfc upstream.
Various gpiolib activity depend on the pinctrl to be up and kicking. Therefore, register the pinctrl before adding a gpiochip.
--- drivers/pinctrl/pinctrl-sx150x.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-)
drivers/pinctrl/pinctrl-sx150x.c +21 -14
@@ -1144,6 +1144,27 @@ static int sx150x_probe(struct i2c_clienif (ret)return ret; +/* Pinctrl_desc */ + pctl->pinctrl_desc.name ="sx150x-pinctrl" ; + pctl->pinctrl_desc.pctlops = &sx150x_pinctrl_ops; + pctl->pinctrl_desc.confops = &sx150x_pinconf_ops; + pctl->pinctrl_desc.pins = pctl->data->pins; + pctl->pinctrl_desc.npins = pctl->data->npins; + pctl->pinctrl_desc.owner =THIS_MODULE ; + + ret =devm_pinctrl_register_and_init (dev, &pctl->pinctrl_desc, + pctl, &pctl->pctldev); +if (ret) { +dev_err (dev,"Failed to register pinctrl device\n" ); +return ret; + } + + ret =pinctrl_enable (pctl->pctldev); +if (ret) { +dev_err (dev,"Failed to enable pinctrl device\n" ); +return ret; + } +/* Register GPIO controller */ pctl->gpio.label =devm_kstrdup (dev, client->name,GFP_KERNEL ); pctl->gpio.base =-1 ;
@@ -1217,20 +1238,6 @@ static int sx150x_probe(struct i2c_clien client->irq); } -/* Pinctrl_desc */ - pctl->pinctrl_desc.name ="sx150x-pinctrl" ; - pctl->pinctrl_desc.pctlops = &sx150x_pinctrl_ops; - pctl->pinctrl_desc.confops = &sx150x_pinconf_ops; - pctl->pinctrl_desc.pins = pctl->data->pins; - pctl->pinctrl_desc.npins = pctl->data->npins; - pctl->pinctrl_desc.owner =THIS_MODULE ; - - pctl->pctldev =devm_pinctrl_register (dev, &pctl->pinctrl_desc, pctl); -if (IS_ERR (pctl->pctldev)) { -dev_err (dev,"Failed to register pinctrl device\n" ); -return PTR_ERR (pctl->pctldev); - } -return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 175/195 pinctrl: sx150x: Add a static gpio/pinctrl pin range mapping
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Rosin <[email protected]>
commit b930151e5b55a0e62a3aad06876de891ac980471 upstream.
Without such a range, gpiolib fails with -EPROBE_DEFER, pending the addition of the range. So, without a range, gpiolib will keep deferring indefinitely.
--- drivers/pinctrl/pinctrl-sx150x.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/pinctrl/pinctrl-sx150x.c +5 -0
@@ -1193,6 +1193,11 @@ static int sx150x_probe(struct i2c_clienif (ret)return ret; + ret =gpiochip_add_pin_range (&pctl->gpio,dev_name (dev), +0 ,0 , pctl->data->npins); +if (ret) +return ret; +/* Add Interrupt support if an irq is specified */ if (client->irq >0 ) { pctl->irq_chip.name = devm_kstrdup(dev, client->name,
Greg Kroah-Hartman
maintainerPATCH 176/195 pktcdvd: Fix pkt_setup_dev() error path
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bart Van Assche <[email protected]>
commit 5a0ec388ef0f6e33841aeb810d7fa23f049ec4cd upstream.
Commit 523e1d399ce0 ("block: make gendisk hold a reference to its queue") modified add_disk() and disk_release() but did not update any of the error paths that trigger a put_disk() call after disk->queue has been assigned. That introduced the following behavior in the pktcdvd driver if pkt_new_dev() fails:
Kernel BUG at 00000000e98fd882 [verbose debug info unavailable]
Since disk_release() calls blk_put_queue() anyway if disk->queue != NULL, fix this by removing the blk_cleanup_queue() call from the pkt_setup_dev() error path.
--- drivers/block/pktcdvd.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/block/pktcdvd.c +1 -3
@@ -2745,7 +2745,7 @@ static int pkt_setup_dev(dev_t dev, dev_ pd->pkt_dev =MKDEV (pktdev_major, idx); ret =pkt_new_dev (pd, dev);if (ret) - goto out_new_dev; + goto out_mem2;/* inherit events of the host device */ disk->events = pd->bdev->bd_disk->events;
@@ -2763,8 +2763,6 @@ static int pkt_setup_dev(dev_t dev, dev_mutex_unlock (&ctl_mutex);return 0 ; -out_new_dev: -blk_cleanup_queue (disk->queue); out_mem2:put_disk (disk); out_mem:
Greg Kroah-Hartman
maintainerPATCH 177/195 pktcdvd: Fix a recently introduced NULL pointer dereference
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bart Van Assche <[email protected]>
commit 882d4171a8950646413b1a3cbe0e4a6a612fe82e upstream.
Call bdev_get_queue(bdev) after bdev->bd_disk has been initialized instead of just before that pointer has been initialized. This patch avoids that the following command
pktsetup 1 /dev/sr0
triggers the following kernel crash:
BUG: unable to handle kernel NULL pointer dereference at 0000000000000548 IP: pkt_setup_dev+0x2db/0x670 [pktcdvd] CPU: 2 PID: 724 Comm: pktsetup Not tainted 4.15.0-rc4-dbg+ #1 Call Trace: pkt_ctl_ioctl+0xce/0x1c0 [pktcdvd] do_vfs_ioctl+0x8e/0x670 SyS_ioctl+0x3c/0x70 entry_SYSCALL_64_fastpath+0x23/0x9a
--- drivers/block/pktcdvd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/block/pktcdvd.c +4 -4
@@ -2579,14 +2579,14 @@ static int pkt_new_dev(struct pktcdvd_de bdev =bdget (dev);if (!bdev)return -ENOMEM ; + ret =blkdev_get (bdev,FMODE_READ |FMODE_NDELAY ,NULL ); +if (ret) +return ret;if (!blk_queue_scsi_passthrough (bdev_get_queue (bdev))) {WARN_ONCE (true,"Attempt to register a non-SCSI queue\n" ); -bdput (bdev); +blkdev_put (bdev,FMODE_READ |FMODE_NDELAY );return -EINVAL ; } - ret =blkdev_get (bdev,FMODE_READ |FMODE_NDELAY ,NULL ); -if (ret) -return ret;/* This is safe, since we have a reference from open(). */ __module_get (THIS_MODULE );
Greg Kroah-Hartman
maintainerPATCH 178/195 blk-mq: quiesce queue before freeing queue
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ming Lei <[email protected]>
commit c2856ae2f315d754a0b6a268e4c6745b332b42e7 upstream.
After queue is frozen, dispatch still may happen, for example:
1) requests are submitted from several contexts
2) requests from all these contexts are inserted to queue, but may dispatch to LLD in one of these paths, but other paths sill need to move on even all these requests are completed(that means blk_mq_freeze_queue_wait() returns at that time)
3) dispatch after queue freezing still moves on and causes use-after-free, because request queue is freed
This patch quiesces queue after it is frozen, and makes sure all in-progress dispatch are completed.
This patch fixes the following kernel crash when running heavy IOs vs. deleting device:
[ 36.719251] BUG: unable to handle kernel NULL pointer dereference at 0000000000000008 [ 36.720318] IP: kyber_has_work+0x14/0x40 [ 36.720847] PGD 254bf5067 P4D 254bf5067 PUD 255e6a067 PMD 0 [ 36.721584] Oops: 0000 [#1] PREEMPT SMP [ 36.722105] Dumping ftrace buffer: [ 36.722570] (ftrace buffer empty) [ 36.723057] Modules linked in: scsi_debug ebtable_filter ebtables ip6table_filter ip6_tables tcm_loop iscsi_target_mod target_core_file target_core_iblock target_core_pscsi target_core_mod xt_CHECKSUM iptable_mangle ipt_MASQUERADE nf_nat_masquerade_ipv4 iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack libcrc32c bridge stp llc fuse iptable_filter ip_tables sd_mod sg btrfs xor zstd_decompress zstd_compress xxhash raid6_pq mptsas mptscsih bcache crc32c_intel ahci mptbase libahci serio_raw scsi_transport_sas nvme libata shpchp lpc_ich virtio_scsi nvme_core binfmt_misc dm_mod iscsi_tcp libiscsi_tcp libiscsi scsi_transport_iscsi null_blk configs [ 36.733438] CPU: 2 PID: 2374 Comm: fio Not tainted 4.15.0-rc2.blk_mq_quiesce+ #714 [ 36.735143] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.9.3-1.fc25 04/01/2014 [ 36.736688] RIP: 0010:kyber_has_work+0x14/0x40 [ 36.737515] RSP: 0018:ffffc9000209bca0 EFLAGS: 00010202 [ 36.738431] RAX: 0000000000000008 RBX: ffff88025578bfc8 RCX: ffff880257bf4ed0 [ 36.739581] RDX: 0000000000000038 RSI: ffffffff81a98c6d RDI: ffff88025578bfc8 [ 36.740730] RBP: ffff880253cebfc8 R08: ffffc9000209bda0 R09: ffff8802554f3480 [ 36.741885] R10: ffffc9000209be60 R11: ffff880263f72538 R12: ffff88025573e9e8 [ 36.743036] R13: ffff88025578bfd0 R14: 0000000000000001 R15: 0000000000000000 [ 36.744189] FS: 00007f9b9bee67c0(0000) GS:ffff88027fc80000(0000) knlGS:0000000000000000 [ 36.746617] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 36.748483] CR2: 0000000000000008 CR3: 0000000254bf4001 CR4: 00000000003606e0 [ 36.750164] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 36.751455] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 36.752796] Call Trace: [ 36.753992] blk_mq_do_dispatch_sched+0x7f/0xe0 [ 36.755110] blk_mq_sched_dispatch_requests+0x119/0x190 [ 36.756179] __blk_mq_run_hw_queue+0x83/0x90 [ 36.757144] __blk_mq_delay_run_hw_queue+0xaf/0x110 [ 36.758046] blk_mq_run_hw_queue+0x24/0x70 [ 36.758845] blk_mq_flush_plug_list+0x1e7/0x270 [ 36.759676] blk_flush_plug_list+0xd6/0x240 [ 36.760463] blk_finish_plug+0x27/0x40 [ 36.761195] do_io_submit+0x19b/0x780 [ 36.761921] ? entry_SYSCALL_64_fastpath+0x1a/0x7d [ 36.762788] entry_SYSCALL_64_fastpath+0x1a/0x7d [ 36.763639] RIP: 0033:0x7f9b9699f697 [ 36.764352] RSP: 002b:00007ffc10f991b8 EFLAGS: 00000206 ORIG_RAX: 00000000000000d1 [ 36.765773] RAX: ffffffffffffffda RBX: 00000000008f6f00 RCX: 00007f9b9699f697 [ 36.766965] RDX: 0000000000a5e6c0 RSI: 0000000000000001 RDI: 00007f9b8462a000 [ 36.768377] RBP: 0000000000000000 R08: 0000000000000001 R09: 00000000008f6420 [ 36.769649] R10: 00007f9b846e5000 R11: 0000000000000206 R12: 00007f9b795d6a70 [ 36.770807] R13: 00007f9b795e4140 R14: 00007f9b795e3fe0 R15: 0000000100000000 [ 36.771955] Code: 83 c7 10 e9 3f 68 d1 ff 0f 1f 44 00 00 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 8b 97 b0 00 00 00 48 8d 42 08 48 83 c2 38 <48> 3b 00 74 06 b8 01 00 00 00 c3 48 3b 40 08 75 f4 48 83 c0 10 [ 36.775004] RIP: kyber_has_work+0x14/0x40 RSP: ffffc9000209bca0 [ 36.776012] CR2: 0000000000000008 [ 36.776690] ---[ end trace 4045cbce364ff2a4 ]--- [ 36.777527] Kernel panic - not syncing: Fatal exception [ 36.778526] Dumping ftrace buffer: [ 36.779313] (ftrace buffer empty) [ 36.780081] Kernel Offset: disabled [ 36.780877] ---[ end Kernel panic - not syncing: Fatal exception
--- block/blk-core.c | 9 +++++++++ 1 file changed, 9 insertions(+)
block/blk-core.c +9 -0
@@ -660,6 +660,15 @@ void blk_cleanup_queue(struct request_ququeue_flag_set (QUEUE_FLAG_DEAD , q);spin_unlock_irq (lock); +/* +* make sure all in-progress dispatch are completed because +* blk_freeze_queue() can only complete all requests, and +* dispatch may still be in-progress since we dispatch requests +* from more than one contexts +*/ +if (q->mq_ops) +blk_mq_quiesce_queue (q); +/* for synchronous bio-based driver finish in-flight integrity i/o */ blk_flush_integrity ();
Greg Kroah-Hartman
maintainerPATCH 179/195 clocksource/drivers/stm32: Fix kernel panic with multiple timers
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Lezcano <[email protected]>
commit e0aeca3d8cbaea514eb98df1149faa918f9ec42d upstream.
The current code hides a couple of bugs:
- The global variable 'clock_event_ddata' is overwritten each time the init function is invoked.
This is fixed with a kmemdup() instead of assigning the global variable. That prevents a memory corruption when several timers are defined in the DT.
- The clockevent's event_handler is NULL if the time framework does not select the clockevent when registering it, this is fine but the init code generates in any case an interrupt leading to dereference this NULL pointer.
The stm32 timer works with shadow registers, a mechanism to cache the registers. When a change is done in one buffered register, we need to artificially generate an event to force the timer to copy the content of the register to the shadowed register.
The auto-reload register (ARR) is one of the shadowed register as well as the prescaler register (PSC), so in order to force the copy, we issue an event which in turn leads to an interrupt and the NULL dereference.
This is fixed by inverting two lines where we clear the status register before enabling the update event interrupt.
As this kernel crash is resulting from the combination of these two bugs, the fixes are grouped into a single patch.
--- drivers/clocksource/timer-stm32.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/clocksource/timer-stm32.c +6 -1
@@ -106,6 +106,10 @@ static int __init stm32_clockevent_init(unsigned long rate, max_delta;int irq, ret, bits, prescaler =1 ; + data =kmemdup (&clock_event_ddata,sizeof (*data),GFP_KERNEL ); +if (!data) +return -ENOMEM ; + clk =of_clk_get (np,0 );if (IS_ERR (clk)) { ret =PTR_ERR (clk);
@@ -156,8 +160,8 @@ static int __init stm32_clockevent_init(writel_relaxed (prescaler -1 , data->base +TIM_PSC );writel_relaxed (TIM_EGR_UG , data->base +TIM_EGR ); -writel_relaxed (TIM_DIER_UIE , data->base +TIM_DIER );writel_relaxed (0 , data->base +TIM_SR ); +writel_relaxed (TIM_DIER_UIE , data->base +TIM_DIER ); data->periodic_top =DIV_ROUND_CLOSEST (rate, prescaler *HZ );
@@ -184,6 +188,7 @@ err_iomap: err_clk_enable:clk_put (clk); err_clk_get: +kfree (data);return ret; }
Greg Kroah-Hartman
maintainerPATCH 180/195 lib/ubsan.c: s/missaligned/misaligned/
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrew Morton <[email protected]>
commit b8fe1120b4ba342b4f156d24e952d6e686b20298 upstream.
A vist from the spelling fairy.
--- lib/ubsan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/ubsan.c +2 -2
@@ -281,7 +281,7 @@ static void handle_null_ptr_deref(structubsan_epilogue (&flags); } -static void handle_missaligned_access (struct type_mismatch_data *data, +static void handle_misaligned_access (struct type_mismatch_data *data,unsigned long ptr) {unsigned long flags;
@@ -322,7 +322,7 @@ void __ubsan_handle_type_mismatch(structif (!ptr)handle_null_ptr_deref (data);else if (data->alignment && !IS_ALIGNED (ptr, data->alignment)) -handle_missaligned_access (data, ptr); +handle_misaligned_access (data, ptr);else handle_object_size_mismatch (data, ptr); }
Greg Kroah-Hartman
maintainerPATCH 181/195 lib/ubsan: add type mismatch handler for new GCC/Clang
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrey Ryabinin <[email protected]>
commit 42440c1f9911b4b7b8ba3dc4e90c1197bc561211 upstream.
UBSAN=y fails to build with new GCC/clang:
arch/x86/kernel/head64.o: In function `sanitize_boot_params':
arch/x86/include/asm/bootparam_utils.h:37: undefined reference to `__ubsan_handle_type_mismatch_v1'
because Clang and GCC 8 slightly changed ABI for 'type mismatch' errors. Compiler now uses new __ubsan_handle_type_mismatch_v1() function with slightly modified 'struct type_mismatch_data'.
Let's add new 'struct type_mismatch_data_common' which is independent from compiler's layout of 'struct type_mismatch_data'. And make __ubsan_handle_type_mismatch[_v1]() functions transform compiler-dependent type mismatch data to our internal representation. This way, we can support both old and new compilers with minimal amount of change.
--- lib/ubsan.c | 48 ++++++++++++++++++++++++++++++++++++++---------- lib/ubsan.h | 14 ++++++++++++++ 2 files changed, 52 insertions(+), 10 deletions(-)
lib/ubsan.c +38 -10
@@ -265,14 +265,14 @@ void __ubsan_handle_divrem_overflow(stru }EXPORT_SYMBOL (__ubsan_handle_divrem_overflow); -static void handle_null_ptr_deref (struct type_mismatch_data *data) +static void handle_null_ptr_deref (struct type_mismatch_data_common *data) {unsigned long flags; -if (suppress_report (&data->location)) +if (suppress_report (data->location))return ; -ubsan_prologue (&data->location, &flags); +ubsan_prologue (data->location, &flags); pr_err("%s null pointer of type %s\n", type_check_kinds[data->type_check_kind],
@@ -281,15 +281,15 @@ static void handle_null_ptr_deref(structubsan_epilogue (&flags); } -static void handle_misaligned_access (struct type_mismatch_data *data, +static void handle_misaligned_access (struct type_mismatch_data_common *data,unsigned long ptr) {unsigned long flags; -if (suppress_report (&data->location)) +if (suppress_report (data->location))return ; -ubsan_prologue (&data->location, &flags); +ubsan_prologue (data->location, &flags); pr_err("%s misaligned address %p for type %s\n", type_check_kinds[data->type_check_kind],
@@ -299,15 +299,15 @@ static void handle_misaligned_access(strubsan_epilogue (&flags); } -static void handle_object_size_mismatch (struct type_mismatch_data *data, +static void handle_object_size_mismatch (struct type_mismatch_data_common *data,unsigned long ptr) {unsigned long flags; -if (suppress_report (&data->location)) +if (suppress_report (data->location))return ; -ubsan_prologue (&data->location, &flags); +ubsan_prologue (data->location, &flags);pr_err ("%s address %p with insufficient space\n" , type_check_kinds[data->type_check_kind], (void *) ptr);
@@ -315,7 +315,7 @@ static void handle_object_size_mismatch(ubsan_epilogue (&flags); } -void __ubsan_handle_type_mismatch (struct type_mismatch_data *data, +static void ubsan_type_mismatch_common (struct type_mismatch_data_common *data,unsigned long ptr) {
@@ -326,8 +326,36 @@ void __ubsan_handle_type_mismatch(structelse handle_object_size_mismatch (data, ptr); } + +void __ubsan_handle_type_mismatch (struct type_mismatch_data *data, +unsigned long ptr) +{ +struct type_mismatch_data_common common_data = { + .location = &data->location, + .type = data->type, + .alignment = data->alignment, + .type_check_kind = data->type_check_kind + }; + +ubsan_type_mismatch_common (&common_data, ptr); +}EXPORT_SYMBOL (__ubsan_handle_type_mismatch); +void __ubsan_handle_type_mismatch_v1 (struct type_mismatch_data_v1 *data, +unsigned long ptr) +{ + +struct type_mismatch_data_common common_data = { + .location = &data->location, + .type = data->type, + .alignment =1UL << data->log_alignment, + .type_check_kind = data->type_check_kind + }; + +ubsan_type_mismatch_common (&common_data, ptr); +} +EXPORT_SYMBOL (__ubsan_handle_type_mismatch_v1); +void __ubsan_handle_nonnull_return (struct nonnull_return_data *data) {unsigned long flags;
lib/ubsan.h +14 -0
@@ -37,6 +37,20 @@ struct type_mismatch_data {unsigned char type_check_kind; }; +struct type_mismatch_data_v1 { +struct source_location location; +struct type_descriptor *type; +unsigned char log_alignment; +unsigned char type_check_kind; +}; + +struct type_mismatch_data_common { +struct source_location *location; +struct type_descriptor *type; +unsigned long alignment; +unsigned char type_check_kind; +}; +struct nonnull_arg_data {struct source_location location;struct source_location attr_location;
Greg Kroah-Hartman
maintainerPATCH 182/195 btrfs: Handle btrfs_set_extent_delalloc failure in fixup worker
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nikolay Borisov <[email protected]>
commit f3038ee3a3f1017a1cbe9907e31fa12d366c5dcb upstream.
This function was introduced by 247e743cbe6e ("Btrfs: Use async helpers to deal with pages that have been improperly dirtied") and it didn't do any error handling then. This function might very well fail in ENOMEM situation, yet it's not handled, this could lead to inconsistent state. So let's handle the failure by setting the mapping error bit.
--- fs/btrfs/inode.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
fs/btrfs/inode.c +9 -2
@@ -2101,8 +2101,15 @@ again: goto out; } -btrfs_set_extent_delalloc (inode, page_start, page_end, &cached_state, -0 ); + ret =btrfs_set_extent_delalloc (inode, page_start, page_end, + &cached_state,0 ); +if (ret) { +mapping_set_error (page->mapping, ret); +end_extent_writepage (page, ret, page_start, page_end); +ClearPageChecked (page); + goto out; + } +ClearPageChecked (page);set_page_dirty (page); out:
Greg Kroah-Hartman
maintainerPATCH 183/195 objtool: Fix switch-table detection
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Zijlstra <[email protected]>
commit 99ce7962d52d1948ad6f2785e308d48e76e0a6ef upstream.
Linus reported that GCC-7.3 generated a switch-table construct that confused objtool. It turns out that, in particular due to KASAN, it is possible to have unrelated .rodata usage in between the .rodata setup for the switch-table and the following indirect jump.
The simple linear reverse search from the indirect jump would hit upon the KASAN .rodata usage first and fail to find a switch_table, resulting in a spurious 'sibling call with modified stack frame' warning.
Fix this by creating a 'jump-stack' which we can 'unwind' during reversal, thereby skipping over much of the in-between code.
This is not fool proof by any means, but is sufficient to make the known cases work. Future work would be to construct more comprehensive flow analysis code.
--- tools/objtool/check.c | 41 +++++++++++++++++++++++++++++++++++++++-- tools/objtool/check.h | 1 + 2 files changed, 40 insertions(+), 2 deletions(-)
tools/objtool/check.c +39 -2
@@ -851,8 +851,14 @@ static int add_switch_table(struct objto* This is a fairly uncommon pattern which is new for GCC 6. As of this * writing, there are 11 occurrences of it in the allmodconfig kernel. * +* As of GCC 7 there are quite a few more of these and the 'in between' code +* is significant. Esp. with KASAN enabled some of the code between the mov +* and jmpq uses .rodata itself, which can confuse things. +* * TODO: Once we have DWARF CFI and smarter instruction decoding logic, * ensure the same register is used in the mov and jump instructions. +* +* NOTE: RETPOLINE made it harder still to decode dynamic jumps. */ static struct rela *find_switch_table(struct objtool_file *file, struct symbol *func,
@@ -874,12 +880,25 @@ static struct rela *find_switch_table(st text_rela->addend + 4);if (!rodata_rela)return NULL ; + file->ignore_unreachables = true;return rodata_rela; }/* case 3 */ -func_for_each_insn_continue_reverse (file, func, insn) { +/* +* Backward search using the @first_jump_src links, these help avoid +* much of the 'in between' code. Which avoids us getting confused by +* it. +*/ +for (insn =list_prev_entry (insn, list); + + &insn->list != &file->insn_list && + insn->sec == func->sec && + insn->offset >= func->offset; + + insn = insn->first_jump_src ?:list_prev_entry (insn, list)) { +if (insn->type ==INSN_JUMP_DYNAMIC )break ;
@@ -909,14 +928,32 @@ static struct rela *find_switch_table(streturn NULL ; } +static int add_func_switch_tables (struct objtool_file *file,struct symbol *func) { -struct instruction *insn, *prev_jump =NULL ; +struct instruction *insn, *last =NULL , *prev_jump =NULL ;struct rela *rela, *prev_rela =NULL ;int ret;func_for_each_insn (file, func, insn) { +if (!last) + last = insn; + +/* +* Store back-pointers for unconditional forward jumps such +* that find_switch_table() can back-track using those and +* avoid some potentially confusing code. +*/ +if (insn->type ==INSN_JUMP_UNCONDITIONAL && insn->jump_dest && + insn->offset > last->offset && + insn->jump_dest->offset > insn->offset && + !insn->jump_dest->first_jump_src) { + + insn->jump_dest->first_jump_src = insn; + last = insn->jump_dest; + } +if (insn->type !=INSN_JUMP_DYNAMIC )continue ;
tools/objtool/check.h +1 -0
@@ -47,6 +47,7 @@ struct instruction {bool alt_group, visited, dead_end, ignore, hint, save, restore, ignore_alts;struct symbol *call_dest;struct instruction *jump_dest; +struct instruction *first_jump_src;struct list_head alts;struct symbol *func;struct stack_op stack_op;
Greg Kroah-Hartman
maintainerPATCH 184/195 arm64: dts: marvell: add Ethernet aliases
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yan Markman <[email protected]>
commit 474c5885582c4a79c21bcf01ed98f98c935f1f4a upstream.
This patch adds Ethernet aliases in the Marvell Armada 7040 DB, 8040 DB and 8040 mcbin device trees so that the bootloader setup the MAC addresses correctly.
--- arch/arm64/boot/dts/marvell/armada-7040-db.dts | 6 ++++++ arch/arm64/boot/dts/marvell/armada-8040-db.dts | 7 +++++++ arch/arm64/boot/dts/marvell/armada-8040-mcbin.dts | 6 ++++++ 3 files changed, 19 insertions(+)
arch/arm64/boot/dts/marvell/armada-7040-db.dts +6 -0
@@ -61,6 +61,12 @@ reg = <0x0 0x0 0x0 0x80000000>; }; + aliases { + ethernet0 = &cpm_eth0; + ethernet1 = &cpm_eth1; + ethernet2 = &cpm_eth2; + }; + cpm_reg_usb3_0_vbus: cpm-usb3-0-vbus { compatible = "regulator-fixed"; regulator-name = "usb3h0-vbus";
arch/arm64/boot/dts/marvell/armada-8040-db.dts +7 -0
@@ -61,6 +61,13 @@ reg = <0x0 0x0 0x0 0x80000000>; }; + aliases { + ethernet0 = &cpm_eth0; + ethernet1 = &cpm_eth2; + ethernet2 = &cps_eth0; + ethernet3 = &cps_eth1; + }; + cpm_reg_usb3_0_vbus: cpm-usb3-0-vbus { compatible = "regulator-fixed"; regulator-name = "cpm-usb3h0-vbus";
arch/arm64/boot/dts/marvell/armada-8040-mcbin.dts +6 -0
@@ -62,6 +62,12 @@ reg = <0x0 0x0 0x0 0x80000000>; }; + aliases { + ethernet0 = &cpm_eth0; + ethernet1 = &cps_eth0; + ethernet2 = &cps_eth1; + }; + /* Regulator labels correspond with schematics */ v_3_3: regulator-3-3v { compatible = "regulator-fixed";
Greg Kroah-Hartman
maintainerPATCH 185/195 drm/i915: Avoid PPS HW/SW state mismatch due to rounding
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Imre Deak <[email protected]>
commit 5643205c6340b565a3be0fe0e7305dc4aa551c74 upstream.
We store a SW state of the t11_t12 timing in 100usec units but have to program it in 100msec as required by HW. The rounding used during programming means there will be a mismatch between the SW and HW states of this value triggering a "PPS state mismatch" error. Avoid this by storing the already rounded-up value in the SW state.
Note that we still calculate panel_power_cycle_delay with the finer 100usec granularity to avoid any needless waits using that version of the delay.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103903
--- drivers/gpu/drm/i915/intel_dp.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/gpu/drm/i915/intel_dp.c +6 -0
@@ -5340,6 +5340,12 @@ intel_dp_init_panel_power_sequencer(stru*/ final->t8 =1 ; final->t9 =1 ; + +/* +* HW has only a 100msec granularity for t11_t12 so round it up +* accordingly. +*/ + final->t11_t12 =roundup (final->t11_t12,100 *10 ); } static void
Greg Kroah-Hartman
maintainerPATCH 186/195 ACPI: sbshc: remove raw pointer from printk() message
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
commit 43cdd1b716b26f6af16da4e145b6578f98798bf6 upstream.
There's no need to be printing a raw kernel pointer to the kernel log at every boot. So just remove it, and change the whole message to use the correct dev_info() call at the same time.
--- drivers/acpi/sbshc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/acpi/sbshc.c +2 -2
@@ -275,8 +275,8 @@ static int acpi_smbus_hc_add(struct acpi device->driver_data = hc;acpi_ec_add_query_handler (hc->ec, hc->query_bit,NULL , smbus_alarm, hc); - printk(KERN_INFO PREFIX "SBS HC: EC = 0x%p, offset = 0x%0x, query_bit = 0x%0x\n", - hc->ec, hc->offset, hc->query_bit); +dev_info (&device->dev,"SBS HC: offset = 0x%0x, query_bit = 0x%0x\n" , + hc->offset, hc->query_bit);return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 187/195 acpi, nfit: fix register dimm error handling
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Toshi Kani <[email protected]>
commit 23fbd7c70aec7600e3227eb24259fc55bf6e4881 upstream.
A NULL pointer reference kernel bug was observed when acpi_nfit_add_dimm() called in acpi_nfit_register_dimms() failed. This error path does not set nfit_mem->nvdimm, but the 2nd list_for_each_entry() loop in the function assumes it's always set. Add a check to nfit_mem->nvdimm.
--- drivers/acpi/nfit/core.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/acpi/nfit/core.c +3 -0
@@ -1618,6 +1618,9 @@ static int acpi_nfit_register_dimms(strustruct kernfs_node *nfit_kernfs; nvdimm = nfit_mem->nvdimm; +if (!nvdimm) +continue ; + nfit_kernfs =sysfs_get_dirent (nvdimm_kobj (nvdimm)->sd,"nfit" );if (nfit_kernfs) nfit_mem->flags_attr = sysfs_get_dirent(nfit_kernfs,
Greg Kroah-Hartman
maintainerPATCH 188/195 ovl: fix failure to fsync lower dir
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
commit d796e77f1dd541fe34481af2eee6454688d13982 upstream.
As a writable mount, it is not expected for overlayfs to return EINVAL/EROFS for fsync, even if dir/file is not changed.
This commit fixes the case of fsync of directory, which is easier to address, because overlayfs already implements fsync file operation for directories.
The problem reported by Raphael is that new PostgreSQL 10.0 with a database in overlayfs where lower layer in squashfs fails to start. The failure is due to fsync error, when PostgreSQL does fsync on all existing db directories on startup and a specific directory exists lower layer with no changes.
--- fs/overlayfs/readdir.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/overlayfs/readdir.c +5 -1
@@ -751,10 +751,14 @@ static int ovl_dir_fsync(struct file *fistruct dentry *dentry = file->f_path.dentry;struct file *realfile = od->realfile; +/* Nothing to sync for lower */ +if (!OVL_TYPE_UPPER (ovl_path_type (dentry))) +return 0 ; +/* * Need to check if we started out being a lower dir, but got copied up */ -if (!od->is_upper &&OVL_TYPE_UPPER (ovl_path_type (dentry))) { +if (!od->is_upper) {struct inode *inode =file_inode (file); realfile =READ_ONCE (od->upperfile);
Greg Kroah-Hartman
maintainerPATCH 189/195 ovl: take mnt_want_write() for removing impure xattr
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
commit a5a927a7c82e28ea76599dee4019c41e372c911f upstream.
The optimization in ovl_cache_get_impure() that tries to remove an unneeded "impure" xattr needs to take mnt_want_write() on upper fs.
--- fs/overlayfs/readdir.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
fs/overlayfs/readdir.c +9 -2
@@ -575,8 +575,15 @@ static struct ovl_dir_cache *ovl_cache_greturn ERR_PTR (res); }if (list_empty (&cache->entries)) { -/* Good oportunity to get rid of an unnecessary "impure" flag */ -ovl_do_removexattr (ovl_dentry_upper (dentry),OVL_XATTR_IMPURE ); +/* +* A good opportunity to get rid of an unneeded "impure" flag. +* Removing the "impure" xattr is best effort. +*/ +if (!ovl_want_write (dentry)) { +ovl_do_removexattr (ovl_dentry_upper (dentry), +OVL_XATTR_IMPURE ); +ovl_drop_write (dentry); + }ovl_clear_flag (OVL_IMPURE ,d_inode (dentry));kfree (cache);return NULL ;
Greg Kroah-Hartman
maintainerPATCH 190/195 mn10300/misalignment: Use SIGSEGV SEGV_MAPERR to report a failed user copy
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric W. Biederman <[email protected]>
commit 6ac1dc736b323011a55ecd1fc5897c24c4f77cbd upstream.
Setting si_code to 0 is the same a setting si_code to SI_USER which is definitely not correct. With si_code set to SI_USER si_pid and si_uid will be copied to userspace instead of si_addr. Which is very wrong.
So fix this by using a sensible si_code (SEGV_MAPERR) for this failure.
--- arch/mn10300/mm/misalignment.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mn10300/mm/misalignment.c +1 -1
@@ -437,7 +437,7 @@ transfer_failed: info.si_signo =SIGSEGV ; info.si_errno =0 ; - info.si_code =0 ; + info.si_code =SEGV_MAPERR ; info.si_addr = (void *) regs->pc;force_sig_info (SIGSEGV , &info, current);return ;
Greg Kroah-Hartman
maintainerPATCH 191/195 devpts: fix error handling in devpts_mntget()
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit c9cc8d01fb04117928830449388512a5047569c9 upstream.
If devpts_ptmx_path() returns an error code, then devpts_mntget() dereferences an ERR_PTR():
BUG: unable to handle kernel paging request at fffffffffffffff5
IP: devpts_mntget+0x13f/0x280 fs/devpts/inode.c:173Fix it by returning early in the error paths.
Reproducer:
#define _GNU_SOURCE
#include <fcntl.h>
#include <sched.h>
#include <sys/ioctl.h>
#define TIOCGPTPEER _IO('T', 0x41)
int main()
{
for (;;) {
int fd = open("/dev/ptmx", 0);
unshare(CLONE_NEWNS);
ioctl(fd, TIOCGPTPEER, 0);
}
}--- fs/devpts/inode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/devpts/inode.c +2 -2
@@ -168,11 +168,11 @@ struct vfsmount *devpts_mntget(struct fidput (path.dentry);if (err) {mntput (path.mnt); - path.mnt =ERR_PTR (err); +return ERR_PTR (err); }if (DEVPTS_SB (path.mnt->mnt_sb) != fsi) {mntput (path.mnt); - path.mnt =ERR_PTR (-ENODEV ); +return ERR_PTR (-ENODEV ); }return path.mnt; }
Greg Kroah-Hartman
maintainerPATCH 192/195 ftrace: Remove incorrect setting of glob search field
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steven Rostedt (VMware) <[email protected]>
commit 7b6586562708d2b3a04fe49f217ddbadbbbb0546 upstream.
__unregister_ftrace_function_probe() will incorrectly parse the glob filter because it resets the search variable that was setup by filter_parse_regex().
Al Viro reported this:
After that call of filter_parse_regex() we could have func_g.search not equal to glob only if glob started with '!' or '*'. In the former case we would've buggered off with -EINVAL (not = 1). In the latter we would've set func_g.search equal to glob + 1, calculated the length of that thing in func_g.len and proceeded to reset func_g.search back to glob.
Suppose the glob is e.g. *foo*. We end up with
func_g.type = MATCH_MIDDLE_ONLY;
func_g.len = 3;
func_g.search = "*foo";
Feeding that to ftrace_match_record() will not do anything sane - we will be looking for names containing "*foo" (->len is ignored for that one).
--- kernel/trace/ftrace.c | 1 - 1 file changed, 1 deletion(-)
kernel/trace/ftrace.c +0 -1
@@ -4488,7 +4488,6 @@ unregister_ftrace_function_probe_func(ch func_g.type =filter_parse_regex (glob,strlen (glob), &func_g.search, ¬); func_g.len =strlen (func_g.search); - func_g.search = glob;/* we do not support '!' for function probes */ if (WARN_ON (not))
Greg Kroah-Hartman
maintainerPATCH 193/195 scsi: core: Ensure that the SCSI error handler gets woken up
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bart Van Assche <[email protected]>
commit 3bd6f43f5cb3714f70c591514f344389df593501 upstream.
If scsi_eh_scmd_add() is called concurrently with scsi_host_queue_ready() while shost->host_blocked > 0 then it can happen that neither function wakes up the SCSI error handler. Fix this by making every function that decreases the host_busy counter wake up the error handler if necessary and by protecting the host_failed checks with the SCSI host lock.
References: https://marc.info/?l=linux-kernel&m=150461610630736
--- drivers/scsi/hosts.c | 6 ++++++ drivers/scsi/scsi_error.c | 18 ++++++++++++++++-- drivers/scsi/scsi_lib.c | 39 ++++++++++++++++++++++++++++----------- include/scsi/scsi_host.h | 2 ++ 4 files changed, 52 insertions(+), 13 deletions(-)
drivers/scsi/hosts.c +6 -0
@@ -318,6 +318,9 @@ static void scsi_host_dev_release(structscsi_proc_hostdir_rm (shost->hostt); +/* Wait for functions invoked through call_rcu(&shost->rcu, ...) */ +rcu_barrier (); +if (shost->tmf_work_q)destroy_workqueue (shost->tmf_work_q);if (shost->ehandler)
@@ -325,6 +328,8 @@ static void scsi_host_dev_release(structif (shost->work_q)destroy_workqueue (shost->work_q); +destroy_rcu_head (&shost->rcu); +if (shost->shost_state ==SHOST_CREATED ) {/* * Free the shost_dev device name here if scsi_host_alloc()
@@ -399,6 +404,7 @@ struct Scsi_Host *scsi_host_alloc(structINIT_LIST_HEAD (&shost->starved_list);init_waitqueue_head (&shost->host_wait);mutex_init (&shost->scan_mutex); +init_rcu_head (&shost->rcu); index =ida_simple_get (&host_index_ida,0 ,0 ,GFP_KERNEL );if (index <0 )
drivers/scsi/scsi_error.c +16 -2
@@ -220,6 +220,17 @@ static void scsi_eh_reset(struct scsi_cm } } +static void scsi_eh_inc_host_failed (struct rcu_head *head) +{ +struct Scsi_Host *shost =container_of (head,typeof (*shost), rcu); +unsigned long flags; + +spin_lock_irqsave (shost->host_lock, flags); + shost->host_failed++; +scsi_eh_wakeup (shost); +spin_unlock_irqrestore (shost->host_lock, flags); +} +/** * scsi_eh_scmd_add - add scsi cmd to error handling. * @scmd: scmd to run eh on.
@@ -242,9 +253,12 @@ void scsi_eh_scmd_add(struct scsi_cmnd *scsi_eh_reset (scmd);list_add_tail (&scmd->eh_entry, &shost->eh_cmd_q); - shost->host_failed++; -scsi_eh_wakeup (shost);spin_unlock_irqrestore (shost->host_lock, flags); +/* +* Ensure that all tasks observe the host state change before the +* host_failed change. +*/ +call_rcu (&shost->rcu, scsi_eh_inc_host_failed); }/**
drivers/scsi/scsi_lib.c +28 -11
@@ -318,22 +318,39 @@ static void scsi_init_cmd_errh(struct sc cmd->cmd_len =scsi_command_size (cmd->cmnd); } -void scsi_device_unbusy (struct scsi_device *sdev) +/* +* Decrement the host_busy counter and wake up the error handler if necessary. +* Avoid as follows that the error handler is not woken up if shost->host_busy +* == shost->host_failed: use call_rcu() in scsi_eh_scmd_add() in combination +* with an RCU read lock in this function to ensure that this function in its +* entirety either finishes before scsi_eh_scmd_add() increases the +* host_failed counter or that it notices the shost state change made by +* scsi_eh_scmd_add(). +*/ +static void scsi_dec_host_busy (struct Scsi_Host *shost) { -struct Scsi_Host *shost = sdev->host; -struct scsi_target *starget =scsi_target (sdev);unsigned long flags; +rcu_read_lock ();atomic_dec (&shost->host_busy); -if (starget->can_queue >0 ) -atomic_dec (&starget->target_busy); - -if (unlikely (scsi_host_in_recovery (shost) && - (shost->host_failed || shost->host_eh_scheduled))) { +if (unlikely (scsi_host_in_recovery (shost))) {spin_lock_irqsave (shost->host_lock, flags); -scsi_eh_wakeup (shost); +if (shost->host_failed || shost->host_eh_scheduled) +scsi_eh_wakeup (shost);spin_unlock_irqrestore (shost->host_lock, flags); } +rcu_read_unlock (); +} + +void scsi_device_unbusy (struct scsi_device *sdev) +{ +struct Scsi_Host *shost = sdev->host; +struct scsi_target *starget =scsi_target (sdev); + +scsi_dec_host_busy (shost); + +if (starget->can_queue >0 ) +atomic_dec (&starget->target_busy);atomic_dec (&sdev->device_busy); }
@@ -1532,7 +1549,7 @@ starved:list_add_tail (&sdev->starved_entry, &shost->starved_list);spin_unlock_irq (shost->host_lock); out_dec: -atomic_dec (&shost->host_busy); +scsi_dec_host_busy (shost);return 0 ; }
@@ -1993,7 +2010,7 @@ static blk_status_t scsi_queue_rq(structreturn BLK_STS_OK ; out_dec_host_busy: -atomic_dec (&shost->host_busy); +scsi_dec_host_busy (shost); out_dec_target_busy:if (scsi_target (sdev)->can_queue >0 )atomic_dec (&scsi_target (sdev)->target_busy);
include/scsi/scsi_host.h +2 -0
@@ -571,6 +571,8 @@ struct Scsi_Host {struct blk_mq_tag_set tag_set; }; +struct rcu_head rcu; +atomic_t host_busy;/* commands actually active on low-level */ atomic_t host_blocked;
Greg Kroah-Hartman
maintainerPATCH 194/195 scsi: lpfc: Fix crash after bad bar setup on driver attachment
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Smart <[email protected]>
commit e4b9794efdce13242f4af6682f3ed48ce3864a87 upstream.
In test cases where an instance of the driver is detached and reattached, the driver will crash on reattachment. There is a compound if statement that will skip over the bar setup if the pci_resource_start call is not successful. The driver erroneously returns success to its bar setup in this scenario even though the bars aren't properly configured.
Rework the offending code segment for proper initialization steps. If the pci_resource_start call fails, -ENOMEM is now returned.
Sample stack:
rport-5:0-10: blocked FC remote port time out: removing rport
BUG: unable to handle kernel NULL pointer dereference at (null) ... lpfc_sli4_wait_bmbx_ready+0x32/0x70 [lpfc] ... ... RIP: 0010:... ... lpfc_sli4_wait_bmbx_ready+0x32/0x70 [lpfc] Call Trace: ... lpfc_sli4_post_sync_mbox+0x106/0x4d0 [lpfc] ... ? __alloc_pages_nodemask+0x176/0x420 ... ? __kmalloc+0x2e/0x230 ... lpfc_sli_issue_mbox_s4+0x533/0x720 [lpfc] ... ? mempool_alloc+0x69/0x170 ... ? dma_generic_alloc_coherent+0x8f/0x140 ... lpfc_sli_issue_mbox+0xf/0x20 [lpfc] ... lpfc_sli4_driver_resource_setup+0xa6f/0x1130 [lpfc] ... ? lpfc_pci_probe_one+0x23e/0x16f0 [lpfc] ... lpfc_pci_probe_one+0x445/0x16f0 [lpfc] ... local_pci_probe+0x45/0xa0 ... work_for_cpu_fn+0x14/0x20 ... process_one_work+0x17a/0x440
--- drivers/scsi/lpfc/lpfc_init.c | 84 +++++++++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 33 deletions(-)
drivers/scsi/lpfc/lpfc_init.c +51 -33
@@ -9413,44 +9413,62 @@ lpfc_sli4_pci_mem_setup(struct lpfc_hbalpfc_sli4_bar0_register_memmap (phba, if_type); } -if ((if_type ==LPFC_SLI_INTF_IF_TYPE_0 ) && - (pci_resource_start (pdev,PCI_64BIT_BAR2 ))) { -/* -* Map SLI4 if type 0 HBA Control Register base to a kernel -* virtual address and setup the registers. -*/ - phba->pci_bar1_map =pci_resource_start (pdev,PCI_64BIT_BAR2 ); - bar1map_len =pci_resource_len (pdev,PCI_64BIT_BAR2 ); - phba->sli4_hba.ctrl_regs_memmap_p = -ioremap (phba->pci_bar1_map, bar1map_len); -if (!phba->sli4_hba.ctrl_regs_memmap_p) { -dev_printk (KERN_ERR , &pdev->dev, -"ioremap failed for SLI4 HBA control registers.\n" ); +if (if_type ==LPFC_SLI_INTF_IF_TYPE_0 ) { +if (pci_resource_start (pdev,PCI_64BIT_BAR2 )) { +/* +* Map SLI4 if type 0 HBA Control Register base to a +* kernel virtual address and setup the registers. +*/ + phba->pci_bar1_map =pci_resource_start (pdev, +PCI_64BIT_BAR2 ); + bar1map_len =pci_resource_len (pdev,PCI_64BIT_BAR2 ); + phba->sli4_hba.ctrl_regs_memmap_p = +ioremap (phba->pci_bar1_map, + bar1map_len); +if (!phba->sli4_hba.ctrl_regs_memmap_p) { +dev_err (&pdev->dev, +"ioremap failed for SLI4 HBA " +"control registers.\n" ); + error = -ENOMEM ; + goto out_iounmap_conf; + } + phba->pci_bar2_memmap_p = + phba->sli4_hba.ctrl_regs_memmap_p; +lpfc_sli4_bar1_register_memmap (phba); + }else { + error = -ENOMEM ; goto out_iounmap_conf; } - phba->pci_bar2_memmap_p = phba->sli4_hba.ctrl_regs_memmap_p; -lpfc_sli4_bar1_register_memmap (phba); } -if ((if_type ==LPFC_SLI_INTF_IF_TYPE_0 ) && - (pci_resource_start (pdev,PCI_64BIT_BAR4 ))) { -/* -* Map SLI4 if type 0 HBA Doorbell Register base to a kernel -* virtual address and setup the registers. -*/ - phba->pci_bar2_map =pci_resource_start (pdev,PCI_64BIT_BAR4 ); - bar2map_len =pci_resource_len (pdev,PCI_64BIT_BAR4 ); - phba->sli4_hba.drbl_regs_memmap_p = -ioremap (phba->pci_bar2_map, bar2map_len); -if (!phba->sli4_hba.drbl_regs_memmap_p) { -dev_printk (KERN_ERR , &pdev->dev, -"ioremap failed for SLI4 HBA doorbell registers.\n" ); - goto out_iounmap_ctrl; - } - phba->pci_bar4_memmap_p = phba->sli4_hba.drbl_regs_memmap_p; - error =lpfc_sli4_bar2_register_memmap (phba,LPFC_VF0 ); -if (error) +if (if_type ==LPFC_SLI_INTF_IF_TYPE_0 ) { +if (pci_resource_start (pdev,PCI_64BIT_BAR4 )) { +/* +* Map SLI4 if type 0 HBA Doorbell Register base to +* a kernel virtual address and setup the registers. +*/ + phba->pci_bar2_map =pci_resource_start (pdev, +PCI_64BIT_BAR4 ); + bar2map_len =pci_resource_len (pdev,PCI_64BIT_BAR4 ); + phba->sli4_hba.drbl_regs_memmap_p = +ioremap (phba->pci_bar2_map, + bar2map_len); +if (!phba->sli4_hba.drbl_regs_memmap_p) { +dev_err (&pdev->dev, +"ioremap failed for SLI4 HBA" +" doorbell registers.\n" ); + error = -ENOMEM ; + goto out_iounmap_ctrl; + } + phba->pci_bar4_memmap_p = + phba->sli4_hba.drbl_regs_memmap_p; + error =lpfc_sli4_bar2_register_memmap (phba,LPFC_VF0 ); +if (error) + goto out_iounmap_all; + }else { + error = -ENOMEM ; goto out_iounmap_all; + } }return 0 ;
Greg Kroah-Hartman
maintainerPATCH 195/195 scsi: cxlflash: Reset command ioasc
In reply to Greg Kroah-Hartman4.14-stable review patch. If anyone has any objections, please let me know.
------------------
From: Uma Krishnan <[email protected]>
commit 96cf727fe8f102bf92150b741db71ee39fb8c521 upstream.
In the event of a command failure, cxlflash returns the failure to the upper layers to process. After processing the error, when the command is queued again, the private command structure will not be zeroed and the ioasc could be stale. Per the SISLite specification, the AFU only sets the ioasc in the presence of a failure. Thus, even though the original command succeeds the second time, the command is considered a failure due to stale ioasc. This cycle repeats indefinitely and can cause a hang or IO failure.
To fix the issue, clear the ioasc before queuing any command.
[mkp: added Cc: stable per request]
--- drivers/scsi/cxlflash/main.c | 1 + 1 file changed, 1 insertion(+)
drivers/scsi/cxlflash/main.c +1 -0
@@ -620,6 +620,7 @@ static int cxlflash_queuecommand(struct cmd->parent = afu; cmd->hwq_index = hwq_index; + cmd->sa.ioasc =0 ; cmd->rcb.ctx_id = hwq->ctx_hndl; cmd->rcb.msi =SISL_MSI_RRQ_UPDATED ; cmd->rcb.port_sel =CHAN2PORTMASK (scp->device->channel);
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 4.14.20 release. There are 195 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Sat Feb 17 15:16:22 UTC 2018. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 9 lines
kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.14.20-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-4.14.y
and the diffstat can be found below.thanks,
greg k-h
Compiled and booted on my test system. No dmesg regressions.
thanks,
-- Shuah
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 4.14.20 release. There are 195 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Sat Feb 17 15:16:22 UTC 2018. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 8 lines
kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.14.20-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-4.14.y
and the diffstat can be found below.thanks,
greg k-h
Results from Linaro’s test farm.
No regressions on arm64, arm and x86_64.
Summary
------------------------------------------------------------------------
kernel: 4.14.20-rc1
git repo: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git
git branch: linux-4.14.y
git commit: ff1db24d7bfc9f8692fd5da29d531c7cb7992b12
git describe: v4.14.19-197-gff1db24d7bfc
Test details: https://qa-reports.linaro.org/lkft/linux-stable-rc-4.14-oe/build/v4.14.19-197-gff1db24d7bfc
No regressions (compared to build v4.14.19-114-g55c6178a2819)
Boards, architectures and test suites:
-------------------------------------
hi6220-hikey - arm64
* boot - pass: 20,
* kselftest - skip: 17, pass: 48,
* libhugetlbfs - skip: 1, pass: 90,
* ltp-cap_bounds-tests - pass: 2,
* ltp-containers-tests - skip: 17, pass: 64,
* ltp-fcntl-locktests-tests - pass: 2,
* ltp-filecaps-tests - pass: 2,
* ltp-fs-tests - skip: 2, pass: 61,
* ltp-fs_bind-tests - pass: 2,
* ltp-fs_perms_simple-tests - pass: 19,
* ltp-fsx-tests - pass: 2,
* ltp-hugetlb-tests - skip: 1, pass: 21,
* ltp-io-tests - pass: 3,
* ltp-ipc-tests - pass: 9,
* ltp-math-tests - pass: 11,
* ltp-nptl-tests - pass: 2,
* ltp-pty-tests - pass: 4,
* ltp-sched-tests - skip: 4, pass: 10,
* ltp-securebits-tests - pass: 4,
* ltp-syscalls-tests - skip: 151, pass: 999,
* ltp-timers-tests - skip: 1, pass: 12,
juno-r2 - arm64
* boot - pass: 20,
* kselftest - skip: 17, pass: 48,
* libhugetlbfs - skip: 1, pass: 90,
* ltp-cap_bounds-tests - pass: 2,
* ltp-containers-tests - skip: 17, pass: 64,
* ltp-fcntl-locktests-tests - pass: 2,
* ltp-filecaps-tests - pass: 2,
* ltp-fs-tests - skip: 2, pass: 61,
* ltp-fs_bind-tests - pass: 2,
* ltp-fs_perms_simple-tests - pass: 19,
* ltp-fsx-tests - pass: 2,
* ltp-hugetlb-tests - pass: 22,
* ltp-io-tests - pass: 3,
* ltp-ipc-tests - pass: 9,
* ltp-math-tests - pass: 11,
* ltp-nptl-tests - pass: 2,
* ltp-pty-tests - pass: 4,
* ltp-sched-tests - skip: 4, pass: 10,
* ltp-securebits-tests - pass: 4,
* ltp-syscalls-tests - skip: 148, pass: 1002,
* ltp-timers-tests - skip: 1, pass: 12,
x15 - arm
* boot - pass: 20,
* kselftest - skip: 19, pass: 45,
* libhugetlbfs - skip: 1, pass: 87,
* ltp-cap_bounds-tests - pass: 2,
* ltp-containers-tests - skip: 17, pass: 64,
* ltp-fcntl-locktests-tests - pass: 2,
* ltp-filecaps-tests - pass: 2,
* ltp-fs-tests - skip: 2, pass: 61,
* ltp-fs_bind-tests - pass: 2,
* ltp-fs_perms_simple-tests - pass: 19,
* ltp-fsx-tests - pass: 2,
* ltp-hugetlb-tests - skip: 2, pass: 20,
* ltp-io-tests - pass: 3,
* ltp-ipc-tests - pass: 9,
* ltp-math-tests - pass: 11,
* ltp-nptl-tests - pass: 2,
* ltp-pty-tests - pass: 4,
* ltp-sched-tests - skip: 1, pass: 13,
* ltp-securebits-tests - pass: 4,
* ltp-syscalls-tests - skip: 97, pass: 1053,
* ltp-timers-tests - skip: 1, pass: 12,
x86_64
* boot - pass: 20,
* kselftest - skip: 19, pass: 61,
* libhugetlbfs - skip: 1, pass: 89,
* ltp-cap_bounds-tests - pass: 2,
* ltp-containers-tests - skip: 17, pass: 64,
* ltp-fcntl-locktests-tests - pass: 2,
* ltp-filecaps-tests - pass: 2,
* ltp-fs-tests - skip: 1, pass: 62,
* ltp-fs_bind-tests - pass: 2,
* ltp-fs_perms_simple-tests - pass: 19,
* ltp-fsx-tests - pass: 2,
* ltp-hugetlb-tests - pass: 22,
* ltp-io-tests - pass: 3,
* ltp-ipc-tests - pass: 9,
* ltp-math-tests - pass: 11,
* ltp-nptl-tests - pass: 2,
* ltp-pty-tests - pass: 4,
* ltp-sched-tests - skip: 5, pass: 9,
* ltp-securebits-tests - pass: 4,
* ltp-syscalls-tests - skip: 118, pass: 1032,
* ltp-timers-tests - skip: 1, pass: 12,
Documentation - https://collaborate.linaro.org/display/LKFT/Email+Reports
Quoted 16 lines · Naresh Kamboju
Quoted 14 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 4.14.20 release. There are 195 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Sat Feb 17 15:16:22 UTC 2018. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.14.20-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-4.14.y
and the diffstat can be found below.
Quoted 4 lines
Quoted 3 lines
thanks,
greg k-h
I somehow lost the original mail, so I am replying to this one - sorry.
Build results:
total: 145 pass: 143 fail: 2
Failed builds:
powerpc:ppc6xx_defconfig
powerpc:mpc83xx_defconfig
Qemu test results:
total: 126 pass: 124 fail: 2 Failed tests: powerpc:mpc8544ds:mpc85xx_defconfig powerpc:mpc8544ds:mpc85xx_smp_defconfig
Build failures:
Building powerpc:ppc6xx_defconfig ... failed
Building powerpc:mpc83xx_defconfig ... failed
Building powerpc:mpc8544ds:mpc85xx_defconfig ... failed
Building powerpc:mpc8544ds:mpc85xx_smp_defconfig ... failed
--------------
Error log:drivers/crypto/talitos.c: In function 'talitos_sg_map':drivers/crypto/talitos.c:1131:3: error: too many arguments to function 'to_talitos_ptr'
Details are available at http://kerneltests.org/builders.
Guenter
Greg Kroah-Hartman
maintainerQuoted 37 lines · Guenter Roeck
Quoted 16 lines · Naresh Kamboju
Quoted 14 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 4.14.20 release. There are 195 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Sat Feb 17 15:16:22 UTC 2018. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.14.20-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-4.14.y
and the diffstat can be found below.Quoted 4 lines
Quoted 3 lines
thanks,
greg k-h
I somehow lost the original mail, so I am replying to this one - sorry.
Build results:
total: 145 pass: 143 fail: 2Failed builds:
powerpc:ppc6xx_defconfig
powerpc:mpc83xx_defconfig
Qemu test results:total: 126 pass: 124 fail: 2 Failed tests: powerpc:mpc8544ds:mpc85xx_defconfig powerpc:mpc8544ds:mpc85xx_smp_defconfigBuild failures:
Quoted 8 lines
Building powerpc:ppc6xx_defconfig ... failed
Building powerpc:mpc83xx_defconfig ... failed
Building powerpc:mpc8544ds:mpc85xx_defconfig ... failed
Building powerpc:mpc8544ds:mpc85xx_smp_defconfig ... failed
--------------
Error log:drivers/crypto/talitos.c: In function 'talitos_sg_map':drivers/crypto/talitos.c:1131:3: error: too many arguments to function 'to_talitos_ptr'
Ugh, sorry about that, now dropping this crypto patch from 4.14.y and 4.9.y to fix this issue.
greg k-h