Received: by 10.223.176.5 with SMTP id f5csp1020490wra; Fri, 2 Feb 2018 09:50:01 -0800 (PST) X-Google-Smtp-Source: AH8x225LG/WE/KyAKRq/EwetMDEqOHg87ynZBzqeI2W/Jg6//zYoYdlYNziHn4FxDMZeaNzkAc/4 X-Received: by 2002:a17:902:61:: with SMTP id 88-v6mr27252264pla.428.1517593801356; Fri, 02 Feb 2018 09:50:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517593801; cv=none; d=google.com; s=arc-20160816; b=QBSy/ucMoVZAAzLs/PFGFjU6qUHSjDmccedLFEpk3v4X0y9w8tabCRyKhk/IKzQOGH NAPl6GrkdvDOC6/tYZlRmAL5r2cw+NtscTVMw7CMFq1EicUvUASePvy4eppWYUzHMXPV DTV50XhKB88rRj4PgtRisCTEg33zPkUsSljRiZ7xysSIZfnbLLhEsQD08J7MvxSIr2SE WnMeeXTR7Z89TSY1CKTo5SsO/neUmDcX7952hxMo4j5VFTZ3rWEnbc3qyU+gdrAodUub MhFhvb4GFanZ8GMMlcRwwLMfGoD6G+86V9WzFM33vwE7uUxsktst9wR/7mGh7y+ssb9q EETw== 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=8qUDj1GCWJRzhZd6FNduVB8Sa8dz8BjMSQh3QnbdBVM=; b=XRhPq5Nv8dBWys8fFqBCw9a8p0OHfxtNZaK8Zbny4GgGQL9U3MwICKs5VvLOrOnh4a 2yxKcD0V5JhShfadZ3eha9AltlExZjm6yFLBKNVHAcsr9Kl5UYjwmnXs75+9dfzpgAcN qDhc+mLEw6I81CsxDmyBOY/waN7mvbB3GjnfZhtr493oe3+zoFclRVmP+EdKAMBlSIpQ pnqrPk3hxtQZbgDOvbnMjdiaxdlfLdVezvvDG4rnxzA9mv4yjZiAe6SRTUmbodhPupAP Koa2Pvt86zuSOvTwTRKkXUjRSnEv7DKq846Ast30neTIpVtkxxXYtfwXEVQhDdCVpL4K QqzA== 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 z5-v6si2112079pln.677.2018.02.02.09.49.46; Fri, 02 Feb 2018 09:50:01 -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 S1753625AbeBBRrc (ORCPT + 99 others); Fri, 2 Feb 2018 12:47:32 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:39406 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752990AbeBBRNn (ORCPT ); Fri, 2 Feb 2018 12:13:43 -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 8EC46F09; Fri, 2 Feb 2018 17:13:41 +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.14 144/156] ANDROID: binder: remove waitqueue when thread exits. Date: Fri, 2 Feb 2018 17:58:45 +0100 Message-Id: <20180202140846.892505124@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140840.242829545@linuxfoundation.org> References: <20180202140840.242829545@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.14-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)