From mboxrd@z Thu Jan 1 00:00:00 1970 From: Greg Kroah-Hartman Subject: [PATCH 3.10 67/74] drm: Prevent overwriting from userspace underallocating core ioctl structs Date: Fri, 8 Nov 2013 22:52:12 -0800 Message-ID: <20131109065118.173242382@linuxfoundation.org> References: <20131109065113.502217951@linuxfoundation.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Return-path: In-Reply-To: <20131109065113.502217951@linuxfoundation.org> Sender: linux-kernel-owner@vger.kernel.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chris Wilson , Dave Airlie , =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= , dri-devel@lists.freedesktop.org List-Id: dri-devel@lists.freedesktop.org 3.10-stable review patch. If anyone has any objections, please let me = know. ------------------ =46rom: Chris Wilson commit b062672e305ce071f21eb9e18b102c2a430e0999 upstream. Apply the protections from commit 1b2f1489633888d4a06028315dc19d65768a1c05 Author: Dave Airlie Date: Sat Aug 14 20:20:34 2010 +1000 drm: block userspace under allocating buffer and having drivers ove= rwrite it (v2) to the core ioctl structs as well, for we found one instance where ther= e is a 32-/64-bit size mismatch and were guilty of writing beyond the end of the user's buffer. Signed-off-by: Chris Wilson Cc: Dave Airlie Reviewed-by: Ville Syrj=C3=A4l=C3=A4 Cc: dri-devel@lists.freedesktop.org Signed-off-by: Dave Airlie Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/drm_drv.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -406,9 +406,16 @@ long drm_ioctl(struct file *filp, cmd =3D ioctl->cmd_drv; } else if ((nr >=3D DRM_COMMAND_END) || (nr < DRM_COMMAND_BASE)) { + u32 drv_size; + ioctl =3D &drm_ioctls[nr]; - cmd =3D ioctl->cmd; + + drv_size =3D _IOC_SIZE(ioctl->cmd); usize =3D asize =3D _IOC_SIZE(cmd); + if (drv_size > asize) + asize =3D drv_size; + + cmd =3D ioctl->cmd; } else goto err_i1; =20