Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp898424pxb; Tue, 1 Feb 2022 12:43:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJyoGkj1jhlu+k/6VTvc42cLbXTC3EewRXzBkF+DG+D+lp0naHSAN9ZnxCDUeRLafiP8bpNU X-Received: by 2002:a63:3804:: with SMTP id f4mr21746516pga.454.1643748221907; Tue, 01 Feb 2022 12:43:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643748221; cv=none; d=google.com; s=arc-20160816; b=UkV4S+2CJlQOt/XZOirJ7N+WYlTw9HAZBQR/9bWX9AqVn5mAWS9O34Uc2bzQe2APxM qS64RDEIZvhwhW6jV7s2lYIxqTqs6beO30SNFUumIHH1dWFI80HkE+QVMA7cmM+6vyI7 p1bem55k/+rpJ49XlJkqq4DTtzc28RMog4/fM8pe4HcWdF4drBp1JOMYze6tfax1WdR8 jF3lvUOxAV+MdOgrr1CcftBw9m6YMlvfUvhMAm6jfbLUQ16sUnQaDKpWp/niAoL4EG0d JJhxH7FMFBpeFAXuZq4RRTij8GrZOCFNldDb76t7JwJE6XT4l7eRPyDMMbMmA7ce6KsP upUg== 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=NLdODiHTPTsbH2gcUJrMZUfjS0qe2bnC35PSPmqa0PU=; b=RlHmpvMApcLY4BuTa+CnKnaQOO6DCRBEvzf6yjPVgejafOTVU0Bh6sgFnEW/HS0TtI wsi9hFOYw2p4zpXTq9/3G1YEBnRw/9ozGrlgf3n6waG1U2DFW3F/UBgGTQ58kjEtMfV2 Hg9ViW7xEkoK1g/4wvrixhIw/ZDEXeqT6EJ8/4EjWRRBS3dKexgi7/I50ZIGYbnuYul3 niOuDVHVKN8miA7x9n+rIokaCuF+VuFdk129mIQRJ2xBP0Tu+8DV9cVn4yXwgPqJofp1 bfl1/vmGsGbjVZs7auUaR/d1NjJtTRC8teUZ3Rq2eZw+NDFU+TwnF/iFL9AgTv66R4le MGSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=KfQvseu3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h70si16532955pge.217.2022.02.01.12.43.30; Tue, 01 Feb 2022 12:43:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=KfQvseu3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379225AbiAaQOE (ORCPT + 99 others); Mon, 31 Jan 2022 11:14:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244114AbiAaQN7 (ORCPT ); Mon, 31 Jan 2022 11:13:59 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DE10C061714; Mon, 31 Jan 2022 08:13:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=NLdODiHTPTsbH2gcUJrMZUfjS0qe2bnC35PSPmqa0PU=; b=KfQvseu3bFxdTGbr/MHWv5i1Vk ZypEn1p52ab5g02GlNK8qYLjtPUyVuBpopwTXNy7ymM7FU7D3vJQApnwtGUF394nu0xFbhdwgK5q0 7y8oxIj63QcxL4kaZoTkfRIcY4a8YQyWFIEEWoLHe6DMgEPeELnyUiFCWxywIUID6A/aH/sV/Saif 4ImrDpOmWnUNfcUJcxywC2UOXLcgXGN6CnGAGnjxtfg5oHv8NC/gHIDSYG8D45CyMXD7+s1KOSkST wkk7ir1ev1/lq0HAo4JONiaHITq1mgxyQwHONqvEA8WGE0Hr/uNyrwMK4Qx/nwwqdfosxOJE0MZKH y81leLpg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nEZJT-00A7DP-2f; Mon, 31 Jan 2022 16:13:55 +0000 Date: Mon, 31 Jan 2022 16:13:55 +0000 From: Matthew Wilcox To: "Eric W. Biederman" Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Alexander Viro , Denys Vlasenko , Kees Cook , Jann Horn , Vlastimil Babka , "Liam R . Howlett" Subject: Re: [PATCH] binfmt_elf: Take the mmap lock when walking the VMA list Message-ID: References: <20220131153740.2396974-1-willy@infradead.org> <871r0nriy4.fsf@email.froward.int.ebiederm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <871r0nriy4.fsf@email.froward.int.ebiederm.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 31, 2022 at 10:03:31AM -0600, Eric W. Biederman wrote: > "Matthew Wilcox (Oracle)" writes: > > > I'm not sure if the VMA list can change under us, but dump_vma_snapshot() > > is very careful to take the mmap_lock in write mode. We only need to > > take it in read mode here as we do not care if the size of the stack > > VMA changes underneath us. > > > > If it can be changed underneath us, this is a potential use-after-free > > for a multithreaded process which is dumping core. > > The problem is not multi-threaded process so much as processes that > share their mm. I don't understand the difference. I appreciate that another process can get read access to an mm through, eg, /proc, but how can another process (that isn't a thread of this process) modify the VMAs? > I think rather than take a lock we should be using the snapshot captured > with dump_vma_snapshot. Otherwise we have the very real chance that the > two get out of sync. Which would result in a non-sense core file. > > Probably that means that dump_vma_snapshot needs to call get_file on > vma->vm_file store it in core_vma_metadata. > > Do you think you can fix it something like that? Uhh .. that seems like it needs a lot more understanding of binfmt_elf than I currently possess. I'd rather spend my time working on folios than learning much more about binfmt_elf. I was just trying to fix an assertion failure with the maple tree patches (we now assert that you're holding a lock when walking the list of VMAs).