Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2304831rwb; Wed, 30 Nov 2022 05:10:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf7fffjOQIjqrcrdaQ8B+upRUYj9s6SAZPbMgSQLCiX6inZUCcZnQtSnSZ0HZs294Ky2ygtZ X-Received: by 2002:a17:902:8698:b0:188:e255:39af with SMTP id g24-20020a170902869800b00188e25539afmr42192269plo.86.1669813835107; Wed, 30 Nov 2022 05:10:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669813835; cv=none; d=google.com; s=arc-20160816; b=YrKrNdUqHs9771pPfNZgJA6QFl45P+H3GtoXIWAtVlTZvj4/VPc5pdHUpEE9H1msQt aMrM/p9Xli8uLH5b2lefYm6abcUa0e1e7LTZgm6hw7MmdfXuMVcBSNvjJ+k6eNLGttuV TWd3Q3oIHQSVs56PQtOC4PSI3rmk1ycst1rKZlSHZ12tj9PJoazqUkhvwFsJjGp5ab8j ig/SdbeaZGfmsekfoQllgZZisLUp48EYxWv/BDD3lL/1HLFU326+JFZCMwdOQ7sVFt2T 4jvtFmFn/V/yHqeWPdidCw29M3fF7XAP7qES3SlPkekmKaoh5N8vTNBL+FnOULHAgBHA sPHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=yr3p1eP9N12VTXRqMQKmukUVFM3qdD9W2aNgvI53JAQ=; b=ECWsVTZ6c23A1eIy1hPM/VJz4XA+sRwrOEr5YQNq/z267fYarH/LWxeNbHyOJtssm9 zwllfO9Htr/Av5KGET9Dl+K2x+CXoFaWgub1D5Tbabf3R3MPq0ePaIaOrrI/UZK8AUvx sV7ZPfAD24wecOdYyXVLLCzSezKdxIJu3muyLUfw6UBfTHuWC4jv+w6WhdrJajBUyIds jOGUPHzpfcAQpksBeFKw1jD+AOzdLwEi85+Zcf+mSGAzL7JFYBS4gtpMWfjguLQFKQVn iL///6m1yrWugq0hvZ55Zw1/eZCwUTG2wQ+c29B1Lv/9eoRxsMQW34gOjRX4HInx2Nd+ RsWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kRlQ0bzr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fz20-20020a17090b025400b00205d0348e7fsi1402631pjb.93.2022.11.30.05.10.23; Wed, 30 Nov 2022 05:10:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kRlQ0bzr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234346AbiK3Mkp (ORCPT + 84 others); Wed, 30 Nov 2022 07:40:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232159AbiK3Mko (ORCPT ); Wed, 30 Nov 2022 07:40:44 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B7E929801; Wed, 30 Nov 2022 04:40:44 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A3D1B61BA3; Wed, 30 Nov 2022 12:40:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87419C433D6; Wed, 30 Nov 2022 12:40:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1669812043; bh=GlkpgJ1w1hGdnqLs36PrTT1mYKX1ZJWOrDUYgdlxAh0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kRlQ0bzrKC6ACEYnbzLH1rkyXoAMvdqblPg9NlIedJZjD0e9+l379mFVqyL7OOf2n flkRnKX/t2J5mmvh/tKN3VxyGASq3m5UUSc045KMIlXlKbizQ6ckz0i+8zq6t17bpt KmTKhbGz85XWV0jH6sNx7NbB6A4WgMmCXzJ56Pjc= Date: Wed, 30 Nov 2022 13:40:40 +0100 From: Greg Kroah-Hartman To: Carlos Llamas Cc: Arve =?iso-8859-1?B?SGr4bm5lduVn?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Suren Baghdasaryan , "Liam R. Howlett" , linux-kernel@vger.kernel.org, kernel-team@android.com, Jann Horn , stable@vger.kernel.org, Todd Kjos Subject: Re: [PATCH 6.0] binder: validate alloc->mm in ->mmap() handler Message-ID: References: <20221123180809.1501779-1-cmllamas@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221123180809.1501779-1-cmllamas@google.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 23, 2022 at 06:08:09PM +0000, Carlos Llamas wrote: > commit 3ce00bb7e91cf57d723905371507af57182c37ef upstream. > > Since commit 1da52815d5f1 ("binder: fix alloc->vma_vm_mm null-ptr > dereference") binder caches a pointer to the current->mm during open(). > This fixes a null-ptr dereference reported by syzkaller. Unfortunately, > it also opens the door for a process to update its mm after the open(), > (e.g. via execve) making the cached alloc->mm pointer invalid. > > Things get worse when the process continues to mmap() a vma. From this > point forward, binder will attempt to find this vma using an obsolete > alloc->mm reference. Such as in binder_update_page_range(), where the > wrong vma is obtained via vma_lookup(), yet binder proceeds to happily > insert new pages into it. > > To avoid this issue fail the ->mmap() callback if we detect a mismatch > between the vma->vm_mm and the original alloc->mm pointer. This prevents > alloc->vm_addr from getting set, so that any subsequent vma_lookup() > calls fail as expected. > > Fixes: 1da52815d5f1 ("binder: fix alloc->vma_vm_mm null-ptr dereference") > Reported-by: Jann Horn > Cc: # 5.15+ > Signed-off-by: Carlos Llamas > Acked-by: Todd Kjos > Link: https://lore.kernel.org/r/20221104231235.348958-1-cmllamas@google.com > Signed-off-by: Greg Kroah-Hartman > [cmllamas: renamed alloc->mm since missing e66b77e50522] > Signed-off-by: Carlos Llamas > --- > drivers/android/binder_alloc.c | 7 +++++++ > 1 file changed, 7 insertions(+) This is already in the 6.0 queue, is this a different version? thanks, greg k-h