Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp2253929ybd; Mon, 24 Jun 2019 03:22:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqxK3gJM33rp0i4tfX8XBTAAzXX1Oi4vA1XHsoOPOo9d/76KD8aCDkLxPYZufxkfc8zSZvJb X-Received: by 2002:a17:902:3a5:: with SMTP id d34mr62266078pld.239.1561371742977; Mon, 24 Jun 2019 03:22:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561371742; cv=none; d=google.com; s=arc-20160816; b=CLJd2C/sjxdJBMxmXJMSUC64B7XVk6KxZbNlrn9nmkpzy7Dcx9ytueghPPZM0VCZm/ E1MmgM2SJ4haBgNP3h08IL7fC34HiYXRYlYOnXN7NDiyshMtUtiG1Q+EnPCetiT9G3Oz JYkNPBJzpyWjCxHjg5KMdmqr3hobom/nsKrU2UgcsPgNevwLN3pmoxk89+iEJlHtEt0Z +fgg0uAoXmk1GkSekfvsOEh7G1c2MVXkCqhq9wih73j4Dvs4jdS30PBekzjScqskw/N5 KbIhvpo5RJ8hjKFAPTk6ssmGlp6AYBxC+rx3KCwXv/H2tRVtuXj424rSANtXtQhF2p3q tvVg== 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=bzduVriB80KEkn52cL8+AK7+uKF/qAdd7+GMuRM4bUU=; b=ChGVtAdAJ5iuAqnDlkiGHb83zrpXJfksVQmvY7W9jjHJQfyC/G7ViuYG7rKXWIvHvb epFvS9zGxwHR9qVSmdnG8Ndq3V7cWd6R1ZnMxKCoew75Ol3Qp6l+07EwXpfaMxXJHwiR SHuBQ/T5RyrGZphOP1C1HitWetcT55oyeQv56CBmuQsu7jYEArB3vCsuszVGWnV3tDGF ARvwZiwKHrd7HAGuAdhsm9YIiH2QdXMcVHMhl1PKm3PnhuvKCakD70Liedo2AbmjAeOA ZACfaJ1nMZ4joaFuUqA1zvOqoXL/D188E1FR2Mvo9dGPxM1uF4OwWwf10fKZwoiqZxvv CqIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PT0ZyFdI; 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 r128si5568144pgr.21.2019.06.24.03.22.07; Mon, 24 Jun 2019 03:22:22 -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; dkim=pass header.i=@kernel.org header.s=default header.b=PT0ZyFdI; 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 S1730725AbfFXKVr (ORCPT + 99 others); Mon, 24 Jun 2019 06:21:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:57492 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730605AbfFXKVp (ORCPT ); Mon, 24 Jun 2019 06:21:45 -0400 Received: from localhost (f4.8f.5177.ip4.static.sl-reverse.com [119.81.143.244]) (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 5C2742089F; Mon, 24 Jun 2019 10:21:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561371704; bh=V5HZXV/YhrsliP3YAP4QFG+MQTQNMfCzWWxrY8RiI4o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PT0ZyFdIazvV7mCF+WibJ68xJNZHPEv1vf6yxs2F81qXClkvcg2PQtGxkTO+jwfx7 MYYq16rtWZARHnrG4bxO1Rh3YXUL8EC0ZM2D4Xb7tzSzQ/IGnVrjE5rULjwT1txb+b 9Jmm7WWYMDpOFlADAphRl18Nxh2Q2j1ETzXSB+Ik= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Todd Kjos Subject: [PATCH 5.1 108/121] binder: fix possible UAF when freeing buffer Date: Mon, 24 Jun 2019 17:57:20 +0800 Message-Id: <20190624092326.204850152@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190624092320.652599624@linuxfoundation.org> References: <20190624092320.652599624@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Todd Kjos commit a370003cc301d4361bae20c9ef615f89bf8d1e8a upstream. There is a race between the binder driver cleaning up a completed transaction via binder_free_transaction() and a user calling binder_ioctl(BC_FREE_BUFFER) to release a buffer. It doesn't matter which is first but they need to be protected against running concurrently which can result in a UAF. Signed-off-by: Todd Kjos Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/android/binder.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -1950,8 +1950,18 @@ static void binder_free_txn_fixups(struc static void binder_free_transaction(struct binder_transaction *t) { - if (t->buffer) - t->buffer->transaction = NULL; + struct binder_proc *target_proc = t->to_proc; + + if (target_proc) { + binder_inner_proc_lock(target_proc); + if (t->buffer) + t->buffer->transaction = NULL; + binder_inner_proc_unlock(target_proc); + } + /* + * If the transaction has no target_proc, then + * t->buffer->transaction has already been cleared. + */ binder_free_txn_fixups(t); kfree(t); binder_stats_deleted(BINDER_STAT_TRANSACTION); @@ -3550,10 +3560,12 @@ err_invalid_target_handle: static void binder_free_buf(struct binder_proc *proc, struct binder_buffer *buffer) { + binder_inner_proc_lock(proc); if (buffer->transaction) { buffer->transaction->buffer = NULL; buffer->transaction = NULL; } + binder_inner_proc_unlock(proc); if (buffer->async_transaction && buffer->target_node) { struct binder_node *buf_node; struct binder_work *w;