Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp785902imm; Fri, 31 Aug 2018 13:14:44 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY6kJ2y8j+lu2EQCFsl2kdKT6BBqX2UBd7eYEFctTDKF5bbzmdjf6mS7o+LwK0q9vkQoYqE X-Received: by 2002:a17:902:1121:: with SMTP id d30-v6mr16602713pla.250.1535746484555; Fri, 31 Aug 2018 13:14:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535746484; cv=none; d=google.com; s=arc-20160816; b=dRJ2i66lA7PeKGZbLO82YEF0B0HWU2Y+MYKOcyvFkLYn469Z1JrM5mP7fFrPbCfn/I jZBvByaW3vzLl7yd7KhBaWl9K7Z1ser9eAUDtwbzmwdxBVLiaQ/RBXCeuPLBWIGrs48V bDWwuip7jcMTboJQi/gCOvpE22ucAZqPtdsZ3eMOOw0h2QP2e95mZM0Q12RoR3UgVnvT GAmqOID15OwL4Ho10Am5gjHrwj/PqzRq4gYhaSxB5/j0uZO2Zhqv13EGY2jt33GPnRSx D8zfP77NPyX+GNtO9tSXjHPB4R3HE2rSIqThsgv6Pf/APdyt5m+VvZYmNep5pMs8BHoz Q72w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=Ub+RFe98JTQc/0SSUa8giB0r9Ixj04oIIoNb4+PC5+c=; b=RKv/Foibzi9WDaxEIkCP7U0TYSfnXKR/8+SQT/2hqjBVoheer3ZAc7DyRDM655/Z6E PY8fRRfrVzlKQv4FyoLGyCUfb9row8s4oyWFgJCeCha8P7UcUFv8paY8qKIdFX7eLSbT Qw6mWSHowuCX0SDyNk2iD0zM20EBiS58T8paesKpAIr9luKq0367+2xjVmTKvHT+xIZ5 LSeF5m9hsGkqKMN/5EUs/6m9TWskQNe0vOtnZtjwF33qiaxEjoqgzHccYuvvGZY6272T ffCck6zNcCNFEL7ELiqRLzIRCMUvZj8lf2nCUxaINTvUCDSJRMwfQVrRPWJYFfSWPMMf Z/mw== 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 a10-v6si9093886pll.303.2018.08.31.13.14.29; Fri, 31 Aug 2018 13:14:44 -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 S1727654AbeIAAVi (ORCPT + 99 others); Fri, 31 Aug 2018 20:21:38 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:50826 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727281AbeIAAVi (ORCPT ); Fri, 31 Aug 2018 20:21:38 -0400 Received: from localhost (unknown [72.28.92.217]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 012E3D29; Fri, 31 Aug 2018 20:12:33 +0000 (UTC) Date: Fri, 31 Aug 2018 13:12:32 -0700 From: Greg Kroah-Hartman To: Greg Hackmann Cc: linux-kernel@vger.kernel.org, Laura Abbott , Sumit Semwal , devel@driverdev.osuosl.org, kernel-team@android.com, Greg Hackmann , stable@vger.kernel.org Subject: Re: [PATCH] staging: android: ion: fix ION_IOC_{MAP,SHARE} use-after-free Message-ID: <20180831201232.GA23559@kroah.com> References: <20180831200627.59712-1-ghackmann@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180831200627.59712-1-ghackmann@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 31, 2018 at 01:06:27PM -0700, Greg Hackmann wrote: > The ION_IOC_{MAP,SHARE} ioctls drop and reacquire client->lock several > times while operating on one of the client's ion_handles. This creates > windows where userspace can call ION_IOC_FREE on the same client with > the same handle, and effectively make the kernel drop its own reference. > For example: > > - thread A: ION_IOC_ALLOC creates an ion_handle with refcount 1 > - thread A: starts ION_IOC_MAP and increments the refcount to 2 > - thread B: ION_IOC_FREE decrements the refcount to 1 > - thread B: ION_IOC_FREE decrements the refcount to 0 and frees the > handle > - thread A: continues ION_IOC_MAP with a dangling ion_handle * to > freed memory > > Fix this by holding client->lock for the duration of > ION_IOC_{MAP,SHARE}, preventing the concurrent ION_IOC_FREE. Also > remove ion_handle_get_by_id(), since there's literally no way to use it > safely. > > This patch is applied on top of 4.9.y. Kernels 4.12 and later are > unaffected, since all the underlying ion_handle infrastructure has been > ripped out. Does 4.4.y or older also need this? If so, can you send backports, as this one does not apply there. thanks, greg k-h