Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2309025rwb; Wed, 30 Nov 2022 05:13:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf6y9yWbmHnyAlc5j7Ba19QMuU4dAFuEuDZQZeK6Bfx0c8GHVMP8NiupSXRavlZ17jiF4wDC X-Received: by 2002:a17:90b:1942:b0:219:42d8:bd3a with SMTP id nk2-20020a17090b194200b0021942d8bd3amr12253592pjb.177.1669813995950; Wed, 30 Nov 2022 05:13:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669813995; cv=none; d=google.com; s=arc-20160816; b=ReeGUIXNanionM/iP5p1IbYXZvUsG1UJRcV5yewPy2SkXRvl/gE74w/ettWOWMykQS GCi8Rtp8hCXmn9LbJlXMwI0PjwjqSg2XT78Cw8pxk7aec+fq1fYnHjah+uKzj2MuMjJ1 KkyNxiNJmp2ib5SsDfKfpCV4s+ubg9VTH2x03O/uAffwPOkWCTmyfPs26Xlg6TAw9ME/ G2ga6H1vu5gItyH+9CyEGHF7yLQgSagqT8BnsLHvP3ezQPt5Pv2d5qzoV0HoXa7pyFP8 HX7HR5kDKe3C4hqJUEFfEJNhfUfxVCcsqCMk6xMl5GwY5ypFBMz6o5ldjGnglUow5bUD ISwA== 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=9wYGB4cgqTgHhd7KiEbTWe6XX2ZPZ5rUESM+A8Yj8Vw=; b=egWD7OWYHanOplhttGXJQZM6GrHcBh/LLWfLp8p3ChkLTk7lba5WxrvLBTVYsrAnYG gkOOAVduRUOgVngKOn/enskflP5AsG6ih67mforNvyMxW8uMV653b0dw3z24gp+N6mS3 c1Ksfo5zFRsv/U10HnRfJi7nrgUVR95Em9gfsyh61GA0ApOmxeBtkj4w4WYA5wGtOCQo 8E+POMBK3na3M3uemvrX80H/cI1PmmB9v80qW4T/GCN4Qdy6qDJv6XAakSOUzWf6GglC r4rKTDKt/6cJwCfNFJSb9wy+y/jmlwpMF7D82QKx/WJLVqlbwo6UmYo1myGnL2G1jq7T NHvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=POsuHHro; 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 x7-20020a636307000000b0047741e1fdb4si1140670pgb.367.2022.11.30.05.13.04; Wed, 30 Nov 2022 05:13:15 -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=POsuHHro; 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 S229604AbiK3MlI (ORCPT + 84 others); Wed, 30 Nov 2022 07:41:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231225AbiK3MlE (ORCPT ); Wed, 30 Nov 2022 07:41:04 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF54442983; Wed, 30 Nov 2022 04:41:03 -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 ams.source.kernel.org (Postfix) with ESMTPS id 8392BB81B30; Wed, 30 Nov 2022 12:41:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A68FFC433C1; Wed, 30 Nov 2022 12:41:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1669812061; bh=bxsZp9sx/SJS953ooVDRz4ylsW4KoL2wq/Zm3PqCvBU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=POsuHHroFNVze1BGqR/4ZoNSyee4FqY5ISz18vUYCgA9Mean4tgnm1aoqs1590uv/ PEbOzWWK5n0FKaRRFs6qiuIooHXmaRyEhN/N+XlS5PlBUZzyjxHzLQ4uDIbK38H51s ozgnpaQBAtV59Ccodjy6UcbBVeU4g0PaI5+bMDqk= Date: Wed, 30 Nov 2022 13:40:58 +0100 From: Greg Kroah-Hartman To: Carlos Llamas Cc: Arve =?iso-8859-1?B?SGr4bm5lduVn?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Hridya Valsaraju , 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 5.15] binder: validate alloc->mm in ->mmap() handler Message-ID: References: <20221123180922.1502550-1-cmllamas@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221123180922.1502550-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:09:21PM +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 too is already in the 5.15 queue, is this a different version? thanks, greg k-h