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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6DA93C004D4 for ; Wed, 18 Jan 2023 09:43:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E7DB96B0071; Wed, 18 Jan 2023 04:43:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E2E7B6B0072; Wed, 18 Jan 2023 04:43:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF77D6B0074; Wed, 18 Jan 2023 04:43:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id BF8766B0071 for ; Wed, 18 Jan 2023 04:43:24 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 912E9140496 for ; Wed, 18 Jan 2023 09:43:24 +0000 (UTC) X-FDA: 80367431928.13.1B44E23 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf10.hostedemail.com (Postfix) with ESMTP id D39D3C0010 for ; Wed, 18 Jan 2023 09:43:22 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=oQppwSHR; spf=pass (imf10.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.29 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674035003; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=xwj2L+9GHMXRMvC0PXKAy4Vi7OOq14XSvOdqanVYA8Y=; b=Xz78SVpr3JuiQUTofheOviHiSpMNZCAYovVfNRJR3QJPWq/b59a3YB8r0uXM5rzsr+bkJy KSnSHnO87ZiU/52QzVXiIW+55qnFosWpi4h3F6XiHzvMqMIMWEgxwzJhR5edaEoyX6DrHy n3eIx9DKbDB8VK55EX6AIfGXMMcGwZs= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=oQppwSHR; spf=pass (imf10.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.29 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674035003; a=rsa-sha256; cv=none; b=XmW7kNVrKgyU3GisOEBUiSJcERy/jTVdr4KIFCO2u7hMnRVcwpk7K355mtZ4zToq+Bb8fM g0P6xb0GM/SA6RtZlevb1u8Ls4iNGxmVA4upwsYeLf215uHvZbzZ0FfHFutnWOdV+xQsk0 sPQ4ZC8bXZU6f4QJbagZYHSXBqAVqhM= 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-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: rk7cahgsxozd4k5dxgs9k8fg48578en5 X-Rspamd-Queue-Id: D39D3C0010 X-HE-Tag: 1674035002-824845 X-HE-Meta: U2FsdGVkX1/TsKQysdnvyjw970pbkmjyu4LJZcQ68pbX7MZ9vqxUQuiyvfSVHlJLZDnfRY9+fa/OHQunqx+fLLVzx14CNvXmcxB96YIMXXFuumSqIRQ8vPP0Fy6iw2a0rhHJvEr0rb+YFLSLmPfcx9Lfmlop7zFULI9/KBDvtMX7N8sfKzHXzLfesQcivTkK3BTBLfflRgQpTFUYFbSMHaRU0Y5t9cz9Rh5unNOyTgOXnUVkPzEZOKB1LeWO5pQELMPvx2XVKIl12zX+ZK262g4TuTl2uWk9pGGAnIXIHR6FrZoITYvXsl9IADuXDrOiJ6XUldsJqWJQPOpnW6v2ZJFqMvaKIYV/X+b9h3Ev3yWcHeqeBjUZBVv+wRRYBRyQ/o4XiaTbM7f2mtNCPzu7ZXEJyr8kovJ8goCFAqspWynVBBOW44XtzL7Tb4kb53+UvuZaoLTU26D/VVqPvq0lQRXT4F99yRpewMPhYGOU/oiCCNg9aiz8Oxpj0oKPVyePW3+VA/H+ej7md1gvRV8ZEMqUn/vdDtgHlmzPZMeih3EvCHQQ2eEYbFH7DMJ/TChsKp4zWAq6dacDZTjdf0trzL4GQ8fXKTLoaUwRFSLrqhpyxutvDDD53sOY3WSaPscQKK58G+0ZyB1UtvoHTolvo6+NDDzLd2SYfH/mHnr8CA/YzFetfWjnqf5Y3LfS9YfZos66d0j53xfAOPooVFZ6wYR8qLhS4Pakn6rcZ35AX1RwLtD/st0OVouNIYEzFzUOy5+VFRXYhIs9FCLrIJrtMw/GLyNSqFdBHG/yRAphpG80Vk01HWbNeBVsFUz8phmpBgSM3I0VsvN1xRhL/7X8Ua5yzXgo9OHc14OVRh7sqwM0R9lfqohGpA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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