Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp6229463rwb; Wed, 18 Jan 2023 02:48:30 -0800 (PST) X-Google-Smtp-Source: AMrXdXva9dT4jXi6Xs1c6Ijj0PcJ74B1fo2sDg9OsWEdjG2PIqo+17ioGCGYlNTcqUnQe2ARFAFj X-Received: by 2002:a17:906:29d8:b0:86f:a1fe:237a with SMTP id y24-20020a17090629d800b0086fa1fe237amr6853697eje.54.1674038910518; Wed, 18 Jan 2023 02:48:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674038910; cv=none; d=google.com; s=arc-20160816; b=bUzvPYZqG81Y5pfv+HcmDlqsFQgc7z3R87wVcLMtUlNbGH0RSUpRyIe98kj0Fjgj8q LDHRwoaxUpBjlsr912W+CJoAMdE/E0Dfe20PEhKMvoh0lQHWKCQXXdJED7hH78FIkNIa NUVtk2GIh5UBB4LwErMWhVAoqyatn4v4EuHo7kWiKdSmauDOAeFAnHiqzfUXwE88JJhs b4qdlUqEbsiHD7HGWydfLP/8+er1CPE8Ya7wD5+nGncTGyZROW6Iqh6VdxkRXWe/C6SN olUeWD7TmhO49n1fSg/ZRVHel/A0zm05iALkaycRJTm1BHv2gaF8R+LVDc2u16h6fnAR 3Nxw== 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=xwj2L+9GHMXRMvC0PXKAy4Vi7OOq14XSvOdqanVYA8Y=; b=DdxcQC22vCCBdgTCTfoRfRyKwVG0feFqwNwnCDUBaPksDS2JiElE8ObG7MuhPIKIMW 6Fz2jMoHpsWpvvuWj5cchFGoat4kCP1jcLgF8vxLb7iUm36P0SH3czGuF4kqskCEb4tv IJ2jlrcKMgW4b43ZO5dHYHmOx9exPzJ+yfVh4JW2VKh6yifAWDVraKv6uYRIup4RoRsz 3A0RxI+FkyfWu7rTZ9q/gjuwK9KoyEnRTEsmmhnd9zMM049SaWNQ5SfHSZvnLSIvY3tj 13U2dhZsliat3kdBxWEmGsj/JZXP355+7aDZLRPwlrs+6FD4+M49/pi4av1f2k2SZR9s SWRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=oQppwSHR; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ht14-20020a170907608e00b0078d484e0e7esi5182803ejc.488.2023.01.18.02.48.19; Wed, 18 Jan 2023 02:48:30 -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=@suse.com header.s=susede1 header.b=oQppwSHR; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229786AbjARKlo (ORCPT + 45 others); Wed, 18 Jan 2023 05:41:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229873AbjARKjU (ORCPT ); Wed, 18 Jan 2023 05:39:20 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC53666FBA for ; Wed, 18 Jan 2023 01:43:46 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 858B02107A; Wed, 18 Jan 2023 09:43:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1674035001; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=xwj2L+9GHMXRMvC0PXKAy4Vi7OOq14XSvOdqanVYA8Y=; b=oQppwSHRZn9nA7psyaLGFQs/n7yu4DC1JHVfljgHkXtLq+DOkvXYVpC0pxpoUjYBm0HTcS BkONlwtTDH8AHIFUQOLXiSJJ2S7HX+NBVrdprdVQ79j6ABRRpBWxtQ58jldQ8maq5weOoW FQcHNE9i90gdNQSHN34UWvlnl2fB3Is= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 5923C139D2; Wed, 18 Jan 2023 09:43:21 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id eEGoFDm/x2OYPwAAMHmgww (envelope-from ); Wed, 18 Jan 2023 09:43:21 +0000 Date: Wed, 18 Jan 2023 10:43:19 +0100 From: Michal Hocko To: Suren Baghdasaryan Cc: akpm@linux-foundation.org, michel@lespinasse.org, jglisse@google.com, vbabka@suse.cz, hannes@cmpxchg.org, mgorman@techsingularity.net, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, peterz@infradead.org, ldufour@linux.ibm.com, laurent.dufour@fr.ibm.com, paulmck@kernel.org, luto@kernel.org, songliubraving@fb.com, peterx@redhat.com, david@redhat.com, dhowells@redhat.com, hughd@google.com, bigeasy@linutronix.de, kent.overstreet@linux.dev, punit.agrawal@bytedance.com, lstoakes@gmail.com, peterjung1337@gmail.com, rientjes@google.com, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, jannh@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, gurua@google.com, arjunroy@google.com, soheil@google.com, hughlynch@google.com, leewalsh@google.com, posk@google.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH 26/41] kernel/fork: assert no VMA readers during its destruction Message-ID: References: <20230109205336.3665937-1-surenb@google.com> <20230109205336.3665937-27-surenb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 Tue 17-01-23 17:53:00, Suren Baghdasaryan wrote: > On Tue, Jan 17, 2023 at 7:42 AM 'Michal Hocko' via kernel-team > wrote: > > > > On Mon 09-01-23 12:53:21, Suren Baghdasaryan wrote: > > > Assert there are no holders of VMA lock for reading when it is about to be > > > destroyed. > > > > > > Signed-off-by: Suren Baghdasaryan > > > --- > > > include/linux/mm.h | 8 ++++++++ > > > kernel/fork.c | 2 ++ > > > 2 files changed, 10 insertions(+) > > > > > > diff --git a/include/linux/mm.h b/include/linux/mm.h > > > index 594e835bad9c..c464fc8a514c 100644 > > > --- a/include/linux/mm.h > > > +++ b/include/linux/mm.h > > > @@ -680,6 +680,13 @@ static inline void vma_assert_write_locked(struct vm_area_struct *vma) > > > VM_BUG_ON_VMA(vma->vm_lock_seq != READ_ONCE(vma->vm_mm->mm_lock_seq), vma); > > > } > > > > > > +static inline void vma_assert_no_reader(struct vm_area_struct *vma) > > > +{ > > > + VM_BUG_ON_VMA(rwsem_is_locked(&vma->lock) && > > > + vma->vm_lock_seq != READ_ONCE(vma->vm_mm->mm_lock_seq), > > > + vma); > > > > Do we really need to check for vm_lock_seq? rwsem_is_locked should tell > > us something is wrong on its own, no? This could be somebody racing with > > the vma destruction and using the write lock. Unlikely but I do not see > > why to narrow debugging scope. > > I wanted to ensure there are no page fault handlers (read-lockers) > when we are destroying the VMA and rwsem_is_locked(&vma->lock) alone > could trigger if someone is concurrently calling vma_write_lock(). But > I don't think we expect someone to be write-locking the VMA while we That would be UAF, no? > are destroying it, so you are right, I'm overcomplicating things here. > I think I can get rid of vma_assert_no_reader() and add > VM_BUG_ON_VMA(rwsem_is_locked(&vma->lock)) directly in > __vm_area_free(). WDYT? Yes, that adds some debugging. Not sure it is really necessary buyt it is VM_BUG_ON so why not. -- Michal Hocko SUSE Labs