From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6137CA9EAC for ; Sat, 19 Oct 2019 13:34:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 93C4621897 for ; Sat, 19 Oct 2019 13:34:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725970AbfJSNeX (ORCPT ); Sat, 19 Oct 2019 09:34:23 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:43927 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725856AbfJSNeW (ORCPT ); Sat, 19 Oct 2019 09:34:22 -0400 Received: from [213.220.153.21] (helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iLos2-0000M5-QG; Sat, 19 Oct 2019 13:34:14 +0000 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 In-Reply-To: <20191018205631.248274-1-jannh@google.com> Date: Sat, 19 Oct 2019 15:34:14 +0200 Cc: , To: "Jann Horn" , "Greg Kroah-Hartman" , =?utf-8?q?Arve_Hj=C3=B8nnev=C3=A5g?= , "Todd Kjos" , "Martijn Coenen" , "Joel Fernandes" , "Christian Brauner" , From: "Christian Brauner" Subject: Re: [PATCH 1/3] binder: Fix race between mmap() and binder_alloc_print_pages() Message-Id: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri Oct 18, 2019 at 10:56 PM Jann Horn wrote: > binder_alloc_print_pages() iterates over > alloc->pages[0..alloc->buffer_size-1] under alloc->mutex. > binder_alloc_mmap_handler() writes alloc->pages and alloc->buffer_size > without holding that lock, and even writes them before the last bailout > point. >=20 > Unfortunately we can't take the alloc->mutex in the ->mmap() handler > because mmap_sem can be taken while alloc->mutex is held. > So instead, we have to locklessly check whether the binder_alloc has been > fully initialized with binder_alloc_get_vma(), like in > binder_alloc_new_buf_locked(). >=20 > Fixes: 8ef4665aa129 ("android: binder: Add page usage in binder stats") > Cc: stable@vger.kernel.org > Signed-off-by: Jann Horn Ok, I see a smp_wmb() in binder_alloc_set_vma() which is called in binder_alloc_mmap_handler() paired with a smp_rmb() in binder_alloc_get_vma(). That makes sense to me. Acked-by: Christian Brauner