Received: by 10.223.176.5 with SMTP id f5csp1011807wra; Fri, 2 Feb 2018 09:40:45 -0800 (PST) X-Google-Smtp-Source: AH8x224Pnbpr7aQ/soIQGFHZTWoYvgZUrkstpT68ZoR7uWnen/KuwS8/b89YqeoRm3wxImwlWaua X-Received: by 10.101.82.141 with SMTP id y13mr2555303pgp.179.1517593245869; Fri, 02 Feb 2018 09:40:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517593245; cv=none; d=google.com; s=arc-20160816; b=0vjozS00hicwv9lFuOgOCr33Flr9GPZQNBeVTBb5lyAuIyVIc33jgBhKRPMHZvdrw1 NEgS4LC6wF8lmOh3uLhwCboGYAAwu6ndbmzVYmcvk5QfL6PPICmM8gsA7Oj7MshcRc9F 4fFksJNQfx/oMO/IQFrKRPoF3F+KAMTDzU3nGsBSgu8eimBt6R61sRPQPPpb28s7vUDW dWGAmSzDG8nrfCkuQ5AHQEtbK150XdxRms9VSfmNfj/QZ2k/p2aAW6i/npJP6lXrXxxz OvdzYcqlJ+BRbQjXs1z1IoDf8YSTWaMHL/AUrsJiS6J+QY9XS7z3XiisiX/Fvxc+HThk zFdA== 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=jDfy7Pq5emuuQxc8kuk93WXZ83nDXTEXgW4mjkeAKHw=; b=WBYbkQGUE0YS5WHp4Nt6TAHuPJZTz7I5Q8BrJPhbnABJmyRE7CEJ91mNwqGev2bzL1 tpfCjHp7Oh0RG8QUqPHy6LjeDjsEHVjolLCP02G0JrEaykhtrpiKM+AC3OSoAEFcQk7T 1h5cIipZ7q/JICij+KpNcn/X7BC2VaRtETQXdamkvJApDKWDzoGYqNx7u4apSXa+R9wr ssYwP063CLk8bj7prIWriRkl0Sxrbj+xYraKb8X9qmhyp/PpQR86oSXF0a0s/k7ckUkt YPxwOy2HykjDnDYysBuDXoHb9krH6DnOizwTxnufIAmHydd+lf3xBRe0ZgjF9yOYGmLd YWAA== 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 o18si2108677pfa.407.2018.02.02.09.40.30; Fri, 02 Feb 2018 09:40:45 -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; 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 S1753394AbeBBRjE (ORCPT + 99 others); Fri, 2 Feb 2018 12:39:04 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:40994 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753529AbeBBRQZ (ORCPT ); Fri, 2 Feb 2018 12:16:25 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id DE895F27; Fri, 2 Feb 2018 17:16:23 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Martijn Coenen , syzbot Subject: [PATCH 4.15 42/55] ANDROID: binder: remove waitqueue when thread exits. Date: Fri, 2 Feb 2018 17:59:00 +0100 Message-Id: <20180202140830.212435163@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140826.117602411@linuxfoundation.org> References: <20180202140826.117602411@linuxfoundation.org> User-Agent: quilt/0.65 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 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Martijn Coenen commit f5cb779ba16334b45ba8946d6bfa6d9834d1527f upstream. binder_poll() passes the thread->wait waitqueue that can be slept on for work. When a thread that uses epoll explicitly exits using BINDER_THREAD_EXIT, the waitqueue is freed, but it is never removed from the corresponding epoll data structure. When the process subsequently exits, the epoll cleanup code tries to access the waitlist, which results in a use-after-free. Prevent this by using POLLFREE when the thread exits. Signed-off-by: Martijn Coenen Reported-by: syzbot Signed-off-by: Greg Kroah-Hartman --- drivers/android/binder.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -4302,6 +4302,18 @@ static int binder_thread_release(struct if (t) spin_lock(&t->lock); } + + /* + * If this thread used poll, make sure we remove the waitqueue + * from any epoll data structures holding it with POLLFREE. + * waitqueue_active() is safe to use here because we're holding + * the inner lock. + */ + if ((thread->looper & BINDER_LOOPER_STATE_POLL) && + waitqueue_active(&thread->wait)) { + wake_up_poll(&thread->wait, POLLHUP | POLLFREE); + } + binder_inner_proc_unlock(thread->proc); if (send_reply)