Received: by 10.213.65.68 with SMTP id h4csp757768imn; Fri, 6 Apr 2018 08:23:56 -0700 (PDT) X-Google-Smtp-Source: AIpwx495+ZKCQ5E/8vHQjKpYzWuKVb0Nt19CchatqRCqejndV9zm53s4iQSyLQzrJuYriL1Y12ck X-Received: by 10.101.64.139 with SMTP id t11mr18338701pgp.119.1523028236582; Fri, 06 Apr 2018 08:23:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523028236; cv=none; d=google.com; s=arc-20160816; b=YMSiQ0X2nZz6U4Sz+lc5V2+6pR/64gyQ83KfvUY2I6004WPCxBpg7DS7duol5/a5Da BsYbWZlodKZp2duMgpEFvdaleUnkEzdlS/ydUaGwcqR9r7MlDODTENsYakae9uRJf5i4 MGx4yDVnb4KJ63i94nvtwS14f01JTr3Cykg8Ge+z/NGklctluIE56ds4YjPwQ4RfhXyT tuJxcAls+x3jxMWxVqx94Mj2PezqxaTzxup+NdKa+5gnmP3ZmrfUGApnu8n1Eon91B8k loU+TSXdLr7PvCPIBvY5OklORWk28d5n29cUaO80RJ2o9LyNoliw4+5YAF0nJEKEOlRA 4XTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=03Nq9UcJTbphqTQAistVhGb39he+KC6nKt2NJokdfoo=; b=AVQKHjppuX0dhQvpQ7krkCy2mzwJrmJl9GhbFtmb6SBHXIfFcp/vo0zt2bLgZTyaTE HtFTx7uxunH9RZmAbXTP7ii6FrT1n0Izio/9KZAPkrzN8ImFB8LG8hyPbx9gBR30eY07 lXcWPHoMUTxCtljY54vbDx9G2r5A08l5aKonBd477IOY7TWky/yK+MmsCRSRQu6FJBQk N70lRKywAz5JGqMrwn4cEogErBbETyeay5RzworPLb0qdKIcbys7M7lXY9AhJQXLaYvq o+Ze99XkUQiwPra6a4eXXWLEC/u/0ahvyWtahk2D5wmJ9wfJz7P+yQpAxb6IJ3kH1LH8 jRXA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k15si7304759pgs.726.2018.04.06.08.23.42; Fri, 06 Apr 2018 08:23:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752584AbeDFPVt (ORCPT + 99 others); Fri, 6 Apr 2018 11:21:49 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:55036 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753636AbeDFN1c (ORCPT ); Fri, 6 Apr 2018 09:27:32 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 4D7E093E; Fri, 6 Apr 2018 13:27:31 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hans Verkuil , Sakari Ailus , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 3.18 63/93] media: v4l2-compat-ioctl32.c: copy m.userptr in put_v4l2_plane32 Date: Fri, 6 Apr 2018 15:23:32 +0200 Message-Id: <20180406084227.687803957@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180406084224.918716300@linuxfoundation.org> References: <20180406084224.918716300@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Hans Verkuil 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. Signed-off-by: Hans Verkuil Acked-by: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 47 +++++++++++++++----------- 1 file changed, 28 insertions(+), 19 deletions(-) --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c @@ -287,19 +287,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; @@ -308,22 +313,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; } @@ -383,6 +398,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; @@ -396,10 +412,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; @@ -456,6 +468,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; @@ -463,10 +476,6 @@ static int put_v4l2_buffer32(struct v4l2 if (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;