From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C6F91E98EF for ; Wed, 8 Jul 2026 00:39:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783471152; cv=none; b=YCdVomyULa7qqKBQkvhNrOIa85i7XByXjVjbFW5KWsfBzi08kuj7BMo980dT2hsuZPPtPa82XorVylRlyjsoHx/tXrOHONWn32ntDlld8yB114Wb95Q/mSQuYxB7nKkzvyI9aEzWv+8KLEIB4DW8cDr5FA7vr+wM4j6CJbdc9AI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783471152; c=relaxed/simple; bh=ISGRrnpKR3KcHZFIxYa0xt0GVkCNKxTW4Krh9Lka5v4=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=GuE73/7BKdLXn9/r2A/9TlsjXRbaLk+c3GwpTpu1wI1EfNcCP2NnzE7mdj5RgImg8kcaTKgBYlOnfF/w1hwYz3IQvS2JdN9cT+lvYd6stwZh3LK87F+klmFQNb/Hpw7axM+ppGB6OM2NVRkxfKDYxakjoXO6f/jnN7X84llCgfk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=PMLYnBck; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="PMLYnBck" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95F711F000E9; Wed, 8 Jul 2026 00:39:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1783471150; bh=c4CgDDH0T+lc2+cqqsojHNN2donJ8E/B1iuCKi3ersE=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=PMLYnBckOyOxWyHnorntM5OPjF0Y69PuWAmCxrTZVexXDDCsFkOsO/pL85IfE6iNG 8/5kvbI/7keXx0Wb/7jE4w+1BCOJGLBotSAoDtfAMboRg+6E4IjL/MlknKQKebHYug swD/3codZcOlkiCXdoFUL9TpQ/inL6o0IZmsZgks= Date: Tue, 7 Jul 2026 17:39:10 -0700 From: Andrew Morton To: Hajime Tazaki Cc: liam@infradead.org, ljs@kernel.org, vbabka@kernel.org, jannh@google.com, pfalcato@suse.de, linux-mm@kvack.org, geert@linux-m68k.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] mm: nommu: fix the error path when vma_iter_prealloc() fails Message-Id: <20260707173910.928c74a7e4dc8a1fdfddae3d@linux-foundation.org> In-Reply-To: <20260707235137.498738-1-thehajime@gmail.com> References: <20260707235137.498738-1-thehajime@gmail.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 8 Jul 2026 08:51:36 +0900 Hajime Tazaki wrote: > When vma_iter_prealloc() fails in do_mmap(), 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 introducing new jump > label, error_vma_iter_prealloc, to correctly handle the error case of > vma_iter_prealloc(), and move the region updates after the place that > the allocation is finished. > > Those issues are discovered by Sashiko, linked below. Thanks. Now I'm wondering if you regret opening this can of worms ;) https://sashiko.dev/#/patchset/20260707235137.498738-1-thehajime@gmail.com afaict, all these issues pertain to failures from vma_iter_prealloc().