Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8107697imu; Tue, 4 Dec 2018 03:07:56 -0800 (PST) X-Google-Smtp-Source: AFSGD/XqCzvJlJHWVxg207lsF3ivAuBsphJpTRq8xkQaeJVLKDWq+b7VwZJQUa3ifXuwObVlEzTL X-Received: by 2002:a63:4c6:: with SMTP id 189mr16564153pge.391.1543921676546; Tue, 04 Dec 2018 03:07:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543921676; cv=none; d=google.com; s=arc-20160816; b=Kis85LgqYA54F986whxjhcvPjx1DGwVQkpVeacT/H3ehI9g2w+0EDsjbX2InnLng7M j98c/cjy92TQNCh2UJNYU/qPb0gJAPKzmj4MFKlWJvU4dcJttmFGXU2RkMIQj8MsX7PC HrI9qRVmhvdyOophRnpvMsNGq2sNyYe5SWGWsfhIv/5TTsARI0YV2L90Dz9LogYAmqhr Y2XCjjaDustVuUTQtwrMfcYW/1NVb2GVELidx+Pzz5KlFlcOsluTyVglpJIZ2NOSRT9W 9r32G/hsBgZXS01V+Om2ThpZMoMzD1LCT25ZdelYsT04lHWZD1JNCL8A7je8oE2D1VCI 2EXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=K7NQXNbwT7KJbule5U4ylH5BGRhzMv0LgRTOI/V5nAo=; b=HJo2XxHyTUKsEbMWMn5vJ3f+wKkHvWYzMGFr6absQ/fcu9Y9Oal8PtePb7skEBQWaC EWw1XbQsn3jKlEJF0OeNsFcS0BzqCufV28TJysUZPXKsLcHkMLClNsldsDOfhD8vgbC3 +w8xezNAtT5sO/ooDc8+QM956nP7CJjZZzdYsu+Q29rUfdNrsul/P/UnQPGGtulx2syC T5Dp4gvZVDGv3ETeTJMIsvG7kazHgkpxnWC8Ap3nsV5gavZIKyGWB490+afad7E+QDQu nvWq1/zYVM9v91FvT2Lf3KWFHUTtdmvsSaqHxOYF+gGSYtFY7hCptm37+8GUaueoCrW/ 01vA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0WQOsd3A; 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 p4si13688994pga.514.2018.12.04.03.07.41; Tue, 04 Dec 2018 03:07:56 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=0WQOsd3A; 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 S1725801AbeLDLGv (ORCPT + 99 others); Tue, 4 Dec 2018 06:06:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:55526 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726591AbeLDLGt (ORCPT ); Tue, 4 Dec 2018 06:06:49 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BB2452087F; Tue, 4 Dec 2018 11:06:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543921609; bh=vgsa1aB3LA0hNvLf9nx9KnSoknRziqtYByWDXwdJlug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0WQOsd3AMCIeSyB8DX0NaWbd61qNIWR72kDs0eLTnPVwil/cXh5sZBIvRx39twkeh qaH5LyB9T7QBajP1At/FsvYmvvaf21i7DczUi26tfo/pdVhr4U2AwOim73nYG4maYv 9RkjfpKSPQe7k/LW78q3duAez0rpc4t2m1/m47qY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ben Wolsieffer , Stefan Wahren Subject: [PATCH 4.14 136/146] staging: vchiq_arm: fix compat VCHIQ_IOC_AWAIT_COMPLETION Date: Tue, 4 Dec 2018 11:50:22 +0100 Message-Id: <20181204103732.299096107@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181204103726.750894136@linuxfoundation.org> References: <20181204103726.750894136@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ben Wolsieffer commit 5a96b2d38dc054c0bbcbcd585b116566cbd877fe upstream. The compatibility ioctl wrapper for VCHIQ_IOC_AWAIT_COMPLETION assumes that the native ioctl always uses a message buffer and decrements msgbufcount. Certain message types do not use a message buffer and in this case msgbufcount is not decremented, and completion->header for the message is NULL. Because the wrapper unconditionally decrements msgbufcount, the calling process may assume that a message buffer has been used even when it has not. This results in a memory leak in the userspace code that interfaces with this driver. When msgbufcount is decremented, the userspace code assumes that the buffer can be freed though the reference in completion->header, which cannot happen when the reference is NULL. This patch causes the wrapper to only decrement msgbufcount when the native ioctl decrements it. Note that we cannot simply copy the native ioctl's value of msgbufcount, because the wrapper only retrieves messages from the native ioctl one at a time, while userspace may request multiple messages. See https://github.com/raspberrypi/linux/pull/2703 for more discussion of this patch. Fixes: 5569a1260933 ("staging: vchiq_arm: Add compatibility wrappers for ioctls") Signed-off-by: Ben Wolsieffer Acked-by: Stefan Wahren Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c @@ -1461,6 +1461,7 @@ vchiq_compat_ioctl_await_completion(stru struct vchiq_await_completion32 args32; struct vchiq_completion_data32 completion32; unsigned int *msgbufcount32; + unsigned int msgbufcount_native; compat_uptr_t msgbuf32; void *msgbuf; void **msgbufptr; @@ -1572,7 +1573,11 @@ vchiq_compat_ioctl_await_completion(stru sizeof(completion32))) return -EFAULT; - args32.msgbufcount--; + if (get_user(msgbufcount_native, &args->msgbufcount)) + return -EFAULT; + + if (!msgbufcount_native) + args32.msgbufcount--; msgbufcount32 = &((struct vchiq_await_completion32 __user *)arg)->msgbufcount;