From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A427E13DDAA for ; Mon, 6 Jul 2026 02:50:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783306204; cv=none; b=VzkPRnpIwdbOxfY8jlJbD23z7vwAo78ZRfn2wZmfzzZxb4jw/tBXlH9qO9ZZGoP14guDvGGxVgudatyF5mF2jh7R0pXCfI2XvvpYLWotDR5FctesMz6ExRtoK7mkGKolpx8QO4wWd4CbsUwyKRsghNvvSZoSyRPBFoEP1UGhr4A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783306204; c=relaxed/simple; bh=QKQm7ZaRhVIjtOpnoqffw55EKWCQimqYetpsNK88YN0=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=iJkjp8hjGIjo4OI002qthAbxVh2n/bN8hp6tEI2hLEt3oVlZ85FnWUloI5WVgemQthgFWvP++N4P2VNInZZELcNWBE6QHOIr7/Q8xWh8iAGPVnbYEGCR6z+flEdlgeroBHLz+Se0mFpqAWSt0sXxzHzxkmAEW1m7srT1quEf5aQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=AFJPNjdU; arc=none smtp.client-ip=209.85.215.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AFJPNjdU" Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-c9d1fc053e0so2132466a12.1 for ; Sun, 05 Jul 2026 19:50:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783306203; x=1783911003; darn=vger.kernel.org; h=content-type:mime-version:user-agent:references:in-reply-to:subject :cc:to:from:message-id:date:from:to:cc:subject:date:message-id :reply-to:content-type; bh=5x1wjFv75jgxPUO4LcE1UoPqAki0+kcH4/30AEBDkAQ=; b=AFJPNjdU2/rD0WHxEO1uie06obSO1IrXBWbC1WgM+ZT436xyxpZBbczrzOhmyVTAYP G+FldEZtjafWAb4CoL06kBkFt+HAf97N5UyYOYZyq20By27szEaFmYB+PLvMhtoODHpd JeGEVM1Jdba2M6QMlMuAktzcoQ3287WF+K+2bPGKDsOOyabHqAToM5D/4aMGTeEHG3d5 NPugTwSn+odY5zMlN3CVgLcG2DCmx02dJk3Bpy6E+wijw0yBMn2f5V9kNkMkulJFkQkV pLFxnRf8nV1g7X3EhgmE56Ay9c5usmHJ+hJEGESXOc7jp1KEEkJ0D/6J0U/YF+w58IXI GF5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783306203; x=1783911003; h=content-type:mime-version:user-agent:references:in-reply-to:subject :cc:to:from:message-id:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=5x1wjFv75jgxPUO4LcE1UoPqAki0+kcH4/30AEBDkAQ=; b=rEbN41ux5xitBIDq1x8Hn9qjL8UGiuHiPBcyqXYxkcM0xS7L+ewW8P5GsIo+Gibbmm Vqqrerz5Xc4MDo+BFX60pqeWFc/PybbsGVCWkLC6F32rdjldJoCpvfzSTPBvMNY68Deq QOPLGXu6RGKLbL2m97fQ7gkboyvYFV1HHRlrT6lgwJd0ZBN82UtejGocdgm84ssuegPz BOta06Dc641J2Uu6S5fFTeMzXjWoK40lGXKyuZDUPrIsyj7RfZUKuWMPcferZNuYDXg2 4xyzVl6xAHeg2j/CLIYBn1zgzQIdo+Uj+58JbenMzQ+1kYsVG02TIfqcATnOSsP6wQS7 1e4g== X-Gm-Message-State: AOJu0YymlbjJr9H6AQew0geBzlw2/2UO6ekPj7lIV2fidiCNBxYDajjb RJotYUpzkRguJAy2n7k597lbCtA5J9/6Dq20xFMiv6JYclRwUegJXvox X-Gm-Gg: AfdE7ck4cj4/v1W3M9hOXv8j+bZPCOJsFKNXOdBKLDnU10Gh4zZ8mN+PTHKnsxG+BFq DJvbUvl1gp/OpELhUcLVuhIcabiJRJjPS/j17jaYDab9H/i06BfzoJUA/roqC2v97/xtAn6cG3k 54oK/CrGG7Jy2tgSGO1U17Dt3mwqyJiJjrY0dbnYmTZjLHdU11k/yKKEFmkpALl6mPue28qOcbj xRO5gFn4B5t9MwdcoUdHhb05rrgm2RzOrLzWMewd5UzY19gvnsHTXQ0613LgOoR7IXbDDY6kNzS ++ZrpMtayrOBXRUtsJftqDwtn6jhXeDuLXHMtcilcsYuT1QOoMUrCrOqurI9Tz6n5SAef5IT+uR EzJ/RQDKMk/StYJhkmLDztvvhk2KB9Won+02oX1A6LDG9PDutK8vKmbUe3TzeAnLN+rjvnuUyrZ wVo5OBCYS8au6nKCCm71hrFCJMt6AHOycFv8kptObR47/LhlxzwrIO7ZaBEhdV6f8ZeGFybVXQE uMQdoIE6ofh X-Received: by 2002:a05:6a21:494:b0:3b3:fdb0:2295 with SMTP id adf61e73a8af0-3c03e1a89c8mr8893007637.6.1783306202992; Sun, 05 Jul 2026 19:50:02 -0700 (PDT) Received: from mars.local.gmail.com ([240a:61:3285:c322:28fc:365:cb6f:6417]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c9e91b09942sm4994194a12.17.2026.07.05.19.50.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jul 2026 19:50:02 -0700 (PDT) Date: Mon, 06 Jul 2026 11:49:58 +0900 Message-ID: From: Hajime Tazaki To: akpm@linux-foundation.org, liam@infradead.org, ljs@kernel.org, vbabka@kernel.org, jannh@google.com, pfalcato@suse.de, linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: nommu: fix the error path when vma_iter_prealloc() fails In-Reply-To: References: User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII On Mon, 06 Jul 2026 11:18:46 +0900, Hajime Tazaki wrote: > > When vma_iter_prealloc() fails, it jumps to error_just_free without > updating ret to -ENOMEM, meaning do_mmap() will return 0 on failure. > > Additionally, this error path unconditionally frees the region struct. > Since the region was already added to the global nommu_region_tree via > add_nommu_region(), leaving it makes a potential dangling pointer in > the tree and may cause a use-after-free on the next tree walk. > > This commit fixes those issues by updating return value as well as moving > the region updates after the place that allocation is finished. > > The issue is discovered by Sashiko, linked below. > > Link: https://sashiko.dev/#/patchset/20260702012830.667205-1-thehajime%40gmail.com > Signed-off-by: Hajime Tazaki hmm, there are still several issues on this function, reported with new sashiko review. https://sashiko.dev/#/patchset/c8513ee5aa8444ec9bf6c276043c9f833016a2fa.1783304131.git.thehajime%40gmail.com I would try to find a way to do a similar review locally, and will be back here once I don't see further pre-existing issues around this code. -- Hajime